Skip to content

Commit 2c1c463

Browse files
committed
Addded schema name per test
1 parent 698267e commit 2c1c463

17 files changed

+169
-122
lines changed

Core.Testing/Core.Testing.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="FluentAssertions" Version="6.7.0" />
1616
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.6" />
1717
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.6" />
18-
<PackageReference Include="Ogooreck" Version="0.2.1" />
18+
<PackageReference Include="Ogooreck" Version="0.3.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/AcknowledgeResolutionIncidentTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ public async Task ResolveCommand_Succeeds()
1313
{
1414
await API
1515
.Given(
16-
URI($"/api/customers/{API.CustomerId}/incidents/{API.IncidentId}/acknowledge"),
16+
URI($"/api/customers/{API.Incident.CustomerId}/incidents/{API.Incident.Id}/acknowledge"),
1717
HEADERS(IF_MATCH(2))
1818
)
1919
.When(POST)
2020
.Then(OK);
2121

2222
await API
23-
.Given(URI($"/api/incidents/{API.IncidentId}"))
23+
.Given(URI($"/api/incidents/{API.Incident.Id}"))
2424
.When(GET)
2525
.Then(
2626
OK,
2727
RESPONSE_BODY(
28-
API.Details with
28+
API.Incident with
2929
{
3030
Status = IncidentStatus.ResolutionAcknowledgedByCustomer,
3131
Version = 3

Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/AssignAgentTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ public async Task AssignAgentCommand_ChangesIncidentCategory()
1212
{
1313
await API
1414
.Given(
15-
URI($"/api/agents/{agentId}/incidents/{API.IncidentId}/assign"),
15+
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/assign"),
1616
HEADERS(IF_MATCH(1))
1717
)
1818
.When(POST)
1919
.Then(OK);
2020

2121
await API
22-
.Given(URI($"/api/incidents/{API.IncidentId}"))
22+
.Given(URI($"/api/incidents/{API.Incident.Id}"))
2323
.When(GET)
2424
.Then(
2525
OK,
2626
RESPONSE_BODY(
27-
API.Details with
27+
API.Incident with
2828
{
2929
AgentId = agentId,
3030
Version = 2

Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/CategoriseIncidentTests.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Bogus;
22
using Helpdesk.Api.Incidents;
3-
using Helpdesk.Api.Incidents.GetIncidentDetails;
43
using Helpdesk.Api.Tests.Incidents.Fixtures;
54
using Xunit;
65
using static Ogooreck.API.ApiSpecification;
@@ -15,20 +14,20 @@ public async Task CategoriseCommand_ChangesIncidentCategory()
1514
{
1615
await API
1716
.Given(
18-
URI($"/api/agents/{agentId}/incidents/{API.IncidentId}/category"),
17+
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/category"),
1918
BODY(new CategoriseIncidentRequest(category)),
2019
HEADERS(IF_MATCH(1))
2120
)
2221
.When(POST)
2322
.Then(OK);
2423

2524
await API
26-
.Given(URI($"/api/incidents/{API.IncidentId}"))
25+
.Given(URI($"/api/incidents/{API.Incident.Id}"))
2726
.When(GET)
2827
.Then(
2928
OK,
3029
RESPONSE_BODY(
31-
API.Details with
30+
API.Incident with
3231
{
3332
Category = category,
3433
Version = 2

Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/CloseIncidentTests.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ public async Task ResolveCommand_Succeeds()
1313
{
1414
await API
1515
.Given(
16-
URI($"/api/agents/{API.AgentId}/incidents/{API.IncidentId}/close"),
16+
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/close"),
1717
HEADERS(IF_MATCH(3))
1818
)
1919
.When(POST)
2020
.Then(OK);
2121

2222
await API
23-
.Given(URI($"/api/incidents/{API.IncidentId}"))
23+
.Given(URI($"/api/incidents/{API.Incident.Id}"))
2424
.When(GET)
2525
.Then(
2626
OK,
2727
RESPONSE_BODY(
28-
API.Details with
28+
API.Incident with
2929
{
3030
Status = IncidentStatus.Closed,
3131
Version = 4
@@ -34,7 +34,8 @@ API.Details with
3434
);
3535
}
3636

37-
private readonly ApiWithResolvedIncident API;
37+
private readonly ApiWithAcknowledgedIncident API;
38+
private Guid agentId = Guid.NewGuid();
3839

3940
public CloseIncidentTests(ApiWithAcknowledgedIncident api) => API = api;
4041
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
using Helpdesk.Api.Incidents;
21
using Helpdesk.Api.Incidents.GetIncidentDetails;
2+
using Ogooreck.API;
33
using Xunit;
4-
using static Ogooreck.API.ApiSpecification;
54

65
namespace Helpdesk.Api.Tests.Incidents.Fixtures;
76

8-
public class ApiWithAcknowledgedIncident: ApiWithResolvedIncident
7+
public class ApiWithAcknowledgedIncident: ApiSpecification<Program>, IAsyncLifetime
98
{
10-
public override async Task InitializeAsync()
9+
public async Task InitializeAsync()
1110
{
12-
await base.InitializeAsync();
11+
Incident = await this.AcknowledgedIncident();
12+
}
1313

14-
await Given(
15-
URI($"/api/customers/{CustomerId}/incidents/{IncidentId}/acknowledge"),
16-
HEADERS(IF_MATCH(2))
17-
)
18-
.When(POST)
19-
.Then(OK);
14+
public IncidentDetails Incident { get; set; } = default!;
2015

21-
Details = new IncidentDetails(
22-
IncidentId,
23-
CustomerId,
24-
IncidentStatus.ResolutionAcknowledgedByCustomer,
25-
Array.Empty<IncidentNote>(),
26-
null,
27-
null,
28-
null,
29-
3
30-
);
31-
}
16+
public Task DisposeAsync() => Task.CompletedTask;
3217
}
3318

Original file line numberDiff line numberDiff line change
@@ -1,54 +1,15 @@
1-
using Bogus;
2-
using Helpdesk.Api.Incidents;
31
using Helpdesk.Api.Incidents.GetIncidentDetails;
42
using Ogooreck.API;
53
using Xunit;
6-
using static Ogooreck.API.ApiSpecification;
74

85
namespace Helpdesk.Api.Tests.Incidents.Fixtures;
96

107
public class ApiWithLoggedIncident: ApiSpecification<Program>, IAsyncLifetime
118
{
12-
public virtual async Task InitializeAsync()
9+
public async Task InitializeAsync()
1310
{
14-
var response = await Given(
15-
URI($"api/customers/{CustomerId}/incidents/"),
16-
BODY(new LogIncidentRequest(Contact, IncidentDescription))
17-
)
18-
.When(POST)
19-
.Then(CREATED_WITH_DEFAULT_HEADERS(locationHeaderPrefix: "/api/incidents/"));
20-
21-
IncidentId = response.GetCreatedId<Guid>();
22-
23-
Details = new IncidentDetails(
24-
IncidentId,
25-
CustomerId,
26-
IncidentStatus.Pending,
27-
Array.Empty<IncidentNote>(),
28-
null,
29-
null,
30-
null,
31-
1
32-
);
11+
Incident = await this.LoggedIncident();
3312
}
34-
35-
public Guid IncidentId { get; set; }
36-
37-
public IncidentDetails Details { get; protected set; } = default!;
38-
39-
public readonly Guid CustomerId = Guid.NewGuid();
40-
41-
private readonly Contact Contact = new Faker<Contact>().CustomInstantiator(
42-
f => new Contact(
43-
f.PickRandom<ContactChannel>(),
44-
f.Name.FirstName(),
45-
f.Name.LastName(),
46-
f.Internet.Email(),
47-
f.Phone.PhoneNumber()
48-
)
49-
).Generate();
50-
51-
private readonly string IncidentDescription = new Bogus.DataSets.Lorem().Sentence();
52-
13+
public IncidentDetails Incident { get; protected set; } = default!;
5314
public Task DisposeAsync() => Task.CompletedTask;
5415
}
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
using Bogus;
2-
using Helpdesk.Api.Incidents;
31
using Helpdesk.Api.Incidents.GetIncidentDetails;
4-
using static Ogooreck.API.ApiSpecification;
2+
using Ogooreck.API;
3+
using Xunit;
54

65
namespace Helpdesk.Api.Tests.Incidents.Fixtures;
76

8-
public class ApiWithResolvedIncident: ApiWithLoggedIncident
7+
public class ApiWithResolvedIncident: ApiSpecification<Program>, IAsyncLifetime
98
{
10-
public override async Task InitializeAsync()
9+
public async Task InitializeAsync()
1110
{
12-
await base.InitializeAsync();
13-
14-
await Given(
15-
URI($"/api/agents/{AgentId}/incidents/{IncidentId}/resolve"),
16-
BODY(new ResolveIncidentRequest(resolutionType)),
17-
HEADERS(IF_MATCH(1))
18-
)
19-
.When(POST)
20-
.Then(OK);
21-
22-
Details = new IncidentDetails(
23-
IncidentId,
24-
CustomerId,
25-
IncidentStatus.Resolved,
26-
Array.Empty<IncidentNote>(),
27-
null,
28-
null,
29-
null,
30-
2
31-
);
11+
Incident = await this.ResolvedIncident();
3212
}
3313

34-
public readonly Guid AgentId = Guid.NewGuid();
35-
private readonly ResolutionType resolutionType = new Faker().PickRandom<ResolutionType>();
14+
public IncidentDetails Incident { get; set; } = default!;
15+
16+
public Task DisposeAsync() => Task.CompletedTask;
3617
}
3718

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using Bogus;
2+
using Bogus.DataSets;
3+
using Helpdesk.Api.Incidents;
4+
using Helpdesk.Api.Incidents.GetIncidentDetails;
5+
using Ogooreck.API;
6+
using static Ogooreck.API.ApiSpecification;
7+
8+
namespace Helpdesk.Api.Tests.Incidents.Fixtures;
9+
10+
public static class Scenarios
11+
{
12+
private static readonly Faker faker = new();
13+
private static readonly Lorem loremIpsum = new();
14+
15+
public static async Task<IncidentDetails> LoggedIncident(
16+
this ApiSpecification<Program> api
17+
)
18+
{
19+
var customerId = Guid.NewGuid();
20+
21+
var contact = new Contact(
22+
faker.PickRandom<ContactChannel>(),
23+
faker.Name.FirstName(),
24+
faker.Name.LastName(),
25+
faker.Internet.Email(),
26+
faker.Phone.PhoneNumber()
27+
);
28+
var incidentDescription = loremIpsum.Sentence();
29+
30+
var response = await api.Scenario(
31+
api.LogIncident(customerId, contact, incidentDescription),
32+
r => api.GetIncidentDetails(r.GetCreatedId<Guid>())
33+
);
34+
35+
return await response.GetResultFromJson<IncidentDetails>();
36+
}
37+
38+
public static async Task<IncidentDetails> ResolvedIncident(
39+
this ApiSpecification<Program> api
40+
)
41+
{
42+
var agentId = Guid.NewGuid();
43+
var resolvedType = faker.PickRandom<ResolutionType>();
44+
var incident = await api.LoggedIncident();
45+
46+
var response = await api.Scenario(
47+
api.ResolveIncident(incident.Id, agentId, resolvedType),
48+
_ => api.GetIncidentDetails(incident.Id)
49+
);
50+
51+
return await response.GetResultFromJson<IncidentDetails>();
52+
}
53+
54+
public static async Task<IncidentDetails> AcknowledgedIncident(
55+
this ApiSpecification<Program> api
56+
)
57+
{
58+
var incident = await api.ResolvedIncident();
59+
60+
var response = await api.Scenario(
61+
api.AcknowledgeIncident(incident.Id, incident.CustomerId),
62+
_ => api.GetIncidentDetails(incident.Id)
63+
);
64+
65+
return await response.GetResultFromJson<IncidentDetails>();
66+
}
67+
68+
private static Task<HttpResponseMessage> LogIncident(
69+
this ApiSpecification<Program> api,
70+
Guid customerId,
71+
Contact contact,
72+
string incidentDescription
73+
) =>
74+
api.Given(
75+
URI($"api/customers/{customerId}/incidents/"),
76+
BODY(new LogIncidentRequest(contact, incidentDescription))
77+
)
78+
.When(POST)
79+
.Then(CREATED_WITH_DEFAULT_HEADERS(locationHeaderPrefix: "/api/incidents/"));
80+
81+
private static Task<HttpResponseMessage> ResolveIncident<T>(
82+
this ApiSpecification<T> api,
83+
Guid incidentId,
84+
Guid agentId,
85+
ResolutionType resolutionType
86+
) where T : class =>
87+
api.Given(
88+
URI($"/api/agents/{agentId}/incidents/{incidentId}/resolve"),
89+
BODY(new ResolveIncidentRequest(resolutionType)),
90+
HEADERS(IF_MATCH(1))
91+
)
92+
.When(POST)
93+
.Then(OK);
94+
95+
private static Task<HttpResponseMessage> AcknowledgeIncident<T>(
96+
this ApiSpecification<T> api,
97+
Guid incidentId,
98+
Guid customerId
99+
) where T : class =>
100+
api.Given(
101+
URI($"/api/customers/{customerId}/incidents/{incidentId}/acknowledge"),
102+
HEADERS(IF_MATCH(2))
103+
)
104+
.When(POST)
105+
.Then(OK);
106+
107+
private static Task<HttpResponseMessage> GetIncidentDetails(
108+
this ApiSpecification<Program> api,
109+
Guid incidentId
110+
) =>
111+
api.Given(URI($"/api/incidents/{incidentId}"))
112+
.When(GET)
113+
.Then(OK);
114+
}

0 commit comments

Comments
 (0)