public void StructureInClasses_CanBeSerializedAndDeserialized() { // Arrange var person = new Person { Id = 8 }; var obj = new ClassWithStruct { Person = person }; // act var deserialized = TestHelper.SerializeAndDeserialize(obj); // assert deserialized.Should().NotBeNull(); deserialized.Person.Should().Be(person); }
private void TestVTablesImpl() { object obj = new object(); Assert.AreEqual(GCImplementation.GetType(obj), ((CosmosRuntimeType)obj.GetType()).mTypeId, "Both methods to get type id return the same value for object"); string s = "a"; Assert.AreEqual(GCImplementation.GetType(s), ((CosmosRuntimeType)s.GetType()).mTypeId, "Both methods to get type id return the same value for string"); Assert.AreEqual(GCImplementation.GetType(s), ((CosmosRuntimeType)typeof(string)).mTypeId, "Methods and constato get type id return the same value for string"); List <int> x = new List <int>(); Assert.AreEqual(GCImplementation.GetType(x), ((CosmosRuntimeType)typeof(List <int>)).mTypeId, "Methods and constant get type id return the same value for List<int>"); TestType tObj = new TestType(); Assert.AreEqual(GCImplementation.GetType(tObj), ((CosmosRuntimeType)typeof(TestType)).mTypeId, "Methods and constant get type id return the same value for TestType"); Assert.AreEqual(4, VTablesImpl.GetGCFieldCount(GCImplementation.GetType(tObj)), "TestType has 4 fields tracked by GC"); var types = VTablesImpl.GetGCFieldTypes(GCImplementation.GetType(tObj)); Assert.AreEqual(4, types.Length, "GetGCFieldTypes returns correct number of values"); Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[0], "GetGCFieldTypes returns object at offset 0"); Assert.AreEqual(((CosmosRuntimeType)typeof(List <int>)).mTypeId, types[1], "GetGCFieldTypes returns List<int> at offset 1"); Assert.AreEqual(((CosmosRuntimeType)typeof(string)).mTypeId, types[2], "GetGCFieldTypes returns string at offset 2"); Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[3], "GetGCFieldTypes returns object at offset 3"); Assert.AreEqual(4, VTablesImpl.GetGCFieldOffsets(GCImplementation.GetType(tObj)).Length, "GetGCFieldOffsets returned the correct number of values"); Assert.AreEqual(new uint[] { 12, 20, 28, 36 }, VTablesImpl.GetGCFieldOffsets(GCImplementation.GetType(tObj)), "GetGCFieldOffsets returns the correct values"); ClassWithStruct classWithStruct = new ClassWithStruct(); Assert.AreEqual(3, VTablesImpl.GetGCFieldCount(GCImplementation.GetType(classWithStruct)), "ClassWithStruct has 3 fields tracked by GC"); types = VTablesImpl.GetGCFieldTypes(GCImplementation.GetType(classWithStruct)); Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[0], "GetGCFieldTypes returns object at offset 0"); Assert.AreEqual(((CosmosRuntimeType)typeof(TestStruct)).mTypeId, types[1], "GetGCFieldTypes returns TestStruct at offset 1"); Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[2], "GetGCFieldTypes returns object at offset 2"); }