Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Nov 26, 2023
1 parent 19a1b91 commit cb68ec0
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.14",
"version": "6.0.18",
"commands": [
"dotnet-ef"
]
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,23 @@ jobs:
RequesterServiceBus__RabbitMQConnectionOptions__PortNumber: 5672
RequesterServiceBus__RabbitMQConnectionOptions__UserName: ${{ secrets.RABBITMQ_INTEGRATION_TEST_USERNAME }}
RequesterServiceBus__RabbitMQConnectionOptions__VirtualHost: aktabook_vhost
RequesterServiceDbContext__SqlServerConfig__DataSource: 127.0.0.1
RequesterServiceDbContext__SqlServerConfig__DataSource: localhost
RequesterServiceDbContext__SqlServerConfig__TrustServerCertificate: true
RequesterServiceDbContext__SqlServerConfig__InitialCatalog: aktabook_common
RequesterServiceDbContext__SqlServerConfig__Password: ${{ secrets.SQLSERVER_INTEGRATION_TEST_SA_PASSWORD }}
RequesterServiceDbContext__SqlServerConfig__UserID: sa
SQLSERVER_CLIENT_NUGET_VERSION: "5.1.0"
SQLSERVER_CLIENT_NUGET_VERSION: "5.1.1"

outputs:
artifact_name: ${{ steps.get_artifact_name.outputs.artifact_name }}

services:
sql_server:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: ${{ secrets.SQLSERVER_INTEGRATION_TEST_SA_PASSWORD }}
ACCEPT_EULA: "Y"
MSSQL_PID: Developer
MSSQL_SA_PASSWORD: ${{ secrets.SQLSERVER_INTEGRATION_TEST_SA_PASSWORD }}
SQLCMDUSER: sa
SQLCMDPASSWORD: ${{ secrets.SQLSERVER_INTEGRATION_TEST_SA_PASSWORD }}
ports:
Expand Down Expand Up @@ -213,7 +214,7 @@ jobs:
TrustServerCertificate = bool.Parse(Args[1]),
UserID = Args[2],
Password = Args[3],
InitialCatalog = Args[4]
InitialCatalog = Args[4],
}).ConnectionString);'
)""
>> $GITHUB_ENV
Expand Down
6 changes: 6 additions & 0 deletions test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = false

[*.cs]

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ public async Task GivenHandle_WhenCommand_ThenChangeBookInfoRequestStatus()
new(new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd"), "Dummy");
ChangeBookInfoRequestStatusHandler handler = new(_bookInfoRequestServiceMock);

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

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

result.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public async Task GivenHandle_WhenCommand_ThenBookInfoRequestId()

PlaceBookInfoRequestHandler handler = new(_bookInfoRequestServiceMock, _endpointInstanceMock);

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

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(true);
.GetEndpointInstance();

Guid bookInfoRequestId = Guid.NewGuid();

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

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

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

context.PublishedMessages.Should().HaveCount(3);
context.RepliedMessages.Should().BeEmpty();
Expand Down Expand Up @@ -97,11 +96,10 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsWork_ThenSaveToDbCont
TestableMessageHandlerContext context = new();

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

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

[Fact]
Expand Down Expand Up @@ -135,8 +133,7 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsNull_ThenPublishThree
TestableMessageHandlerContext context = new();

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

context.PublishedMessages.Should().HaveCount(3);
context.RepliedMessages.Should().BeEmpty();
Expand Down Expand Up @@ -174,10 +171,9 @@ public async Task GivenHandle_WhenGetBookByIsbnAsyncReturnsNull_ThenDoNotUseDbCo
TestableMessageHandlerContext context = new();

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

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

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

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

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

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

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

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

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

result.Should().BeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public async Task GivenGetBookByIsbnAsync_WhenIsbnFound_ThenBook()

OpenLibraryClient openLibraryClient = new(httpClient);

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

result.Should().BeOfType<Work>();
}
Expand All @@ -38,8 +37,7 @@ public async Task GivenGetBookByIsbnAsync_WhenIsbnNotFound_ThenNull()

OpenLibraryClient openLibraryClient = new(httpClient);

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

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

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

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

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

[Fact]
Expand All @@ -76,8 +74,7 @@ public async Task GivenGetAuthorAsync_WhenAuthorId_ThenAuthor()
JsonSerializer.Serialize(new Author()));
OpenLibraryClient openLibraryClient = new(httpClient);

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

result.Should().BeOfType<Author>();
}
Expand All @@ -89,8 +86,7 @@ public async Task GivenGetAuthorAsync_WhenAuthorIdNotFound_ThenNull()
HttpClientMockFactory.CreateHttpClient(HttpStatusCode.NotFound, string.Empty);
OpenLibraryClient openLibraryClient = new(httpClient);

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

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

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

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

await openLibraryClient.Awaiting(x => x.GetAuthorAsync(
"Dummy author ID", CancellationToken.None)).Should()
.ThrowExactlyAsync<JsonException>().ConfigureAwait(true);
.ThrowExactlyAsync<JsonException>();
}
}
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(true);
await httpClient.GetAsync("/api/bookinforequest/");

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(true);
HttpResponseMessage response = await httpClient.GetAsync(uri);

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(true);
HttpResponseMessage response = await httpClient.GetAsync(uri);

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(true);
_ = await response.Content.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(true);
uri, new CreateBookInfoRequestRequest { Isbn = "9780199572199" });
_ = await response.Content.ReadFromJsonAsync<CreateBookInfoRequestResponse>();

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(true);
new CreateBookInfoRequestRequest { Isbn = "9780199572199" });
CreateBookInfoRequestResponse? result = await response.Content
.ReadFromJsonAsync<CreateBookInfoRequestResponse>().ConfigureAwait(true);
.ReadFromJsonAsync<CreateBookInfoRequestResponse>();

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(true);
new CreateBookInfoRequestRequest { Isbn = "9780199572199" });

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

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

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(true);
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" });

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(true);
new CreateBookInfoRequestRequest { Isbn = "Invalid ISBN" });

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

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

0 comments on commit cb68ec0

Please sign in to comment.