Skip to content

Commit bba276e

Browse files
committed
test listener opt-in validation
1 parent 68cbcab commit bba276e

15 files changed

+208
-96
lines changed

src/ReactiveDomain.Foundation.Tests/Domain/AggregateRootEntityTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using System;
1+
using ReactiveDomain.Foundation.Tests.Domain;
2+
using System;
23
using Xunit;
34

45
// ReSharper disable once CheckNamespace
5-
namespace ReactiveDomain.Domain.Tests {
6-
namespace AggregateRootEntityTests {
6+
namespace ReactiveDomain.Domain.Tests
7+
{
8+
namespace AggregateRootEntityTests
9+
{
710
public class AnyInstance {
811
// IEventSource behavior
912

src/ReactiveDomain.Foundation.Tests/Domain/CapturingRoute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ReactiveDomain.Domain.Tests
1+
namespace ReactiveDomain.Foundation.Tests.Domain
22
{
33
public class CapturingRoute
44
{

src/ReactiveDomain.Foundation.Tests/Domain/CorrelatedAggregate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using ReactiveDomain.Messaging;
44

55
// ReSharper disable once CheckNamespace
6-
namespace ReactiveDomain.Foundation.Tests
6+
namespace ReactiveDomain.Foundation.Tests.Domain
77
{
88
public class CorrelatedAggregate : AggregateRoot
99
{

src/ReactiveDomain.Foundation.Tests/Domain/with_correlated_aggregate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Xunit;
44

55
// ReSharper disable once CheckNamespace
6-
namespace ReactiveDomain.Foundation.Tests
6+
namespace ReactiveDomain.Foundation.Tests.Domain
77
{
88
// ReSharper disable once InconsistentNaming
99
public class with_correlated_aggregate
@@ -28,7 +28,7 @@ public void can_raise_correlated_events_from_constructor_source()
2828
},
2929
e =>{
3030
if( e is CorrelatedAggregate.CorrelatedEvent @event){
31-
Assert.Equal(_command.CorrelationId, @event.CorrelationId);
31+
Assert.Equal(_command.CorrelationId, @event.CorrelationId);
3232
}
3333
else{
3434
throw new Exception("wrong event");

src/ReactiveDomain.Foundation.Tests/Domain/with_correlated_repository.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Xunit;
55

66
// ReSharper disable once CheckNamespace
7-
namespace ReactiveDomain.Foundation.Tests
7+
namespace ReactiveDomain.Foundation.Tests.Domain
88
{
99
[Collection(nameof(EmbeddedStreamStoreConnectionCollection))]
1010
// ReSharper disable once InconsistentNaming
@@ -83,36 +83,40 @@ public void correlation_and_causation_are_injected()
8383

8484
var raisedEvents = ((IEventSource)agg).TakeEvents();
8585
Assert.Collection(raisedEvents,
86-
@event => {
86+
@event =>
87+
{
8788
var created = @event as CorrelatedAggregate.Created;
8889
Assert.NotNull(created);
89-
Assert.Equal(command1.MsgId,created.CausationId);
90-
Assert.Equal(command1.CorrelationId,created.CorrelationId);
90+
Assert.Equal(command1.MsgId, created.CausationId);
91+
Assert.Equal(command1.CorrelationId, created.CorrelationId);
9192
},
92-
@event => {
93+
@event =>
94+
{
9395
var corrEvent = @event as CorrelatedAggregate.CorrelatedEvent;
9496
Assert.NotNull(corrEvent);
95-
Assert.Equal(command1.MsgId,corrEvent.CausationId);
96-
Assert.Equal(command1.CorrelationId,corrEvent.CorrelationId);
97+
Assert.Equal(command1.MsgId, corrEvent.CausationId);
98+
Assert.Equal(command1.CorrelationId, corrEvent.CorrelationId);
9799
},
98-
@event => {
100+
@event =>
101+
{
99102
var corrEvent = @event as CorrelatedAggregate.CorrelatedEvent;
100103
Assert.NotNull(corrEvent);
101-
Assert.Equal(command1.MsgId,corrEvent.CausationId);
102-
Assert.Equal(command1.CorrelationId,corrEvent.CorrelationId);
104+
Assert.Equal(command1.MsgId, corrEvent.CausationId);
105+
Assert.Equal(command1.CorrelationId, corrEvent.CorrelationId);
103106
});
104107
var command2 = MessageBuilder.New(() => new TestCommands.Command2());
105-
((ICorrelatedEventSource) agg).Source = command2;
106-
108+
((ICorrelatedEventSource)agg).Source = command2;
109+
107110
agg.RaiseCorrelatedEvent();
108111
raisedEvents = ((IEventSource)agg).TakeEvents();
109112
Assert.Collection(raisedEvents,
110-
@event => {
111-
var corrEvent = @event as CorrelatedAggregate.CorrelatedEvent;
112-
Assert.NotNull(corrEvent);
113-
Assert.Equal(command2.MsgId,corrEvent.CausationId);
114-
Assert.Equal(command2.CorrelationId,corrEvent.CorrelationId);
115-
});
113+
@event =>
114+
{
115+
var corrEvent = @event as CorrelatedAggregate.CorrelatedEvent;
116+
Assert.NotNull(corrEvent);
117+
Assert.Equal(command2.MsgId, corrEvent.CausationId);
118+
Assert.Equal(command2.CorrelationId, corrEvent.CorrelationId);
119+
});
116120
}
117121
}
118122
}

src/ReactiveDomain.Foundation.Tests/Domain/with_repository.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Xunit;
88

99
// ReSharper disable once CheckNamespace
10-
namespace ReactiveDomain.Foundation.Tests
10+
namespace ReactiveDomain.Foundation.Tests.Domain
1111
{
1212
[Collection(nameof(EmbeddedStreamStoreConnectionCollection))]
1313
// ReSharper disable once InconsistentNaming
@@ -25,20 +25,20 @@ public with_repository(StreamStoreConnectionFixture fixture)
2525
_streamNameBuilder,
2626
fixture.Connection,
2727
_serializer,
28-
GetPolicyUserId);
28+
GetPolicyUserId);
2929
}
3030
private Guid GetPolicyUserId() { return _policyUserId; }
3131
private Guid _policyUserId = Guid.NewGuid();
3232
[Fact]
3333
public void policy_user_id_is_saved()
3434
{
35-
35+
3636
var id = Guid.NewGuid();
37-
var agg = new TestAggregate(id);
37+
var agg = new TestAggregate(id);
3838
var userId = Guid.NewGuid();
3939
_policyUserId = userId;
4040
_repo.Save(agg);
41-
41+
4242

4343
agg.RaiseBy(10);
4444
var nextUser = Guid.NewGuid();
@@ -52,13 +52,13 @@ public void policy_user_id_is_saved()
5252
var md = newAggregate.ReadMetadatum<AuditRecord>();
5353
Assert.NotNull(md);
5454
Assert.Equal(userId, md.PolicyUserId);
55-
Assert.True((DateTime.UtcNow - md.EventDateUTC) < TimeSpan.FromSeconds(5)); // just check for a fresh timestamp, not trying to test built in .Now
55+
Assert.True(DateTime.UtcNow - md.EventDateUTC < TimeSpan.FromSeconds(5)); // just check for a fresh timestamp, not trying to test built in .Now
5656
var evt2 = slice.Events[1];
5757
var incremented = _serializer.Deserialize(evt2) as TestAggregateMessages.Increment;
5858
var md2 = incremented.ReadMetadatum<AuditRecord>();
5959
Assert.NotNull(md2);
6060
Assert.Equal(nextUser, md2.PolicyUserId);
61-
Assert.True((DateTime.UtcNow - md2.EventDateUTC) < TimeSpan.FromSeconds(5)); // just check for a fresh timestamp, not trying to test built in .Now
61+
Assert.True(DateTime.UtcNow - md2.EventDateUTC < TimeSpan.FromSeconds(5)); // just check for a fresh timestamp, not trying to test built in .Now
6262
#if NETCOREAPP
6363
Assert.NotEqual(md.EventDateUTC, md2.EventDateUTC);
6464
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ReactiveDomain.Messaging;
33
using ReactiveDomain.Testing;
44

5-
namespace ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests.Common
5+
namespace ReactiveDomain.Foundation.Tests.StreamListenerTests.Common
66
{
77
internal static class CommonHelpers
88
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22

3-
namespace ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests.Common
3+
namespace ReactiveDomain.Foundation.Tests.StreamListenerTests.Common
44
{
55
/// <summary>
66
/// Generate stream names for testing.
77
/// </summary>
88
/// <remarks>
99
/// todo:
10-
/// The use of the extra Guid doesn't match the generation by the <see cref="ReactiveDomain.Foundation.IStreamNameBuilder"/>
10+
/// The use of the extra Guid doesn't match the generation by the <see cref="IStreamNameBuilder"/>
1111
/// and the checks for existing category and event streams fail. <see cref="PrefixedCamelCaseStreamNameBuilderTests"/>
1212
/// tests the stream name generation. So switching to the PrefixedCamelCaseStreamNameBuilder. Leaving these here so Chris can
1313
/// agree and remove or correct me.
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@
33
using ReactiveDomain.Messaging;
44
using ReactiveDomain.Messaging.Bus;
55
using ReactiveDomain.Testing;
6-
using ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests.Common;
76
using Xunit;
7+
using ReactiveDomain.Foundation.Tests.StreamListenerTests.Common;
88

9-
namespace ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests {
9+
namespace ReactiveDomain.Foundation.Tests.StreamListenerTests
10+
{
1011
// ReSharper disable once InconsistentNaming
1112
[Collection(nameof(EmbeddedStreamStoreConnectionCollection))]
1213
public class when_using_listener_start_with_aggregate_and_guid
1314
{
1415
private readonly IStreamNameBuilder _streamNameBuilder = new PrefixedCamelCaseStreamNameBuilder();
1516
private readonly IEventSerializer _eventSerializer = new JsonMessageSerializer();
1617

17-
public when_using_listener_start_with_aggregate_and_guid(StreamStoreConnectionFixture fixture){
18+
public when_using_listener_start_with_aggregate_and_guid(StreamStoreConnectionFixture fixture)
19+
{
1820
var conn = fixture.Connection;
1921
conn.Connect();
2022

21-
// Build an origin stream to which the the events are appended. We are testing this stream directly
23+
// Build an origin stream to which the events are appended. We are testing this stream directly
2224
var originalStreamGuid = Guid.NewGuid();
2325
var originStreamName = _streamNameBuilder.GenerateForAggregate(typeof(AggregateIdTestAggregate), originalStreamGuid);
2426

25-
27+
2628
// Drop an event into the stream testAggregate-guid
2729
var result = conn.AppendToStream(
28-
originStreamName,
29-
ExpectedVersion.NoStream,
30-
null,
30+
originStreamName,
31+
ExpectedVersion.NoStream,
32+
null,
3133
_eventSerializer.Serialize(new TestEvent()));
3234
Assert.True(result.NextExpectedVersion == 0);
3335

@@ -49,16 +51,18 @@ public when_using_listener_start_with_aggregate_and_guid(StreamStoreConnectionFi
4951
[Fact]
5052
public void can_get_events_from_aggregate_id_stream()
5153
{
52-
AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _testEventCount) == 1,3000);
54+
AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _testEventCount) == 1, 3000);
5355
}
5456

55-
private void Handle(IMessage message) {
57+
private void Handle(IMessage message)
58+
{
5659
dynamic evt = message;
57-
if (evt is TestEvent) {
60+
if (evt is TestEvent)
61+
{
5862
Interlocked.Increment(ref _testEventCount);
5963
}
6064

6165
}
62-
public class AggregateIdTestAggregate:EventDrivenStateMachine{}
66+
public class AggregateIdTestAggregate : EventDrivenStateMachine { }
6367
}
6468
}
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
using ReactiveDomain.Messaging;
44
using ReactiveDomain.Messaging.Bus;
55
using ReactiveDomain.Testing;
6-
using ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests.Common;
76
using Xunit;
7+
using ReactiveDomain.Foundation.Tests.StreamListenerTests.Common;
88

9-
namespace ReactiveDomain.Foundation.Tests.SynchronizedStreamListenerTests {
9+
namespace ReactiveDomain.Foundation.Tests.StreamListenerTests
10+
{
1011
// ReSharper disable once InconsistentNaming
1112
[Collection(nameof(EmbeddedStreamStoreConnectionCollection))]
1213
public class when_using_listener_start_with_category_aggregate
@@ -24,38 +25,41 @@ public when_using_listener_start_with_category_aggregate(StreamStoreConnectionFi
2425

2526
// Drop an event into the stream testAggregate-guid
2627
var result = conn.AppendToStream(
27-
aggStream,
28-
ExpectedVersion.NoStream,
29-
null,
28+
aggStream,
29+
ExpectedVersion.NoStream,
30+
null,
3031
_eventSerializer.Serialize(new TestEvent()));
3132
Assert.True(result.NextExpectedVersion == 0);
3233

3334
//wait for the projection to be written.
3435
CommonHelpers.WaitForStream(conn, categoryStream);
35-
36+
3637
// Now set up the projection listener, and start it.
3738
var listener = new QueuedStreamListener(
3839
"category listener",
3940
conn,
4041
streamNameBuilder,
4142
new JsonMessageSerializer());
42-
listener.EventStream.Subscribe<TestEvent>(new AdHocHandler<TestEvent>(Handle));
43+
listener.EventStream.Subscribe(new AdHocHandler<TestEvent>(Handle));
4344
listener.Start<AggregateCategoryTestAggregate>();
4445
}
4546

4647
private long _testEventCount;
4748
[Fact]
48-
public void can_get_events_from_category_projection() {
49+
public void can_get_events_from_category_projection()
50+
{
4951
AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _testEventCount) == 1, 4000);
5052
}
5153

52-
private void Handle(IMessage message) {
54+
private void Handle(IMessage message)
55+
{
5356
dynamic evt = message;
54-
if (evt is TestEvent) {
57+
if (evt is TestEvent)
58+
{
5559
Interlocked.Increment(ref _testEventCount);
5660
}
5761

5862
}
59-
public class AggregateCategoryTestAggregate:EventDrivenStateMachine{}
63+
public class AggregateCategoryTestAggregate : EventDrivenStateMachine { }
6064
}
6165
}

0 commit comments

Comments
 (0)