public void ConditionMetWithPossibleCandidateExpectation(int candidate, bool present, string testCaseDate, bool expectation) { var testDate = DateTime.Parse(testCaseDate); var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.Contains(TypeOfLimitedLifeLookup.TTAccom, candidate)) .Returns(present); if (present) { mockService .Setup(x => x.IsCurrent(TypeOfLimitedLifeLookup.TTAccom, candidate, testDate)) .Returns(expectation); } var mockDerived = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); var result = sut.ConditionMet(candidate, testDate); Assert.Equal(expectation, result); mockHandler.VerifyAll(); mockService.VerifyAll(); }
public void ValidItemDoesNotRaiseAValidationMessage(int candidate, string testCaseDate) { const string LearnRefNumber = "123456789X"; var testDate = DateTime.Parse(testCaseDate); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); var mockHE = new Mock <ILearnerHE>(); mockHE .SetupGet(x => x.TTACCOMNullable) .Returns(candidate); mockLearner .SetupGet(x => x.LearnerHEEntity) .Returns(mockHE.Object); var mockDelivery = new Mock <ILearningDelivery>(); var deliveries = new List <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); mockLearner .SetupGet(x => x.LearningDeliveries) .Returns(deliveries); var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.Contains(TypeOfLimitedLifeLookup.TTAccom, candidate)) .Returns(true); mockService .Setup(x => x.IsCurrent(TypeOfLimitedLifeLookup.TTAccom, candidate, testDate)) .Returns(true); var mockDerived = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); mockDerived .Setup(x => x.Derive(deliveries)) .Returns(testDate); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); sut.Validate(mockLearner.Object); mockHandler.VerifyAll(); mockService.VerifyAll(); mockDerived.VerifyAll(); }
public void ValidItemDoesNotRaiseAValidationMessage(int candidate, string testCaseDate) { // arrange const string LearnRefNumber = "123456789X"; var testDate = DateTime.Parse(testCaseDate); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); var mockHE = new Mock <ILearnerHE>(); mockHE .SetupGet(x => x.TTACCOMNullable) .Returns(candidate); mockLearner .SetupGet(x => x.LearnerHEEntity) .Returns(mockHE.Object); var mockDelivery = new Mock <ILearningDelivery>(); var deliveries = Collection.Empty <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); mockLearner .SetupGet(x => x.LearningDeliveries) .Returns(deliveries.AsSafeReadOnlyList()); var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.IsCurrent(LookupTimeRestrictedKey.TTAccom, candidate, testDate)) .Returns(true); var mockDerived = new Mock <IDD06>(MockBehavior.Strict); mockDerived .Setup(x => x.Derive(deliveries)) .Returns(testDate); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); // act sut.Validate(mockLearner.Object); // assert mockHandler.VerifyAll(); mockService.VerifyAll(); mockDerived.VerifyAll(); }
public void ConditionMetWithNullTTAccomReturnsTrue() { var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); var mockDerived = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); var result = sut.ConditionMet(null, DateTime.MaxValue); Assert.True(result); mockHandler.VerifyAll(); mockService.VerifyAll(); mockDerived.VerifyAll(); }
public void ConditionMetWithCandidateMatchesExpectation(int candidate, string testCaseDate, bool expectation) { // arrange var testDate = DateTime.Parse(testCaseDate); var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.IsCurrent(LookupTimeRestrictedKey.TTAccom, candidate, testDate)) .Returns(expectation); var mockDerived = new Mock <IDD06>(MockBehavior.Strict); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); // act var result = sut.ConditionMet(candidate, testDate); // assert Assert.Equal(expectation, result); mockHandler.VerifyAll(); mockService.VerifyAll(); }
public void InvalidItemRaisesValidationMessage(int candidate, string testCaseDate) { const string LearnRefNumber = "123456789X"; var testDate = DateTime.Parse(testCaseDate); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); var mockHE = new Mock <ILearnerHE>(); mockHE .SetupGet(x => x.TTACCOMNullable) .Returns(candidate); mockLearner .SetupGet(x => x.LearnerHEEntity) .Returns(mockHE.Object); var mockDelivery = new Mock <ILearningDelivery>(); var deliveries = new List <ILearningDelivery>(); mockLearner .SetupGet(x => x.LearningDeliveries) .Returns(deliveries); var mockHandler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); mockHandler.Setup(x => x.Handle( Moq.It.Is <string>(y => y == TTACCOM_02Rule.Name), Moq.It.Is <string>(y => y == LearnRefNumber), null, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); mockHandler .Setup(x => x.BuildErrorMessageParameter( Moq.It.Is <string>(y => y == TTACCOM_02Rule.MessagePropertyName), Moq.It.Is <int>(y => y == candidate))) .Returns(new Mock <IErrorMessageParameter>().Object); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.Contains(TypeOfLimitedLifeLookup.TTAccom, candidate)) .Returns(true); mockService .Setup(x => x.IsCurrent(TypeOfLimitedLifeLookup.TTAccom, candidate, testDate)) .Returns(false); var mockDerived = new Mock <IDerivedData_06Rule>(MockBehavior.Strict); mockDerived .Setup(x => x.Derive(deliveries)) .Returns(testDate); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); sut.Validate(mockLearner.Object); mockHandler.VerifyAll(); mockService.VerifyAll(); mockDerived.VerifyAll(); }
public void InvalidItemRaisesValidationMessage(int candidate, string testCaseDate) { // arrange const string LearnRefNumber = "123456789X"; var testDate = DateTime.Parse(testCaseDate); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); var mockHE = new Mock <ILearnerHE>(); mockHE .SetupGet(x => x.TTACCOMNullable) .Returns(candidate); mockLearner .SetupGet(x => x.LearnerHEEntity) .Returns(mockHE.Object); var mockDelivery = new Mock <ILearningDelivery>(); var deliveries = Collection.Empty <ILearningDelivery>(); 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 == TTACCOM_02Rule.Name), Moq.It.Is <string>(y => y == LearnRefNumber), null, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); mockHandler .Setup(x => x.BuildErrorMessageParameter( Moq.It.Is <string>(y => y == TTACCOM_02Rule.MessagePropertyName), Moq.It.Is <int>(y => y == candidate))) .Returns(new Mock <IErrorMessageParameter>().Object); var mockService = new Mock <IProvideLookupDetails>(MockBehavior.Strict); mockService .Setup(x => x.IsCurrent(LookupTimeRestrictedKey.TTAccom, candidate, testDate)) .Returns(false); var mockDerived = new Mock <IDD06>(MockBehavior.Strict); mockDerived .Setup(x => x.Derive(deliveries)) .Returns(testDate); var sut = new TTACCOM_02Rule(mockHandler.Object, mockService.Object, mockDerived.Object); // act sut.Validate(mockLearner.Object); // assert mockHandler.VerifyAll(); mockService.VerifyAll(); mockDerived.VerifyAll(); }