Skip to content

Commit

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

var createTripJson = JsonSerializer.Serialize(createTripDto);
var createTripContent = new StringContent(createTripJson, Encoding.UTF8, "application/json");
var createTripResponse = await _httpClient.PostAsync("/trips", createTripContent);
createTripResponse.EnsureSuccessStatusCode();
var tripID = await createTripResponse.Content.ReadFromJsonAsync<int>();
Assert.NotEqual(0, tripID);
country);

await _dbContext.AddAsync(trip);
await _dbContext.SaveChangesAsync();

var deleteTripResponse = await _httpClient.DeleteAsync($"/trips/{tripID}");
var deleteTripResponse = await _httpClient.DeleteAsync($"/trips/{trip.ID}");

deleteTripResponse.EnsureSuccessStatusCode();
var deletedTrip = await _dbContext.Trips.FindAsync(tripID);
var wasDeleted = await deleteTripResponse.Content.ReadFromJsonAsync<bool>();
Assert.True(wasDeleted);

var deletedTrip = await _dbContext.Trips.FirstOrDefaultAsync(x => x.ID == trip.ID);
Assert.Null(deletedTrip);
}

Expand Down

0 comments on commit 4b85a4b

Please sign in to comment.