Skip to content

Commit

Permalink
Added Incident tests
Browse files Browse the repository at this point in the history
Updated Ogooreck version to 0.2.1, adjusted other tests to the new tests convention
  • Loading branch information
oskardudycz committed Jun 30, 2022
1 parent b3f257f commit 3fd95e1
Show file tree
Hide file tree
Showing 44 changed files with 585 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Core.Testing/Core.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
Expand All @@ -14,7 +15,7 @@
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.6" />
<PackageReference Include="Ogooreck" Version="0.1.1" />
<PackageReference Include="Ogooreck" Version="0.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public async Task InitializeAsync()
);

await CREATED(openResponse);
await RESPONSE_LOCATION_HEADER()(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
using Carts.ShoppingCarts.GettingCartById;
using Carts.ShoppingCarts.Products;
using Core.Testing;
using Ogooreck.API;
using Xunit;
using Ogooreck.API;
using static Ogooreck.API.ApiSpecification;

namespace Carts.Api.Tests.ShoppingCarts.Opening;

public class OpenShoppingCartTests: IClassFixture<TestWebApplicationFactory<Program>>
{
private readonly ApiSpecification<Program> API;

[Fact]
public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
API.Scenario(
Expand All @@ -21,7 +19,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1)),

response =>
API.Given(
Expand All @@ -43,5 +41,6 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
public OpenShoppingCartTests(TestWebApplicationFactory<Program> fixture) =>
API = ApiSpecification<Program>.Setup(fixture);

public readonly Guid ClientId = Guid.NewGuid();
private readonly ApiSpecification<Program> API;
private readonly Guid ClientId = Guid.NewGuid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task InitializeOrder_ShouldReturn_CreatedStatus_With_OrderId() =>
))
)
.When(POST)
.Then(CREATED);
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1));

private readonly Guid ClientId = Guid.NewGuid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task RequestPayment_ShouldReturn_CreatedStatus_With_PaymentId() =>
BODY(new RequestPaymentRequest {OrderId = OrderId, Amount = Amount})
)
.When(POST)
.Then(CREATED);
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1));

private readonly Guid OrderId = Guid.NewGuid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Task SendPackage_ShouldReturn_CreatedStatus_With_PackageId() =>
BODY(new SendPackage(OrderId, ProductItems))
)
.When(POST)
.Then(CREATED)
.Then(CREATED_WITH_DEFAULT_HEADERS())
.And(response => fixture.ShouldPublishInternalEventOfType<PackageWasSent>(
@event =>
@event.PackageId == response.GetCreatedId<Guid>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 0)),

response =>
API.Given(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 0)),

response =>
API.Given(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class AcknowledgeResolutionIncidentTests: IClassFixture<ApiWithResolvedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task ResolveCommand_Succeeds()
{
await API
.Given(
URI($"/api/customers/{API.CustomerId}/incidents/{API.IncidentId}/acknowledge"),
HEADERS(IF_MATCH(2))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.IncidentId}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Details with
{
Status = IncidentStatus.ResolutionAcknowledgedByCustomer,
Version = 3
}
)
);
}

private readonly ApiWithResolvedIncident API;

public AcknowledgeResolutionIncidentTests(ApiWithResolvedIncident api) => API = api;
}
40 changes: 40 additions & 0 deletions Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/AssignAgentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class AssignAgentToIncidentTests: IClassFixture<ApiWithLoggedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task AssignAgentCommand_ChangesIncidentCategory()
{
await API
.Given(
URI($"/api/agents/{agentId}/incidents/{API.IncidentId}/assign"),
HEADERS(IF_MATCH(1))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.IncidentId}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Details with
{
AgentId = agentId,
Version = 2
}
)
);
}

private readonly Guid agentId = Guid.NewGuid();
private readonly ApiWithLoggedIncident API;

public AssignAgentToIncidentTests(ApiWithLoggedIncident api) => API = api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Bogus;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class CategoriseIncidentTests: IClassFixture<ApiWithLoggedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task CategoriseCommand_ChangesIncidentCategory()
{
await API
.Given(
URI($"/api/agents/{agentId}/incidents/{API.IncidentId}/category"),
BODY(new CategoriseIncidentRequest(category)),
HEADERS(IF_MATCH(1))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.IncidentId}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Details with
{
Category = category,
Version = 2
}
)
);
}

private readonly Guid agentId = Guid.NewGuid();
private readonly IncidentCategory category = new Faker().PickRandom<IncidentCategory>();
private readonly ApiWithLoggedIncident API;

public CategoriseIncidentTests(ApiWithLoggedIncident api) => API = api;

}
40 changes: 40 additions & 0 deletions Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/CloseIncidentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class CloseIncidentTests: IClassFixture<ApiWithAcknowledgedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task ResolveCommand_Succeeds()
{
await API
.Given(
URI($"/api/agents/{API.AgentId}/incidents/{API.IncidentId}/close"),
HEADERS(IF_MATCH(3))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.IncidentId}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Details with
{
Status = IncidentStatus.Closed,
Version = 4
}
)
);
}

private readonly ApiWithResolvedIncident API;

public CloseIncidentTests(ApiWithAcknowledgedIncident api) => API = api;
}
Loading

0 comments on commit 3fd95e1

Please sign in to comment.