public async Task Invoke_MethodWithSingleMessageParameterOfAncestorType_MethodInvoked() { var calls = 0; var subscribedMethod = new DelegateSubscription((Action <IEvent>)Method1, new SubscriptionOptions()); var messages = new object[] { new TestEventOne(), new TestEventTwo(), new TestEventOne() }; await new SubscribedMethodInvoker(_returnValueHandler, _serviceProvider) .InvokeAsync( subscribedMethod.GetSubscribedMethods(_serviceProvider).First(), messages, true); calls.Should().Be(3); void Method1(IEvent @event) => calls++; }
public async Task Invoke_MethodWithEnumerableParameter_MethodInvokedForMatchingMessages() { var receivedMessages = 0; var(resolver, handler) = GetDefaultResolverAndHandler(); var subscribedMethod = new DelegateSubscription((Action <IEnumerable <TestEventOne> >)Method1, new SubscriptionOptions()); var messages = new object[] { new TestEventOne(), new TestEventTwo(), new TestEventOne() }; await new SubscribedMethodInvoker(resolver, handler, ServiceProvider) .Invoke( subscribedMethod.GetSubscribedMethods(ServiceProvider).First(), messages, true); receivedMessages.Should().Be(2); void Method1(IEnumerable <TestEventOne> events) => receivedMessages += events.Count(); }
public async Task Invoke_MethodWithSingleMessageParameterOfNotMatchingType_MethodNotInvoked() { var calls = 0; var(resolver, handler) = GetDefaultResolverAndHandler(); var subscribedMethod = new DelegateSubscription((Action <TestCommandOne>)Method1, new SubscriptionOptions()); var messages = new object[] { new TestEventOne(), new TestEventTwo(), new TestEventOne() }; await new SubscribedMethodInvoker(resolver, handler, ServiceProvider) .Invoke( subscribedMethod.GetSubscribedMethods(ServiceProvider).First(), messages, true); calls.Should().Be(0); void Method1(TestCommandOne command) => calls++; }
public async Task Invoke_MethodWithReadOnlyCollectionParameterOfAncestorType_MethodInvoked() { var receivedMessages = 0; var subscribedMethod = new DelegateSubscription((Action <IReadOnlyCollection <IEvent> >)Method1, new SubscriptionOptions()); var messages = new object[] { new TestEventOne(), new TestEventTwo(), new TestEventOne() }; await new SubscribedMethodInvoker(_returnValueHandler, _serviceProvider) .InvokeAsync( subscribedMethod.GetSubscribedMethods(_serviceProvider).First(), messages, true); receivedMessages.Should().Be(3); void Method1(IReadOnlyCollection <IEvent> events) => receivedMessages += events.Count; }
public async Task Invoke_NoMessagesMatchingReadOnlyCollectionType_MethodNotInvoked() { var calls = 0; var subscribedMethod = new DelegateSubscription( (Action <IReadOnlyCollection <TestCommandOne> >)Method1, new SubscriptionOptions()); var messages = new object[] { new TestEventOne(), new TestEventTwo(), new TestEventOne() }; await new SubscribedMethodInvoker(_returnValueHandler, _serviceProvider) .InvokeAsync( subscribedMethod.GetSubscribedMethods(_serviceProvider).First(), messages, true); calls.Should().Be(0); void Method1(IReadOnlyCollection <TestCommandOne> events) => calls++; }
public async Task Invoke_Envelopes_MethodInvoked() { var calls = 0; var subscribedMethod = new DelegateSubscription((Action <TestEnvelope>)Method1, new SubscriptionOptions()); var envelopes = new object[] { new TestEnvelope(new TestEventOne()), new TestEnvelope(new TestEventTwo()), new TestEnvelope(new TestEventOne()) }; await new SubscribedMethodInvoker(_returnValueHandler, _serviceProvider) .InvokeAsync( subscribedMethod.GetSubscribedMethods(_serviceProvider).First(), envelopes, true); calls.Should().Be(3); void Method1(TestEnvelope envelope) => calls++; }