Beispiel #1
0
        public void Test_Add_Happy_Flow()
        {
            var todoResponse = processor.Handle(new TodoCommand()
            {
                Operation = EnumOperation.Add,
                Title     = "some task"
            });

            Assert.IsTrue(todoResponse.IsSuccess);
        }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] TodoCommand command)
        {
            try
            {
                var processorResponse = await Task.Run(() => _processor.Handle(command)); //wrapping as Task to utilize async/await pattern

                if (processorResponse.IsSuccess)
                {
                    _logger.LogInformation($"Command {command.OperationUUID} Operation:{command.Operation} completed successfully");
                    return(Ok(processorResponse));
                }
                else
                {
                    _logger.LogError($"Command {command.OperationUUID} Operation:{command.Operation} completed with error: {processorResponse.ErrorMessage}");
                    return(StatusCode(500, processorResponse));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Command {command.OperationUUID} Operation:{command.Operation} completed with error: {ex.ToString()}");
                return(StatusCode(500, command.CreateErrorResponse(ex.Message)));
            }
        }