Skip to content

Commit

Permalink
Removed AutoFixture in functional test for Create Order Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jflaga committed Jan 12, 2024
1 parent 47875c6 commit 3957920
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@
<PackageVersion Include="xunit" Version="2.5.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.1" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0-preview.1.23556.5" />
<PackageVersion Include="AutoFixture" Version="4.18.1" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/Ordering.API/Ordering.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

<ItemGroup>
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="AutoFixture" />
<PackageReference Include="Dapper" />
<PackageReference Include="FluentValidation.AspNetCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
Expand Down
28 changes: 22 additions & 6 deletions tests/Ordering.FunctionalTests/OrderingApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Net;
using System.Text;
using System.Text.Json;
using AutoFixture;
using eShop.Ordering.API.Application.Commands;
using eShop.Ordering.API.Application.Models;
using eShop.Ordering.API.Application.Queries;
Expand Down Expand Up @@ -185,11 +184,8 @@ public async Task PostDraftOrder()
[Fact]
public async Task CreateOrderDraftSucceeds()
{
Fixture fixture = new Fixture();
var payload = fixture.Build<CreateOrderDraftCommand>()
.FromFactory(() => new CreateOrderDraftCommand(fixture.Create<string>(), fixture.CreateMany<BasketItem>(3)))
.Create();
var content = new StringContent(JsonSerializer.Serialize(payload), UTF8Encoding.UTF8, "application/json")
var payload = FakeOrderDraftCommand();
var content = new StringContent(JsonSerializer.Serialize(FakeOrderDraftCommand()), UTF8Encoding.UTF8, "application/json")
{
Headers = { { "x-requestid", Guid.NewGuid().ToString() } }
};
Expand All @@ -200,9 +196,29 @@ public async Task CreateOrderDraftSucceeds()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(payload.Items.Count(), responseData.OrderItems.Count());
Assert.Equal(payload.Items.Sum(o => o.Quantity * o.UnitPrice), responseData.Total);
AssertThatOrderItemsAreTheSameAsRequestPayloadItems(payload, responseData);
}

private CreateOrderDraftCommand FakeOrderDraftCommand()
{
return new CreateOrderDraftCommand(
BuyerId: Guid.NewGuid().ToString(),
new List<BasketItem>()
{
new BasketItem()
{
Id = Guid.NewGuid().ToString(),
ProductId = 1,
ProductName = "Test Product 1",
UnitPrice = 10.2m,
OldUnitPrice = 9.8m,
Quantity = 2,
PictureUrl = Guid.NewGuid().ToString(),
}
});
}

private static void AssertThatOrderItemsAreTheSameAsRequestPayloadItems(CreateOrderDraftCommand payload, OrderDraftDTO responseData)
{
// check that OrderItems contain all product Ids from the payload
Expand Down

0 comments on commit 3957920

Please sign in to comment.