public void HasInvalidFinancialDateMeetsExpectation(string finDate, string fileDate, bool expectation)
        {
            // arrange
            var mockFinRec = new Mock <IAppFinRecord>();

            mockFinRec
            .SetupGet(x => x.AFinDate)
            .Returns(DateTime.Parse(finDate));

            var handler  = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var fileData = new Mock <IFileDataService>(MockBehavior.Strict);

            fileData
            .Setup(x => x.FilePreparationDate())
            .Returns(DateTime.Parse(fileDate));

            var sut = new AFinDate_03Rule(handler.Object, fileData.Object);

            // act
            var result = sut.HasInvalidFinancialDate(mockFinRec.Object);

            // assert
            Assert.Equal(expectation, result);
            handler.VerifyAll();
            fileData.VerifyAll();
        }
        public void InvalidItemRaisesValidationMessage(string finDate, string fileDate)
        {
            const string LearnRefNumber = "123456789X";

            var testDate        = DateTime.Parse(finDate);
            var preparationDate = DateTime.Parse(fileDate);

            var mockFinRec = new Mock <IAppFinRecord>();

            mockFinRec
            .SetupGet(x => x.AFinDate)
            .Returns(testDate);

            var records = new List <IAppFinRecord>();

            records.Add(mockFinRec.Object);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.AppFinRecords)
            .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(RuleNameConstants.AFinDate_03, LearnRefNumber, 0, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter("AFinDate", testDate.ToString("d", AbstractRule.RequiredCulture)))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter("FilePrepDate", preparationDate.ToString("d", AbstractRule.RequiredCulture)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var fileData = new Mock <IFileDataService>(MockBehavior.Strict);

            fileData
            .Setup(x => x.FilePreparationDate())
            .Returns(preparationDate);

            var sut = new AFinDate_03Rule(handler.Object, fileData.Object);

            sut.Validate(mockLearner.Object);

            handler.VerifyAll();
            fileData.VerifyAll();
        }
        public void ValidItemDoesNotRaiseAValidationMessage(string finDate, string fileDate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var testDate        = DateTime.Parse(finDate);
            var preparationDate = DateTime.Parse(fileDate);

            var mockFinRec = new Mock <IAppFinRecord>();

            mockFinRec
            .SetupGet(x => x.AFinDate)
            .Returns(testDate);

            var records = Collection.Empty <IAppFinRecord>();

            records.Add(mockFinRec.Object);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.AppFinRecords)
            .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 fileData = new Mock <IFileDataService>(MockBehavior.Strict);

            fileData
            .Setup(x => x.FilePreparationDate())
            .Returns(preparationDate);

            var sut = new AFinDate_03Rule(handler.Object, fileData.Object);

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

            // assert
            handler.VerifyAll();
            fileData.VerifyAll();
        }
Exemplo n.º 4
0
        public void InvalidItemRaisesValidationMessage(string finDate, string fileDate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var mockFinRec = new Mock <IAppFinRecord>();

            mockFinRec
            .SetupGet(x => x.AFinDate)
            .Returns(DateTime.Parse(finDate));

            var records = Collection.Empty <IAppFinRecord>();

            records.Add(mockFinRec.Object);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.AppFinRecords)
            .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);

            handler
            .Setup(x => x.Handle(
                       Moq.It.Is <string>(y => y == AFinDate_03Rule.Name),
                       Moq.It.Is <string>(y => y == LearnRefNumber),
                       0,
                       Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter(
                       Moq.It.Is <string>(y => y == AFinDate_03Rule.MessagePropertyName),
                       Moq.It.Is <object>(y => y == mockDelivery.Object)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var fileData = new Mock <IFileDataService>(MockBehavior.Strict);

            fileData
            .Setup(x => x.FilePreparationDate())
            .Returns(DateTime.Parse(fileDate));

            var sut = new AFinDate_03Rule(handler.Object, fileData.Object);

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

            // assert
            handler.VerifyAll();
            fileData.VerifyAll();
        }