Esempio n. 1
0
        public void CultureDependentPrinting_us()
        {
            var usPrinter = new Stateprinter();
            usPrinter.Configuration.Culture = new CultureInfo("en-US");

            Assert.AreEqual("12345.343", usPrinter.PrintObject(DecimalNumber));
            Assert.AreEqual("12345.34", usPrinter.PrintObject((float)DecimalNumber));
            Assert.AreEqual("2/28/2010 10:10:59 PM", usPrinter.PrintObject(dateTime));
        }
Esempio n. 2
0
        public void CultureDependentPrinting_dk()
        {
            var dkPrinter = new Stateprinter();
            dkPrinter.Configuration.Culture = new CultureInfo("da-DK");

            Assert.AreEqual("12345,343", dkPrinter.PrintObject(DecimalNumber));
            Assert.AreEqual("12345,34", dkPrinter.PrintObject((float)DecimalNumber));
            Assert.AreEqual("28-02-2010 22:10:59", dkPrinter.PrintObject(dateTime));
        }
Esempio n. 3
0
            public void Dictionary_int_int_withRootName()
            {
                var expected = @"<IntDict type='Dictionary(Int32, Int32)'>
    <Element key='1'>2</Element>
    <Element key='2'>4</Element>
    <Element key='3'>6</Element>
</IntDict>";

                printer.Assert.AreEqual(expected, printer.PrintObject(int_int, "IntDict"));
            }
Esempio n. 4
0
            public void Dictionary_int_int_withRootName()
            {
                var expected = @"""IntDict"": {
    ""1"": 2,
    ""2"": 4,
    ""3"": 6
}";

                printer.Assert.AreEqual(expected, printer.PrintObject(int_int, "IntDict"));
            }
Esempio n. 5
0
        public void CultureDependentPrinting_us()
        {
            var usPrinter = new Stateprinter();

            usPrinter.Configuration.Culture = new CultureInfo("en-US");

            Assert.AreEqual("12345.343", usPrinter.PrintObject(DecimalNumber));
            Assert.AreEqual("12345.34", usPrinter.PrintObject((float)DecimalNumber));
            Assert.AreEqual("2/28/2010 10:10:59 PM", usPrinter.PrintObject(dateTime));
        }
Esempio n. 6
0
            public void Dictionary_int_int_withRootName()
            {
                var expected = @"""IntDict"" : [
    { 1 : 2 },
    { 2 : 4 },
    { 3 : 6 }
]";

                printer.Assert.AreEqual(expected, printer.PrintObject(int_int, "IntDict"));
            }
        public void NullContent()
        {
            curly.Assert.PrintEquals("null", null);
            json.Assert.PrintEquals("null", null);
            xml.Assert.PrintEquals("<Root>null</Root>", null);

            Assert.AreEqual("a = null", curly.PrintObject(null, "a"));
            Assert.AreEqual("\"a\": null", json.PrintObject(null, "a"));
            Assert.AreEqual("<a>null</a>", xml.PrintObject(null, "a"));
        }
Esempio n. 8
0
        public void CultureDependentPrinting_dk()
        {
            var dkPrinter = new Stateprinter();

            dkPrinter.Configuration.Culture = new CultureInfo("da-DK");

            Assert.AreEqual("12345,343", dkPrinter.PrintObject(DecimalNumber));
            Assert.AreEqual("12345,34", dkPrinter.PrintObject((float)DecimalNumber));
            Assert.AreEqual("28-02-2010 22:10:59", dkPrinter.PrintObject(dateTime));
        }
Esempio n. 9
0
            public void Dictionary_int_int_withRootName()
            {
                var expected = @"IntDict = new Dictionary<Int32, Int32>()
{
    [1] = 2
    [2] = 4
    [3] = 6
}";

                printer.Assert.AreEqual(expected, printer.PrintObject(int_int, "IntDict"));
            }
        public void Int_xml()
        {
            var cfg = ConfigurationHelper.GetStandardConfiguration();

            cfg.OutputFormatter = new XmlStyle(cfg);
            printer             = new Stateprinter(cfg);

            Assert.AreEqual("<ROOT>-1</ROOT>", printer.PrintObject(-1f));
            Assert.AreEqual("<ROOT>3</ROOT>", printer.PrintObject(3));
            Assert.AreEqual("<ROOT>1E+23</ROOT>", printer.PrintObject(1E23));
        }
        public void Int_json()
        {
            var cfg = ConfigurationHelper.GetStandardConfiguration();

            cfg.OutputFormatter = new JsonStyle(cfg);
            printer             = new Stateprinter(cfg);

            Assert.AreEqual("-1", printer.PrintObject(-1f));
            Assert.AreEqual("3", printer.PrintObject(3));
            Assert.AreEqual("1E+23", printer.PrintObject(1E23));
        }
Esempio n. 12
0
            public void Dictionary_int_int_withRootName()
            {
                var expected = @"<IntDict>
    <Enumeration>
    <key>1</key><value>2</value>
    <key>2</key><value>4</value>
    <key>3</key><value>6</value>
    </Enumeration>
</IntDict>";

                printer.Assert.AreEqual(expected, printer.PrintObject(int_int, "IntDict"));
            }
        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 TestFluintInterface_Include()
        {
            var cfg = TestHelper.CreateTestConfiguration();
            cfg.Project.Include<A>(x => x.Name);
            var printer = new Stateprinter(cfg);

            var state = printer.PrintObject(new A { X = DateTime.Now, Name = "Charly" });
            Assert.AreEqual(@"new A() { Name = ""Charly"" }", state);

            state = printer.PrintObject(new B { X = DateTime.Now, Name = "Charly", Age = 43 });
            Assert.AreEqual(@"new B() { Name = ""Charly"" }", state);

            state = printer.PrintObject(new C { X = new DateTime(2010, 9, 8) });
            Assert.AreEqual(@"new C() { X = 08-09-2010 00:00:00 }", state);
        }
Esempio n. 15
0
            public void IncludeSubsetOfFields()
            {
                B b1 = new B()
                {
                    Age = 1, Name = "m", X = DateTime.Now, Y = DateTime.Now
                };

                var stateprinter =
                    new Stateprinter(
                        ConfigurationHelper.GetStandardConfiguration()
                        .Add(
                            new ProjectionHarvester().Include <B>(
                                x => x.Name,
                                x => x.Age)));

                stateprinter.Configuration.Test.SetAreEqualsMethod(Assert.AreEqual);

                var expected = @"new B()
{
    Name = ""m""
    Age = 1
}";
                var actual   = stateprinter.PrintObject(b1);

                stateprinter.Assert.AreEqual(expected, actual);

                // in array
                expected = @"new B[]()
{
    [0] = new B()
    {
        Name = ""m""
        Age = 1
    }
    [1] = new B()
    {
        Name = ""a""
        Age = 2
    }
}";
                B b2 = new B()
                {
                    Age = 2, Name = "a", X = DateTime.Now, Y = DateTime.Now
                };

                actual = stateprinter.PrintObject(new[] { b1, b2 });
                stateprinter.Assert.AreEqual(expected, actual);
            }
Esempio n. 16
0
            public void IntArray_oneline()
            {
                printer.Configuration.SetNewlineDefinition(" ");
                var expected = " [     { 0 : 1 },     { 1 : 2 },     { 2 : 3 } ]";

                printer.Assert.AreEqual(expected, printer.PrintObject(new[] { 1, 2, 3 }));
            }
Esempio n. 17
0
        public static string ToDebugString <T>(this T obj, Action <ProjectionHarvester> config = null)
        {
            var stateprinter = new Stateprinter();

            config?.Invoke(stateprinter.Configuration.Project);
            return(stateprinter.PrintObject(obj));
        }
Esempio n. 18
0
        public void TiminAllOutputFormattersAtNElements()
        {
            //var warmup
            new Stateprinter().PrintObject(new ToDump());
            new Stateprinter().PrintObject(new ToDump());
            new Stateprinter().PrintObject(new ToDump());

            var x      = CreateObjectsToDump(N);
            int length = 0;

            Console.WriteLine("Printing {0:0,0} objects.", N);

            var curly = new Stateprinter();

            curly.Configuration.SetOutputFormatter(new CurlyBraceStyle(curly.Configuration));
            long time = Time(() => length = curly.PrintObject(x).Length);

            Console.WriteLine("curly: {0} length: {1,10}", time, length);

            var json = new Stateprinter();

            json.Configuration.SetOutputFormatter(new JsonStyle(json.Configuration));
            time = Time(() => length = json.PrintObject(x).Length);
            Console.WriteLine("json:  {0} length: {1,10}", time, length);

            var xml = new Stateprinter();

            xml.Configuration.SetOutputFormatter(new XmlStyle(xml.Configuration));
            time = Time(() => length = xml.PrintObject(x).Length);
            Console.WriteLine("xml:   {0} length: {1,10}", time, length);
        }
            public void TwoDimArray_LegacyApi()
            {
                var printer = new Stateprinter();

                printer.Configuration.LegacyBehaviour.TrimTrailingNewlines = false;
                Assert.AreEqual(expected + "\r\n", printer.PrintObject(twoDimArray, ""));
            }
 private void CreateMessageAndTest()
 {
     CombinationApprovals.VerifyAllCombinations(
         (name, type, newRate) => printer.PrintObject(messager.CreateMessage(name, type, newRate)),
         new[] { "Olga", "Evgeniy" },
         new[] { AccountType.Cheque, AccountType.Credit, AccountType.Savings },
         new[] { 0.1m, 0.01m, 0.2m });
 }
Esempio n. 21
0
        public void TestManyPrintings()
        {
            var toPrint = new Base();
            var printer = new Stateprinter();

            printer.PrintObject(toPrint);
            var mills = Time(
                () =>
            {
                for (int i = 0; i < N; i++)
                {
                    printer.PrintObject(toPrint);
                }
            });

            Console.WriteLine("  " + mills);
        }
Esempio n. 22
0
            public void Dictionary_empty_int_int_with_rootName()
            {
                var expected = @"new List<Token>()
{
    [0] = new Token()
    {
        Tokenkind = FieldnameWithTypeAndReference
        FieldType = new RuntimeType()
        {
        }
        Field = new Field()
        {
            Name = null
            Key = null
            Index = null
        }
        Value = null
        ReferenceNo = new Reference()
        {
            Number = 0
        }
    }
    [1] = new Token()
    {
        Tokenkind = StartDict
        FieldType = null
        Field = null
        Value = null
        ReferenceNo = null
    }
    [2] = new Token()
    {
        Tokenkind = EndDict
        FieldType = null
        Field = null
        Value = null
        ReferenceNo = null
    }
}";


                printer.PrintObject(empty_int_int);
                var tokens = tokenOutputter.IntrospectedTokens;

                TestHelper.Assert().PrintEquals(expected, tokens);
            }
        public void Obsolete_TestFluintInterface_exclude()
        {
            var cfg = TestHelper.CreateTestConfiguration();
            cfg.Projectionharvester().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);
        }
Esempio n. 24
0
            static AClass()
            {
                tunedPrinter = new Stateprinter();

                var genericConverter = new GenericValueConverter <int[]>(y => string.Join(", ", y.Select(x => x.ToString()).ToArray()));

                tunedPrinter.Configuration.Add(genericConverter);
                tunedPrinter.PrintObject(new AClass()); // warmup
            }
Esempio n. 25
0
        protected QueryResult <TOuputDTO> WhenQueryingThen <TQueryFunction, TOuputDTO>(TQueryFunction queryFunction, TOuputDTO expectedOutput) where TQueryFunction : FunctionMessage, new()
            where TOuputDTO : IFunctionOutputDTO, new()
        {
            TestLogger.LogWhenQueryFunctionThen(queryFunction, expectedOutput);
            var result = ContractHandler.QueryDeserializingToObjectAsync <TQueryFunction, TOuputDTO>(queryFunction).Result;

            Stateprinter.Assert.AreEqual(
                Stateprinter.PrintObject(expectedOutput),
                Stateprinter.PrintObject(result));
            return(new QueryResult <TOuputDTO>(ContractHandler, result, TestLogger, Stateprinter));
        }
Esempio n. 26
0
        public void GetEntry_ParsesEachColumn()
        {
            var provider = CreateProvider();
            var row      = CreateDataRow();

            row["QueryName"] = "Title";
            row["QueryText"] = "Text";

            var entry = provider.GetEntry(row);

            var expected = new InformationEntry
            {
                Title = "Title",
                Text  = "Text"
            };

            var printer = new Stateprinter();

            Assert.AreEqual(printer.PrintObject(expected), printer.PrintObject(entry));
        }
Esempio n. 27
0
        public void GetterOnly_NotIncluded_WhenUsing_FieldHarvester()
        {
            var sut = new GetterOnly() { i = 1, j = 2 };
            var printer = new Stateprinter(ConfigurationHelper.GetStandardConfiguration());

            Assert.AreEqual(@"new GetterOnly()
            {
            i = 1
            j = 2
            }", printer.PrintObject(sut));
        }
Esempio n. 28
0
        public void TwoDimArray()
        {
            int[,] twoDimArray = { { 1, 2 }, { 3, 4 } };
            var printer = new Stateprinter();

            Assert.AreEqual(@"new Int32[,]()
[0] = 1
[1] = 2
[2] = 3
[3] = 4
", printer.PrintObject(twoDimArray, ""));
        }
        public void SpecializedClassHandlerNotHandledClass()
        {
            var cfg = new Configuration(" ");

            AddAnonymousHandler(cfg);

            var sut = new Stateprinter(cfg);

            Assert.Throws <Exception>(() => sut.PrintObject(new A {
                Name = "MyName"
            }), "");
        }
        public void GetEntry_ParsesEachColumn()
        {
            var provider = CreateProvider();
            var row      = CreateDataRow();

            row["ConnectionString"] = "CustomConnectionString";
            row["ConnectionOp"]     = "new SqlConnection()";
            row["Context"]          = "StackTrace";

            var entry = provider.GetEntry(row);

            var expected = new ConnectionEntry
            {
                CustomConnectionStringName = "Custom",
                Text       = "new SqlConnection()",
                StackTrace = "StackTrace"
            };

            var printer = new Stateprinter();

            Assert.AreEqual(printer.PrintObject(expected), printer.PrintObject(entry));
        }
Esempio n. 31
0
        protected void ThenEventFirst <TEventDTO>(TEventDTO expectedEvent, TransactionReceipt transactionReceipt) where TEventDTO : IEventDTO, new()
        {
            TestLogger.LogExpectedEvent(expectedEvent);

            var eventItem  = ContractHandler.GetEvent <TEventDTO>();
            var eventFirst = eventItem.DecodeAllEventsForEvent(transactionReceipt.Logs).FirstOrDefault();

            Assert.NotNull(eventFirst);

            Stateprinter.Assert.AreEqual(
                Stateprinter.PrintObject(expectedEvent),
                Stateprinter.PrintObject(eventFirst.Event));
        }
        public void Obsolete_TestFluintInterface_exclude()
        {
            var cfg = TestHelper.CreateTestConfiguration();

            cfg.Projectionharvester().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);
        }
Esempio n. 33
0
        public void GetterOnly_NotIncluded_WhenUsing_FieldHarvester()
        {
            var sut = new GetterOnly()
            {
                i = 1, j = 2
            };
            var printer = new Stateprinter(ConfigurationHelper.GetStandardConfiguration());

            Assert.AreEqual(@"new GetterOnly()
{
    i = 1
    j = 2
}", printer.PrintObject(sut));
        }
        public void TestFluintInterface_Include()
        {
            var cfg = TestHelper.CreateTestConfiguration();

            cfg.Project.Include <A>(x => x.Name);
            var printer = new Stateprinter(cfg);

            var state = printer.PrintObject(new A {
                X = DateTime.Now, Name = "Charly"
            });

            Assert.AreEqual(@"new A() { Name = ""Charly"" }", state);

            state = printer.PrintObject(new B {
                X = DateTime.Now, Name = "Charly", Age = 43
            });
            Assert.AreEqual(@"new B() { Name = ""Charly"" }", state);

            state = printer.PrintObject(new C {
                X = new DateTime(2010, 9, 8)
            });
            Assert.AreEqual(@"new C() { X = 08-09-2010 00:00:00 }", state);
        }
Esempio n. 35
0
        public void ApproveProductData()
        {
            var product = new Product
            {
                Id        = Guid.Empty,
                Name      = "Name",
                Price     = 3.14m,
                UnitsCode = "112"
            };
            var sp = new Stateprinter();

            sp.Configuration.Project.Exclude <Product>(x => x.TemporaryData);

            Approvals.Verify(sp.PrintObject(product));
        }
Esempio n. 36
0
        public void Xml_Dictionary_person_address()
        {
            printer = TestHelper.CreateTestPrinter();
            printer.Configuration.OutputFormatter = new XmlStyle(printer.Configuration);

            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>";

            printer.Assert.AreEqual(expected, printer.PrintObject(d));
        }
        public void Int_json()
        {
            var cfg = ConfigurationHelper.GetStandardConfiguration();
            cfg.OutputFormatter = new JsonStyle(cfg);
            printer = new Stateprinter(cfg);

            Assert.AreEqual("-1", printer.PrintObject(-1f));
            Assert.AreEqual("3", printer.PrintObject(3));
            Assert.AreEqual("1E+23", printer.PrintObject(1E23));
        }
        public void Int_xml()
        {
            var cfg = ConfigurationHelper.GetStandardConfiguration();
            cfg.OutputFormatter = new XmlStyle(cfg);
            printer = new Stateprinter(cfg);

            Assert.AreEqual("<ROOT>-1</ROOT>", printer.PrintObject(-1f));
            Assert.AreEqual("<ROOT>3</ROOT>", printer.PrintObject(3));
            Assert.AreEqual("<ROOT>1E+23</ROOT>", printer.PrintObject(1E23));
        }
 public void TwoDimArray_LegacyApi()
 {
     var printer = new Stateprinter();
     printer.Configuration.LegacyBehaviour.TrimTrailingNewlines = false;
     Assert.AreEqual(expected + "\r\n", printer.PrintObject(twoDimArray, ""));
 }
Esempio n. 40
0
 public void TwoDimArray()
 {
     var printer = new Stateprinter();
     Assert.AreEqual(expected, printer.PrintObject(twoDimArray, ""));
 }
Esempio n. 41
0
            static AClass()
            {
                tunedPrinter = new Stateprinter();

                var genericConverter = new GenericValueConverter<int[]>(y => string.Join(", ", y.Select(x => x.ToString()).ToArray()));
                tunedPrinter.Configuration.Add(genericConverter);
                tunedPrinter.PrintObject(new AClass()); // warmup
            }
            public void IncludeSubsetOfFields()
            {
                B b1 = new B() { Age = 1, Name = "m", X = DateTime.Now, Y = DateTime.Now };

                var stateprinter =
                    new Stateprinter(
                        ConfigurationHelper.GetStandardConfiguration()
                            .Add(
                                new ProjectionHarvester().Include<B>(
                                    x => x.Name,
                                    x => x.Age)));
                stateprinter.Configuration.Test.SetAreEqualsMethod(Assert.AreEqual);

                var expected = @"new B()
                {
                Name = ""m""
                Age = 1
                }";
                var actual = stateprinter.PrintObject(b1);
                stateprinter.Assert.AreEqual(expected, actual);

                // in array
                expected = @"new B[]()
                [0] = new B()
                {
                Name = ""m""
                Age = 1
                }
                [1] = new B()
                {
                Name = ""a""
                Age = 2
                }";
                B b2 = new B() { Age = 2, Name = "a", X = DateTime.Now, Y = DateTime.Now };
                actual = stateprinter.PrintObject(new[] { b1, b2 });
                stateprinter.Assert.AreEqual(expected, actual);
            }
        public void UserStory()
        {
            var cfg = TestHelper.CreateTestConfiguration();
            cfg.Project.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);

            state =
                printer.PrintObject(new B { X = DateTime.Now, Name = "Charly", Age = 43 });
            Assert.AreEqual(@"new B() { Name = ""Charly"" Age = 43 }", state);

            state = printer.PrintObject(new C { X = new DateTime(2010, 9, 8) });
            Assert.AreEqual(@"new C() { X = 08-09-2010 00:00:00 }", state);
        }
Esempio n. 44
0
        public void TestTheOverheadOfStartingUp()
        {
            var toPrint = new Base();

            //var warmup =
            new Stateprinter().PrintObject(toPrint);
            new Stateprinter().PrintObject(toPrint);
            new Stateprinter().PrintObject(toPrint);

            var mills = Time(
              () =>
              {
                  for (int i = 0; i < N/400; i++)
                  {
                      var printer = new Stateprinter();
                      printer.PrintObject(toPrint);
                  }
              });
            Console.WriteLine("  " + mills);
        }
Esempio n. 45
0
        private void DumpNObjects(int max)
        {
            List<ToDump> x = CreateObjectsToDump(max);

            var cfg = ConfigurationHelper.GetStandardConfiguration();
            cfg.OutputFormatter = new JsonStyle(cfg);
            int length = 0;
            var mills = Time(() =>
                             {
                                 var printer = new Stateprinter(cfg);
                                 length = printer.PrintObject(x).Length;
                             });
            Console.WriteLine("{0,8}:  Time: {1,6} length {2,10}", max, mills, length);
        }
Esempio n. 46
0
        public void TiminAllOutputFormattersAtNElements()
        {
            //var warmup
            new Stateprinter().PrintObject(new ToDump());
            new Stateprinter().PrintObject(new ToDump());
            new Stateprinter().PrintObject(new ToDump());

            var x = CreateObjectsToDump(N);
            int length = 0;
            Console.WriteLine("Printing {0:0,0} objects.", N);

            var curly = new Stateprinter();
            curly.Configuration.SetOutputFormatter(new CurlyBraceStyle(curly.Configuration));
            long time = Time(() => length = curly.PrintObject(x).Length);
            Console.WriteLine("curly: {0} length: {1,10}", time, length);

            var json = new Stateprinter();
            json.Configuration.SetOutputFormatter(new JsonStyle(json.Configuration));
            time = Time(() => length = json.PrintObject(x).Length);
            Console.WriteLine("json:  {0} length: {1,10}", time, length);

            var xml = new Stateprinter();
            xml.Configuration.SetOutputFormatter(new XmlStyle(xml.Configuration));
            time = Time(() => length = xml.PrintObject(x).Length);
            Console.WriteLine("xml:   {0} length: {1,10}", time, length);
        }