Skip to content

Commit e83ba75

Browse files
authored
Register the TestProperty on deserialization. (#56)
1 parent e7faacf commit e83ba75

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/Microsoft.TestPlatform.ObjectModel/TestObject.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ private List<KeyValuePair<TestProperty, object>> StoreKeyValuePairs
4343
// Store each property and value in the property data store.
4444
foreach (var property in value)
4545
{
46+
TestProperty.Register(
47+
property.Key.Id,
48+
property.Key.Label,
49+
property.Key.Category,
50+
property.Key.Description,
51+
property.Key.GetValueType(),
52+
null,
53+
property.Key.Attributes,
54+
typeof(TestObject));
4655
this.SetPropertyValue(property.Key, property.Value, CultureInfo.InvariantCulture);
4756
}
4857
}

test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Serialization/TestObjectConverterTests.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void TestObjectShouldSerializeDateTimeOffsetForProperty()
7979
[TestMethod]
8080
public void TestObjectShouldDeserializeCustomProperties()
8181
{
82-
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"1\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.Guid\"},\"Value\":\"02048dfd-3da7-475d-a011-8dd1121855ec\"},{\"Key\":{\"Id\":\"2\",\"Label\":\"label2\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.Int32\"},\"Value\":29}]}";
82+
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"13\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.Guid\"},\"Value\":\"02048dfd-3da7-475d-a011-8dd1121855ec\"},{\"Key\":{\"Id\":\"2\",\"Label\":\"label2\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.Int32\"},\"Value\":29}]}";
8383

8484
var test = Deserialize<TestableTestObject>(json);
8585

@@ -92,7 +92,7 @@ public void TestObjectShouldDeserializeCustomProperties()
9292
[TestMethod]
9393
public void TestObjectShouldDeserializeNullValueForProperty()
9494
{
95-
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"1\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.String\"},\"Value\":null}]}";
95+
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"14\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.String\"},\"Value\":null}]}";
9696

9797
var test = Deserialize<TestableTestObject>(json);
9898

@@ -104,7 +104,7 @@ public void TestObjectShouldDeserializeNullValueForProperty()
104104
[TestMethod]
105105
public void TestObjectShouldDeserializeStringArrayValueForProperty()
106106
{
107-
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"1\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.String[]\"},\"Value\":[\"val1\", \"val2\"]}]}";
107+
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"15\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.String[]\"},\"Value\":[\"val1\", \"val2\"]}]}";
108108

109109
var test = Deserialize<TestableTestObject>(json);
110110

@@ -116,7 +116,7 @@ public void TestObjectShouldDeserializeStringArrayValueForProperty()
116116
[TestMethod]
117117
public void TestObjectShouldDeserializeDatetimeOffset()
118118
{
119-
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"11\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.DateTimeOffset\"},\"Value\":\"9999-12-31T23:59:59.9999999+00:00\"}]}";
119+
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"16\",\"Label\":\"label1\",\"Category\":\"\",\"Description\":\"\",\"Attributes\":0,\"ValueType\":\"System.DateTimeOffset\"},\"Value\":\"9999-12-31T23:59:59.9999999+00:00\"}]}";
120120

121121
var test = Deserialize<TestableTestObject>(json);
122122

@@ -125,6 +125,24 @@ public void TestObjectShouldDeserializeDatetimeOffset()
125125
Assert.AreEqual(DateTimeOffset.MaxValue, test.GetPropertyValue(properties[0]));
126126
}
127127

128+
[TestMethod]
129+
public void TestObjectShouldAddPropertyToTestPropertyStoreOnDeserialize()
130+
{
131+
var json = "{\"Properties\":[{\"Key\":{\"Id\":\"17\",\"Label\":\"label1\",\"Category\":\"c\",\"Description\":\"d\",\"Attributes\":0,\"ValueType\":\"System.String\"},\"Value\":\"DummyValue\"}]}";
132+
133+
var test = Deserialize<TestableTestObject>(json);
134+
135+
var property = TestProperty.Find("17");
136+
Assert.IsNotNull(property);
137+
Assert.AreEqual("17", property.Id);
138+
Assert.AreEqual("label1", property.Label);
139+
Assert.AreEqual("c", property.Category);
140+
Assert.AreEqual("d", property.Description);
141+
Assert.AreEqual(typeof(string), property.GetValueType());
142+
Assert.AreEqual(TestPropertyAttributes.None, property.Attributes);
143+
Assert.AreEqual("DummyValue", test.GetPropertyValue(property));
144+
}
145+
128146
private static string Serialize<T>(T data)
129147
{
130148
return JsonDataSerializer.Instance.Serialize(data);

0 commit comments

Comments
 (0)