Exemplo n.º 1
0
        public void write_the_not_supported_exception()
        {
            var results = CodegenScenario.ForAction <int>(x =>
            {
                x.Frames.ThrowNotSupportedException();
            });

            results.LinesOfCode.ShouldContain("throw new System.NotSupportedException();");
        }
Exemplo n.º 2
0
        public void write_with_arguments()
        {
            var results = CodegenScenario.ForAction <int>(x =>
            {
                x.Frames.Throw <InvalidOperationException>("foo");
            });

            results.LinesOfCode.ShouldContain("throw new System.InvalidOperationException(\"foo\");");
        }
Exemplo n.º 3
0
        public void write_text_with_substitution()
        {
            var result = CodegenScenario.ForAction <int>(m =>
            {
                m.Frames.Code("var x = {0};", 22);
            });

            result.LinesOfCode.ShouldContain("var x = 22;");
        }
Exemplo n.º 4
0
        public void write_text_with_formatted_text()
        {
            var result = CodegenScenario.ForAction <int>(m =>
            {
                m.Frames.Code("var x = {0};", "hi");
            });

            result.LinesOfCode.ShouldContain("var x = \"hi\";");
        }
Exemplo n.º 5
0
        public void just_write_text()
        {
            var result = CodegenScenario.ForAction <int>(m =>
            {
                m.Frames.Code("var x = 0;");
            });

            result.LinesOfCode.ShouldContain("var x = 0;");
        }
Exemplo n.º 6
0
        public void simple_execution_with_action_2()
        {
            var result = CodegenScenario.ForAction <Tracer>(m => m.Frames.Call <Tracer>(x => x.Call()));

            var tracer = new Tracer();

            result.Object.DoStuff(tracer);

            tracer.Called.ShouldBeTrue();

            result.LinesOfCode.ShouldContain("arg1.Call();");
        }
Exemplo n.º 7
0
        public void write_text_with_variables()
        {
            var result = CodegenScenario.ForAction <int>(m =>
            {
                var x = Variable.For <string>("x");
                m.Frames.Code("var {0} = {1};", x, "hi").Creates(x);
                m.Frames.Code("System.Console.WriteLine({0});", Use.Type <string>());
            });

            result.LinesOfCode.ShouldContain("var x = \"hi\";");
            result.LinesOfCode.ShouldContain("System.Console.WriteLine(x);");
        }
Exemplo n.º 8
0
        public void writes_with_source_writer_fanciness()
        {
            var result = CodegenScenario.ForAction <int>(m =>
            {
                m.Frames.Code(@"BLOCK:if (true)
// Comment
END
");
            });

            result.Code.ShouldContain("if");
            result.Code.ShouldNotContain("BLOCK");
        }
Exemplo n.º 9
0
        public void no_arg_inside_of_using_block_simplest_case()
        {
            var result = CodegenScenario.ForAction <NoArgGuyCatcher>(m =>
            {
                m.Frames.CallConstructor(() => new NoArgGuy(), c => c.Mode = ConstructorCallMode.UsingNestedVariable);
                m.Frames.Call <NoArgGuyCatcher>(x => x.Catch(null));
            });

            result.LinesOfCode.ShouldContain($"using (var noArgGuy = new {typeof(NoArgGuy).FullNameInCode()}())");

            var catcher = new NoArgGuyCatcher();

            result.Object.DoStuff(catcher);

            catcher.Guy.ShouldNotBeNull();
            catcher.Guy.WasDisposed.ShouldBeTrue();
        }
Exemplo n.º 10
0
        public void activator_with_no_return()
        {
            var result = CodegenScenario.ForAction <NoArgGuyCatcher>(m =>
            {
                m.Frames.CallConstructor(() => new NoArgGuy(), ctor =>
                {
                    ctor.ActivatorFrames.Call <NoArgGuyCatcher>(x => x.Catch(null));
                });
            });


            var catcher = new NoArgGuyCatcher();

            result.Object.DoStuff(catcher);

            catcher.Guy.ShouldNotBeNull();
        }
        public void activator_with_nested_in_using()
        {
            var result = CodegenScenario.ForAction <NoArgGuyCatcher>(m =>
            {
                m.Frames.CallConstructor(() => new NoArgGuy(), ctor =>
                {
                    ctor.Mode = ConstructorCallMode.UsingNestedVariable;
                    ctor.ActivatorFrames.Call <NoArgGuyCatcher>(x => x.Catch(null));
                });
            });

            var catcher = new NoArgGuyCatcher();

            result.Object.DoStuff(catcher);

            catcher.Guy.Should().NotBeNull();
            catcher.Guy.WasDisposed.Should().BeTrue();
        }