示例#1
0
        public override async Task <Empty> UpdateToDo(UpdateToDoRequest request, ServerCallContext context)
        {
            var command = new UpdateToDoCommand(request.Id, request.Description, request.Status, request.Username);
            await _mediator.Send(command);

            return(new Empty());
        }
        public async Task <IActionResult> UpdateToDo(UpdateToDoCommand command)
        {
            command.Username = User.Identity.Name;
            var result = await _mediator.Send(command);

            return(Ok(result));
        }
示例#3
0
        public async Task <ActionResult> UpdateToDo(int id, UpdateToDoCommand command)
        {
            command.UserId = User.GetUserId();
            command.Id     = id;

            await this.SendRequest(command);

            return(Ok());
        }
示例#4
0
        public async Task <IActionResult> Patch(int id, [FromBody] UpdateToDoRequest request)
        {
            var updatedCommand = new UpdateToDoCommand(id, request.Title, request.Completed, request.Order);
            await _commandProcessor.SendAsync(updatedCommand);

            var addedToDo = await _queryProcessor.ExecuteAsync(new ToDoByIdQuery(id));

            addedToDo.Url = Url.RouteUrl("GetTodo", new { id = addedToDo.Id }, protocol: Request.Scheme);

            return(Ok(addedToDo));
        }
        public async Task <IActionResult> PutAsync(UpdateToDoCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _itemToDoRepository.UpdateAsync(new ItemTodo
            {
                Id   = command.Id,
                Name = command.Name
            });

            return(Ok(command));
        }
        public async Task <ActionResult <int> > UpdateToDo([FromBody] UpdateToDoCommand command)
        {
            var result = await _mediator.Send(command);

            if (result.IsBadRequest)
            {
                return(BadRequest(result.ValidationFailures));
            }
            if (result.IsNotFound)
            {
                return(NotFound());
            }

            return(Ok());
        }
示例#7
0
        public ICommandResult Handler(UpdateToDoCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "ops, parece que sua tarefa esta errada", command.Notifications));
            }

            var todo = _repository.GetById(command.Id, command.User);

            todo.UpdateTitle(command.Title);

            _repository.Update(todo);

            return(new GenericCommandResult(true, "Salvo com sucesso", todo.Id));
        }
        public async Task <IActionResult> SaveUpdate(ToDoViewModel model)
        {
            //TODO: AutoMapper
            var command = new UpdateToDoCommand
            {
                Id          = model.Id,
                UserId      = model.UserId,
                Title       = model.Title,
                Description = model.Description,
                IsCompleted = model.IsCompleted
            };

            await _endpointInstance.Send(command).ConfigureAwait(false);

            return(RedirectToAction("ToDoList", "Home", new { userId = model.UserId }));
        }
示例#9
0
        public async Task Test_Updating_The_ToDo_Title_Completed_Order()
        {
            /*
             *  Given that I have a command to update a ToDo's title, complete, & order
             *  When I handle that command
             *  Then I should update the ToDo
             *
             */

            const string NEW_TITLE     = "New Title";
            const bool   NEW_COMPLETED = false;
            const int    NEW_ORDER     = 523;

            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase("order_title_completed_writes_to_database")
                          .Options;

            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem {
                Title = "Title", Completed = true, Order = 10
            };

            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, NEW_TITLE, NEW_COMPLETED, NEW_ORDER);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(NEW_TITLE, context.ToDoItems.Single().Title);
                Assert.AreEqual(NEW_COMPLETED, context.ToDoItems.Single().Completed);
                Assert.AreEqual(NEW_ORDER, context.ToDoItems.Single().Order);
            }

            // Should not send task complete event
            Assert.IsFalse(fakeCommandProcessor.SentCompletedEvent);
        }
示例#10
0
        public async Task Test_Updating_a_ToDo_Title_and_Completed()
        {
            /*
             *  Given that I have a command to pdate add a ToDo's Title and Completed
             *  When I handle that command
             *  Then I should update the ToDo
             *
             */

            const string TODO_TITLE = "test_title";

            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase("titlecompleted_writes_to_database")
                          .Options;

            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem {
                Title = "This title will be changed"
            };

            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, TODO_TITLE, true);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(TODO_TITLE, context.ToDoItems.Single().Title);
                Assert.AreEqual(true, context.ToDoItems.Single().Completed);
            }

            // Has sent task complete event
            Assert.IsTrue(fakeCommandProcessor.SentCompletedEvent);
        }
示例#11
0
        public async Task Test_Updating_The_ToDo_Order()
        {
            /*
                Given that I have a command to update a ToDo's complete
                When I handle that command
                Then I should update the ToDo

            */

            const int NEW_ORDER = 523;

            var options = new DbContextOptionsBuilder<ToDoContext>()
                .UseInMemoryDatabase(databaseName: "order_writes_to_database")
                .Options;
            
            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem() { Title = "This title won't be changed", Completed = true, Order = 10};
            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, order: NEW_ORDER);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(toDoItem.Title, context.ToDoItems.Single().Title);
                Assert.AreEqual(true, context.ToDoItems.Single().Completed);
                Assert.AreEqual(NEW_ORDER, context.ToDoItems.Single().Order);
            }

            // Should not send task complete event
            Assert.IsFalse(fakeCommandProcessor.SentCompletedEvent);
        }
示例#12
0
        public async Task ShouldHavePassWhenPutModelStateIsValidAndReturnOkAsync()
        {
            //arrange
            var controller = new ToDosController(_itemToDoRepository.Object);

            var command = new UpdateToDoCommand(_firstItem.Id, "Hello world!");

            //actual
            var result = await controller.PutAsync(command);

            //assert
            Assert.IsInstanceOf <OkObjectResult>(result);

            var response = result as OkObjectResult;

            Assert.IsInstanceOf <UpdateToDoCommand>(response.Value);

            var model = response.Value as UpdateToDoCommand;

            Assert.AreEqual(command.Name, model.Name);
        }
        public async Task <ActionResult> Update([FromBody] UpdateToDoCommand command)
        {
            await _mediator.Send(command);

            return(NoContent());
        }
示例#14
0
 public GenericCommandResult Update([FromBody] UpdateToDoCommand commad, [FromServices] TodoHandler handler)
 {
     commad.User = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;;
     return((GenericCommandResult)handler.Handler(commad));
 }