public async Task HandleApproveDocument(ApproveDocument command) { var aggregate = await _eventStreamReader.GetAggregate <DocumentAggregate>(command.StreamId); var resultedEvent = aggregate.ApproveDocument(command); await aggregate.Save(resultedEvent); }
public DocumentApproved ApproveDocument(ApproveDocument command) { return(new DocumentApproved { EventType = nameof(DocumentApproved), Timstamp = DateTime.UtcNow, DateApproved = DateTime.UtcNow, ApprovedBy = command.Approver }); }
private static async Task Main(string[] args) { IoC.RegisterServices(); var commandHandler = new CommandHandler((IEventStreamReader)IoC.ServiceProvider.GetService(typeof(IEventStreamReader))); var streamId = Guid.Parse("e8512419-0183-42c9-b6df-0c4ea603ad00"); Guid documentId; var quit = false; while (!quit) { var key = UI(); switch (key) { case "1": var command = new CreateDocument { StreamId = streamId, Artifacts = new Dictionary <string, string>(), Name = Guid.NewGuid().ToString() }; await commandHandler.HandleCreateDocument(command); Console.WriteLine(); Console.WriteLine("Document created."); Console.WriteLine(); break; case "2": Console.WriteLine(); Console.WriteLine("Please, inform the new name of the dcocument:"); var name = Console.ReadLine(); var commandRename = new RenameDocument { StreamId = streamId, Name = name }; await commandHandler.HandleRenameDocument(commandRename); Console.WriteLine(); Console.WriteLine($"Document renamed"); Console.WriteLine(); break; case "3": Console.WriteLine(); var commandUpdate = new UpdateArtifacts { StreamId = streamId, AddArtifacts = new Dictionary <string, string> { { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() } }, RemoveArtifacts = new List <string>() }; await commandHandler.HandleUpdateArtifacts(commandUpdate); Console.WriteLine(); Console.WriteLine($"Artifacts Updated!"); Console.WriteLine(); break; case "4": Console.WriteLine(); Console.WriteLine("Please, inform the approver name"); var approverName = Console.ReadLine(); var commandApprove = new ApproveDocument { StreamId = streamId, Approver = approverName }; await commandHandler.HandleApproveDocument(commandApprove); Console.WriteLine(); Console.WriteLine($"Document approved"); Console.WriteLine(); break; case "5": Console.WriteLine(); Console.WriteLine("Please, inform the approver name"); var rejecterName = Console.ReadLine(); var commandReject = new RejectDocument { StreamId = streamId, Rejecter = rejecterName }; await commandHandler.HandleRejectDocument(commandReject); Console.WriteLine(); Console.WriteLine($"Document rejected"); Console.WriteLine(); break; case "6": Console.WriteLine(); var commandDelete = new DeleteDocument { StreamId = streamId }; await commandHandler.HandleDeleteDocument(commandDelete); Console.WriteLine(); Console.WriteLine($"Document deleted"); Console.WriteLine(); break; case "Q": quit = true; break; case "q": quit = true; break; default: Console.WriteLine(); Console.WriteLine("Invalid option, chose a valid command"); Console.WriteLine(); break; } } }
public void Setup() { _dbGatewayMock = new Mock <ILocalDatabaseGateway>(); _subject = new ApproveDocument(_dbGatewayMock.Object); _fixture = new Fixture(); }