Skip to content

Add HaveLocation, NotHaveLocation and Be308PermanentRedirect assertions - #153

Merged
adrianiftode merged 8 commits into
masterfrom
features/add-location-assertions
Jul 27, 2026
Merged

Add HaveLocation, NotHaveLocation and Be308PermanentRedirect assertions#153
adrianiftode merged 8 commits into
masterfrom
features/add-location-assertions

Conversation

@adrianiftode

@adrianiftode adrianiftode commented Jul 27, 2026

Copy link
Copy Markdown
Owner

HaveLocation assertions

 [Fact]
 public async Task Post_ReturnsCreatedAndWithContent()
 {
     // Arrange
     var client = _factory.CreateClient();

     // Act
     var response = await client.PostAsync("/api/comments", new StringContent(/*lang=json,strict*/ @"{
               ""author"": ""John"",
               ""content"": ""Hey, you...""
             }", Encoding.UTF8, "application/json"));

     // Assert
     response.Should().Be201Created()
         .And.HaveLocation().And.BeValue("http://localhost/api/Comments/1")
         .And.BeAs(new
     {
         Author = "John",
         Content = "Hey, you..."
     });
 }

NotHaveLocation assertions

        [Fact]
        public async Task Post_WithNoAuthorButWithContent_Returns_Bad_Request_With_No_Location()
        {
            // Arrange
            var client = _factory.CreateClient();

            // Act
            var response = await client.PostAsync("/api/comments", new StringContent(/*lang=json,strict*/ @"{
                                          ""content"": ""Hey, you...""
                                        }", Encoding.UTF8, "application/json"));

            // Assert
            response.Should().Be400BadRequest()
                .And.NotHaveLocation("Bad Request responses are not designed to have Location headers.");
        }

Addresses issue #58

@adrianiftode
adrianiftode marked this pull request as ready for review July 27, 2026 19:48
@adrianiftode
adrianiftode merged commit cfb3d6b into master Jul 27, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant