Exemple #1
0
        public void TestFormatLargeSet()
        {
            // GIVEN a parser that returns a single segment
            mockFormatStringProvider.Setup(m => m.ParseFormatString("format-string", It.IsAny <IParsedStringBuilder>()))
            .Callback((string s, IParsedStringBuilder b) =>
            {
                b.AddTextSegment("result");
                b.AddTextSegment("2");
                b.AddTextSegment("3");
                b.AddTextSegment("4");
                b.AddTextSegment("5");
                b.AddTextSegment("6");
                b.AddTextSegment("7");
            });

            // WHEN the compiler is run
            FastStringFormatCompiler compiler  = new FastStringFormatCompiler(mockFormatStringProvider.Object);
            Func <object, string>    formatter = compiler.Compile <object>("format-string");

            // AND the generated formatter is run
            string result = formatter.Invoke(new object());

            // THEN the result is as expected
            Assert.AreEqual("result234567", result);
        }
        public void TestFormatString(string formatString, string expected)
        {
            // GIVEN a valid format string
            // WHEN compiled
            Func <DataObject, string> formatter = new FastStringFormatCompiler().Compile <DataObject>(formatString);

            // THEN the formatter is not null
            Assert.IsNotNull(formatter);

            // GIVEN an data object to format
            DataObject data = new DataObject(
                "Steve",
                "Irwin",
                new DateTime(1962, 9, 22),
                true,
                new Coordinates(-26.835488321500016, 152.96309154093498)
                );

            // WHEN the formatter is invoked
            string result = formatter(data);

            // THEN the result is as expected
            Assert.AreEqual(expected, result);
        }