-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathIntegrationTests.cs
124 lines (114 loc) · 6.68 KB
/
IntegrationTests.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Autofac;
using CommandLine.Text;
using EventFlow.Aggregates;
using EventFlow.Autofac.Extensions;
using EventFlow.EventStores;
using EventFlow.Extensions;
using EventFlow.MongoDB.Extensions;
using EventFlow.Queries;
using EventFlow.RabbitMQ;
using EventFlow.RabbitMQ.Extensions;
using EventFlow.Snapshots.Strategies;
using EventFlowExample;
using EventFlowExample.Aggregates;
using EventFlowExample.Aggregates.CommandHandlers;
using EventFlowExample.Aggregates.Commands;
using EventFlowExample.Aggregates.Events;
using EventFlowExample.Aggregates.ReadModels;
using EventFlowExample.Aggregates.Snapshots;
using EventFlowExample.Jobs;
using EventFlowExample.Models;
using FluentAssertions;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace EventFlow.Tests
{
public class IntegrationTests : IntegrationTestBase
{
[Fact]
public async Task PassingTest()
{
using (var resolver = EventFlowOptions.New
.UseAutofacContainerBuilder(new ContainerBuilder())
.Configure(c => c.ThrowSubscriberExceptions = true)
.AddEvents(typeof(ExampleEvent))
.AddEvents(typeof(ResetEvent))
.AddCommands(typeof(ExampleCommand))
.AddCommands(typeof(ResetCommand))
.AddCommandHandlers(typeof(ExampleCommandHandler))
.AddCommandHandlers(typeof(ResetCommandHandler))
.ConfigureEventStore()
.ConfigureMongoDb(MongoClient, SNAPSHOT_CONTAINER_NAME)
.AddSnapshots(typeof(ExampleSnaphost))
.UseMongoDbSnapshotStore()
.UseInMemoryReadStoreFor<ExampleReadModel>()
.RegisterServices(sr => sr.Register(i => SnapshotEveryFewVersionsStrategy.Default))
.RegisterServices(DecorateCommandBus)
.PublishToRabbitMq(RabbitMqConfiguration.With(RabbitMqUri, true, 4, "eventflow"))
.Configure(c => c.IsAsynchronousSubscribersEnabled = true)
.AddJobs(typeof(ExampleJob))
.CreateResolver())
{
Int32 magicNumber = 2;
CommandBus = resolver.Resolve<ICommandBus>();
ExampleId exampleId = PublishCommand.GetStreamName("Tenant", "EXAMPLE");
CommandReturnResult result = await CommandBus.PublishAsync(
new ExampleCommand(exampleId, magicNumber), CancellationToken.None)
.ConfigureAwait(false);
IAggregateStore aggregateStore = resolver.Resolve<IAggregateStore>();
var @aggregate = await aggregateStore.LoadAsync<ExampleAggregate, ExampleId>(exampleId, CancellationToken.None);
//Command side
result.IsSuccess.Should().BeTrue();
result.AggregateRoot.Should().NotBeNull();
result.AggregateRoot.Version.Should().Be(1);
result.AggregateRoot.Name.Value.Should().Be("ExampleAggregate");
result.AggregateRoot.GetIdentity().Value.Should().Be(exampleId.Value);
@aggregate.Should().NotBeNull();
result.AggregateRoot.Should().Equals(@aggregate);
}
}
[Fact]
public async Task ReadModelTest()
{
using (var resolver = EventFlowOptions.New
.UseAutofacContainerBuilder(new ContainerBuilder())
.Configure(c => c.ThrowSubscriberExceptions = true)
.AddEvents(typeof(ExampleEvent))
.AddEvents(typeof(ResetEvent))
.AddCommands(typeof(ExampleCommand))
.AddCommands(typeof(ResetCommand))
.AddCommandHandlers(typeof(ExampleCommandHandler))
.AddCommandHandlers(typeof(ResetCommandHandler))
.ConfigureEventStore()
.ConfigureMongoDb(MongoClient, SNAPSHOT_CONTAINER_NAME)
.AddSnapshots(typeof(ExampleSnaphost))
.UseMongoDbSnapshotStore()
.UseInMemoryReadStoreFor<ExampleReadModel>()
.RegisterServices(sr => sr.Register(i => SnapshotEveryFewVersionsStrategy.Default))
.RegisterServices(DecorateCommandBus)
.PublishToRabbitMq(RabbitMqConfiguration.With(RabbitMqUri, true, 4, "eventflow"))
.Configure(c => c.IsAsynchronousSubscribersEnabled = true)
.AddJobs(typeof(ExampleJob))
.CreateResolver())
{
Int32 magicNumber = 2;
CommandBus = resolver.Resolve<ICommandBus>();
ExampleId exampleId = PublishCommand.GetStreamName("Tenant", "EXAMPLE");
CommandReturnResult result = await CommandBus.PublishAsync(
new ExampleCommand(exampleId, magicNumber), CancellationToken.None)
.ConfigureAwait(false);
var queryProcessor = resolver.Resolve<IQueryProcessor>();
ExampleReadModel exampleReadModel = await queryProcessor.ProcessAsync(
new ReadModelByIdQuery<ExampleReadModel>(exampleId),
CancellationToken.None)
.ConfigureAwait(false);
exampleReadModel.Should().NotBeNull();
exampleReadModel.MagicNumber.Should().ContainSingle();
exampleReadModel.MagicNumber.First().Should().Be(2);
}
}
}
}