public void ValidItemDoesNotRaiseAValidationMessage(string candidate) { // arrange const string LearnRefNumber = "123456789X"; var records = Collection.Empty <ILearningDeliveryFAM>(); var famType = candidate.Substring(0, 3); var famCode = candidate.Substring(3); var mockItem = new Mock <ILearningDeliveryFAM>(); mockItem .SetupGet(y => y.LearnDelFAMType) .Returns(famType); mockItem .SetupGet(y => y.LearnDelFAMCode) .Returns(famCode); records.Add(mockItem.Object); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(x => x.LearningDeliveryFAMs) .Returns(records.AsSafeReadOnlyList()); var deliveries = Collection.Empty <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(x => x.LearningDeliveries) .Returns(deliveries.AsSafeReadOnlyList()); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var lookups = new Mock <IProvideLookupDetails>(MockBehavior.Strict); lookups .Setup(x => x.Contains(TypeOfLimitedLifeLookup.LearningDeliveryFAM, $"{famType}{famCode}")) .Returns(true); var sut = new LearnDelFAMType_04Rule(handler.Object, lookups.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); lookups.VerifyAll(); }
public void InvalidItemRaisesValidationMessage(string candidate) { const string LearnRefNumber = "123456789X"; var records = new List <ILearningDeliveryFAM>(); var famType = candidate.Substring(0, 3); var famCode = candidate.Substring(3); var mockItem = new Mock <ILearningDeliveryFAM>(); mockItem .SetupGet(y => y.LearnDelFAMType) .Returns(famType); mockItem .SetupGet(y => y.LearnDelFAMCode) .Returns(famCode); records.Add(mockItem.Object); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(x => x.LearningDeliveryFAMs) .Returns(records); var deliveries = new List <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(x => x.LearningDeliveries) .Returns(deliveries); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); handler .Setup(x => x.Handle(LearnDelFAMType_04Rule.Name, LearnRefNumber, null, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); handler .Setup(x => x.BuildErrorMessageParameter("LearnDelFAMType", famType)) .Returns(new Mock <IErrorMessageParameter>().Object); handler .Setup(x => x.BuildErrorMessageParameter("LearnDelFAMCode", famCode)) .Returns(new Mock <IErrorMessageParameter>().Object); var lookups = new Mock <IProvideLookupDetails>(MockBehavior.Strict); lookups .Setup(x => x.Contains(TypeOfLimitedLifeLookup.LearnDelFAMType, $"{famType}{famCode}")) .Returns(false); var sut = new LearnDelFAMType_04Rule(handler.Object, lookups.Object); sut.Validate(mockLearner.Object); handler.VerifyAll(); lookups.VerifyAll(); }