Skip to content

Commit

Permalink
Refactor test CreateTrip_TripWithNameExists_ReturnsBadRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
oreze committed Jun 2, 2024
1 parent b3c0637 commit a056f80
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions BackendTripRecruitmentTask.IntegrationTests/Features/TripTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,29 @@ public async Task CreateTrip_ValidInput_ReturnsOk()
[Fact]
public async Task CreateTrip_TripWithNameExists_ReturnsBadRequest()
{
var randomTripName = Guid.NewGuid().ToString();
var createTripDto = new CreateTripDto(
randomTripName,
var country = _dbContext.Countries.First(x => x.ThreeLetterCode == "POL");
var firstTrip = Trip.Create(
Guid.NewGuid().ToString(),
"Random description",
DateTime.UtcNow.AddDays(10),
50,
"Poland");
country);

await _dbContext.Trips.AddAsync(firstTrip);
await _dbContext.SaveChangesAsync();

var createTripWithSameNameDto = new CreateTripDto(
randomTripName,
firstTrip.Name,
"Random description2",
DateTime.UtcNow.AddDays(5),
10,
"Poland");

var json = JsonSerializer.Serialize(createTripDto);
var json = JsonSerializer.Serialize(createTripWithSameNameDto);
var content = new StringContent(json, Encoding.UTF8, "application/json");

var response = await _httpClient.PostAsync("/trips", content);

response.EnsureSuccessStatusCode();

var secondTripJson = JsonSerializer.Serialize(createTripWithSameNameDto);
var secondTripContent = new StringContent(secondTripJson, Encoding.UTF8, "application/json");
var secondTripResponse = await _httpClient.PostAsync("/trips", secondTripContent);

Assert.Equal(HttpStatusCode.BadRequest, secondTripResponse.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact]
Expand Down

0 comments on commit a056f80

Please sign in to comment.