public void StrategyWithNoObjectDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();

            ctx.InnerChain.Add(strategy);

            ctx.HeadOfChain.BuildUp(ctx, typeof(object), null, null);
        }
        public void StrategyDoesNothingWithNoPolicy()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);

            Assert.IsFalse(obj.ParameterlessWasCalled);
        }
        public void SettingPolicyForMissingMethodDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            policy.Methods.Add("NonExistantMethod", new MethodCallInfo("NonExistantMethod"));
            ctx.Policies.Set<IMethodPolicy>(policy, typeof (MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);
        }
        public void IncompatibleTypesThrows()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            MethodInfo mi = typeof(MockObject).GetMethod("IntMethod");
            policy.Methods.Add("IntMethod", new MethodCallInfo( mi, new ValueParameter<string>(String.Empty)));
            ctx.Policies.Set<IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);
        }
		public void StrategyCallsMethodsUsingIParameterValues()
		{
			MethodExecutionStrategy strategy = new MethodExecutionStrategy();
			MockBuilderContext ctx = new MockBuilderContext();
			MockObject obj = new MockObject();
			ctx.InnerChain.Add(strategy);

			MethodPolicy policy = new MethodPolicy();
			policy.Methods.Add("IntMethod", new MethodCallInfo("IntMethod", new ValueParameter<int>(32)));
			ctx.Policies.Set<IMethodPolicy>(policy, typeof (MockObject), null);

			ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);

			Assert.AreEqual(32, obj.IntValue);
		}
        public void SettingPolicyForWrongParameterCountDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod", 123));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);
        }
        public void SettingPolicyForMissingMethodDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("NonExistantMethod", new MethodCallInfo("NonExistantMethod"));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);
        }
		public void StrategyDoesWorkBasedOnConcreteTypeInsteadOfPassedType()
		{
			MethodExecutionStrategy strategy = new MethodExecutionStrategy();
			MockBuilderContext ctx = new MockBuilderContext();
			MockObject obj = new MockObject();
			ctx.InnerChain.Add(strategy);

			MethodPolicy policy = new MethodPolicy();
			policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod"));
			ctx.Policies.Set<IMethodPolicy>(policy, typeof(MockObject), null);

			ctx.HeadOfChain.BuildUp(ctx, typeof (object), obj, null);

			Assert.IsTrue(obj.ParameterlessWasCalled);
		}
        public void IncompatibleTypesThrows()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            MethodInfo   mi     = typeof(MockObject).GetMethod("IntMethod");

            policy.Methods.Add("IntMethod", new MethodCallInfo(mi, new ValueParameter <string>(String.Empty)));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);
        }
        public void CanCallMultiParameterMethods()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            policy.Methods.Add("MultiParamMethod", new MethodCallInfo("MultiParamMethod", 1.0, "foo"));
            ctx.Policies.Set<IMethodPolicy>(policy, typeof (MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);

            Assert.AreEqual(1.0, obj.MultiDouble);
            Assert.AreEqual("foo", obj.MultiString);
        }
        public void StrategyCallsMethodsUsingIParameterValues()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("IntMethod", new MethodCallInfo("IntMethod", new ValueParameter <int>(32)));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);

            Assert.AreEqual(32, obj.IntValue);
        }
        public void StrategyDoesWorkBasedOnConcreteTypeInsteadOfPassedType()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod"));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(object), obj, null);

            Assert.IsTrue(obj.ParameterlessWasCalled);
        }
        public void CanCallMultiParameterMethods()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("MultiParamMethod", new MethodCallInfo("MultiParamMethod", 1.0, "foo"));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);

            Assert.AreEqual(1.0, obj.MultiDouble);
            Assert.AreEqual("foo", obj.MultiString);
        }
        public void StrategyCallsMultipleMethodsAndCallsThemInOrder()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext      ctx      = new MockBuilderContext();
            MockObject obj = new MockObject();

            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();

            policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod"));
            policy.Methods.Add("IntMethod", new MethodCallInfo("IntMethod", new ValueParameter <int>(32)));
            ctx.Policies.Set <IMethodPolicy>(policy, typeof(MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof(MockObject), obj, null);

            Assert.AreEqual(1, obj.CallOrderParameterless);
            Assert.AreEqual(2, obj.CallOrderInt);
        }
        public void SettingPolicyForWrongParameterCountDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod", 123));
            ctx.Policies.Set<IMethodPolicy>(policy, typeof (MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);
        }
        public void StrategyCallsMultipleMethodsAndCallsThemInOrder()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            MethodPolicy policy = new MethodPolicy();
            policy.Methods.Add("ParameterlessMethod", new MethodCallInfo("ParameterlessMethod"));
            policy.Methods.Add("IntMethod", new MethodCallInfo("IntMethod", new ValueParameter<int>(32)));
            ctx.Policies.Set<IMethodPolicy>(policy, typeof (MockObject), null);

            ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);

            Assert.AreEqual(1, obj.CallOrderParameterless);
            Assert.AreEqual(2, obj.CallOrderInt);
        }
        public void StrategyWithNoObjectDoesntThrow()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            ctx.InnerChain.Add(strategy);

            ctx.HeadOfChain.BuildUp(ctx, typeof (object), null, null);
        }
        public void StrategyDoesNothingWithNoPolicy()
        {
            MethodExecutionStrategy strategy = new MethodExecutionStrategy();
            MockBuilderContext ctx = new MockBuilderContext();
            MockObject obj = new MockObject();
            ctx.InnerChain.Add(strategy);

            ctx.HeadOfChain.BuildUp(ctx, typeof (MockObject), obj, null);

            Assert.IsFalse(obj.ParameterlessWasCalled);
        }