Skip to content

Commit b91bb2c

Browse files
authored
Test specifications implement IDisposable (#154)
1 parent abee7c2 commit b91bb2c

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=specifications/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/ReactiveDomain.Testing/Specifications/DispatcherSpecification.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ReactiveDomain.Testing
66
{
7-
public abstract class DispatcherSpecification
7+
public abstract class DispatcherSpecification : IDisposable
88
{
99
public readonly IDispatcher Dispatcher;
1010
public readonly IDispatcher LocalBus;
@@ -16,5 +16,25 @@ protected DispatcherSpecification()
1616
LocalBus = new Dispatcher("Fixture LocalBus");
1717
TestQueue = new TestQueue(Dispatcher, new[] { typeof(Event), typeof(Command) });
1818
}
19+
20+
private bool _disposed;
21+
protected virtual void Dispose(bool disposing)
22+
{
23+
if (_disposed)
24+
return;
25+
if (disposing)
26+
{
27+
Dispatcher?.Dispose();
28+
LocalBus?.Dispose();
29+
TestQueue?.Dispose();
30+
}
31+
_disposed = true;
32+
}
33+
34+
public void Dispose()
35+
{
36+
Dispose(true);
37+
GC.SuppressFinalize(this);
38+
}
1939
}
2040
}

src/ReactiveDomain.Testing/Specifications/MockRepositorySpecification.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class MockRepositorySpecification : DispatcherSpecification
1515
public IEventSerializer EventSerializer { get; }
1616
public IConfiguredConnection ConfiguredConnection { get; }
1717

18-
private string _schema;
19-
public string Schema => _schema;
18+
public string Schema { get; }
2019

2120
/// <summary>
2221
/// Creates a mock repository.
@@ -25,7 +24,7 @@ public class MockRepositorySpecification : DispatcherSpecification
2524
/// <param name="dataStore">Stream store connection.</param>
2625
private MockRepositorySpecification(string schema, IStreamStoreConnection dataStore)
2726
{
28-
_schema = schema;
27+
Schema = schema;
2928
StreamNameBuilder = string.IsNullOrEmpty(schema) ? new PrefixedCamelCaseStreamNameBuilder() : new PrefixedCamelCaseStreamNameBuilder(schema);
3029
StreamStoreConnection = dataStore;
3130
StreamStoreConnection.Connect();
@@ -47,17 +46,13 @@ private MockRepositorySpecification(string schema, IStreamStoreConnection dataSt
4746
/// Creates a mock repository with a prefix.
4847
/// </summary>
4948
/// <param name="schema">Schema prefix for stream name. Default value is "Test".</param>
50-
public MockRepositorySpecification(string schema = "Test") : this(schema, new MockStreamStoreConnection(schema))
51-
{
52-
}
49+
public MockRepositorySpecification(string schema = "Test") : this(schema, new MockStreamStoreConnection(schema)) { }
5350

5451
/// <summary>
5552
/// Creates a mock repository connected to a StreamStore.
5653
/// </summary>
5754
/// <param name="dataStore">Stream store connection.</param>
58-
public MockRepositorySpecification(IStreamStoreConnection dataStore) : this(dataStore.ConnectionName, dataStore)
59-
{
60-
}
55+
public MockRepositorySpecification(IStreamStoreConnection dataStore) : this(dataStore.ConnectionName, dataStore) { }
6156

6257
public virtual void ClearQueues()
6358
{
@@ -71,5 +66,19 @@ public IListener GetListener(string name) =>
7166
StreamStoreConnection,
7267
StreamNameBuilder,
7368
EventSerializer);
69+
70+
private bool _disposed;
71+
protected override void Dispose(bool disposing)
72+
{
73+
if (_disposed)
74+
return;
75+
if (disposing)
76+
{
77+
StreamStoreConnection.Dispose();
78+
RepositoryEvents.Dispose();
79+
}
80+
_disposed = true;
81+
base.Dispose(disposing);
82+
}
7483
}
7584
}

src/ReactiveDomain.Testing/Specifications/MockRepositoryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public MockRepositoryTests()
2121
public void Dispose()
2222
{
2323
_fixture.Dispatcher.Unsubscribe<TestCommands.Command1>(this);
24+
_fixture.Dispose();
2425
}
2526
[Fact]
2627
public void can_get_repository_events()

0 commit comments

Comments
 (0)