public async Task WhenNoPreviousDates_ReturnsMovementDate() { var movementDate = new DateTime(2015, 1, 1); var movement = new Movement(1, AnyGuid, movementDate, userId); var dateService = new OriginalMovementDate(historyRepository); Assert.Equal(movementDate, await dateService.Get(movement)); }
public async Task WhenOnePreviousDate_ReturnsPreviousDate() { var movement = new Movement(1, AnyGuid, AnyDate, userId); var previousDate = new DateTime(2015, 1, 2); A.CallTo(() => historyRepository.GetByMovementId(A <Guid> .Ignored)) .Returns(new[] { new MovementDateHistory(AnyGuid, previousDate) }); var dateService = new OriginalMovementDate(historyRepository); Assert.Equal(previousDate, await dateService.Get(movement)); }
public async Task WhenOnePreviousDate_ReturnsPreviousDate() { var movement = new Movement(1, AnyGuid, AnyDate, userId); var previousDate = new DateTime(2015, 1, 2); A.CallTo(() => historyRepository.GetByMovementId(A<Guid>.Ignored)) .Returns(new[] { new MovementDateHistory(AnyGuid, previousDate) }); var dateService = new OriginalMovementDate(historyRepository); Assert.Equal(previousDate, await dateService.Get(movement)); }
public MovementDateValidatorTests() { consentRepository = A.Fake <INotificationConsentRepository>(); notificationRepository = A.Fake <INotificationApplicationRepository>(); historyRepository = A.Fake <IMovementDateHistoryRepository>(); workingDayCalculator = A.Fake <IWorkingDayCalculator>(); dateValidator = new MovementDateValidator(consentRepository); originalMovementDate = new OriginalMovementDate(historyRepository); updatedDateValidator = new UpdatedMovementDateValidator(dateValidator, originalMovementDate, workingDayCalculator, notificationRepository); SystemTime.Freeze(Today.AddHours(5)); A.CallTo(() => consentRepository.GetByNotificationId(NotificationId)) .Returns(new Consent( NotificationId, new DateRange(ConsentStart, ConsentEnd), AnyString, AnyGuid)); A.CallTo(() => notificationRepository.GetByMovementId(A <Guid> .Ignored)) .Returns(new NotificationApplication( AnyGuid, NotificationType.Recovery, UKCompetentAuthority.England, 10)); A.CallTo(() => historyRepository.GetByMovementId(A <Guid> .Ignored)) .Returns(new MovementDateHistory[0]); A.CallTo(() => workingDayCalculator.AddWorkingDays(A <DateTime> .Ignored, A <int> .Ignored, A <bool> .Ignored, A <UKCompetentAuthority> .Ignored)) .ReturnsLazily((DateTime inputDate, int inputDays, bool includeStartDay, UKCompetentAuthority ca) => //A very simple working day formula that ignores bank holidays taken from http://stackoverflow.com/a/279370 inputDate.AddDays(inputDays + ((inputDays / 5) * 2) + ((((int)inputDate.DayOfWeek + (inputDays % 5)) >= 5) ? 2 : 0))); }
public MovementDateValidatorTests() { consentRepository = A.Fake<INotificationConsentRepository>(); notificationRepository = A.Fake<INotificationApplicationRepository>(); historyRepository = A.Fake<IMovementDateHistoryRepository>(); workingDayCalculator = A.Fake<IWorkingDayCalculator>(); dateValidator = new MovementDateValidator(consentRepository); originalMovementDate = new OriginalMovementDate(historyRepository); updatedDateValidator = new UpdatedMovementDateValidator(dateValidator, originalMovementDate, workingDayCalculator, notificationRepository); SystemTime.Freeze(Today.AddHours(5)); A.CallTo(() => consentRepository.GetByNotificationId(NotificationId)) .Returns(new Consent( NotificationId, new DateRange(ConsentStart, ConsentEnd), AnyString, AnyGuid)); A.CallTo(() => notificationRepository.GetByMovementId(A<Guid>.Ignored)) .Returns(new NotificationApplication( AnyGuid, NotificationType.Recovery, UKCompetentAuthority.England, 10)); A.CallTo(() => historyRepository.GetByMovementId(A<Guid>.Ignored)) .Returns(new MovementDateHistory[0]); A.CallTo(() => workingDayCalculator.AddWorkingDays(A<DateTime>.Ignored, A<int>.Ignored, A<bool>.Ignored, A<UKCompetentAuthority>.Ignored)) .ReturnsLazily((DateTime inputDate, int inputDays, bool includeStartDay, UKCompetentAuthority ca) => //A very simple working day formula that ignores bank holidays taken from http://stackoverflow.com/a/279370 inputDate.AddDays(inputDays + ((inputDays / 5) * 2) + ((((int)inputDate.DayOfWeek + (inputDays % 5)) >= 5) ? 2 : 0))); }
public async Task WhenMultiPreviousDates_ReturnsOldestPreviousDate() { var movement = new Movement(1, AnyGuid, AnyDate, userId); var oldestDateHistory = new MovementDateHistory(AnyGuid, new DateTime(2015, 1, 5)); ObjectInstantiator<MovementDateHistory>.SetProperty(m => m.DateChanged, new DateTime(2015, 10, 10), oldestDateHistory); var otherDateHistory = new MovementDateHistory(AnyGuid, new DateTime(2015, 1, 3)); ObjectInstantiator<MovementDateHistory>.SetProperty(m => m.DateChanged, new DateTime(2015, 10, 11), otherDateHistory); A.CallTo(() => historyRepository.GetByMovementId(A<Guid>.Ignored)) .Returns(new[] { oldestDateHistory, otherDateHistory }); var dateService = new OriginalMovementDate(historyRepository); Assert.Equal(oldestDateHistory.PreviousDate, await dateService.Get(movement)); }
public async Task WhenMultiPreviousDates_ReturnsOldestPreviousDate() { var movement = new Movement(1, AnyGuid, AnyDate, userId); var oldestDateHistory = new MovementDateHistory(AnyGuid, new DateTime(2015, 1, 5)); ObjectInstantiator <MovementDateHistory> .SetProperty(m => m.DateChanged, new DateTime(2015, 10, 10), oldestDateHistory); var otherDateHistory = new MovementDateHistory(AnyGuid, new DateTime(2015, 1, 3)); ObjectInstantiator <MovementDateHistory> .SetProperty(m => m.DateChanged, new DateTime(2015, 10, 11), otherDateHistory); A.CallTo(() => historyRepository.GetByMovementId(A <Guid> .Ignored)) .Returns(new[] { oldestDateHistory, otherDateHistory }); var dateService = new OriginalMovementDate(historyRepository); Assert.Equal(oldestDateHistory.PreviousDate, await dateService.Get(movement)); }