Skip to content

Commit

Permalink
Adds XML comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkempner authored and condron committed Jul 10, 2024
1 parent 8dcc755 commit c74f21c
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/ReactiveDomain.Foundation/StreamStore/ReadModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,20 @@ protected virtual void Dispose(bool disposing)
}
_disposed = true;
}
/// <summary>
/// Applies a message synchronously to the read model while ensuring that the <see cref="ReaderLock"/>
/// is respected and bypasses both the queue and listeners. This is primarily useful in tests.
/// </summary>
/// <param name="message">The message to apply.</param>
public void DirectApply(IMessage message) { DequeueMessage(message); }
public void Handle(Message message) { ((IHandle<IMessage>)_queue).Handle(message); }
public void Handle(IMessage message) { ((IHandle<IMessage>)_queue).Handle(message); }
/// <summary>
/// Publishes a message onto the read model's internal queue.
/// This bypasses the Listeners while ensuring that the <see cref="ReaderLock"/>
/// is respected. All messages will be processed in order from the queue thread.
/// </summary>
/// <param name="message">The message to publish.</param>
public void Publish(IMessage message) { ((IPublisher)_queue).Publish(message); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@

namespace ReactiveDomain.Testing
{
/// <summary>
/// An empty configured connection that produces null repositories, readers, etc.
/// Implements <see cref="IConfiguredConnection"/>.
/// </summary>
public class NullConfiguredConnection : IConfiguredConnection
{
/// <summary>
/// Gets a <see cref="NullConnection"/>.
/// </summary>
public IStreamStoreConnection Connection => new NullConnection();

/// <summary>
/// Gets a standard stream name builder
/// </summary>
public IStreamNameBuilder StreamNamer => new PrefixedCamelCaseStreamNameBuilder();

/// <summary>
/// Gets a default Json message serializer.
/// </summary>
public IEventSerializer Serializer => new JsonMessageSerializer();

/// <summary>
/// Gets a <see cref="NullRepository"/>.
/// </summary>
/// <param name="baseRepository">This parameter is ignored.</param>
/// <param name="caching">This parameter is ignored.</param>
/// <param name="currentPolicyUserId">This parameter is ignored.</param>
/// <returns>A <see cref="NullRepository"/>.</returns>
public ICorrelatedRepository GetCorrelatedRepository(
IRepository baseRepository = null,
bool caching = false,
Expand All @@ -20,21 +40,43 @@ public ICorrelatedRepository GetCorrelatedRepository(
return new NullRepository();
}

/// <summary>
/// Gets a <see cref="NullListener"/>.
/// </summary>
/// <param name="name">The name of the listener.</param>
/// <returns>A <see cref="NullListener"/></returns>
public IListener GetListener(string name)
{
return new NullListener(name);
}

/// <summary>
/// Gets a <see cref="NullListener"/>.
/// </summary>
/// <param name="name">The name of the listener.</param>
/// <returns>A <see cref="NullListener"/></returns>
public IListener GetQueuedListener(string name)
{
return new NullListener(name);
}

/// <summary>
/// Gets a <see cref="NullReader"/>.
/// </summary>
/// <param name="name">The name of the reader.</param>
/// <param name="handle">This parameter is ignored.</param>
/// <returns>A <see cref="NullListener"/></returns>
public IStreamReader GetReader(string name, Action<IMessage> handle)
{
return new NullReader(name);
}

/// <summary>
/// Gets a <see cref="NullRepository"/>.
/// </summary>
/// <param name="caching">This parameter is ignored.</param>
/// <param name="currentPolicyUserId">This parameter is ignored.</param>
/// <returns>A <see cref="NullRepository"/>.</returns>
public IRepository GetRepository(bool caching = false, Func<Guid> currentPolicyUserId = null)
{
return new NullRepository();
Expand Down
91 changes: 89 additions & 2 deletions src/ReactiveDomain.Testing/Specifications/NullConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,148 @@

namespace ReactiveDomain.Testing
{
/// <summary>
/// An empty connection that implements <see cref="IStreamStoreConnection"/>.
/// </summary>
public class NullConnection : IStreamStoreConnection
{

/// <summary>
/// The name of the connection.
/// </summary>
public string ConnectionName => "NullConnection";

/// <summary>
/// Drops the events and returns a write result at the default version.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="expectedVersion">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <param name="events">This parameter is ignored.</param>
/// <returns>A <see cref="WriteResult"/> at the default version.</returns>
public WriteResult AppendToStream(string stream, long expectedVersion, UserCredentials credentials = null, params EventData[] events)
{
return new WriteResult(0);
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
public void Close() { }

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
public void Connect() { }

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="expectedVersion">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
public void DeleteStream(string stream, long expectedVersion, UserCredentials credentials = null)
{
}

/// <summary>
/// Cleans up resources.
/// </summary>
public void Dispose()
{
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="expectedVersion">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
public void HardDeleteStream(string stream, long expectedVersion, UserCredentials credentials = null)
{
}

/// <summary>
/// Gets an empty stream slice.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="start">This parameter is ignored.</param>
/// <param name="count">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <returns>An empty <see cref="StreamEventsSlice"/>.</returns>
public StreamEventsSlice ReadStreamBackward(string stream, long start, long count, UserCredentials credentials = null)
{
return new StreamEventsSlice(stream, 0, ReadDirection.Backward, Array.Empty<RecordedEvent>(), 0, 0, true);
}

/// <summary>
/// Gets an empty stream slice.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="start">This parameter is ignored.</param>
/// <param name="count">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <returns>An empty <see cref="StreamEventsSlice"/>.</returns>
public StreamEventsSlice ReadStreamForward(string stream, long start, long count, UserCredentials credentials = null)
{
return new StreamEventsSlice(stream, 0, ReadDirection.Forward, Array.Empty<RecordedEvent>(), 0, 0, true);
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="eventAppeared">This parameter is ignored.</param>
/// <param name="subscriptionDropped">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <param name="resolveLinkTos">This parameter is ignored.</param>
/// <returns>This connection.</returns>
public IDisposable SubscribeToAll(Action<RecordedEvent> eventAppeared, Action<SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials credentials = null, bool resolveLinkTos = true)
{
return this;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="from">This parameter is ignored.</param>
/// <param name="eventAppeared">This parameter is ignored.</param>
/// <param name="settings">This parameter is ignored.</param>
/// <param name="liveProcessingStarted">This parameter is ignored.</param>
/// <param name="subscriptionDropped">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <param name="resolveLinkTos">This parameter is ignored.</param>
/// <returns>This connection.</returns>
public IDisposable SubscribeToAllFrom(Position from, Action<RecordedEvent> eventAppeared, CatchUpSubscriptionSettings settings = null, Action liveProcessingStarted = null, Action<SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials credentials = null, bool resolveLinkTos = true)
{
return this;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="eventAppeared">This parameter is ignored.</param>
/// <param name="subscriptionDropped">This parameter is ignored.</param>
/// <param name="credentials">This parameter is ignored.</param>
/// <returns>This connection.</returns>
public IDisposable SubscribeToStream(string stream, Action<RecordedEvent> eventAppeared, Action<SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials credentials = null)
{
return this;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="IStreamStoreConnection"/>.
/// </summary>
/// <param name="stream">This parameter is ignored.</param>
/// <param name="lastCheckpoint">This parameter is ignored.</param>
/// <param name="settings">This parameter is ignored.</param>
/// <param name="eventAppeared">This parameter is ignored.</param>
/// <param name="liveProcessingStarted">This parameter is ignored.</param>
/// <param name="subscriptionDropped">This parameter is ignored.</param>
/// <param name="credentials"></param>
/// <returns>This connection.</returns>
public IDisposable SubscribeToStreamFrom(string stream, long? lastCheckpoint, CatchUpSubscriptionSettings settings, Action<RecordedEvent> eventAppeared, Action<Unit> liveProcessingStarted = null, Action<SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials credentials = null)
{
return this;
}

}
}
74 changes: 70 additions & 4 deletions src/ReactiveDomain.Testing/Specifications/NullListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,121 @@

namespace ReactiveDomain.Testing
{
/// <summary>
/// An empty listener that implements <see cref="IListener"/>.
/// </summary>
public class NullListener : IListener, ISubscriber
{

private string _stream = "";
public long _position = 0;
private string _stream;
private long _position;
/// <summary>
/// Gets a <see cref="NullListener"/>
/// </summary>
public ISubscriber EventStream => this;

/// <summary>
/// Gets the position of the stream.
/// </summary>
public long Position => _position;

/// <summary>
/// Gets the name of the stream.
/// </summary>
public string StreamName => _stream;

/// <summary>
/// Creates an empty lister.
/// </summary>
/// <param name="name">This parameter is ignored.</param>
public NullListener(string name = "")
{
_stream = name;
{
}

/// <summary>
/// Cleans up resources.
/// </summary>
public void Dispose()
{
}

/// <summary>
/// Starts the listener at the requested checkpoint. Since the listener is not connected to anything,
/// this simply sets the listener's initial checkpoint.
/// </summary>
/// <param name="stream">The name of the stream.</param>
/// <param name="checkpoint">The position at which the listener should start.</param>
/// <param name="blockUntilLive">This parameter is ignored.</param>
/// <param name="cancelWaitToken">This parameter is ignored.</param>
public void Start(string stream, long? checkpoint = null, bool blockUntilLive = false, CancellationToken cancelWaitToken = default)
{
_stream = stream;
_position = checkpoint ?? 0;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="ISubscriber"/>.
/// </summary>
/// <param name="handler"></param>
/// <returns></returns>
public IDisposable SubscribeToAll(IHandle<IMessage> handler)
{
return this;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="ISubscriber"/>.
/// </summary>
/// <typeparam name="T">This type parameter is ignored.</typeparam>
/// <param name="includeDerived">This parameter is ignored.</param>
/// <returns><c>false</c> since the listener does not actually subscribe to anything.</returns>
bool ISubscriber.HasSubscriberFor<T>(bool includeDerived)
{
return false;
}

/// <summary>
/// Does nothing other than set the stream name. Required for implementation of <see cref="IListener"/>.
/// </summary>
/// <typeparam name="TAggregate">The type of aggregate. Used for building the listener's stream name.</typeparam>
/// <param name="id">The ID of the aggregate whose stream to listen to.</param>
/// <param name="checkpoint">This parameter is ignored.</param>
/// <param name="blockUntilLive">This parameter is ignored.</param>
/// <param name="cancelWaitToken">This parameter is ignored.</param>
void IListener.Start<TAggregate>(Guid id, long? checkpoint, bool blockUntilLive, CancellationToken cancelWaitToken)
{
_stream = new PrefixedCamelCaseStreamNameBuilder().GenerateForAggregate(typeof(TAggregate), id);
}

/// <summary>
/// Does nothing other than set the stream name. Required for implementation of <see cref="IListener"/>.
/// </summary>
/// <typeparam name="TAggregate">The type of aggregate. Used for building the listener's stream name.</typeparam>
/// <param name="checkpoint">This parameter is ignored.</param>
/// <param name="blockUntilLive">This parameter is ignored.</param>
/// <param name="cancelWaitToken">This parameter is ignored.</param>
void IListener.Start<TAggregate>(long? checkpoint, bool blockUntilLive, CancellationToken cancelWaitToken)
{
_stream = nameof(TAggregate);
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="ISubscriber"/>.
/// </summary>
/// <typeparam name="T">This type parameter is ignored.</typeparam>
/// <param name="handler">This parameter is ignored.</param>
/// <param name="includeDerived">This parameter is ignored.</param>
/// <returns></returns>
IDisposable ISubscriber.Subscribe<T>(IHandle<T> handler, bool includeDerived)
{
return this;
}

/// <summary>
/// Does nothing. Required for implementation of <see cref="ISubscriber"/>.
/// </summary>
/// <typeparam name="T">This type parameter is ignored.</typeparam>
/// <param name="handler">This parameter is ignored.</param>
void ISubscriber.Unsubscribe<T>(IHandle<T> handler)
{
}
Expand Down
Loading

0 comments on commit c74f21c

Please sign in to comment.