public void ValidItemDoesNotRaiseValidationMessage(int deliveryCount, params int[] testCodes)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var deliveries = Collection.Empty <ILearningDelivery>();

            for (int i = 0; i < deliveryCount; i++)
            {
                var code = testCodes.ElementAt(i);

                var records = Collection.Empty <IAppFinRecord>();
                for (int j = deliveryCount; j < testCodes.Length; j++)
                {
                    var rec2 = new Mock <IAppFinRecord>();
                    rec2.SetupGet(x => x.AFinCode).Returns(testCodes.ElementAt(j));
                    rec2.SetupGet(x => x.AFinDate).Returns(DateTime.Today);
                    rec2.SetupGet(x => x.AFinType).Returns("TestType");

                    records.Add(rec2.Object);
                }

                var mockDel = new Mock <ILearningDelivery>();
                mockDel
                .SetupGet(y => y.AimType)
                .Returns(TypeOfAim.ProgrammeAim);
                mockDel
                .SetupGet(y => y.ProgTypeNullable)
                .Returns(TypeOfLearningProgramme.ApprenticeshipStandard);
                mockDel
                .SetupGet(y => y.StdCodeNullable)
                .Returns(code);
                mockDel
                .SetupGet(y => y.AppFinRecords)
                .Returns(records.AsSafeReadOnlyList());

                deliveries.Add(mockDel.Object);
            }

            var mockItem = new Mock <ILearner>();

            mockItem
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockItem
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries.AsSafeReadOnlyList());

            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);

            var sut = new R68Rule(handler.Object);

            // act
            sut.Validate(mockItem.Object);

            // assert
            handler.VerifyAll();
        }
        public void InvalidItemRaisesValidationMessage(int deliveryCount, params int[] testCodes)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var deliveries = Collection.Empty <ILearningDelivery>();

            for (int i = 0; i < deliveryCount; i++)
            {
                var code = testCodes.ElementAt(i);

                var records = Collection.Empty <IAppFinRecord>();
                for (int j = deliveryCount; j < testCodes.Length; j++)
                {
                    var rec2 = new Mock <IAppFinRecord>();
                    rec2.SetupGet(x => x.AFinCode).Returns(testCodes.ElementAt(j));
                    rec2.SetupGet(x => x.AFinDate).Returns(DateTime.Today);
                    rec2.SetupGet(x => x.AFinType).Returns("TestType");

                    records.Add(rec2.Object);
                }

                var mockDel = new Mock <ILearningDelivery>();
                mockDel
                .SetupGet(y => y.AimType)
                .Returns(TypeOfAim.ProgrammeAim);
                mockDel
                .SetupGet(y => y.ProgTypeNullable)
                .Returns(TypeOfLearningProgramme.ApprenticeshipStandard);
                mockDel
                .SetupGet(y => y.StdCodeNullable)
                .Returns(code);
                mockDel
                .SetupGet(y => y.AppFinRecords)
                .Returns(records.AsSafeReadOnlyList());

                deliveries.Add(mockDel.Object);
            }

            var mockItem = new Mock <ILearner>();

            mockItem
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockItem
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries.AsSafeReadOnlyList());

            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);

            handler
            .Setup(x => x.Handle(
                       Moq.It.Is <string>(y => y == R68Rule.Name),
                       Moq.It.Is <string>(y => y == LearnRefNumber),
                       null,
                       Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == PropertyNameConstants.ProgType),
                       TypeOfLearningProgramme.ApprenticeshipStandard))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == PropertyNameConstants.AFinType),
                       Moq.It.Is <string>(y => y == "TestType")))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == PropertyNameConstants.AFinCode),
                       Moq.It.IsAny <int>()))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == PropertyNameConstants.AFinDate),
                       Moq.It.Is <DateTime>(y => y == DateTime.Today)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var sut = new R68Rule(handler.Object);

            var invocationCount = testCodes.Skip(deliveryCount).Distinct().Count();

            // act
            sut.Validate(mockItem.Object);

            // assert
            handler
            .Verify(x => x.BuildErrorMessageParameter(Moq.It.Is <string>(y => y == PropertyNameConstants.AFinType), Moq.It.Is <string>(y => y == "TestType")), Times.Exactly(invocationCount));
            handler.VerifyAll();
        }