public async Task NotificationNoMovements_AnyMovementNumber_ReturnsTrue() { A.CallTo(() => repository.GetAllMovements(NotificationId)).Returns(new Movement[0]); var result = await validator.Validate(NotificationId, 1); Assert.True(result); }
public async Task <Movement> Create(Guid notificationId, int number, DateTime?prenotificationDate, DateTime actualShipmentDate, bool hasNoPrenotification) { if (hasNoPrenotification && prenotificationDate.HasValue) { throw new ArgumentException("Can't provide prenotification date if there is no prenotification", "prenotificationDate"); } if (!await movementNumberValidator.Validate(notificationId, number)) { throw new MovementNumberException("Cannot create a movement with a conflicting movement number (" + number + ") for notification: " + notificationId); } var notificationStatus = (await assessmentRepository.GetByNotificationId(notificationId)).Status; if (notificationStatus != NotificationStatus.Consented) { throw new InvalidOperationException( string.Format("Cannot create a movement for notification {0} because its status is {1}", notificationId, notificationStatus)); } if (prenotificationDate.HasValue) { if (prenotificationDate > SystemTime.UtcNow.Date) { throw new InvalidOperationException("The prenotification date cannot be in the future."); } if (actualShipmentDate < prenotificationDate) { throw new InvalidOperationException("The actual date of shipment cannot be before the prenotification date."); } if (actualShipmentDate > prenotificationDate.Value.AddDays(60)) { throw new InvalidOperationException("The actual date of shipment should not be more than 30 calendar days after the prenotification date."); } } var movement = Movement.Capture(number, notificationId, actualShipmentDate, prenotificationDate, hasNoPrenotification, userContext.UserId); return(movement); }
public async Task SameNumberAlreadyExists_Throws() { A.CallTo(() => validator.Validate(NotificationId, A <int> .Ignored)) .Returns(false); await Assert.ThrowsAsync <MovementNumberException>(() => factory.Create(NotificationId, 1, null, AnyDate, true)); }