Ejemplo n.º 1
0
        public async Task <ActionResult <PublisherDto> > Create([FromBody] CreatePublisherCommand command)
        {
            var res = await Mediator.Send(command);

            return(Ok(await Mediator.Send(new GetPublisherDetailQuery {
                Id = res
            })));
        }
Ejemplo n.º 2
0
        public void Should_Not_Create_When_Command_Is_Invalid()
        {
            //Arrange
            var publisher = new CreatePublisherCommand {Name = String.Empty};

            //Act
            _createPublisherCommandHandler.Handle(publisher);

            //Assert
            _publisherRepository.Verify(r => r.Add(It.IsAny<Domain.Entities.Publisher>()), Times.Never);
        }
Ejemplo n.º 3
0
        public void Should_Create_When_Command_Is_Valid()
        {
            //Arrange
            var publisher = new CreatePublisherCommand {Name = "Robert Cecil Martin"};

            //Act
            _createPublisherCommandHandler.Handle(publisher);

            //Assert
            _publisherRepository.Verify(r => r.Add(It.IsAny<Domain.Entities.Publisher>()), Times.Once);
        }
Ejemplo n.º 4
0
        public IActionResult Post(CreatePublisherCommand command)
        {
            var result = _createPublisherCommandHandler.Handle(command);

            if (result.Success)
            {
                return(Ok(command));
            }

            return(BadRequest(result.Errors));
        }
Ejemplo n.º 5
0
        public void Name_Cant_Be_Null_Or_Empty(string name, bool isValid)
        {
            //Arrange
            var publisher = new CreatePublisherCommand {
                Name = name
            };

            //Act
            var validationResult = _createPublisherCommandValidator.Validate(publisher);

            //Assert
            validationResult.IsValid.Should().Be(isValid);
        }
        public void Must_Add_Valid_Publisher(string publisherName, HttpStatusCode httpStatusCode, int count)
        {
            //Arrange
            var publisher = new CreatePublisherCommand {
                Name = publisherName
            };

            //Act
            var httpResponseMessage = _httpClient.PostAsJsonAsync(url, publisher).Result;

            //Assert
            httpResponseMessage.StatusCode.Should().Be(httpStatusCode);
            (_publisherRepository.GetAllAsync().Result).Count().Should().Be(count);
        }
Ejemplo n.º 7
0
        public void Name_Cant_Be_Repeated(string name, bool exists)
        {
            //Arrange
            var createPublisherCommand = new CreatePublisherCommand {
                Name = name
            };

            _publisherRepositoryMock.Setup(a => a.ExistsAsync(name)).Returns(Task.FromResult(exists));

            //Act
            var validationResults = _createPublisherCommandValidator.Validate(createPublisherCommand);

            //Assert
            validationResults.IsValid.Should().Be(!exists);
        }
Ejemplo n.º 8
0
        public async Task <PublisherDto> CreatePublisher(CreatePublisherCommand command)
        {
            var publisher = await this.Add(new Publisher { Name = command.Name });

            return(publisher.ToDto());
        }
Ejemplo n.º 9
0
 public async Task <IHttpActionResult> Create([FromBody] CreatePublisherCommand command)
 {
     return(await this.Try(async() => await this._publisherRepository.CreatePublisher(command)));
 }