1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 //----------------------------------------------------------------------- 4 // </copyright> 5 // <summary>Tests for ProjectPropertyInstance internal members</summary> 6 //----------------------------------------------------------------------- 7 8 using System.Collections.Generic; 9 using Microsoft.Build.Execution; 10 using Microsoft.Build.Shared; 11 using System; 12 using Microsoft.Build.Evaluation; 13 using Microsoft.Build.Construction; 14 using Microsoft.Build.UnitTests.BackEnd; 15 using Xunit; 16 17 namespace Microsoft.Build.UnitTests.OM.Instance 18 { 19 /// <summary> 20 /// Tests for ProjectPropertyInstance internal members 21 /// </summary> 22 public class ProjectPropertyInstance_Internal_Tests 23 { 24 /// <summary> 25 /// Cloning 26 /// </summary> 27 [Fact] DeepClone()28 public void DeepClone() 29 { 30 ProjectPropertyInstance property = GetPropertyInstance(); 31 32 ProjectPropertyInstance clone = property.DeepClone(); 33 34 Assert.Equal(false, Object.ReferenceEquals(property, clone)); 35 Assert.Equal("p", clone.Name); 36 Assert.Equal("v1", clone.EvaluatedValue); 37 } 38 39 /// <summary> 40 /// Serialization test 41 /// </summary> 42 [Fact] Serialization()43 public void Serialization() 44 { 45 ProjectPropertyInstance property = GetPropertyInstance(); 46 47 TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization); 48 ProjectPropertyInstance deserializedProperty = null; 49 TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization); 50 51 Assert.Equal(property.Name, deserializedProperty.Name); 52 Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue); 53 } 54 55 /// <summary> 56 /// Tests serialization. 57 /// </summary> 58 [Fact] ProjectPropertyInstanceSerializationTest_Mutable()59 public void ProjectPropertyInstanceSerializationTest_Mutable() 60 { 61 var property = ProjectPropertyInstance.Create("p", "v", false /*mutable*/); 62 Assert.Equal(false, property.IsImmutable); 63 64 TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization); 65 ProjectPropertyInstance deserializedProperty = null; 66 TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization); 67 68 Assert.Equal(property.Name, deserializedProperty.Name); 69 Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue); 70 Assert.Equal(property.IsImmutable, deserializedProperty.IsImmutable); 71 Assert.Equal(typeof(ProjectPropertyInstance), property.GetType()); 72 } 73 74 /// <summary> 75 /// Tests serialization. 76 /// </summary> 77 [Fact] ProjectPropertyInstanceSerializationTest_Immutable()78 public void ProjectPropertyInstanceSerializationTest_Immutable() 79 { 80 var property = ProjectPropertyInstance.Create("p", "v", mayBeReserved: true, isImmutable: true); 81 Assert.Equal(true, property.IsImmutable); 82 83 TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization); 84 ProjectPropertyInstance deserializedProperty = null; 85 TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization); 86 87 Assert.Equal(property.Name, deserializedProperty.Name); 88 Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue); 89 Assert.Equal(property.IsImmutable, deserializedProperty.IsImmutable); 90 Assert.Equal("Microsoft.Build.Execution.ProjectPropertyInstance+ProjectPropertyInstanceImmutable", property.GetType().ToString()); 91 } 92 93 /// <summary> 94 /// Get a ProjectPropertyInstance 95 /// </summary> GetPropertyInstance()96 private static ProjectPropertyInstance GetPropertyInstance() 97 { 98 Project project = new Project(); 99 ProjectInstance projectInstance = project.CreateProjectInstance(); 100 ProjectPropertyInstance property = projectInstance.SetProperty("p", "v1"); 101 102 return property; 103 } 104 } 105 } 106