public void PocoDerivedPocoPopulation() { List<Tuple<PocoDerivedPocoType, string>> testCases = new List<Tuple<PocoDerivedPocoType, string>>() { new Tuple<PocoDerivedPocoType, string>(new PocoDerivedPocoType(), "{\"DerivedPublicProperty\":null,\"PublicProperty\":null,\"DerivedPublicField\":null,\"PublicField\":null}"), new Tuple<PocoDerivedPocoType, string>(new PocoDerivedPocoType("_XYZ", onlySetSerializableMembers: true), "{\"DerivedPublicProperty\":\"DerivedPublicProperty_XYZ\",\"PublicProperty\":\"PublicProperty_XYZ\",\"DerivedPublicField\":\"DerivedPublicField_XYZ\",\"PublicField\":\"PublicField_XYZ\"}" ), }; // Need to ensure that the type is registered as a table to force the id property check DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(PocoDerivedPocoType)); foreach (var testCase in testCases) { var input = testCase.Item2; var expected = testCase.Item1; PocoDerivedPocoType actual = new PocoDerivedPocoType("_ABC", onlySetSerializableMembers: true); DefaultSerializer.Deserialize(input, actual); Assert.AreEqual(actual, expected); } }
public async Task InsertAsync_DerivedTypeOnBaseTable_Succeeds() { var hijack = new TestHttpHandler(); hijack.SetResponseContent("{\"id\":23,\"PublicProperty\":\"Hey\"}"); IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack); IMobileServiceTable<PocoType> table = service.GetTable<PocoType>(); var item = new PocoDerivedPocoType() { PublicProperty = "Hey" }; await table.InsertAsync(item); Assert.AreEqual(23L, item.Id); Assert.AreEqual("Hey", item.PublicProperty); }