public void ShouldRegiserAChannelAndSubscribeThrowArgumentNull() { //Arrange var eventChannelRepository = new EventChannelRepository("ECommerce.Data.FileStore", new ConnectionOptions { Provider = "FileDb", ConnectionString = new FileInfo($"data\\data_{Guid.NewGuid()}.json").FullName }, _loggerFactory, new MyDiagnosticSource()); //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 = () => { subscriptionService.SubscribeAsync(null).Wait(); }; //Assert comparison.Should().Throw <ArgumentNullException>(); }
public static EventSubscription AddSubscription(EventChannel channel, EventSubscriptionService subscriptionService) { var subscriptionResult = subscriptionService.SubscribeAsync(new EventSubscription { Channel = channel, Key = Guid.NewGuid().ToString() }).Result; subscriptionResult.Should().NotBeNull(); subscriptionResult.IsSuccessful.Should().BeTrue(); return(subscriptionResult.Result); }
private EventSubscription AddSubscription(out EventChannel channel, out EventSubscriptionService subscriptionService, int timeout = 30) { AddChannel(out var eventChannelRepository, out channel, timeout); //Arrange Subscription service 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 subscription = EventSubscriptionTests.AddSubscription(channel, subscriptionService); return(subscription); }
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(); }
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); }
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>(); }
public void ShouldAddTheMessageAndPassItToTheSubscriberAfterStarting() { //Arrange AddChannel(out var eventChannelRepository, out var eventChannel); 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())); var resultPublish = eventMessageService.PublishAsync(new EventMessage { Channel = eventChannel, Key = Guid.NewGuid().ToString(), PublishDateTime = DateTime.Now }).Result; resultPublish.Should().NotBeNull(); resultPublish.IsSuccessful.Should().BeTrue(); var searchResult = eventMessageService.GetEventsByChannelAsync(eventChannel).Result; searchResult.Should().NotBeNull(); searchResult.IsSuccessful.Should().BeTrue(); var message = searchResult.Result?.FirstOrDefault(); message.Should().NotBeNull(); message?.IsProcessing.Should().BeFalse(); // Act 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 subscription = EventSubscriptionTests.AddSubscription(eventChannel, subscriptionService); subscription.Should().NotBeNull(); eventMessageService.GetMessageBySubscriberAsync(subscription).Wait(); Task.Delay(100).Wait(); searchResult = eventMessageService.GetEventsByChannelAsync(eventChannel).Result; searchResult.Should().NotBeNull(); searchResult.IsSuccessful.Should().BeTrue(); message = searchResult.Result?.FirstOrDefault(); Assert.NotNull(message); message.IsProcessing.Should().BeTrue(); }