コード例 #1
0
        public void ShouldRegisterAChannelAddASubscriptionAndPublishAnEvent()
        {
            //Arrange
            AddSubscription(out var channel, out var subscriptionService);

            var eventMessageService = new EventMessageService(new EventRepository(subscriptionService.Repository.ChannelRepository, "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            var resultPublish = eventMessageService.PublishAsync(new EventMessage
            {
                Channel         = channel,
                Key             = Guid.NewGuid().ToString(),
                PublishDateTime = DateTime.Now
            }).Result;

            //Assert
            resultPublish.Should().NotBeNull();
            resultPublish.IsSuccessful.Should().BeTrue();
        }
コード例 #2
0
        public void ShouldReturnTheListOfMessageExpiredWithoutProcessing()
        {
            AddChannel(out var eventChannelRepository, out var channel, 1);

            var eventMessageService = new EventMessageService(new EventRepository(eventChannelRepository,
                                                                                  "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            var resultPublish = eventMessageService.PublishAsync(new EventMessage
            {
                Channel         = channel,
                Key             = Guid.NewGuid().ToString(),
                PublishDateTime = DateTime.Now
            }).Result;

            //Assert
            resultPublish.Should().NotBeNull();
            resultPublish.IsSuccessful.Should().BeTrue();

            var searchResult = eventMessageService.GetEventsByChannelAsync(channel).Result;

            searchResult.Should().NotBeNull();
            searchResult.IsSuccessful.Should().BeTrue();

            var message = searchResult.Result?.FirstOrDefault();

            message.Should().NotBeNull();

            // Assert
            message?.IsProcessing.Should().BeFalse();

            Task.Delay(1000).Wait();

            var revokeResult = eventMessageService.RevokeExpiredMessageAsync(channel).Result;

            revokeResult.Should().NotBeNull();
            revokeResult.IsSuccessful.Should().BeTrue();

            revokeResult.Result.Should().HaveCountGreaterOrEqualTo(1);
        }
コード例 #3
0
        public void ShouldAddTheMessageAndPassItDirectlyToTheSubscriber()
        {
            var subscription = AddSubscription(out var channel, out var eventSubscriptionService);

            var eventMessageService = new EventMessageService(new EventRepository(eventSubscriptionService.Repository.ChannelRepository,
                                                                                  "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            var resultPublish = eventMessageService.PublishAsync(new EventMessage
            {
                Channel         = channel,
                Key             = Guid.NewGuid().ToString(),
                PublishDateTime = DateTime.Now
            }).Result;

            //Assert
            resultPublish.Should().NotBeNull();
            resultPublish.IsSuccessful.Should().BeTrue();

            var resultGetMessage = eventMessageService.GetMessageBySubscriberAsync(subscription).Result;

            resultGetMessage.Should().NotBeNull();
            resultGetMessage.IsSuccessful.Should().BeTrue();

            Task.Delay(100).Wait();

            var searchResult = eventMessageService.GetEventsByChannelAsync(channel).Result;

            searchResult.Should().NotBeNull();
            searchResult.IsSuccessful.Should().BeTrue();

            var message = searchResult.Result?.FirstOrDefault();

            message.Should().NotBeNull();

            // Assert
            message?.IsProcessing.Should().BeTrue();
        }
コード例 #4
0
        public void ShouldRegisterAChannelAddASubscriptionAndPublishAnEventThrowInvalideOperation()
        {
            //Arrange
            AddSubscription(out var _, out var subscriptionService);

            var eventMessageService = new EventMessageService(new EventRepository(subscriptionService.Repository.ChannelRepository, "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            Action comparison = () =>
            {
                try
                {
                    var resultPublish = eventMessageService.PublishAsync(new EventMessage
                    {
                        Channel = new EventChannel
                        {
                            IsFifo                = true,
                            Key                   = Guid.NewGuid().ToString(),
                            MaxLifeTimeMessage    = 30,
                            Name                  = "Test",
                            MaxLifeTimeSubscriber = 30
                        },
                        Key             = Guid.NewGuid().ToString(),
                        PublishDateTime = DateTime.Now
                    }).Result;

                    resultPublish.Should().NotBeNull();
                    resultPublish.IsSuccessful.Should().BeTrue();
                }
                catch (AggregateException ex)
                {
                    ex.Handle((x) => throw x);
                }
            };

            //Assert
            comparison.Should().Throw <InvalidOperationException>();
        }
コード例 #5
0
        public void ShouldRegisterAChannelAddASubscriptionAndPublishAnEventThrowArgumentNull()
        {
            //Arrange
            AddSubscription(out var _, out var subscriptionService);

            var eventMessageService = new EventMessageService(new EventRepository(subscriptionService.Repository.ChannelRepository, "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            Action comparison = () =>
            {
                eventMessageService.PublishAsync(null).Wait();
            };

            //Assert
            comparison.Should().Throw <ArgumentNullException>();
        }
コード例 #6
0
        public void ShouldPoolInWaitingQueeUntilASubscriberArrives()
        {
            AddChannel(out var eventChannelRepository, out var channel);

            var eventMessageService = new EventMessageService(new EventRepository(eventChannelRepository,
                                                                                  "ECommerce.Data.FileStore",
                                                                                  new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                                  _loggerFactory, new MyDiagnosticSource()));

            //Act
            var resultPublish = eventMessageService.PublishAsync(new EventMessage
            {
                Channel         = channel,
                Key             = Guid.NewGuid().ToString(),
                PublishDateTime = DateTime.Now
            }).Result;

            //Assert
            resultPublish.Should().NotBeNull();
            resultPublish.IsSuccessful.Should().BeTrue();

            var searchResult = eventMessageService.GetEventsByChannelAsync(channel).Result;

            searchResult.Should().NotBeNull();
            searchResult.IsSuccessful.Should().BeTrue();

            var message = searchResult.Result?.FirstOrDefault();

            message.Should().NotBeNull();

            // Assert
            message?.IsProcessing.Should().BeFalse();
        }