public void InvalidItemRaisesValidationMessage(string candidate) { const string learnRefNumber = "123456789X"; var preferences = new List <IContactPreference>(); var prefType = candidate.Substring(0, 3); var prefCode = int.Parse(candidate.Substring(3)); var preference = new Mock <IContactPreference>(); preference .SetupGet(y => y.ContPrefType) .Returns(prefType); preference .SetupGet(y => y.ContPrefCode) .Returns(prefCode); preferences.Add(preference.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(learnRefNumber); mockLearner .SetupGet(x => x.ContactPreferences) .Returns(preferences); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); handler .Setup(x => x.Handle("ContPrefType_03", learnRefNumber, null, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); handler .Setup(y => y.BuildErrorMessageParameter("DD06", DateTime.Today.ToString("d", AbstractRule.RequiredCulture))) .Returns(new Mock <IErrorMessageParameter>().Object); handler .Setup(y => y.BuildErrorMessageParameter("ContPrefType", prefType)) .Returns(new Mock <IErrorMessageParameter>().Object); handler .Setup(y => y.BuildErrorMessageParameter("ContPrefCode", prefCode)) .Returns(new Mock <IErrorMessageParameter>().Object); var ddRule06 = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); ddRule06 .Setup(x => x.Derive(Moq.It.IsAny <IReadOnlyCollection <ILearningDelivery> >())) .Returns(DateTime.Today); var provider = new Mock <IProvideLookupDetails>(MockBehavior.Strict); provider .Setup(x => x.IsCurrent(TypeOfLimitedLifeLookup.ContPrefType, candidate, DateTime.Today)) .Returns(false); var sut = new ContPrefType_03Rule(handler.Object, ddRule06.Object, provider.Object); sut.Validate(mockLearner.Object); handler.VerifyAll(); }
public void ValidItemDoesNotRaiseValidationMessage(string candidate) { // arrange const string learnRefNumber = "123456789X"; var preferences = Collection.Empty <IContactPreference>(); var prefType = candidate.Substring(0, 3); var prefCode = int.Parse(candidate.Substring(3)); var preference = new Mock <IContactPreference>(); preference .SetupGet(y => y.ContPrefType) .Returns(prefType); preference .SetupGet(y => y.ContPrefCode) .Returns(prefCode); preferences.Add(preference.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(learnRefNumber); mockLearner .SetupGet(x => x.ContactPreferences) .Returns(preferences.AsSafeReadOnlyList()); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var ddRule06 = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); ddRule06 .Setup(x => x.Derive(Moq.It.IsAny <IReadOnlyCollection <ILearningDelivery> >())) .Returns(DateTime.Today); // pass or fail is determined by this call var provider = new Mock <IProvideLookupDetails>(MockBehavior.Strict); provider .Setup(x => x.IsCurrent(TypeOfLimitedLifeLookup.ContactPreference, candidate, DateTime.Today)) .Returns(true); var sut = new ContPrefType_03Rule(handler.Object, ddRule06.Object, provider.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); }