Stubbing Out IConnection

We have been looking at evolving our unit testing by stubbing IConnection so we can inject event history and action subscriptions etc on it, and then verify the results. It would be a really nice end to end verification mechanism.

I have implemented by own IConnection subscription

public EventStoreAllCatchUpSubscription SubscribeToAllFrom(Position? lastCheckpoint, CatchUpSubscriptionSettings settings,

Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, Action liveProcessingStarted = null, Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,

UserCredentials userCredentials = null)

{

// CreateInstance enabled to access protected methods

var subscription = (EventStoreAllCatchUpSubscription)Activator.CreateInstance(

typeof(EventStoreAllCatchUpSubscription),

BindingFlags.NonPublic | BindingFlags.Instance,

null,

new object[]

{

EventStoreServer.Connection,

new TestLogging(),

lastCheckpoint,

new UserCredentials(“user”, “pass”),

eventAppeared,

liveProcessingStarted,

subscriptionDropped,

settings

},

CultureInfo.InvariantCulture);

return subscription;

}

When I spin up the code that uses this (in an MSTest test), it runs ok, but just completes straight away, and none of the stream r/w methods are accessed (they should throw notImplemented if currently called).

Any advice you can give, or info you need to clarify

I dont understand what you are trying to ask.

You have not included anything about your read/write methods or how
you are calling them etc?

If you are expecting the CatchUpAllSubscription to start doing things
(it doesnt do writes)
https://github.com/EventStore/EventStore/blob/release-v3.9.0/src/EventStore.ClientAPI/EventStoreCatchUpSubscription.cs#L128
you need to call the Start method.

This really feels like you are testing event store code though not
your code and probably is a code smell.

Fair enough. Would make more sense to do this at the level of our repository. Thanks for the nudge

Cheerz, Dave