Exemple #1
0
        public ActionResult Post([FromBody] BookReadModel model)
        {
            var command = new RegisterBookCommand {
                Id = model.Id
            };

            _commandAdapter.Dispatch(command);

            return(CreatedAtAction("Get", new { id = model.Id }, model));
        }
Exemple #2
0
        public ActionResult Put(int id, [FromBody] BookReadModel model)
        {
            if (id != model.Id)
            {
                return(BadRequest());
            }

            var command = new UpdateBookCommand {
                Id = model.Id
            };

            _commandAdapter.Dispatch(command);

            return(NoContent());
        }
        public void Post_ValidObjectPassed_ReturnsCreatedResponse()
        {
            using (var mock = AutoMock.GetStrict())
            {
                // Arrange
                mock.Mock <IAzureServiceBusCommandAdapter>()
                .Setup(_ => _.Dispatch(It.IsAny <ICreateBookCommand>()));

                var controller = mock.Create <BooksController>();
                var model      = new BookReadModel {
                    Id = 1
                };

                // Act
                var response = controller.Post(model);

                // Assert
                Assert.IsType <CreatedAtActionResult>(response);
                mock.Mock <IAzureServiceBusCommandAdapter>().VerifyAll();
            }
        }