Skip to content

Commit

Permalink
test: Set ConfigureAwait
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Nov 12, 2023
1 parent c549146 commit fd61a76
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public async Task GivenHandle_WhenCommand_ThenChangeBookInfoRequestStatus()
ChangeBookInfoRequestStatusHandler handler = new(_bookInfoRequestServiceMock);

bool result = await handler.Handle(changeBookInfoRequestStatus, CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

await _bookInfoRequestServiceMock.Received(1).ChangeRequestStatus(
new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd"), "Dummy",
CancellationToken.None).ConfigureAwait(false);
CancellationToken.None).ConfigureAwait(true);

result.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task GivenHandle_WhenCommand_ThenBookInfoRequestId()
PlaceBookInfoRequestHandler handler = new(_bookInfoRequestServiceMock, _endpointInstanceMock);

Guid bookInfoRequestId = await handler.Handle(placeBookInfoRequest, CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

bookInfoRequestId.Should().Be(new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd"));
}
Expand Down
4 changes: 2 additions & 2 deletions test/Aktabook.Bus.IntegrationTest/EndpointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public EndpointTest(BusEndpointFixture busEndpointFixture)
public async Task GivenSend_WhenMessage_ThenMessageInQueue()
{
IEndpointInstance endpointInstance = await _busEndpointFixture
.GetEndpointInstance().ConfigureAwait(false);
.GetEndpointInstance().ConfigureAwait(true);

Guid bookInfoRequestId = Guid.NewGuid();

ProcessBookInfoRequest processBookInfoRequest = new(bookInfoRequestId, "Dummy ISBN");

await endpointInstance.Awaiting(x => x
.Send(processBookInfoRequest)).Should().NotThrowAsync().ConfigureAwait(false);
.Send(processBookInfoRequest)).Should().NotThrowAsync().ConfigureAwait(true);
}
}
14 changes: 7 additions & 7 deletions test/Aktabook.Bus.UnitTest/BookInfoRequestHandlerUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task GivenHandle_WhenProcessBookInfoRequest_ThenPublishThreeMessage

await handler
.Handle(new ProcessBookInfoRequest(Guid.Empty, "Dummy ISBN"), context)
.ConfigureAwait(false);
.ConfigureAwait(true);

context.PublishedMessages.Should().HaveCount(3);
context.RepliedMessages.Should().BeEmpty();
Expand Down Expand Up @@ -98,10 +98,10 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsWork_ThenSaveToDbCont

await handler
.Handle(new ProcessBookInfoRequest(Guid.Empty, "Dummy ISBN"), context)
.ConfigureAwait(false);
.ConfigureAwait(true);

await _bookSetMock.Received(1).AddAsync(Arg.Any<Book>(), Arg.Any<CancellationToken>()).ConfigureAwait(false);
await _requesterServiceDbContextMock.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>()).ConfigureAwait(false);
await _bookSetMock.Received(1).AddAsync(Arg.Any<Book>(), Arg.Any<CancellationToken>()).ConfigureAwait(true);
await _requesterServiceDbContextMock.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>()).ConfigureAwait(true);
}

[Fact]
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsNull_ThenPublishThree

await handler
.Handle(new ProcessBookInfoRequest(Guid.Empty, "Dummy ISBN"), context)
.ConfigureAwait(false);
.ConfigureAwait(true);

context.PublishedMessages.Should().HaveCount(3);
context.RepliedMessages.Should().BeEmpty();
Expand Down Expand Up @@ -175,9 +175,9 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsNull_ThenDoNotUseDbCo

await handler
.Handle(new ProcessBookInfoRequest(Guid.Empty, "Dummy ISBN"), context)
.ConfigureAwait(false);
.ConfigureAwait(true);

var _ = _bookSetMock.DidNotReceive().AddAsync(Arg.Any<Book>(), Arg.Any<CancellationToken>());
await _requesterServiceDbContextMock.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>()).ConfigureAwait(false);
await _requesterServiceDbContextMock.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>()).ConfigureAwait(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task GivenGetBookByIsbnAsync_WhenIsbnForExistingBook_ThenWork(strin
OpenLibraryClient openLibraryClient = new(HttpClient);

Work? result = await openLibraryClient.GetBookByIsbnAsync(isbn, CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeOfType<Work>();
}
Expand All @@ -46,7 +46,7 @@ public async Task GivenGetBookByIsbnAsync_WhenInvalidIsbn_ThenValueIsNull()
OpenLibraryClient openLibraryClient = new(HttpClient);

Work? result = await openLibraryClient.GetBookByIsbnAsync("0", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeNull();
}
Expand All @@ -57,7 +57,7 @@ public async Task GivenGetAuthorAsync_WhenAuthorId_ThenAuthor()
OpenLibraryClient openLibraryClient = new(HttpClient);

Author? result = await openLibraryClient.GetAuthorAsync("OL23919A", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeOfType<Author>();
}
Expand All @@ -68,7 +68,7 @@ public async Task GivenGetAuthorAsync_WhenNonExistingAuthorId_ThenValueIsNull()
OpenLibraryClient openLibraryClient = new(HttpClient);

Author? result = await openLibraryClient.GetAuthorAsync("0", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task GivenGetBookByIsbnAsync_WhenIsbnFound_ThenBook()
OpenLibraryClient openLibraryClient = new(httpClient);

Work? result = await openLibraryClient.GetBookByIsbnAsync("Dummy ISBN", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeOfType<Work>();
}
Expand All @@ -39,7 +39,7 @@ public async Task GivenGetBookByIsbnAsync_WhenIsbnNotFound_ThenNull()
OpenLibraryClient openLibraryClient = new(httpClient);

Work? result = await openLibraryClient.GetBookByIsbnAsync("Dummy ISBN", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeNull();
}
Expand All @@ -54,7 +54,7 @@ public async Task GivenGetBookByIsbnAsync_WhenError_ThenError()

await openLibraryClient.Awaiting(x => x.GetBookByIsbnAsync(
"Dummy ISBN", CancellationToken.None))
.Should().ThrowExactlyAsync<HttpRequestException>().ConfigureAwait(false);
.Should().ThrowExactlyAsync<HttpRequestException>().ConfigureAwait(true);
}

[Fact]
Expand All @@ -66,7 +66,7 @@ public async Task GivenGetBookByIsbnAsync_WhenInvalidResponse_ThenException()

await openLibraryClient.Awaiting(x => x.GetBookByIsbnAsync("Dummy ISBN",
CancellationToken.None))
.Should().ThrowExactlyAsync<JsonException>().ConfigureAwait(false);
.Should().ThrowExactlyAsync<JsonException>().ConfigureAwait(true);
}

[Fact]
Expand All @@ -77,7 +77,7 @@ public async Task GivenGetAuthorAsync_WhenAuthorId_ThenAuthor()
OpenLibraryClient openLibraryClient = new(httpClient);

Author? result = await openLibraryClient.GetAuthorAsync("Dummy author ID", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeOfType<Author>();
}
Expand All @@ -90,7 +90,7 @@ public async Task GivenGetAuthorAsync_WhenAuthorIdNotFound_ThenNull()
OpenLibraryClient openLibraryClient = new(httpClient);

Author? result = await openLibraryClient.GetAuthorAsync("Dummy author ID", CancellationToken.None)
.ConfigureAwait(false);
.ConfigureAwait(true);

result.Should().BeNull();
}
Expand All @@ -104,7 +104,7 @@ public async Task GivenGetAuthorAsync_WhenHttpError_ThenThrowHttpRequestExceptio

await openLibraryClient.Awaiting(x =>
x.GetAuthorAsync("Dummy author ID", CancellationToken.None))
.Should().ThrowExactlyAsync<HttpRequestException>().ConfigureAwait(false);
.Should().ThrowExactlyAsync<HttpRequestException>().ConfigureAwait(true);
}

[Fact]
Expand All @@ -115,6 +115,6 @@ public async Task GivenGetAuthorAsync_WhenInvalidResponse_ThenException()

await openLibraryClient.Awaiting(x => x.GetAuthorAsync(
"Dummy author ID", CancellationToken.None)).Should()
.ThrowExactlyAsync<JsonException>().ConfigureAwait(false);
.ThrowExactlyAsync<JsonException>().ConfigureAwait(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task GivenGet_WhenNoId_ThenResponseStatusCodeIsNotImplemented()
HttpClient httpClient = _app.CreateClient();

HttpResponseMessage response =
await httpClient.GetAsync("/api/bookinforequest/").ConfigureAwait(false);
await httpClient.GetAsync("/api/bookinforequest/").ConfigureAwait(true);

response.Should().HaveStatusCode(HttpStatusCode.NotImplemented)
.And.HaveError()
Expand All @@ -53,7 +53,7 @@ public async Task GivenGet_WhenIncorrectEndpointHandle_ThenRespondWithNotFound(s
{
HttpClient httpClient = _app.CreateClient();

HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(true);

response.Should().HaveStatusCode(HttpStatusCode.NotFound)
.And.Subject.Content.Headers.ContentType.Should().BeNull();
Expand All @@ -65,7 +65,7 @@ public async Task GivenGet_WhenCorrectEndpointHandle_ThenResponseStatusCodeIsNot
{
HttpClient httpClient = _app.CreateClient();

HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(true);

response.Should().HaveStatusCode(HttpStatusCode.NotImplemented)
.And.HaveError()
Expand All @@ -83,8 +83,8 @@ public async Task GivenPostEndpoints_WhenValidRequest_ThenResponseStatusCodeIsAc
HttpClient httpClient = _app.CreateClient();

HttpResponseMessage response = await httpClient.PostAsJsonAsync(
uri, new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(false);
_ = await response.Content.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(false);
uri, new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(true);
_ = await response.Content.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(true);

response.Should().HaveStatusCode(HttpStatusCode.Accepted)
.And.Subject.Content
Expand All @@ -100,9 +100,9 @@ public async Task GivenPostEndpoints_WhenValidRequest_ThenResponseIsValid()

HttpResponseMessage response = await httpClient.PostAsJsonAsync(
"api/BookInfoRequest",
new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(false);
new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(true);
CreateBookInfoRequestResponse? result = await response.Content
.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(false);
.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(true);

result.Should().BeOfType<CreateBookInfoRequestResponse>()
.Which.BookInfoRequestId.Should().NotBeEmpty();
Expand All @@ -115,17 +115,17 @@ public async Task GivenPostEndpoints_WhenValidRequest_ThenDatabaseIsUpdated()

HttpResponseMessage response = await httpClient.PostAsJsonAsync(
"api/BookInfoRequest",
new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(false);
new CreateBookInfoRequestRequest { Isbn = "9780199572199" }).ConfigureAwait(true);

CreateBookInfoRequestResponse? result = await response.Content
.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(false);
.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(true);
result.Should().BeOfType<CreateBookInfoRequestResponse>();

BookInfoRequest bookInfoRequest = await _app.RequesterServiceDbContext
.BookInfoRequests
.AsNoTracking()
.Include(x => x.BookInfoRequestLogEntries)
.SingleAsync(x => x.BookInfoRequestId == result!.BookInfoRequestId).ConfigureAwait(false);
.SingleAsync(x => x.BookInfoRequestId == result!.BookInfoRequestId).ConfigureAwait(true);

BookInfoRequest expected = new() { Isbn = "9780199572199" };
expected.BookInfoRequestLogEntries.Add(new BookInfoRequestLogEntry
Expand All @@ -148,7 +148,7 @@ public async Task GivenPostEndpoints_WhenInvalidRequest_ThenResponseStatusCodeIs

HttpResponseMessage response = await httpClient.PostAsJsonAsync(
"api/BookInfoRequest",
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" }).ConfigureAwait(false);
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" }).ConfigureAwait(true);

response.Should().HaveStatusCode(HttpStatusCode.BadRequest)
.And.Subject.Content.Headers.ContentType.Should()
Expand All @@ -164,10 +164,10 @@ public async Task GivenPostEndpoints_WhenInvalidRequest_ThenResponseIsError()

HttpResponseMessage response = await httpClient.PostAsJsonAsync(
"api/BookInfoRequest",
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" }).ConfigureAwait(false);
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" }).ConfigureAwait(true);

ValidationProblemDetails? result = await response.Content
.ReadFromJsonAsync<ValidationProblemDetails>().ConfigureAwait(false);
.ReadFromJsonAsync<ValidationProblemDetails>().ConfigureAwait(true);

result.Should().BeOfType<ValidationProblemDetails>()
.Which.Errors.Should().HaveCount(1);
Expand Down
Loading

0 comments on commit fd61a76

Please sign in to comment.