public void RegisterANewChannel_ShouldThrowDuplicateKeyException()
        {
            //Arange
            var channelService = new EventChannelService
                                 (
                new EventChannelRepository("ECommerce.Data.FileStore",
                                           new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                           _loggerFactory, new MyDiagnosticSource())
                                 );

            //Act
            Action comparison = () =>
            {
                var channel = new EventChannel
                {
                    IsFifo                = true,
                    Key                   = Guid.NewGuid().ToString(),
                    Name                  = "TestChannel",
                    MaxLifeTimeMessage    = 30,
                    MaxLifeTimeSubscriber = 30
                };

                channelService.RegisterChannelAsync(channel).Wait();

                channelService.RegisterChannelAsync(channel).Wait();
            };

            //Assert
            comparison.Should().Throw <DuplicateNameException>();
        }
        public void RegisterANewChannel_ShouldReturnTrue()
        {
            //Arrange
            var channelService = new EventChannelService
                                 (
                new EventChannelRepository("ECommerce.Data.FileStore",
                                           new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                           _loggerFactory, new MyDiagnosticSource())
                                 );

            //Act
            var executionResult = channelService.RegisterChannelAsync(new EventChannel
            {
                IsFifo                = true,
                Key                   = Guid.NewGuid().ToString(),
                Name                  = "TestChannel",
                MaxLifeTimeMessage    = 30,
                MaxLifeTimeSubscriber = 30
            }).Result;

            //Assert
            executionResult.Should().NotBeNull();
            executionResult.IsSuccessful.Should().BeTrue();
        }
Exemplo n.º 3
0
        private void AddChannel(out EventChannelRepository eventChannelRepository, out EventChannel channel, int timeout = 30)
        {
            //Arrange
            eventChannelRepository = new EventChannelRepository("ECommerce.Data.FileStore",
                                                                new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                _loggerFactory, new MyDiagnosticSource());
            var channelService = new EventChannelService
                                 (
                eventChannelRepository
                                 );

            channel = EventChannelRegistrationTests.AddChannel(channelService, timeout);

            channel.Should().NotBeNull();
        }
        public void RegisterANewChannel_ShouldThrowArgumentNullException()
        {
            //Arange
            var channelService = new EventChannelService
                                 (
                new EventChannelRepository("ECommerce.Data.FileStore",
                                           new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                           _loggerFactory, new MyDiagnosticSource())
                                 );

            //Act
            Action comparison = () => { channelService.RegisterChannelAsync(null).Wait(); };

            //Assert
            comparison.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 5
0
        public void ShouldRegiserAChannelAndSubscribe()
        {
            //Arrange
            var eventChannelRepository = new EventChannelRepository("ECommerce.Data.FileStore",
                                                                    new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                    _loggerFactory, new MyDiagnosticSource());

            var channelService = new EventChannelService
                                 (
                eventChannelRepository
                                 );

            var channel = EventChannelRegistrationTests.AddChannel(channelService);

            //Arrange Subscription service
            var subscriptionService = new EventSubscriptionService
                                      (
                new EventSubscriptionRepository(eventChannelRepository, "ECommerce.Data.FileStore",
                                                new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                _loggerFactory, new MyDiagnosticSource())
                                      );

            var subscriptionResult = subscriptionService.SubscribeAsync(new EventSubscription
            {
                Channel = channel,
                Key     = Guid.NewGuid().ToString()
            }).Result;

            //Assert
            subscriptionResult.Should().NotBeNull();
            subscriptionResult.IsSuccessful.Should().BeTrue();
        }
Exemplo n.º 6
0
        public void ShouldRegiserAChannelThenSubscribeAndGetListOfSubscriptions()
        {
            //Arrange
            var eventChannelRepository = new EventChannelRepository("ECommerce.Data.FileStore",
                                                                    new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                    _loggerFactory, new MyDiagnosticSource());

            var channelService = new EventChannelService
                                 (
                eventChannelRepository
                                 );

            EventChannel channel;

            //Act
            var executionGetResult = channelService.GetChannelAsync(x => x.Name == "TestChannel").Result;

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

            if (executionGetResult.Result == null)
            {
                var executionResult = channelService.RegisterChannelAsync(new EventChannel
                {
                    IsFifo                = true,
                    Key                   = Guid.NewGuid().ToString(),
                    Name                  = "TestChannel",
                    MaxLifeTimeMessage    = 30,
                    MaxLifeTimeSubscriber = 30
                }).Result;

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

                channel = executionResult.Result;
            }
            else
            {
                channel = executionGetResult.Result;
            }

            channel.Should().NotBeNull();

            //Arrange Subscription service
            var subscriptionService = new EventSubscriptionService
                                      (
                new EventSubscriptionRepository(eventChannelRepository, "ECommerce.Data.FileStore",
                                                new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                _loggerFactory, new MyDiagnosticSource())
                                      );

            var subscriptionResult = subscriptionService.SubscribeAsync(new EventSubscription
            {
                Channel = channel,
                Key     = Guid.NewGuid().ToString()
            }).Result;

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

            var searchResult = subscriptionService.GetListByChannel(channel.Key).Result;

            //Assert
            searchResult.Should().NotBeNull();
            searchResult.IsSuccessful.Should().BeTrue();
            searchResult.Result.Should().HaveCount(1);
        }
Exemplo n.º 7
0
        public void ShouldRegiserAChannelAndSubscribeThrowKeyNotFoundException()
        {
            //Arrange
            var eventChannelRepository = new EventChannelRepository("ECommerce.Data.FileStore",
                                                                    new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                                    _loggerFactory, new MyDiagnosticSource());

            var channelService = new EventChannelService
                                 (
                eventChannelRepository
                                 );

            EventChannel channel;

            //Act
            var executionGetResult = channelService.GetChannelAsync(x => x.Name == "TestChannel").Result;

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

            if (executionGetResult.Result == null)
            {
                var executionResult = channelService.RegisterChannelAsync(new EventChannel
                {
                    IsFifo                = true,
                    Key                   = Guid.NewGuid().ToString(),
                    Name                  = "TestChannel",
                    MaxLifeTimeMessage    = 30,
                    MaxLifeTimeSubscriber = 30
                }).Result;

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

                channel = executionResult.Result;
            }
            else
            {
                channel = executionGetResult.Result;
            }

            channel.Should().NotBeNull();

            //Arrange Subscription service
            var subscriptionService = new EventSubscriptionService
                                      (
                new EventSubscriptionRepository(eventChannelRepository, "ECommerce.Data.FileStore",
                                                new ConnectionOptions
            {
                Provider         = "FileDb",
                ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName
            },
                                                _loggerFactory, new MyDiagnosticSource())
                                      );

            Action comparison = () =>
            {
                var eventSubscription = new EventSubscription
                {
                    Channel = new EventChannel
                    {
                        IsFifo                = true,
                        Key                   = Guid.NewGuid().ToString(),
                        MaxLifeTimeMessage    = 30,
                        MaxLifeTimeSubscriber = 30,
                        Name                  = "test"
                    },
                    Key = Guid.NewGuid().ToString()
                };

                subscriptionService.SubscribeAsync(eventSubscription).Wait();
            };

            //Assert
            comparison.Should().Throw <KeyNotFoundException>();
        }