Ejemplo n.º 1
0
        public async Task Should_Not_Add_Url_Due_To_Project_Not_Found()
        {
            // Arrange
            var urlCreateDto = new UrlCreateBodyDto
            {
                Href       = "http://www.landesblasorchester.de",
                AnchorText = "Landesblasorchester Baden-Württemberg"
            };

            // Act
            HttpClient          client          = _authenticatedServer.CreateClient().AuthenticateWith(_staff);
            HttpResponseMessage responseMessage = await client
                                                  .PostAsync(ApiEndpoints.ProjectsController.AddUrl(Guid.NewGuid()), BuildStringContent(urlCreateDto));

            // Assert
            responseMessage.StatusCode.Should().Be(HttpStatusCode.NotFound);
            ValidationProblemDetails errorMessage = await DeserializeResponseMessageAsync <ValidationProblemDetails>(responseMessage);

            errorMessage.Title.Should().Be("Resource not found.");
            errorMessage.Status.Should().Be(404);
            errorMessage.Errors.Should().BeEquivalentTo(new Dictionary <string, string[]>()
            {
                { "ProjectId", new[] { "Project could not be found." } }
            });
        }
Ejemplo n.º 2
0
        public async Task Should_Add_Url()
        {
            // Arrange
            var urlCreateDto = new UrlCreateBodyDto
            {
                Href       = "http://www.landesblasorchester.de",
                AnchorText = "Landesblasorchester Baden-Württemberg"
            };
            var expectedDto = new UrlDto()
            {
                Href       = urlCreateDto.Href,
                AnchorText = urlCreateDto.AnchorText,
                CreatedBy  = _staff.DisplayName,
                CreatedAt  = FakeDateTime.UtcNow
            };

            // Act
            HttpResponseMessage responseMessage = await _authenticatedServer
                                                  .CreateClient()
                                                  .AuthenticateWith(_staff)
                                                  .PostAsync(ApiEndpoints.ProjectsController.AddUrl(ProjectDtoData.HoorayForHollywood.Id), BuildStringContent(urlCreateDto));

            // Assert
            responseMessage.StatusCode.Should().Be(HttpStatusCode.Created);
            UrlDto result = await DeserializeResponseMessageAsync <UrlDto>(responseMessage);

            result.Should().BeEquivalentTo(expectedDto, opt => opt.Excluding(r => r.Id));
            result.Id.Should().NotBeEmpty();
            responseMessage.Headers.Location.AbsolutePath.Should().Be($"/{ApiEndpoints.UrlsController.Get(result.Id)}");
        }