public void activator_with_return()
        {
            var result = CodegenScenario.ForBuilds <NoArgGuy, NoArgGuyCatcher>(m =>
            {
                m.Frames.CallConstructor(() => new NoArgGuy(), ctor =>
                {
                    ctor.Mode = ConstructorCallMode.ReturnValue;
                    ctor.ActivatorFrames.Call <NoArgGuyCatcher>(x => x.Catch(null));
                });
            });

            var catcher = new NoArgGuyCatcher();
            var guy     = result.Object.Create(catcher);

            catcher.Guy.Should().BeSameAs(guy);
        }
Example #2
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();
        }
Example #3
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();
        }