public void WhenMethodIsHidden_ThenAdapterDoesNotHaveMethod(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b.Decoration.IsHidden = true);

            manager.GetAdapter();

            manager.MethodInfo.ShouldBeNull();
        }
        public void WhenMethodIsVirtual_ThenAdapterMethodIsVirtual(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b.Decoration.IsVirtual = true);

            manager.GetAdapter();

            manager.MethodInfo.IsVirtual.ShouldBeTrue();
        }
        public void WhenDecorationIsMadePrivate_AdapterMethodIsPrivate(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b.Decoration.AccessModifier = Access.Private);

            manager.GetAdapter();

            manager.MethodInfo.IsPrivate.ShouldBeTrue();
        }
        public void WhenMethodNameIsChanged_ThenAdapterHasMethodWithNewName(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b.Decoration.PublicName = "NewName");

            manager.GetAdapter();

            manager.AdapterType.GetMethod("NewName", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
            .ShouldNotBeNull();
        }
        public void WhenLinqParamIsSpecifiedByIndex_ThenLinqReceivesCorrectParam(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b
                             .SpecifyLinq(c => manager.Spec.Linq.Arg <string>(1)));

            manager.GetAdapter();

            string result = manager.DynamicAdapter.Run("test");

            result.ShouldBe("test");
        }
        public void WhenMethodAttributeIsHidden_ThenAdapterMethodDoesNotHaveAttribute(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b
                             .Decoration
                             .Attributes
                             .HideAttributesOfType <CustomizedMethodShould1Attribute>());

            manager.GetAdapter();

            manager.MethodInfo.GetCustomAttributes(true).ShouldBeEmpty();
        }
        public void WhenMethodAttributeIsAdded_ThenAdapterMethodHasAttribute(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b.Decoration
                             .Attributes
                             .AddAttribute(() => new CustomizedMethodShould2Attribute()));

            manager.GetAdapter();

            manager.MethodInfo.GetCustomAttributes(true)
            .OfType <CustomizedMethodShould2Attribute>()
            .ShouldHaveSingleItem()
            .ShouldNotBeNull();
        }
        public void WhenMethodAttributeIsConverted_ThenAdapterMethodDoesNotHaveOriginalAttribute(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b
                             .Decoration
                             .Attributes
                             .RegisterAttributeConversion <CustomizedMethodShould1Attribute>(a => new CustomizedMethodShould2Attribute()));

            manager.GetAdapter();

            manager.MethodInfo.GetCustomAttributes(true)
            .OfType <CustomizedMethodShould1Attribute>()
            .ShouldBeEmpty();
        }
        public void WhenParamIsSpecifiedAsDeclared_ThenDelegateReceivesDeclaredValue(MethodBehaviorManager manager)
        {
            string value = "test1";

            manager.Behavior(b => b
                             .SpecifyDelegate(Param.Declare(value), x => x));

            manager.GetAdapter();
            value = "test2";    // To ensure that the value is bound early.

            string result = manager.DynamicAdapter.Run("test3");

            result.ShouldBe("test1");
        }
        public void WhenMethodAttributeIsConverted_ThenAdapterMethodHasConvertedAttribute(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b
                             .Decoration
                             .Attributes
                             .RegisterAttributeConversion <CustomizedMethodShould1Attribute>(a => new CustomizedMethodShould2Attribute()));

            manager.GetAdapter();

            manager.MethodInfo.GetCustomAttributes(true)
            .Cast <CustomizedMethodShould2Attribute>()
            .ShouldHaveSingleItem()
            .ShouldNotBeNull();
        }
        public void WhenLinqParamIsSpecifiedAsConstableLocal_ThenLinqReceivesDeclaredValue(MethodBehaviorManager manager)
        {
            string value = "test1";

            manager.Behavior(b => b
                             .SpecifyLinq(x => value));

            dynamic adapter = manager.GetAdapter();

            value = "test2";    // To ensure that the value is bound early.

            string result = adapter.Run("test3");

            result.ShouldBe("test1");
        }
        public void WhenParamIsSpecifiedAsDeclaredNull_ThenDelegateReceivesNull(MethodBehaviorManager manager)
        {
            manager.Behavior(b => b
                             .SpecifyDelegate(Param.DeclareNull <string>(), x =>
            {
                x.ShouldBeNull();
                return("pass");
            }));

            manager.GetAdapter();

            string result = manager.DynamicAdapter.Run("test");

            result.ShouldBe("pass");
        }
        public void WhenParamIsSpecifiedByIndex_ThenDelegateReceivesCorrectParam(MethodBehaviorManager manager)
        {
            string backingField = null;

            manager.Behavior(b => b
                             .SpecifyDelegate(Param.Arg <string>(1),
                                              a =>
            {
                backingField = a;
                return("blocked");
            }));

            manager.GetAdapter();

            string result = manager.DynamicAdapter.Run("test");

            result.ShouldBe("blocked");
            backingField.ShouldBe("test");
        }