Esempio n. 1
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);
        }
Esempio n. 2
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>();
        }