public void InvalidItemRaisesValidationMessage() { // arrange const string LearnRefNumber = "123456789X"; const int EmpStat = 3; var mockStatus = new Mock <ILearnerEmploymentStatus>(); mockStatus .SetupGet(y => y.EmpStat) .Returns(EmpStat); var statii = Collection.Empty <ILearnerEmploymentStatus>(); statii.Add(mockStatus.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(x => x.LearnerEmploymentStatuses) .Returns(statii.AsSafeReadOnlyList()); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); handler .Setup(x => x.Handle( Moq.It.Is <string>(y => y == EmpStat_05Rule.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 == EmpStat_05Rule.MessagePropertyName), EmpStat)) .Returns(new Mock <IErrorMessageParameter>().Object); var lookups = new Mock <IProvideLookupDetails>(MockBehavior.Strict); lookups .Setup(x => x.Contains(TypeOfIntegerCodedLookup.EmpStat, EmpStat)) .Returns(false); var sut = new EmpStat_05Rule(handler.Object, lookups.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); lookups.VerifyAll(); }
public void ValidItemDoesNotRaiseValidationMessage() { // arrange const string LearnRefNumber = "123456789X"; const int EmpStat = 3; var mockStatus = new Mock <ILearnerEmploymentStatus>(); mockStatus .SetupGet(y => y.EmpStat) .Returns(EmpStat); var statii = Collection.Empty <ILearnerEmploymentStatus>(); statii.Add(mockStatus.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(x => x.LearnerEmploymentStatuses) .Returns(statii.AsSafeReadOnlyList()); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var lookups = new Mock <IProvideLookupDetails>(MockBehavior.Strict); lookups .Setup(x => x.Contains(TypeOfIntegerCodedLookup.EmpStat, EmpStat)) .Returns(true); var sut = new EmpStat_05Rule(handler.Object, lookups.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); lookups.VerifyAll(); }
public void IsNotValidMeetsExpectation(bool expectation) { var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var lookups = new Mock <IProvideLookupDetails>(MockBehavior.Strict); lookups .Setup(x => x.Contains(TypeOfIntegerCodedLookup.EmpStat, Moq.It.IsAny <int>())) .Returns(!expectation); var sut = new EmpStat_05Rule(handler.Object, lookups.Object); var mockItem = new Mock <ILearnerEmploymentStatus>(); mockItem .SetupGet(y => y.EmpStat) .Returns(4); var result = sut.IsNotValid(mockItem.Object); Assert.Equal(expectation, result); }