예제 #1
0
        public void ValidItemDoesNotRaiseValidationMessage(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);

            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 = Collection.Empty <ILARSLearningDeliveryValidity>();

            larsValidities.Add(mockValidity.Object);

            var service = new Mock <ILARSDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.GetValiditiesFor(learnAimRef))
            .Returns(larsValidities.AsSafeReadOnlyList());

            var sut = new LearnAimRef_88Rule(handler.Object, provider.Object, service.Object);

            // act
            sut.Validate(mockLearner.Object);

            // assert
            handler.VerifyAll();
            provider.VerifyAll();
            service.VerifyAll();
        }
예제 #2
0
        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();
        }