public void InvalidItemRaisesValidationMessage(string candidate, string startDate, string endDate, string category) { // arrange const string learnRefNumber = "123456789X"; const string learnAimRef = "salddfkjeifdnase"; var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(y => y.LearnAimRef) .Returns(learnAimRef); mockDelivery .SetupGet(y => y.LearnStartDate) .Returns(DateTime.Parse(candidate)); var deliveries = new ILearningDelivery[] { 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("LearnAimRef_88", learnRefNumber, 0, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); handler .Setup(x => x.BuildErrorMessageParameter("LearnAimRef", learnAimRef)) .Returns(new Mock <IErrorMessageParameter>().Object); handler .Setup(x => x.BuildErrorMessageParameter("Expected Category", category)) .Returns(new Mock <IErrorMessageParameter>().Object); var mockResult = new Mock <IBranchResult>(); mockResult .SetupGet(x => x.OutOfScope) .Returns(false); mockResult .SetupGet(x => x.Category) .Returns(category); var provider = new Mock <IProvideLearnAimRefRuleActions>(MockBehavior.Strict); provider .Setup(x => x.GetBranchingResultFor(mockDelivery.Object, mockLearner.Object)) .Returns(mockResult.Object); var mockValidity = new Mock <ILARSLearningDeliveryValidity>(MockBehavior.Strict); mockValidity .SetupGet(x => x.ValidityCategory) .Returns(category); mockValidity .SetupGet(x => x.StartDate) .Returns(DateTime.Parse(startDate)); mockValidity .SetupGet(x => x.EndDate) .Returns(DateTime.Parse(endDate)); mockValidity .SetupGet(x => x.LastNewStartDate) .Returns((DateTime?)null); var larsValidities = new ILARSLearningDeliveryValidity[] { mockValidity.Object }; var service = new Mock <ILARSDataService>(MockBehavior.Strict); service .Setup(x => x.GetValiditiesFor(learnAimRef)) .Returns(larsValidities); var sut = new LearnAimRef_88Rule(handler.Object, provider.Object, service.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); provider.VerifyAll(); service.VerifyAll(); }
/// <summary> /// Determines whether [has valid start range] [the specified validity]. /// caters for the custom and practice of setting the end date to before /// the start date as a means of withdrawing funding /// </summary> /// <param name="validity">The validity.</param> /// <param name="delivery">The delivery.</param> /// <returns> /// <c>true</c> if [in valid start range] [the specified validity]; otherwise, <c>false</c>. /// </returns> public bool HasValidStartRange(ILARSLearningDeliveryValidity validity, ILearningDelivery delivery) => validity.IsCurrent(delivery.LearnStartDate, validity.LastNewStartDate);