public void SerializeDogOmittingTypesResultsInProperOutput() { var owner = new Owner("Joe", "J", "Smith") { BirthDate = new DateTime(1970, 3, 20) }; var mother = new Owner("Jane", "M", "Smith") { BirthDate = new DateTime(1951, 6, 12) }; var father = new Owner("John", "K", "Smith") { BirthDate = new DateTime(1948, 4, 16) }; var child1 = new Owner("Simon", "P", "Smith") { BirthDate = new DateTime(2000, 3, 22) }; var child2 = new Owner("Sally", "P", "Smith") { BirthDate = new DateTime(2001, 1, 1) }; owner.Father = father; owner.Mother = mother; father.Children = new List <Person> { owner }; mother.Children = new List <Person> { owner }; owner.Children = new List <Person> { child1, child2 }; child1.Father = owner; child2.Father = owner; var dog = new Dog("Fido", "Golden Retriever", true, owner) { BirthDate = new DateTime(2003, 5, 10), Collar = DogCollarFactory.GetCollar(20, true) }; owner.Pets = new Pet[] { dog }; child1.Pets = new Pet[] { dog }; child2.Pets = new Pet[] { dog }; var serializer = new Serializer { Settings = { OmitTypeWhenPossible = true } }; string xml = serializer.SerializeObject(dog); Approvals.VerifyXml(xml); }
public void SerializeDogResultsInExpectedOutput() { var dog = new Dog("Fido", "Golden Retriever", true, null) { BirthDate = new DateTime(2003, 5, 10), Collar = DogCollarFactory.GetCollar(20, true) }; var serializer = new Serializer(); serializer.RegisterType <Dog>().ToTypeSerializer <DogSerializer>().WithConstructorArgument("title", "King"); string xml = serializer.SerializeObject(dog); Approvals.VerifyXml(xml); }