public void ThreeLinkedGraph() { var car = new Car(new SteeringWheel(new FoamGrip("Plastic"))); car.Brand = "Toyota"; var expected = @"new Car() { StereoAmplifiers = null steeringWheel = new SteeringWheel() { Size = 3 Grip = new FoamGrip() { Material = ""Plastic"" } Weight = 525 } Brand = ""Toyota"" } "; Assert.AreEqual(expected, printer.PrintObject(car)); }
public void UserStory() { var cfg = ConfigurationHelper.GetStandardConfiguration(" "); cfg.SelectiveHarvester() .AddFilter <A>(x => x.Where(y => y.SanitizedName != "X" && y.SanitizedName != "Y")); var printer = new StatePrinter(cfg); var state = printer.PrintObject(new A { X = DateTime.Now, Name = "Charly" }); Assert.AreEqual(@"new A(){ Name = ""Charly""}", state.Replace("\r\n", "")); state = printer.PrintObject(new B { X = DateTime.Now, Name = "Charly", Age = 43 }); Assert.AreEqual(@"new B(){ Name = ""Charly"" Age = 43}", state.Replace("\r\n", "")); state = printer.PrintObject(new C { X = new DateTime(2010, 9, 8) }); Assert.AreEqual(@"new C(){ X = 08-09-2010 00:00:00}", state.Replace("\r\n", "")); }
public void Dictionary_int_int() { var d = new Dictionary <int, int> { { 1, 2 }, { 2, 4 }, { 3, 6 } }; Assert.AreEqual("[1] = 2\r\n[2] = 4\r\n[3] = 6\r\n", printer.PrintObject(d)); }
public void CultureDependentPrinting_us() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.Culture = new CultureInfo("en-US"); var usPrinter = new StatePrinter(cfg); Assert.AreEqual("12345.343\r\n", usPrinter.PrintObject(decimalNumber)); Assert.AreEqual("12345.34\r\n", usPrinter.PrintObject((float)decimalNumber)); Assert.AreEqual("2/28/2010 10:10:59 PM\r\n", usPrinter.PrintObject(dateTime)); }
public void CultureDependentPrinting_dk() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.Culture = new CultureInfo("da-DK"); var dkPrinter = new StatePrinter(cfg); Assert.AreEqual("12345,343\r\n", dkPrinter.PrintObject(decimalNumber)); Assert.AreEqual("12345,34\r\n", dkPrinter.PrintObject((float)decimalNumber)); Assert.AreEqual("28-02-2010 22:10:59\r\n", dkPrinter.PrintObject(dateTime)); }
public void Int_xml() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("<ROOT>-1</ROOT>\r\n", printer.PrintObject(-1f)); Assert.AreEqual("<ROOT>3</ROOT>\r\n", printer.PrintObject(3)); Assert.AreEqual("<ROOT>1E+23</ROOT>\r\n", printer.PrintObject(1E23)); }
public void CultureDependentPrinting_us() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.Culture = new CultureInfo("en-US"); var usPrinter = new StatePrinter(cfg); Assert.AreEqual("12345.343\r\n", usPrinter.PrintObject(decimalNumber)); Assert.AreEqual("12345.34\r\n", usPrinter.PrintObject((float)decimalNumber)); Assert.AreEqual("2/28/2010 10:10:59 PM\r\n", usPrinter.PrintObject(dateTime)); }
public void CultureDependentPrinting_dk() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.Culture = new CultureInfo("da-DK"); var dkPrinter = new StatePrinter(cfg); Assert.AreEqual("12345,343\r\n", dkPrinter.PrintObject(decimalNumber)); Assert.AreEqual("12345,34\r\n", dkPrinter.PrintObject((float)decimalNumber)); Assert.AreEqual("28-02-2010 22:10:59\r\n", dkPrinter.PrintObject(dateTime)); }
public void Int_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("-1\r\n", printer.PrintObject(-1f)); Assert.AreEqual("3\r\n", printer.PrintObject(3)); Assert.AreEqual("1E+23\r\n", printer.PrintObject(1E23)); }
public void TestFluintInterface() { var cfg = ConfigurationHelper.GetStandardConfiguration(" "); cfg.SelectiveHarvester().Exclude<A>(x => x.X, x => x.Y); var printer = new StatePrinter(cfg); var state = printer.PrintObject(new A {X = DateTime.Now, Name = "Charly"}); Assert.AreEqual(@"new A(){ Name = ""Charly""}", state.Replace("\r\n", "")); state = printer.PrintObject(new B {X = DateTime.Now, Name = "Charly", Age = 43}); Assert.AreEqual(@"new B(){ Name = ""Charly"" Age = 43}", state.Replace("\r\n", "")); state = printer.PrintObject(new C {X = new DateTime(2010, 9, 8)}); Assert.AreEqual(@"new C(){ X = 08-09-2010 00:00:00}", state.Replace("\r\n", "")); }
public void TwoDimArray() { int[,] twoDimArray = { { 1, 2 }, { 3, 4 } }; var printer = new StatePrinter(); Console.WriteLine(printer.PrintObject(twoDimArray, "")); }
public void ThreeLinkedGraph_xmlstyle() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var car = new Car(new SteeringWheel(new FoamGrip("Plastic"))); car.Brand = "Toyota"; var expected = @"<ROOT type='Car'> <StereoAmplifiers>null</StereoAmplifiers> <steeringWheel type='SteeringWheel'> <Size>3</Size> <Grip type='FoamGrip'> <Material>""Plastic""</Material> </Grip> <Weight>525</Weight> </steeringWheel> <Brand>""Toyota""</Brand> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(car)); }
public void CyclicGraph_Json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var course = new Course(); course.Members.Add(new Student("Stan", course)); course.Members.Add(new Student("Richy", course)); var expected = @" { ""Members"" : [ { ""name"" : ""Stan"", ""course"" : root } { ""name"" : ""Richy"", ""course"" : root } ] } "; Assert.AreEqual(expected, printer.PrintObject(course)); }
public void CyclicGraph_xmlstyle() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var course = new Course(); course.Members.Add(new Student("Stan", course)); course.Members.Add(new Student("Richy", course)); var expected = @"<ROOT type='Course' ref='0'> <Members type='List(Student)'> <Enumeration> <Members type='Student'> <name>""Stan""</name> <course ref='0' /> </Members> <Members type='Student'> <name>""Richy""</name> <course ref='0' /> </Members> </Enumeration> </Members> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(course)); }
public void TwoDimArray_LegacyApi() { var printer = new StatePrinter(); printer.Configuration.LegacyBehaviour.TrimTrailingNewlines = false; Assert.AreEqual(expected + "\r\n", printer.PrintObject(twoDimArray, "")); }
public void ThreeLinkedGraph_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var car = new Car(new SteeringWheel(new FoamGrip("Plastic"))); car.Brand = "Toyota"; var expected = @" { ""StereoAmplifiers"" : null, ""steeringWheel"" : { ""Size"" : 3, ""Grip"" : { ""Material"" : ""Plastic"" } ""Weight"" : 525 } ""Brand"" : ""Toyota"" } "; Assert.AreEqual(expected, printer.PrintObject(car)); }
public void UserStory() { var cfg = ConfigurationHelper.GetStandardConfiguration(" "); cfg.SelectiveHarvester() .AddFilter<A>(x => x.Where(y => y.SanitizedName != "X" && y.SanitizedName != "Y")); var printer = new StatePrinter(cfg); var state = printer.PrintObject(new A {X = DateTime.Now, Name = "Charly"}); Assert.AreEqual(@"new A(){ Name = ""Charly""}", state.Replace("\r\n", "")); state = printer.PrintObject(new B {X = DateTime.Now, Name = "Charly", Age = 43}); Assert.AreEqual(@"new B(){ Name = ""Charly"" Age = 43}", state.Replace("\r\n", "")); state = printer.PrintObject(new C {X = new DateTime(2010, 9, 8)}); Assert.AreEqual(@"new C(){ X = 08-09-2010 00:00:00}", state.Replace("\r\n", "")); }
public void TestManyPrintings() { var toPrint = new Base(); var printer = new StatePrinter(); for (int i = 0; i < N; i++) printer.PrintObject(toPrint); }
public void EmptyIntArray_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("[]\r\n", printer.PrintObject(new int[0])); }
public void EmptyIntArray_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("[]\r\n", printer.PrintObject(new int[0])); }
public void MegaCyclicGraph_Json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var mother = MakeFamily(); var expected = @" { ""Name"" : ""Mom"", ""Mother"" : { ""Name"" : ""grandMom"", ""Mother"" : null, ""Children"" : [ ""Children"" : root ], ""Father"" : null } ""Children"" : [ { ""Name"" : ""son"", ""Mother"" : root, ""Children"" : [], ""Father"" : { ""Name"" : ""grandDad"", ""Mother"" : null, ""Children"" : [ ""Children"" : root, ""Children"" : root.Children[0], { ""Name"" : ""daughter"", ""Mother"" : root, ""Children"" : [], ""Father"" : root.Children[0].Father } ], ""Father"" : null } } ""Children"" : root.Children[0].Father.Children[2] ], ""Father"" : root.Children[0].Father } "; var actual = printer.PrintObject(mother); Assert.AreEqual(expected, actual); }
public void TestManyPrintings() { var toPrint = new Base(); var printer = new StatePrinter(); for (int i = 0; i < N; i++) { printer.PrintObject(toPrint); } }
public void TestFluintInterface() { var cfg = ConfigurationHelper.GetStandardConfiguration(" "); cfg.SelectiveHarvester().Exclude <A>(x => x.X, x => x.Y); var printer = new StatePrinter(cfg); var state = printer.PrintObject(new A { X = DateTime.Now, Name = "Charly" }); Assert.AreEqual(@"new A(){ Name = ""Charly""}", state.Replace("\r\n", "")); state = printer.PrintObject(new B { X = DateTime.Now, Name = "Charly", Age = 43 }); Assert.AreEqual(@"new B(){ Name = ""Charly"" Age = 43}", state.Replace("\r\n", "")); state = printer.PrintObject(new C { X = new DateTime(2010, 9, 8) }); Assert.AreEqual(@"new C(){ X = 08-09-2010 00:00:00}", state.Replace("\r\n", "")); }
private void DumpNObjects(int max) { var x = new List<ToDump>(); for (int i = 0; i < max; i++) x.Add(new ToDump()); var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var mills = time(() => { var printer = new StatePrinter(cfg); printer.PrintObject(x); }); Console.WriteLine(max + ": " + mills); }
public void xml_Dictionary_person_address() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(" "); printer = new StatePrinter(cfg); var d = new Dictionary <Person, Address> { { new Person { Age = 37, FirstName = "Klaus", LastName = "Meyer" }, new Address() { Street = "Fairway Dr.", StreetNumber = 50267, Country = Country.USA, Zip = "CA 91601" } }, }; var expected = @"<ROOT type='Dictionary(Person, Address)'> <Enumeration> <ROOT type='KeyValuePair(Person, Address)'> <key type='Person'> <Age>37</Age> <FirstName>""Klaus""</FirstName> <LastName>""Meyer""</LastName> </key> <value type='Address'> <Street>""Fairway Dr.""</Street> <StreetNumber>50267</StreetNumber> <Zip>""CA 91601""</Zip> <Country>USA</Country> </value> </ROOT> </Enumeration> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(d)); }
private void DumpNObjects(int max) { var x = new List <ToDump>(); for (int i = 0; i < max; i++) { x.Add(new ToDump()); } var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var mills = time(() => { var printer = new StatePrinter(cfg); printer.PrintObject(x); }); Console.WriteLine(max + ": " + mills); }
public void StringArray() { B b = new B(); ((A)b).SomeFieldOnlyInA = 1; ((A)b).SameFieldInAB = "A part"; b.SomeFieldOnlyInB = 2; b.SameFieldInAB = "B part"; Assert.AreEqual( @"new B() { SomeFieldOnlyInA = 1 SameFieldInAB = ""A part"" SomeFieldOnlyInB = 2 SameFieldInAB = ""B part"" } " , printer.PrintObject(b)); }
public void CyclicGraph_Json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var course = new Course(); course.Members.Add(new Student("Stan", course)); course.Members.Add(new Student("Richy", course)); var expected = @" { ""Members"" : [ { ""name"" : ""Stan"", ""course"" : root } { ""name"" : ""Richy"", ""course"" : root } ] } "; Assert.AreEqual(expected, printer.PrintObject(course)); }
public override string ToString() { return(StatePrinter.PrintObject(this)); }
public void TwoDimArray_LegacyApi() { var printer = new StatePrinter(); printer.Configuration.LegacyBehaviour.TrimTrailingNewlines = false; Assert.AreEqual(expected + "\r\n", printer.PrintObject(twoDimArray, "")); }
public void Int_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("-1\r\n", printer.PrintObject(-1f)); Assert.AreEqual("3\r\n", printer.PrintObject(3)); Assert.AreEqual("1E+23\r\n", printer.PrintObject(1E23)); }
public void TwoDimArray() { int[,] twoDimArray = {{1, 2}, {3, 4}}; var printer = new StatePrinter(); Console.WriteLine(printer.PrintObject(twoDimArray, "")); }
public void xml_Dictionary_person_address() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(" "); printer = new StatePrinter(cfg); var d = new Dictionary<Person, Address> { { new Person {Age = 37, FirstName = "Klaus", LastName = "Meyer"}, new Address() {Street = "Fairway Dr.", StreetNumber = 50267, Country = Country.USA, Zip = "CA 91601"} }, }; var expected = @"<ROOT type='Dictionary(Person, Address)'> <Enumeration> <ROOT type='KeyValuePair(Person, Address)'> <key type='Person'> <Age>37</Age> <FirstName>""Klaus""</FirstName> <LastName>""Meyer""</LastName> </key> <value type='Address'> <Street>""Fairway Dr.""</Street> <StreetNumber>50267</StreetNumber> <Zip>""CA 91601""</Zip> <Country>USA</Country> </value> </ROOT> </Enumeration> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(d)); }
public void NullContent() { Assert.AreEqual("null\r\n", printer.PrintObject(null)); }
public void ThreeLinkedGraph_xmlstyle() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var car = new Car(new SteeringWheel(new FoamGrip("Plastic"))); car.Brand = "Toyota"; var expected = @"<ROOT type='Car'> <StereoAmplifiers>null</StereoAmplifiers> <steeringWheel type='SteeringWheel'> <Size>3</Size> <Grip type='FoamGrip'> <Material>""Plastic""</Material> </Grip> <Weight>525</Weight> </steeringWheel> <Brand>""Toyota""</Brand> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(car)); }
public void ThreeLinkedGraph_json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var car = new Car(new SteeringWheel(new FoamGrip("Plastic"))); car.Brand = "Toyota"; var expected = @" { ""StereoAmplifiers"" : null, ""steeringWheel"" : { ""Size"" : 3, ""Grip"" : { ""Material"" : ""Plastic"" } ""Weight"" : 525 } ""Brand"" : ""Toyota"" } "; Assert.AreEqual(expected, printer.PrintObject(car)); }
public void CyclicGraph_xmlstyle() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var course = new Course(); course.Members.Add(new Student("Stan", course)); course.Members.Add(new Student("Richy", course)); var expected = @"<ROOT type='Course' ref='0'> <Members type='List(Student)'> <Enumeration> <Members type='Student'> <name>""Stan""</name> <course ref='0' /> </Members> <Members type='Student'> <name>""Richy""</name> <course ref='0' /> </Members> </Enumeration> </Members> </ROOT> "; Assert.AreEqual(expected, printer.PrintObject(course)); }
public void MegaCyclicGraph_Json() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new JsonStyle(cfg.IndentIncrement); var printer = new StatePrinter(cfg); var mother = MakeFamily(); var expected = @" { ""Name"" : ""Mom"", ""Mother"" : { ""Name"" : ""grandMom"", ""Mother"" : null, ""Children"" : [ ""Children"" : root ], ""Father"" : null } ""Children"" : [ { ""Name"" : ""son"", ""Mother"" : root, ""Children"" : [], ""Father"" : { ""Name"" : ""grandDad"", ""Mother"" : null, ""Children"" : [ ""Children"" : root, ""Children"" : root.Children[0], { ""Name"" : ""daughter"", ""Mother"" : root, ""Children"" : [], ""Father"" : root.Children[0].Father } ], ""Father"" : null } } ""Children"" : root.Children[0].Father.Children[2] ], ""Father"" : root.Children[0].Father } "; var actual = printer.PrintObject(mother); Assert.AreEqual(expected, actual); }
public void TwoDimArray_LegacyApi() { var printer = new StatePrinter(); Assert.AreEqual(expected, printer.PrintObject(twoDimArray, "")); }
public void Int_xml() { var cfg = ConfigurationHelper.GetStandardConfiguration(); cfg.OutputFormatter = new XmlStyle(cfg.IndentIncrement); printer = new StatePrinter(cfg); Assert.AreEqual("<ROOT>-1</ROOT>\r\n", printer.PrintObject(-1f)); Assert.AreEqual("<ROOT>3</ROOT>\r\n", printer.PrintObject(3)); Assert.AreEqual("<ROOT>1E+23</ROOT>\r\n", printer.PrintObject(1E23)); }