-
-
Notifications
You must be signed in to change notification settings - Fork 506
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 a989f43
Showing
41 changed files
with
591 additions
and
784 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
66 changes: 22 additions & 44 deletions
66
Sample/ECommerce/Carts/Carts.Api.Tests/ShoppingCarts/AddingProduct/AddProductTests.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,69 +1,47 @@ | ||
using Carts.Api.Requests; | ||
using Carts.ShoppingCarts; | ||
using Carts.ShoppingCarts.GettingCartById; | ||
using Carts.ShoppingCarts.Products; | ||
using FluentAssertions; | ||
using Ogooreck.API; | ||
using static Ogooreck.API.ApiSpecification; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
|
||
namespace Carts.Api.Tests.ShoppingCarts.AddingProduct; | ||
|
||
public class AddProductFixture: ApiSpecification<Program>, IAsyncLifetime | ||
{ | ||
public Guid ShoppingCartId { get; private set; } | ||
|
||
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(openResponse); | ||
await RESPONSE_LOCATION_HEADER()(openResponse); | ||
using static ShoppingCartsApi; | ||
|
||
ShoppingCartId = openResponse.GetCreatedId<Guid>(); | ||
} | ||
|
||
public Task DisposeAsync() => Task.CompletedTask; | ||
} | ||
|
||
public class AddProductTests: IClassFixture<AddProductFixture> | ||
public class AddProductTests: IClassFixture<ApiSpecification<Program>> | ||
{ | ||
private readonly AddProductFixture API; | ||
private readonly ApiSpecification<Program> API; | ||
|
||
public AddProductTests(AddProductFixture api) => API = api; | ||
public AddProductTests(ApiSpecification<Program> api) => API = api; | ||
|
||
private readonly ProductItemRequest product = new(Guid.NewGuid(), 1); | ||
|
||
[Fact] | ||
[Trait("Category", "Acceptance")] | ||
public async Task Post_Should_AddProductItem_To_ShoppingCart() | ||
{ | ||
var product = new ProductItemRequest(Guid.NewGuid(), 1); | ||
|
||
await API | ||
.Given( | ||
URI($"/api/ShoppingCarts/{API.ShoppingCartId}/products"), | ||
public Task Post_Should_AddProductItem_To_ShoppingCart() => | ||
API | ||
.Given("Opened Shopping Cart", OpenShoppingCart()) | ||
.When( | ||
"Add new product", | ||
POST, | ||
URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}/products"), | ||
BODY(new AddProductRequest(product)), | ||
HEADERS(IF_MATCH(1)) | ||
) | ||
.When(POST) | ||
.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()}")) | ||
.Then( | ||
RESPONSE_BODY<ShoppingCartDetails>(details => | ||
RESPONSE_BODY<ShoppingCartDetails>((details, ctx) => | ||
{ | ||
details.Id.Should().Be(API.ShoppingCartId); | ||
details.Id.Should().Be(ctx.OpenedShoppingCartId()); | ||
details.Status.Should().Be(ShoppingCartStatus.Pending); | ||
details.ProductItems.Should().HaveCount(1); | ||
details.ProductItems.Single().ProductItem.Should() | ||
.Be(ProductItem.From(product.ProductId, product.Quantity)); | ||
var productItem = details.ProductItems.Single(); | ||
productItem.Quantity.Should().Be(product.Quantity); | ||
productItem.ProductId.Should().Be(product.ProductId!.Value); | ||
details.Version.Should().Be(2); | ||
}) | ||
); | ||
} | ||
} |
72 changes: 22 additions & 50 deletions
72
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}"), | ||
public Task Delete_Should_Return_OK_And_Cancel_Shopping_Cart() => | ||
API | ||
.Given(OpenShoppingCart(ClientId)) | ||
.When( | ||
"Cancel Shopping Cart", | ||
DELETE, | ||
URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}"), | ||
HEADERS(IF_MATCH(1)) | ||
) | ||
.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(2)) | ||
.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(2); | ||
})); | ||
|
||
// API.PublishedExternalEventsOfType<CartFinalized>(); | ||
} | ||
} |
104 changes: 32 additions & 72 deletions
104
Sample/ECommerce/Carts/Carts.Api.Tests/ShoppingCarts/Confirming/ConfirmShoppingCartTests.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,95 +1,55 @@ | ||
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; | ||
|
||
namespace Carts.Api.Tests.ShoppingCarts.Confirming; | ||
|
||
public class ConfirmShoppingCartFixture: ApiSpecification<Program>, IAsyncLifetime | ||
{ | ||
public Guid ShoppingCartId { get; private set; } | ||
|
||
public readonly Guid ClientId = Guid.NewGuid(); | ||
|
||
public readonly ProductItemRequest ProductItem = new(Guid.NewGuid(), 1); | ||
|
||
public decimal UnitPrice; | ||
|
||
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>(); | ||
|
||
var addResponse = await Send( | ||
new ApiRequest( | ||
POST, | ||
URI($"/api/ShoppingCarts/{ShoppingCartId}/products"), | ||
BODY(new AddProductRequest(ProductItem)), | ||
HEADERS(IF_MATCH(1))) | ||
); | ||
|
||
await OK(addResponse); | ||
|
||
var getResponse = await Send( | ||
new ApiRequest( | ||
GET_UNTIL(RESPONSE_ETAG_IS(2)), | ||
URI($"/api/ShoppingCarts/{ShoppingCartId}") | ||
) | ||
); | ||
using static ShoppingCartsApi; | ||
|
||
var cartDetails = await getResponse.GetResultFromJson<ShoppingCartDetails>(); | ||
UnitPrice = cartDetails.ProductItems.Single().UnitPrice; | ||
} | ||
|
||
public Task DisposeAsync() => Task.CompletedTask; | ||
} | ||
|
||
public class ConfirmShoppingCartTests: IClassFixture<ConfirmShoppingCartFixture> | ||
public class ConfirmShoppingCartTests: IClassFixture<ApiSpecification<Program>> | ||
{ | ||
private readonly ConfirmShoppingCartFixture API; | ||
private readonly ApiSpecification<Program> API; | ||
|
||
public ConfirmShoppingCartTests(ConfirmShoppingCartFixture api) => API = api; | ||
public ConfirmShoppingCartTests(ApiSpecification<Program> api) => API = api; | ||
|
||
[Fact] | ||
[Trait("Category", "Acceptance")] | ||
public async Task Put_Should_Return_OK_And_Confirm_Shopping_Cart() | ||
{ | ||
await API | ||
public Task Put_Should_Return_OK_And_Confirm_Shopping_Cart() => | ||
API | ||
.Given( | ||
URI($"/api/ShoppingCarts/{API.ShoppingCartId}/confirmation"), | ||
HEADERS(IF_MATCH(2)) | ||
"Shopping Cart with Product Item", | ||
OpenShoppingCart(ClientId), | ||
AddProductItem(ProductItem, ifMatch: 1) | ||
) | ||
.When(PUT) | ||
.Then(OK); | ||
|
||
await API | ||
.Given( | ||
URI($"/api/ShoppingCarts/{API.ShoppingCartId}") | ||
.When( | ||
PUT, | ||
URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}/confirmation"), | ||
HEADERS(IF_MATCH(2)) | ||
) | ||
.When(GET_UNTIL(RESPONSE_ETAG_IS(3))) | ||
.Then(OK) | ||
.And() | ||
.When(GET, URI(ctx => $"/api/ShoppingCarts/{ctx.OpenedShoppingCartId()}")) | ||
.Until(RESPONSE_ETAG_IS(3)) | ||
.Then( | ||
OK, | ||
RESPONSE_BODY(new ShoppingCartDetails | ||
RESPONSE_BODY<ShoppingCartDetails>((details, ctx) => | ||
{ | ||
Id = API.ShoppingCartId, | ||
Status = ShoppingCartStatus.Confirmed, | ||
ClientId = API.ClientId, | ||
ProductItems = new List<PricedProductItem> | ||
{ | ||
PricedProductItem.Create( | ||
ProductItem.From(API.ProductItem.ProductId, API.ProductItem.Quantity), | ||
API.UnitPrice | ||
) | ||
}, | ||
Version = 3, | ||
details.Id.Should().Be(ctx.OpenedShoppingCartId()); | ||
details.Status.Should().Be(ShoppingCartStatus.Confirmed); | ||
details.ProductItems.Count.Should().Be(1); | ||
details.ProductItems.Single().ProductItem.Should() | ||
.Be(Carts.ShoppingCarts.Products.ProductItem.From(ProductItem.ProductId, ProductItem.Quantity)); | ||
details.ClientId.Should().Be(ClientId); | ||
details.Version.Should().Be(3); | ||
})); | ||
} | ||
|
||
// API.PublishedExternalEventsOfType<CartFinalized>(); | ||
|
||
private readonly Guid ClientId = Guid.NewGuid(); | ||
|
||
private readonly ProductItemRequest ProductItem = new(Guid.NewGuid(), 1); | ||
} |
40 changes: 19 additions & 21 deletions
40
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)), | ||
|
||
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(1)) | ||
.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(1); | ||
})) | ||
); | ||
|
||
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.