public when_calling_publish()
        {
            this.partitionKey = Guid.NewGuid().ToString();
            this.version = "0001";
            string rowKey = "Unpublished_" + version;
            this.testEvent = Mock.Of<IEventRecord>(x =>
                x.PartitionKey == partitionKey
                && x.RowKey == rowKey
                && x.TypeName == "TestEventType"
                && x.SourceId == "TestId"
                && x.SourceType == "TestSourceType"
                && x.Payload == "serialized event"
                && x.CorrelationId == "correlation"
                && x.AssemblyName == "Assembly"
                && x.Namespace == "Namespace"
                && x.FullName == "Namespace.TestEventType");
            this.queue = new Mock<IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(partitionKey, It.IsAny<Action<IEnumerable<IEventRecord>, bool>>(), It.IsAny<Action<Exception>>()))
                .Callback<string, Action<IEnumerable<IEventRecord>, bool>, Action<Exception>>((key, success, error) => success(new[] { testEvent }, false));
            this.sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);

            sut.SendAsync(partitionKey, 0);

            Assert.True(sender.SendSignal.WaitOne(3000));
            cancellationTokenSource.Cancel();
        }
示例#2
0
        public when_calling_publish()
        {
            partitionKey = Guid.NewGuid().ToString();
            version      = "0001";
            var rowKey = "Unpublished_" + version;

            testEvent = Mock.Of <IEventRecord>(x =>
                                               x.PartitionKey == partitionKey &&
                                               x.RowKey == rowKey &&
                                               x.TypeName == "TestEventType" &&
                                               x.SourceId == "TestId" &&
                                               x.SourceType == "TestSourceType" &&
                                               x.Payload == "serialized event" &&
                                               x.CorrelationId == "correlation" &&
                                               x.AssemblyName == "Assembly" &&
                                               x.Namespace == "Namespace" &&
                                               x.FullName == "Namespace.TestEventType");
            queue = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(partitionKey, It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >((key, success, error) => success(new[] { testEvent }, false));
            sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();

            sut.Start(cancellationTokenSource.Token);

            sut.SendAsync(partitionKey, 0);

            Assert.True(sender.SendSignal.WaitOne(3000));
            cancellationTokenSource.Cancel();
        }
        public when_calling_publish()
        {
            this.partitionKey = Guid.NewGuid().ToString();
            this.version = "0001";
            string rowKey = "Unpublished_" + version;
            this.testEvent = Mock.Of<IEventRecord>(x =>
                x.PartitionKey == partitionKey
                && x.RowKey == rowKey
                && x.TypeName == "TestEventType"
                && x.SourceId == "TestId"
                && x.SourceType == "TestSourceType"
                && x.Payload == "serialized event"
                && x.AssemblyName == "Assembly"
                && x.Namespace == "Namespace"
                && x.FullName == "Namespace.TestEventType");
            this.queue = new Mock<IPendingEventsQueue>();
            queue.Setup(x => x.GetPending(partitionKey)).Returns(new[] { testEvent });
            this.sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object);
            var cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);

            sut.SendAsync(partitionKey);

            Assert.True(sender.ResetEvent.WaitOne(3000));
            cancellationTokenSource.Cancel();
        }
示例#4
0
        public when_starting_with_pending_events()
        {
            version = "0001";
            rowKey  = "Unpublished_" + version;

            pendingKeys = new[] { "Key1", "Key2", "Key3" };
            queue       = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny <string>(), It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >(
                (key, success, error) =>
                success(new[] {
                Mock.Of <IEventRecord>(
                    x => x.PartitionKey == key &&
                    x.RowKey == rowKey &&
                    x.TypeName == "TestEventType" &&
                    x.SourceId == "TestId" &&
                    x.SourceType == "TestSourceType" &&
                    x.Payload == "serialized event")
            },
                        false));

            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(pendingKeys);
            sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();

            sut.Start(cancellationTokenSource.Token);

            for (var i = 0; i < pendingKeys.Length; i++)
            {
                Assert.True(sender.SendSignal.WaitOne(5000));
            }
            cancellationTokenSource.Cancel();
        }
示例#5
0
        public given_event_store_with_events_after_it_is_started()
        {
            version = "0001";
            rowKey  = "Unpublished_" + version;

            partitionKeys = Enumerable.Range(0, 200).Select(i => "Key" + i).ToArray();
            queue         = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny <string>(), It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >(
                (key, success, error) =>
                success(new[] {
                Mock.Of <IEventRecord>(
                    x => x.PartitionKey == key &&
                    x.RowKey == rowKey &&
                    x.TypeName == "TestEventType" &&
                    x.SourceId == "TestId" &&
                    x.SourceType == "TestSourceType" &&
                    x.Payload == "serialized event")
            },
                        false));

            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(Enumerable.Empty <string>());
            queue
            .Setup(x =>
                   x.DeletePendingAsync(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <Action <bool> >(),
                       It.IsAny <Action <Exception> >()))
            .Callback <string, string, Action <bool>, Action <Exception> >((p, r, s, e) => s(true));
            sender = new MessageSenderMock();
            sut    = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);
        }
示例#6
0
            public void Assure_confirmation_message_is_sent_to_the_user()
            {
                var messageSenderMock = new MessageSenderMock();
                var shoppingCart = new ShoppingCart(new EmailMessageSenderAdapter());

                shoppingCart.PlaceOrder();

                Assert.AreEqual(1, messageSenderMock.SendCallCount);
            }
        public void when_sending_then_sets_command_id_as_messageid()
        {
            var sender = new MessageSenderMock();
            var sut = new CommandBus(sender, Mock.Of<IMetadataProvider>(), new JsonTextSerializer());

            var command = new FooCommand { Id = Guid.NewGuid() };
            sut.Send(command);

            Assert.Equal(command.Id.ToString(), sender.Sent.Single().MessageId);
        }
示例#8
0
        public void when_specifying_delay_then_sets_in_message()
        {
            var sender = new MessageSenderMock();
            var sut = new CommandBus(sender, Mock.Of<IMetadataProvider>(), new JsonTextSerializer());

            var command = new Envelope<ICommand>(new FooCommand { Id = Guid.NewGuid() })
            {
                Delay = TimeSpan.FromMinutes(15)
            };
            sut.Send(command);
            Assert.IsTrue(sender.Sent.Single().TimeToLive > TimeSpan.FromMinutes(14.9) && sender.Sent.Single().TimeToLive < TimeSpan.FromMinutes(15.1));
        }
        public void when_specifying_delay_then_sets_in_message()
        {
            var sender = new MessageSenderMock();
            var sut = new CommandBus(sender, Mock.Of<IMetadataProvider>(), new JsonTextSerializer());

            var command = new Envelope<ICommand>(new FooCommand { Id = Guid.NewGuid() })
            {
                Delay = TimeSpan.FromMinutes(15)
            };
            sut.Send(command);

            Assert.InRange(sender.Sent.Single().ScheduledEnqueueTimeUtc, DateTime.UtcNow.AddMinutes(14.9), DateTime.UtcNow.AddMinutes(15.1));
        }
示例#10
0
        public void when_sending_then_sets_command_id_as_messageid()
        {
            var sender = new MessageSenderMock();
            var sut    = new CommandBus(sender, Mock.Of <IMetadataProvider>(), new JsonTextSerializer());

            var command = new FooCommand {
                Id = Guid.NewGuid()
            };

            sut.Send(command);

            Assert.Equal(command.Id.ToString(), sender.Sent.Single().MessageId);
        }
示例#11
0
        public void when_specifying_delay_then_sets_in_message()
        {
            var sender = new MessageSenderMock();
            var sut    = new CommandBus(sender, Mock.Of <IMetadataProvider>(), new JsonTextSerializer());

            var command = new Envelope <ICommand>(new FooCommand {
                Id = Guid.NewGuid()
            })
            {
                Delay = TimeSpan.FromMinutes(15)
            };

            sut.Send(command);

            Assert.InRange(sender.Sent.Single().ScheduledEnqueueTimeUtc, DateTime.UtcNow.AddMinutes(14.9), DateTime.UtcNow.AddMinutes(15.1));
        }
示例#12
0
        public void when_specifying_time_to_live_then_sets_in_message()
        {
            var sender = new MessageSenderMock();
            var sut    = new CommandBus(sender, Mock.Of <IMetadataProvider>(), new JsonTextSerializer());

            var command = new Envelope <ICommand>(new FooCommand {
                Id = Guid.NewGuid()
            })
            {
                TimeToLive = TimeSpan.FromMinutes(15)
            };

            sut.Send(command);

            Assert.InRange(sender.Sent.Single().TimeToLive, TimeSpan.FromMinutes(14.9), TimeSpan.FromMinutes(15.1));
        }
 public void Expect_the_ack_request_to_be_sent()
 {
     MessageSenderMock.Verify((ms) => ms.SendRequest(It.Is <SipRequest>(r => r.RequestLine.Method == SipMethods.Ack)), Times.Once());
 }
        public when_starting_with_pending_events()
        {
            this.version = "0001";
            this.rowKey = "Unpublished_" + version;

            this.pendingKeys = new[] { "Key1", "Key2", "Key3" };
            this.queue = new Mock<IPendingEventsQueue>();
            queue.Setup(x => x.GetPending(It.IsAny<string>())).Returns<string>(
                key => new[]
                           {
                               Mock.Of<IEventRecord>(
                                   x => x.PartitionKey == key
                                        && x.RowKey == rowKey
                                        && x.TypeName == "TestEventType"
                                        && x.SourceId == "TestId"
                                        && x.SourceType == "TestSourceType"
                                        && x.Payload == "serialized event")
                           });
            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(pendingKeys);
            this.sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object);
            var cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);

            for (int i = 0; i < pendingKeys.Length; i++)
            {
                Assert.True(sender.ResetEvent.WaitOne(5000));
            }
            cancellationTokenSource.Cancel();
        }
        public given_event_store_with_events_after_it_is_started()
        {
            this.version = "0001";
            this.rowKey = "Unpublished_" + version;

            this.partitionKeys = Enumerable.Range(0, 200).Select(i => "Key" + i).ToArray();
            this.queue = new Mock<IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny<string>(), It.IsAny<Action<IEnumerable<IEventRecord>, bool>>(), It.IsAny<Action<Exception>>()))
                .Callback<string, Action<IEnumerable<IEventRecord>, bool>, Action<Exception>>(
                (key, success, error) =>
                    success(new[]
                                {
                                    Mock.Of<IEventRecord>(
                                        x => x.PartitionKey == key
                                            && x.RowKey == rowKey
                                            && x.TypeName == "TestEventType"
                                            && x.SourceId == "TestId"
                                            && x.SourceType == "TestSourceType"
                                            && x.Payload == "serialized event")
                                },
                    false));

            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(Enumerable.Empty<string>());
            queue
                .Setup(x =>
                    x.DeletePendingAsync(
                        It.IsAny<string>(),
                        It.IsAny<string>(),
                        It.IsAny<Action<bool>>(),
                        It.IsAny<Action<Exception>>()))
                .Callback<string, string, Action<bool>, Action<Exception>>((p, r, s, e) => s(true));
            this.sender = new MessageSenderMock();
            this.sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            this.cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);
        }
        public when_starting_with_pending_events()
        {
            this.version = "0001";
            this.rowKey = "Unpublished_" + version;

            this.pendingKeys = new[] { "Key1", "Key2", "Key3" };
            this.queue = new Mock<IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny<string>(), It.IsAny<Action<IEnumerable<IEventRecord>, bool>>(), It.IsAny<Action<Exception>>()))
                .Callback<string, Action<IEnumerable<IEventRecord>, bool>, Action<Exception>>(
                (key, success, error) => 
                    success(new[]
                           {
                               Mock.Of<IEventRecord>(
                                   x => x.PartitionKey == key
                                        && x.RowKey == rowKey
                                        && x.TypeName == "TestEventType"
                                        && x.SourceId == "TestId"
                                        && x.SourceType == "TestSourceType"
                                        && x.Payload == "serialized event")
                           },
                    false));
            
                
            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(pendingKeys);
            this.sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);

            for (int i = 0; i < pendingKeys.Length; i++)
            {
                Assert.True(sender.SendSignal.WaitOne(5000));
            }
            cancellationTokenSource.Cancel();
        }
 public void Expect_the_Request_to_be_sent()
 {
     MessageSenderMock.Verify((ms) => ms.SendRequest(It.IsAny <SipRequest>()), Times.Once());
 }