public async Task GivenProperCreateSlideCommandHandlerSuccessfullyCreatesSlide() { const int slideId = 1; const string slideName = "slideName"; const string slideContent = "slideContent"; var command = new CreateSlideCommand { Name = slideName, Content = slideContent }; var expectedResult = new SlideResponse { Id = slideId }; var createdSlide = new Slide { Id = slideId, Name = slideName, Content = slideContent }; _mockSlideWriter.CreateSlideAsync(Arg.Is(slideName), Arg.Is(slideContent)) .Returns(createdSlide); var handler = CreateHandler(); var actualResult = await handler.Handle(command, new CancellationToken()); actualResult.Should().BeEquivalentTo(expectedResult); }
public async Task GivenValidCreateCommandCreateSlideCreatesSlideSuccessfully() { // Arrange const string slideName = "slideName"; const string slideContent = "slideContent"; const string endpoint = "api/v1/slides/"; const int expectedId = 2; var command = new CreateSlideCommand { Name = slideName, Content = slideContent }; var expectedResult = new SlideResponse { Id = expectedId, Name = slideName, Content = slideContent }; var client = _factory.CreateClient(); var expectedLocation = client.BaseAddress + endpoint + expectedId; var json = JsonConvert.SerializeObject(command); var requestContent = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); // Act var response = await client.PostAsync(endpoint, requestContent); // Assert response.StatusCode.Should().Be((int)HttpStatusCode.Created); response.Headers.Location.AbsoluteUri.Should().BeEquivalentTo(expectedLocation); var responseBody = await response.Content.ReadAsStringAsync(); responseBody.Should().NotBeNullOrEmpty(); var slideResponse = JsonConvert.DeserializeObject <SlideResponse>(responseBody); slideResponse.Should().BeEquivalentTo(expectedResult); }
public async Task GivenCreateSlideCommandWithMissingNameCreateSlideReturnsBadRequest() { // Arrange const string slideContent = "slideContent"; const string endpoint = "api/v1/slides/"; var command = new CreateSlideCommand { Content = slideContent }; var client = _factory.CreateClient(); var json = JsonConvert.SerializeObject(command); var requestContent = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); // Act var response = await client.PostAsync(endpoint, requestContent); // Assert response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }
public async Task <IActionResult> CreateSlide([FromBody] CreateSlideCommand createSlideCommand) { var result = await _mediator.Send(createSlideCommand); return(CreatedAtAction(nameof(GetSlide), new { slideId = result.Id }, result)); }