-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncidentTests.cs
70 lines (58 loc) · 2.73 KB
/
IncidentTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Ogooreck.BusinessLogic;
namespace Ogooreck.Sample.BusinessLogic.Tests.Functions.EventSourced;
using static IncidentEventsBuilder;
using static IncidentService;
public class IncidentTests
{
private static readonly DateTimeOffset now = DateTimeOffset.UtcNow;
private static readonly Func<Incident, object, Incident> evolve =
(incident, @event) =>
{
return @event switch
{
IncidentLogged logged => Incident.Create(logged),
IncidentCategorised categorised => incident.Apply(categorised),
IncidentPrioritised prioritised => incident.Apply(prioritised),
AgentRespondedToIncident agentResponded => incident.Apply(agentResponded),
CustomerRespondedToIncident customerResponded => incident.Apply(customerResponded),
IncidentResolved resolved => incident.Apply(resolved),
ResolutionAcknowledgedByCustomer acknowledged => incident.Apply(acknowledged),
IncidentClosed closed => incident.Apply(closed),
_ => incident
};
};
private readonly HandlerSpecification<Incident> Spec = Specification.For<Incident>(evolve);
[Fact]
public void GivenNonExistingIncident_WhenOpenWithValidParams_ThenSucceeds()
{
var incidentId = Guid.NewGuid();
var customerId = Guid.NewGuid();
var contact = new Contact(ContactChannel.Email, EmailAddress: "john@doe.com");
var description = Guid.NewGuid().ToString();
var loggedBy = Guid.NewGuid();
Spec.Given()
.When(() => Handle(() => now, new LogIncident(incidentId, customerId, contact, description, loggedBy)))
.Then(new IncidentLogged(incidentId, customerId, contact, description, loggedBy, now));
}
[Fact]
public void GivenOpenIncident_WhenCategoriseWithValidParams_ThenSucceeds()
{
var incidentId = Guid.NewGuid();
var category = IncidentCategory.Database;
var categorisedBy = Guid.NewGuid();
Spec.Given(IncidentLogged(incidentId, now))
.When(incident => Handle(() => now, incident, new CategoriseIncident(incidentId, category, categorisedBy)))
.Then(new IncidentCategorised(incidentId, category, categorisedBy, now));
}
}
public static class IncidentEventsBuilder
{
public static IncidentLogged IncidentLogged(Guid incidentId, DateTimeOffset now)
{
var customerId = Guid.NewGuid();
var contact = new Contact(ContactChannel.Email, EmailAddress: "john@doe.com");
var description = Guid.NewGuid().ToString();
var loggedBy = Guid.NewGuid();
return new IncidentLogged(incidentId, customerId, contact, description, loggedBy, now);
}
}