Пример #1
0
        public void Fragment_MethodCallCodeFragment_works()
        {
            var method = new MethodCallCodeFragment("Test", true, 42);

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(".Test(true, 42)", result);
        }
        public void Fragment_MethodCallCodeFragment_works_when_niladic()
        {
            var method = new MethodCallCodeFragment("Test");

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(".Test()", result);
        }
        public void Fragment_MethodCallCodeFragment_works_with_arrays()
        {
            var method = new MethodCallCodeFragment("Test", new byte[] { 1, 2 }, new[] { 3, 4 }, new[] { "foo", "bar" });

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(".Test(new byte[] { 1, 2 }, new[] { 3, 4 }, new[] { \"foo\", \"bar\" })", result);
        }
Пример #4
0
        public void Fragment_MethodCallCodeFragment_works_when_chaining_on_chain_with_call()
        {
            var method = new MethodCallCodeFragment(_testFuncMethodInfo, "One").Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Two"))
                         .Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Three").Chain(new MethodCallCodeFragment(_testFuncMethodInfo, "Four")));

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(@$ ".TestFunc(" "One" "){EOL}.TestFunc(" "Two" "){EOL}.TestFunc(" "Three" "){EOL}.TestFunc(" "Four" ")", result);
        }
Пример #5
0
        public void Fragment_MethodCallCodeFragment_works_when_chaining()
        {
            var method = new MethodCallCodeFragment(_testFuncMethodInfo)
                         .Chain(_testFuncMethodInfo);

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal($".TestFunc(){EOL}.TestFunc()", result);
        }
Пример #6
0
        public void Fragment_MethodCallCodeFragment_works_when_chaining_on_chain_with_call()
        {
            var method = new MethodCallCodeFragment("One", Array.Empty <object>(), new MethodCallCodeFragment("Two"))
                         .Chain(new MethodCallCodeFragment("Three", Array.Empty <object>(), new MethodCallCodeFragment("Four")));

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(".One().Two().Three().Four()", result);
        }
        public void Fragment_MethodCallCodeFragment_works_when_chaining()
        {
            var method = new MethodCallCodeFragment("Test")
                         .Chain("Test");

            var result = new CSharpHelper().Fragment(method);

            Assert.Equal(".Test().Test()", result);
        }
Пример #8
0
        public void Fragment_MethodCallCodeFragment_works_when_nested_closure()
        {
            var method = new MethodCallCodeFragment(
                _testFuncMethodInfo,
                new NestedClosureCodeFragment("x", new MethodCallCodeFragment(_testFuncMethodInfo)));

            var result = new CSharpHelper(TypeMappingSource).Fragment(method);

            Assert.Equal(".TestFunc(x => x.TestFunc())", result);
        }
        public void Fragment_MethodCallCodeFragment_works_when_nested_closure()
        {
            var method = new MethodCallCodeFragment(
                "Test",
                new NestedClosureCodeFragment("x", new MethodCallCodeFragment("Test")));

            var result = new CSharpHelper().Fragment(method);

            Assert.Equal(".Test(x => x.Test())", result);
        }
Пример #10
0
        public void Literal_works_when_MultidimensionalArray()
        {
            var value = new object[, ] {
                { 'A', 1 }, { 'B', 2 }
            };

            var result = new CSharpHelper(TypeMappingSource).Literal(value);

            Assert.Equal(
                "new object[,]" + EOL + "{" + EOL + "    { 'A', 1 }," + EOL + "    { 'B', 2 }" + EOL + "}",
                result);
        }
Пример #11
0
        public void Literal_works_when_ObjectArray()
        {
            var literal = new CSharpHelper(TypeMappingSource).Literal(new object[] { 'A', 1 });

            Assert.Equal("new object[] { 'A', 1 }", literal);
        }
Пример #12
0
        public void Literal_works_when_empty_StringArray()
        {
            var literal = new CSharpHelper(TypeMappingSource).Literal(new string[] { });

            Assert.Equal("new string[0]", literal);
        }
Пример #13
0
        public void Literal_works_when_StringArray()
        {
            var literal = new CSharpHelper(TypeMappingSource).Literal(new[] { "A", "B" });

            Assert.Equal("new[] { \"A\", \"B\" }", literal);
        }
Пример #14
0
        public void Literal_works(object value, string expected)
        {
            var literal = new CSharpHelper(TypeMappingSource).UnknownLiteral(value);

            Assert.Equal(expected, literal);
        }