public void Slim_SerializeRow_ComplexTypedRow() { var row1 = new PersonWithNesting{ ID = "A1", FirstName = "Joseph", LastName = "Mc'Cloud", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" }, History1 = new List<HistoryItem> { new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" }, new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" } }, History2 = new HistoryItem[2] }; var ser = new SlimSerializer(); using(var ms = new MemoryStream()) { ser.Serialize(ms, row1); Console.WriteLine("1 row took {0} bytes".Args(ms.Position)); ms.Position = 0; var row2 = ser.Deserialize(ms) as PersonWithNesting; Assert.IsNotNull( row2 ); Assert.IsFalse( object.ReferenceEquals(row1 , row2) ); Assert.AreEqual("A1", row2.ID); Assert.AreEqual("Joseph", row2.FirstName); Assert.AreEqual("Mc'Cloud",row2.LastName); Assert.AreEqual("111", row2.LatestHistory.ID); Assert.AreEqual(2, row2.History1.Count); Assert.AreEqual("234234", row2.History1[1].ID); } }
public void JSON_SerializeRow_ComplexTypedRow_WithSchema() { var row1 = new PersonWithNesting{ ID = "A1", FirstName = "Joseph", LastName = "Mc'Cloud", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" }, History1 = new List<HistoryItem> { new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" }, new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" } }, History2 = new HistoryItem[2] }; var tbl1 = new Rowset(row1.Schema); tbl1.Add(row1); var json = tbl1.ToJSON( new NFX.Serialization.JSON.JSONWritingOptions { RowsetMetadata = true, SpaceSymbols = true, IndentWidth = 2, MemberLineBreak = true, ObjectLineBreak = true, RowsAsMap = true, Purpose = JSONSerializationPurpose.Marshalling });//AS MAP Console.WriteLine(json); var tbl2 = json.JSONToDynamic(); var row2 = tbl2.Rows[0]; Assert.AreEqual("A1", row2.ID); Assert.AreEqual("Joseph", row2.FirstName); Assert.AreEqual("Mc'Cloud",row2.LastName); Assert.AreEqual("111", row2.LatestHistory.ID); Assert.AreEqual(2, row2.History1.Count); Assert.AreEqual("234234", row2.History1[1].ID); }
public void JSON_SerializeRow_ComplexTypedRow_Map() { var row1 = new PersonWithNesting{ ID = "A1", FirstName = "Joseph", LastName = "Mc'Cloud", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" }, History1 = new List<HistoryItem> { new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" }, new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" } }, History2 = new HistoryItem[2] }; var json = row1.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrintRowsAsMap);//AS MAP!!!! Console.WriteLine(json); var row2 = json.JSONToDynamic(); Assert.AreEqual("A1", row2.ID); Assert.AreEqual("Joseph", row2.FirstName); Assert.AreEqual("Mc'Cloud",row2.LastName); Assert.AreEqual("111", row2.LatestHistory.ID); Assert.AreEqual(2, row2.History1.Count); Assert.AreEqual("234234", row2.History1[1].ID); }
public void JSON_SerializeRow_ComplexTypedRow_Array() { var row1 = new PersonWithNesting{ ID = "A1", FirstName = "Joseph", LastName = "Mc'Cloud", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" }, History1 = new List<HistoryItem> { new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" }, new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" } }, History2 = new HistoryItem[2] }; var json = row1.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrint);//AS ARRAY Console.WriteLine(json); var row2 = json.JSONToDynamic(); Assert.AreEqual("A1", row2[row1.Schema["ID"].Order]); Assert.AreEqual("Joseph", row2[row1.Schema["FirstName"].Order]); Assert.AreEqual("Mc'Cloud",row2[row1.Schema["LastName"].Order]); Assert.AreEqual("111", row2[row1.Schema["LatestHistory"].Order][0]); Assert.AreEqual(2, row2[row1.Schema["History1"].Order].Count); Assert.AreEqual("234234", row2[row1.Schema["History1"].Order][1][0]); }
public void Validate_PersonWithNesting_Error_ComplexFieldSubFieldRequired() { var person = new PersonWithNesting{ ID = "POP1", FirstName = "Oleg", LastName = "Popov", DOB = new DateTime(1953, 12, 10), YearsInSpace = 45, Amount = 100, LatestHistory = new HistoryItem{ ID = null, StartDate = DateTime.Now, Description="Chaplin is here" }, History1 = new List<HistoryItem>(), History2 = new HistoryItem[2] }; var error = person.Validate(); Console.WriteLine( error ); Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error); Assert.AreEqual("ID", ((CRUDFieldValidationException)error).FieldName); }
public void Validate_PersonWithNesting_Error_ComplexFieldCustomValidation() { var person = new PersonWithNesting{ ID = "POP1", FirstName = "Oleg", LastName = "Popov", DOB = new DateTime(1953, 12, 10), YearsInSpace = 45, Amount = 100, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Someone is an idiot!" }, History1 = new List<HistoryItem>(), History2 = new HistoryItem[2] }; var error = person.Validate(); Console.WriteLine( error ); Assert.IsInstanceOf(typeof(CRUDFieldValidationException), error); Assert.AreEqual("Description", ((CRUDFieldValidationException)error).FieldName); Assert.IsTrue(error.Message.Contains("Chaplin")); }