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 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(); }