public void ValidItemWithEmptyEmploymentsDoesNotRaiseValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var statii = Collection.EmptyAndReadOnly <ILearnerEmploymentStatus>();

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(y => y.LearnerEmploymentStatuses)
            .Returns(statii);

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

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

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

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

            var status = new Mock <ILearnerEmploymentStatus>();

            status
            .SetupGet(x => x.EmpIdNullable)
            .Returns(candidate);

            var statii = Collection.Empty <ILearnerEmploymentStatus>();

            statii.Add(status.Object);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(y => y.LearnerEmploymentStatuses)
            .Returns(statii.AsSafeReadOnlyList());

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

            handler
            .Setup(x => x.Handle(
                       Moq.It.Is <string>(y => y == RuleNameConstants.EmpId_01),
                       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.EmpId),
                       candidate))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            // the crux of the test runs on the return value from this call
            var edrsData = new Mock <IEmployersDataService>(MockBehavior.Strict);

            edrsData
            .Setup(x => x.IsValid(candidate))
            .Returns(false);

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

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

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

            var status = new Mock <ILearnerEmploymentStatus>();

            status
            .SetupGet(x => x.EmpIdNullable)
            .Returns(candidate);

            var statii = Collection.Empty <ILearnerEmploymentStatus>();

            statii.Add(status.Object);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(y => y.LearnerEmploymentStatuses)
            .Returns(statii.AsSafeReadOnlyList());

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

            // the crux of the test runs on the return value from this call
            var edrsData = new Mock <IEmployersDataService>(MockBehavior.Strict);

            edrsData
            .Setup(x => x.IsValid(candidate))
            .Returns(true);

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

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

            // assert
            handler.VerifyAll();
            edrsData.VerifyAll();
        }
        public void ValidItemWithNullEmploymentsDoesNotRaiseValidationMessage()
        {
            const string LearnRefNumber = "123456789X";

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);

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

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

            sut.Validate(mockLearner.Object);

            handler.VerifyAll();
            edrsData.VerifyAll();
        }
        public void IsNotValidMeetsExpectation(int?candidate, bool expectation)
        {
            var handler  = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var edrsData = new Mock <IEmployersDataService>(MockBehavior.Strict);

            edrsData
            .Setup(x => x.IsValid(candidate))
            .Returns(!expectation);

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

            var mockItem = new Mock <ILearnerEmploymentStatus>();

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

            var result = sut.IsNotValid(candidate);

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

            var status = new Mock <ILearnerEmploymentStatus>();

            status
            .SetupGet(x => x.EmpIdNullable)
            .Returns(candidate);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(y => y.LearnerEmploymentStatuses)
            .Returns(new List <ILearnerEmploymentStatus> {
                status.Object
            });

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

            var edrsData = new Mock <IEmployersDataService>(MockBehavior.Strict);

            edrsData
            .Setup(x => x.IsValid(candidate))
            .Returns(true);

            var sut = new EmpId_01Rule(handler.Object, edrsData.Object);

            sut.Validate(mockLearner.Object);

            handler.VerifyAll();
            edrsData.VerifyAll();
        }