public void IsValidStandardCodeLARSDataServiceVerifiesOK(int candidate, bool expectation)
        {
            // arrange
            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var service = new Mock <ILARSDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.ContainsStandardFor(candidate))
            .Returns(expectation);

            var sut = new StdCode_02Rule(handler.Object, service.Object);

            var mockItem = new Mock <ILearningDelivery>();

            mockItem
            .SetupGet(x => x.StdCodeNullable)
            .Returns(candidate);

            // act
            var result = sut.IsValidStandardCode(mockItem.Object);

            // assert
            Assert.Equal(expectation, result);
            handler.VerifyAll();
            service.VerifyAll();
        }
        public void InvalidItemRaisesValidationMessage(int candidate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.StdCodeNullable)
            .Returns(candidate);

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

            deliveries.Add(mockDelivery.Object);

            var mock = new Mock <ILearner>();

            mock
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mock
            .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 == "StdCode_02"),
                       Moq.It.Is <string>(y => y == LearnRefNumber),
                       0,
                       Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == StdCode_02Rule.MessagePropertyName),
                       candidate))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var service = new Mock <ILARSDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.ContainsStandardFor(candidate))
            .Returns(false);

            var sut = new StdCode_02Rule(handler.Object, service.Object);

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
        }
        public void ValidItemDoesNotRaiseAValidationMessage(int candidate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.StdCodeNullable)
            .Returns(candidate);

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

            deliveries.Add(mockDelivery.Object);

            var mock = new Mock <ILearner>();

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

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

            service
            .Setup(x => x.ContainsStandardFor(candidate))
            .Returns(true);

            var sut = new StdCode_02Rule(handler.Object, service.Object);

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
        }