public void InvalidItemRaisesValidationMessage(int fundingModel, params string[] candidates) { // arrange const string LearnRefNumber = "123456789X"; var records = Collection.Empty <ILearningDeliveryFAM>(); candidates.ForEach(x => { var mockFAM = new Mock <ILearningDeliveryFAM>(); mockFAM .SetupGet(y => y.LearnDelFAMType) .Returns(x); records.Add(mockFAM.Object); }); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(y => y.FundModel) .Returns(fundingModel); 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 mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); mockHandler.Setup(x => x.Handle( Moq.It.Is <string>(y => y == LearnDelFAMType_01Rule.Name), Moq.It.Is <string>(y => y == LearnRefNumber), 0, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); mockHandler .Setup(x => x.BuildErrorMessageParameter( Moq.It.Is <string>(y => y == LearnDelFAMType_01Rule.MessagePropertyName), Moq.It.Is <object>(y => y == mockDelivery.Object))) .Returns(new Mock <IErrorMessageParameter>().Object); var sut = new LearnDelFAMType_01Rule(mockHandler.Object); // act sut.Validate(mockLearner.Object); // assert mockHandler.VerifyAll(); }
public void ValidItemDoesNotRaiseAValidationMessage(int fundingModel, params string[] candidates) { // arrange const string LearnRefNumber = "123456789X"; var records = Collection.Empty <ILearningDeliveryFAM>(); candidates.ForEach(x => { var mockFAM = new Mock <ILearningDeliveryFAM>(); mockFAM .SetupGet(y => y.LearnDelFAMType) .Returns(x); records.Add(mockFAM.Object); }); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(y => y.FundModel) .Returns(fundingModel); 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 mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var sut = new LearnDelFAMType_01Rule(mockHandler.Object); // act sut.Validate(mockLearner.Object); // assert mockHandler.VerifyAll(); }