public void CanCreateInvocationDelegateFor_CalledWhenAllInnerInvocationsReturnFalse_ExpectFalseIsReturned(
			[WithinInclusiveRange(1, 10)] int numberOfInnerInvocations, MethodInfo method)
		{
			var innerInvocations = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfInnerInvocations, method);
			var chain = new ServiceMethodInvocationChain(innerInvocations);
			chain.CanCreateInvocationDelegateFor(method).Should().BeFalse();
		}
        public void CanCreateInvocationDelegateFor_CalledWhenAllInnerInvocationsReturnFalse_ExpectFalseIsReturned(
            [WithinInclusiveRange(1, 10)] int numberOfInnerInvocations, MethodInfo method)
        {
            var innerInvocations = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfInnerInvocations, method);
            var chain            = new ServiceMethodInvocationChain(innerInvocations);

            chain.CanCreateInvocationDelegateFor(method).Should().BeFalse();
        }
        public void CanCreateInvocationDelegateFor_CalledMultipleTimes_ExpectEnumerableOfInnerInvocationsIsOnlyEnumeratedOnce(
            MethodInfo method1, MethodInfo method2)
        {
            var innerInvocations = Mock.Enumerable <IServiceMethodInvocation>();
            var chain            = new ServiceMethodInvocationChain(innerInvocations);

            chain.CanCreateInvocationDelegateFor(method1);
            chain.CanCreateInvocationDelegateFor(method2);

            innerInvocations.AssertWasCalled(x => x.GetEnumerator(), x => x.Repeat.Once());
        }
        public void CreateInvocationDelegate_CalledMultipleTimes_ExpectEnumerableOfInnerInvocationsIsOnlyEnumeratedOnce(
            MethodInfo method1, ServiceMethodInvocationContext context1, MethodInfo method2, ServiceMethodInvocationContext context2)
        {
            var innerInvocations = Mock.Enumerable <IServiceMethodInvocation>();
            var chain            = new ServiceMethodInvocationChain(innerInvocations);

            chain.Invoking(x => x.CreateInvocationDelegate(method1, context1)).ShouldThrow <Exception>();
            chain.Invoking(x => x.CreateInvocationDelegate(method2, context2)).ShouldThrow <Exception>();

            innerInvocations.AssertWasCalled(x => x.GetEnumerator(), x => x.Repeat.Once());
        }
		public void CanCreateInvocationDelegateFor_CalledWhenAtLeastOneInnerInvocationReturnsTrue_ExpectTrueIsReturned(
			[WithinInclusiveRange(0, 10)] int numberOfFalseInnerInvocations,
			[WithinInclusiveRange(1, 10)] int numberOfTrueInnerInvocations,
			MethodInfo method)
		{
			var falseInvocations = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfFalseInnerInvocations, method);
			var trueInvocations = CreateNumberOfStubServiceMethodInvocationsAbleToCreateDelegate(numberOfTrueInnerInvocations, method);

			var chain = new ServiceMethodInvocationChain(falseInvocations.Concat(trueInvocations).Shuffle());
			chain.CanCreateInvocationDelegateFor(method).Should().BeTrue();
		}
        public void CanCreateInvocationDelegateFor_CalledWhenAtLeastOneInnerInvocationReturnsTrue_ExpectTrueIsReturned(
            [WithinInclusiveRange(0, 10)] int numberOfFalseInnerInvocations,
            [WithinInclusiveRange(1, 10)] int numberOfTrueInnerInvocations,
            MethodInfo method)
        {
            var falseInvocations = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfFalseInnerInvocations, method);
            var trueInvocations  = CreateNumberOfStubServiceMethodInvocationsAbleToCreateDelegate(numberOfTrueInnerInvocations, method);

            var chain = new ServiceMethodInvocationChain(falseInvocations.Concat(trueInvocations).Shuffle());

            chain.CanCreateInvocationDelegateFor(method).Should().BeTrue();
        }
        public void CreateInvocationDelegate_CalledWhenAtLeastOneInnerInvocationCanCreateDelegate_ExpectReturnedDelegateIsFromInnerInvocation(
            [WithinInclusiveRange(0, 10)] int numberOfFalseInnerInvocations,
            [WithinInclusiveRange(1, 10)] int numberOfTrueInnerInvocations,
            MethodInfo method,
            ServiceMethodInvocationContext context)
        {
            Action constructedDelegate = () => { };
            var    falseInvocations    = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfFalseInnerInvocations, method);
            var    trueInvocations     = CreateNumberOfStubServiceMethodInvocationsAbleToCreateDelegate(numberOfTrueInnerInvocations, method);

            trueInvocations.ForEach(inv => inv.Stub(
                                        x => x.CreateInvocationDelegate(Arg <MethodInfo> .Is.Same(method), Arg <ServiceMethodInvocationContext> .Is.Same(context)))
                                    .Return(constructedDelegate));

            var chain = new ServiceMethodInvocationChain(falseInvocations.Concat(trueInvocations).Shuffle());

            chain.CreateInvocationDelegate(method, context).Should().BeSameAs(constructedDelegate);
        }
		public void CanCreateInvocationDelegateFor_CalledMultipleTimes_ExpectEnumerableOfInnerInvocationsIsOnlyEnumeratedOnce(
			MethodInfo method1, MethodInfo method2)
		{
			var innerInvocations = Mock.Enumerable<IServiceMethodInvocation>();
			var chain = new ServiceMethodInvocationChain(innerInvocations);
			chain.CanCreateInvocationDelegateFor(method1);
			chain.CanCreateInvocationDelegateFor(method2);

			innerInvocations.AssertWasCalled(x => x.GetEnumerator(), x => x.Repeat.Once());
		}
		public void CreateInvocationDelegate_CalledMultipleTimes_ExpectEnumerableOfInnerInvocationsIsOnlyEnumeratedOnce(
			MethodInfo method1, ServiceMethodInvocationContext context1, MethodInfo method2, ServiceMethodInvocationContext context2)
		{
			var innerInvocations = Mock.Enumerable<IServiceMethodInvocation>();
			var chain = new ServiceMethodInvocationChain(innerInvocations);
			chain.Invoking(x => x.CreateInvocationDelegate(method1, context1)).ShouldThrow<Exception>();
			chain.Invoking(x => x.CreateInvocationDelegate(method2, context2)).ShouldThrow<Exception>();

			innerInvocations.AssertWasCalled(x => x.GetEnumerator(), x => x.Repeat.Once());
		}
		public void CreateInvocationDelegate_CalledWhenAtLeastOneInnerInvocationCanCreateDelegate_ExpectReturnedDelegateIsFromInnerInvocation(
			[WithinInclusiveRange(0, 10)] int numberOfFalseInnerInvocations,
			[WithinInclusiveRange(1, 10)] int numberOfTrueInnerInvocations,
			MethodInfo method,
			ServiceMethodInvocationContext context)
		{
			Action constructedDelegate = () => { };
			var falseInvocations = CreateNumberOfStubServiceMethodInvocationsUnableToCreateDelegate(numberOfFalseInnerInvocations, method);
			var trueInvocations = CreateNumberOfStubServiceMethodInvocationsAbleToCreateDelegate(numberOfTrueInnerInvocations, method);
			trueInvocations.ForEach(inv => inv.Stub(
				x => x.CreateInvocationDelegate(Arg<MethodInfo>.Is.Same(method), Arg<ServiceMethodInvocationContext>.Is.Same(context)))
					.Return(constructedDelegate));

			var chain = new ServiceMethodInvocationChain(falseInvocations.Concat(trueInvocations).Shuffle());
			chain.CreateInvocationDelegate(method, context).Should().BeSameAs(constructedDelegate);
		}