-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded api tests to breaking changes in Ogooreck
- Loading branch information
1 parent
e990396
commit 8b1fe99
Showing
41 changed files
with
558 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 23 additions & 51 deletions
74
Sample/ECommerce/Carts/Carts.Api.Tests/ShoppingCarts/Canceling/CancelShoppingCartTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,43 @@ | ||
using Carts.Api.Requests; | ||
using Carts.ShoppingCarts; | ||
using Carts.ShoppingCarts.GettingCartById; | ||
using Carts.ShoppingCarts.Products; | ||
using FluentAssertions; | ||
using Ogooreck.API; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
using static Carts.Api.Tests.ShoppingCarts.ShoppingCartsApi; | ||
|
||
namespace Carts.Api.Tests.ShoppingCarts.Canceling; | ||
|
||
public class CancelShoppingCartFixture: ApiSpecification<Program>, IAsyncLifetime | ||
public class CancelShoppingCartTests: IClassFixture<ApiSpecification<Program>> | ||
{ | ||
public Guid ShoppingCartId { get; private set; } | ||
private readonly ApiSpecification<Program> API; | ||
public CancelShoppingCartTests(ApiSpecification<Program> api) => API = api; | ||
|
||
public readonly Guid ClientId = Guid.NewGuid(); | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
var openResponse = await Send( | ||
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId))) | ||
); | ||
|
||
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse); | ||
|
||
ShoppingCartId = openResponse.GetCreatedId<Guid>(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
Dispose(); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public class CancelShoppingCartTests: IClassFixture<CancelShoppingCartFixture> | ||
{ | ||
private readonly CancelShoppingCartFixture API; | ||
|
||
public CancelShoppingCartTests(CancelShoppingCartFixture api) => API = api; | ||
|
||
[Fact] | ||
[Trait("Category", "Acceptance")] | ||
public async Task Delete_Should_Return_OK_And_Cancel_Shopping_Cart() | ||
{ | ||
await API | ||
.Given( | ||
URI($"/api/ShoppingCarts/{API.ShoppingCartId}"), | ||
HEADERS(IF_MATCH(1)) | ||
public Task Delete_Should_Return_OK_And_Cancel_Shopping_Cart() => | ||
API | ||
.Given("Opened Shopping Cart", OpenShoppingCart(ClientId)) | ||
.When( | ||
"Cancel Shopping Cart", | ||
DELETE, | ||
URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}"), | ||
HEADERS(IF_MATCH(0)) | ||
) | ||
.When(DELETE) | ||
.Then(OK); | ||
|
||
await API | ||
.Given( | ||
URI($"/api/ShoppingCarts/{API.ShoppingCartId}") | ||
) | ||
.When(GET_UNTIL(RESPONSE_ETAG_IS(2))) | ||
.Then(OK) | ||
.And() | ||
.When(GET, URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}")) | ||
.Until(RESPONSE_ETAG_IS(1)) | ||
.Then( | ||
OK, | ||
RESPONSE_BODY(new ShoppingCartDetails | ||
RESPONSE_BODY<ShoppingCartDetails>((details, ctx) => | ||
{ | ||
Id = API.ShoppingCartId, | ||
Status = ShoppingCartStatus.Canceled, | ||
ProductItems = new List<PricedProductItem>(), | ||
ClientId = API.ClientId, | ||
Version = 2, | ||
details.Id.Should().Be(ctx.OpenedShoppingCartId()); | ||
details.Status.Should().Be(ShoppingCartStatus.Canceled); | ||
details.ProductItems.Should().BeEmpty(); | ||
details.ClientId.Should().Be(ClientId); | ||
details.Version.Should().Be(1); | ||
})); | ||
|
||
// API.PublishedExternalEventsOfType<CartFinalized>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 20 additions & 22 deletions
42
Sample/ECommerce/Carts/Carts.Api.Tests/ShoppingCarts/Opening/OpenShoppingCartTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
using Carts.Api.Requests; | ||
using Carts.ShoppingCarts; | ||
using Carts.ShoppingCarts.GettingCartById; | ||
using Carts.ShoppingCarts.Products; | ||
using Core.Testing; | ||
using Xunit; | ||
using FluentAssertions; | ||
using Ogooreck.API; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
|
||
namespace Carts.Api.Tests.ShoppingCarts.Opening; | ||
|
||
public class OpenShoppingCartTests: IClassFixture<TestWebApplicationFactory<Program>> | ||
public class OpenShoppingCartTests: IClassFixture<ApiSpecification<Program>> | ||
{ | ||
private readonly ApiSpecification<Program> API; | ||
|
||
[Fact] | ||
public Task Post_ShouldReturn_CreatedStatus_With_CartId() => | ||
API.Scenario( | ||
API.Given( | ||
API.Given() | ||
.When( | ||
POST, | ||
URI("/api/ShoppingCarts/"), | ||
BODY(new OpenShoppingCartRequest(ClientId)) | ||
) | ||
.When(POST) | ||
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1)), | ||
|
||
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 0)), | ||
response => | ||
API.Given( | ||
URI($"/api/ShoppingCarts/{response.GetCreatedId()}") | ||
) | ||
.When(GET_UNTIL(RESPONSE_ETAG_IS(1))) | ||
API.Given() | ||
.When(GET, URI($"/api/ShoppingCarts/{response.GetCreatedId()}")) | ||
.Until(RESPONSE_ETAG_IS(0)) | ||
.Then( | ||
OK, | ||
RESPONSE_BODY(new ShoppingCartDetails | ||
RESPONSE_BODY<ShoppingCartDetails>(details => | ||
{ | ||
Id = response.GetCreatedId<Guid>(), | ||
Status = ShoppingCartStatus.Pending, | ||
ProductItems = new List<PricedProductItem>(), | ||
ClientId = ClientId, | ||
Version = 1, | ||
details.Id.Should().Be(response.GetCreatedId<Guid>()); | ||
details.Status.Should().Be(ShoppingCartStatus.Pending); | ||
details.ProductItems.Should().BeEmpty(); | ||
details.ClientId.Should().Be(ClientId); | ||
details.Version.Should().Be(0); | ||
})) | ||
); | ||
|
||
public OpenShoppingCartTests(TestWebApplicationFactory<Program> fixture) => | ||
API = ApiSpecification<Program>.Setup(fixture); | ||
public OpenShoppingCartTests(ApiSpecification<Program> api) => API = api; | ||
|
||
private readonly ApiSpecification<Program> API; | ||
private readonly Guid ClientId = Guid.NewGuid(); | ||
public readonly Guid ClientId = Guid.NewGuid(); | ||
} |
Oops, something went wrong.