public void InvalidItemRaisesValidationMessage(string candidate, params string[] conflicts) { const string learnRefNumber = "123456789X"; var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); handler .Setup(x => x.Handle("ContPrefType_02", learnRefNumber, null, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); var preferences = new List <IContactPreference>(); var preference = new Mock <IContactPreference>(); preference .SetupGet(y => y.ContPrefType) .Returns(candidate.Substring(0, 3)); preference .SetupGet(y => y.ContPrefCode) .Returns(int.Parse(candidate.Substring(3))); preferences.Add(preference.Object); conflicts.ForEach(x => { var prefType = x.Substring(0, 3); var prefCode = int.Parse(x.Substring(3)); var conflict = new Mock <IContactPreference>(); conflict .SetupGet(y => y.ContPrefType) .Returns(x.Substring(0, 3)); conflict .SetupGet(y => y.ContPrefCode) .Returns(int.Parse(x.Substring(3))); handler .Setup(y => y.BuildErrorMessageParameter("ContPrefType", prefType)) .Returns(new Mock <IErrorMessageParameter>().Object); handler .Setup(y => y.BuildErrorMessageParameter("ContPrefCode", prefCode)) .Returns(new Mock <IErrorMessageParameter>().Object); preferences.Add(conflict.Object); }); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(learnRefNumber); mockLearner .SetupGet(x => x.ContactPreferences) .Returns(preferences); var sut = new ContPrefType_02Rule(handler.Object); sut.Validate(mockLearner.Object); handler.VerifyAll(); }
public void ValidItemDoesNotRaiseValidationMessage(params string[] candidates) { // arrange const string learnRefNumber = "123456789X"; var preferences = Collection.Empty <IContactPreference>(); candidates.ForEach(x => { var prefType = x.Substring(0, 3); var prefCode = int.Parse(x.Substring(3)); var conflict = new Mock <IContactPreference>(); conflict .SetupGet(y => y.ContPrefType) .Returns(x.Substring(0, 3)); conflict .SetupGet(y => y.ContPrefCode) .Returns(int.Parse(x.Substring(3))); preferences.Add(conflict.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 sut = new ContPrefType_02Rule(handler.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); }