예제 #1
0
            public async Task SetUp()
            {
                await ClearAllDataFiles();

                var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan);

                _bus = new DurableMessageBus(retryPolicy);

                _commands = new CommandSubscribers();
                _events   = new EventSubscribers();
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);
            }
예제 #2
0
            public async Task SetUp()
            {
                await ClearAllDataFiles();

                var retryPolicy = new RetryPolicy();

                Assume.That(retryPolicy.Retries, Is.EqualTo(0));

                _bus = new DurableMessageBus(retryPolicy);

                _commands = new CommandSubscribers();
                _events   = new EventSubscribers();
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);
            }
        public async Task MultipleSubscribersCanProcessMessageOnEventPublish()
        {
            const string input = "test";

            //two identical handlers will be registered for the single event,
            // so the result will be the input value twice
            var expected = string.Format("{0}{0}", input);

            var events = new EventSubscribers();

            _bus.RegisterSubscriptionFor <TestEvent>(events.Handle);
            _bus.RegisterSubscriptionFor <TestEvent>(events.Handle);

            await _bus.Publish(new TestEvent(input));

            Assert.That(events.ProcessedMessagePayload, Is.EqualTo(expected));
        }
        public void CanUnregisterSubscriberByKey()
        {
            Assume.That(_bus.HasSubscriptionFor <TestEvent>(), Is.False, "Expected the bus to not have any subscriptions for TestEvent");

            var events = new EventSubscribers();

            _bus.RegisterSubscriptionFor <TestEvent>("Key1", events.Handle);
            _bus.RegisterSubscriptionFor <TestEvent>("Key2", events.Handle);

            Assume.That(_bus.HasSubscription("Key1"), Is.True, "Expected a subscriber registered with key: Key1");
            Assume.That(_bus.HasSubscription("Key2"), Is.True, "Expected a subscriber registered with key: Key2");

            _bus.UnRegisterSubscription("Key1");

            Assert.That(_bus.HasSubscription("Key1"), Is.False);
            Assert.That(_bus.HasSubscription("Key2"), Is.True);
        }
예제 #5
0
            public async Task MessageIsNotSendToSubscriberOnStart()
            {
                const string singleValue = "0";

                //we need a retry policy with at least one retry
                //  so that we'd expect the call to Start() to attempt a retry
                var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan);

                var bus    = new DurableMessageBus(retryPolicy);
                var events = new EventSubscribers();

                bus.RegisterSubscriptionFor <TestDurableEvent>(events.Handle);

                await bus.PublishDurable(new TestDurableEvent(singleValue));

                Assume.That(events.ProcessedMessagePayload, Is.EqualTo(singleValue), "Event Subscriber didn't receive the expected message.");

                bus.UnRegisterAllSubscriptionsFor <TestDurableEvent>();

                await bus.Start();

                Assert.That(events.ProcessedMessagePayload, Is.EqualTo(singleValue), "Bus did not properly ignore queued event.");
            }