public async Task UpdateMovementDateHandler_LogsAuditAsEdited() { var request = GetRequest(); await handler.HandleAsync(request); A.CallTo( () => movementAuditRepository.Add( A <MovementAudit> .That.Matches( m => m.NotificationId == notificationId && m.Type == (int)MovementAuditType.Edited))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task <bool> HandleAsync(UpdateMovementDate message) { var movement = await repository.GetById(message.MovementId); await movement.UpdateDate(message.NewDate, validator); await context.SaveChangesAsync(); await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number, userContext.UserId.ToString(), (int)MovementAuditType.Edited, SystemTime.Now)); await context.SaveChangesAsync(); return(true); }
public async Task <Guid> HandleAsync(SetMovementAccepted message) { var movement = await movementRepository.GetById(message.MovementId); movement.Receive(message.FileId, message.DateReceived, new Domain.ShipmentQuantity(message.Quantity, message.Units), userContext.UserId); await context.SaveChangesAsync(); await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number, userContext.UserId.ToString(), (int)MovementAuditType.Received, message.AuditDate)); await context.SaveChangesAsync(); return(message.MovementId); }
public async Task <Guid[]> HandleAsync(CreateMovements message) { var newIds = new List <Guid>(); using (var transaction = context.Database.BeginTransaction()) { try { for (int i = 0; i < message.NumberToCreate; i++) { var movement = await movementFactory.Create(message.NotificationId, message.ActualMovementDate); context.Movements.Add(movement); await context.SaveChangesAsync(); var shipmentQuantity = new ShipmentQuantity(message.Quantity, message.Units); var packagingInfos = await GetPackagingInfos(message.NotificationId, message.PackagingTypes); var movementDetails = await movementDetailsFactory.Create( movement, shipmentQuantity, packagingInfos); context.MovementDetails.Add(movementDetails); await context.SaveChangesAsync(); newIds.Add(movement.Id); await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number, userContext.UserId.ToString(), (int)MovementAuditType.Incomplete, SystemTime.Now)); await context.SaveChangesAsync(); } } catch { transaction.Rollback(); throw; } transaction.Commit(); } return(newIds.ToArray()); }
public async Task <Guid> HandleAsync(SetMovementRejected message) { var movement = await movementRepository.GetById(message.MovementId); var file = await certificateFactory.CreateForMovement(nameGenerator, movement, message.FileBytes, message.FileType); var fileId = await fileRepository.Store(file); var movementRejection = await rejectMovement.Reject(message.MovementId, message.DateReceived, message.Reason); movementRejection.SetFile(fileId); await context.SaveChangesAsync(); await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number, userContext.UserId.ToString(), (int)MovementAuditType.Rejected, SystemTime.Now)); await context.SaveChangesAsync(); return(message.MovementId); }