public void InvalidItemRaisesValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";
            const string domicile       = "foo";

            var mockHE = new Mock <ILearningDeliveryHE>();

            mockHE.SetupGet(m => m.DOMICILE).Returns(domicile);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearningDeliveryHEEntity)
            .Returns(mockHE.Object);

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

            deliveries.Add(mockDelivery.Object);

            var mockLearner = new Mock <ILearner>();

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

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

            handler
            .Setup(x => x.Handle(
                       Moq.It.Is <string>(y => y == DOMICILE_02Rule.Name),
                       Moq.It.Is <string>(y => y == LearnRefNumber),
                       0,
                       Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == "DOMICILE"),
                       Moq.It.Is <string>(y => y == domicile)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

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

            service
            .Setup(x => x.Contains(TypeOfStringCodedLookup.Domicile, Moq.It.IsAny <string>()))
            .Returns(false);

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

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
        }
        public void HasValidDomicileMeetsExpectation(bool expectation, string domicile)
        {
            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var service = new Mock <IProvideLookupDetails>(MockBehavior.Strict);

            service
            .Setup(x => x.Contains(TypeOfStringCodedLookup.Domicile, domicile))
            .Returns(expectation);

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

            var mockItem = new Mock <ILearningDeliveryHE>();

            mockItem.Setup(x => x.DOMICILE).Returns(domicile);

            var result = sut.HasValidDomicile(mockItem.Object);

            Assert.Equal(expectation, result);
        }
        public void ValidItemDoesNotRaiseValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var mockHE       = new Mock <ILearningDeliveryHE>();
            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearningDeliveryHEEntity)
            .Returns(mockHE.Object);

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

            deliveries.Add(mockDelivery.Object);

            var mockLearner = new Mock <ILearner>();

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

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

            service
            .Setup(x => x.Contains(TypeOfStringCodedLookup.Domicile, Moq.It.IsAny <string>()))
            .Returns(true);

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

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

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