c#
[Fact]
public async Task UpdatePost_OwnPost_ReturnsOk()
{
// Arrange
var (token, userId) = await factory.AuthenticateUser("updateuser1");
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var postId = await factory.CreateTestPost(userId, "Original Title", "Original body content");
var updateRequest = new UpdatePost.Request(
postId,
"Updated Title",
"Updated body content",
new Uri("https://example.com/updated.jpg")
);
// Act
var response = await _client.PutAsJsonAsync($"/api/posts/{postId}", updateRequest);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var result = await response.Content.ReadFromJsonAsync<UpdatePost.Response>(_jsonOptions);
result.Should().NotBeNull();
result.Id.Should().Be(postId);
result.Title.Should().Be(updateRequest.Title);
// Verify database was updated
using var scope = factory.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<BlogDbContext>();
var updatedPost = await dbContext.Posts.FindAsync(postId);
updatedPost.Should().NotBeNull();
updatedPost.Title.Should().Be(updateRequest.Title);
updatedPost.Body.Should().Be(updateRequest.Body);
updatedPost.CoverImageUrl.Should().Be(updateRequest.CoverImageUrl);
updatedPost.UpdatedAtUtc.Should().NotBeNull();
}