public async Task ReceivesAndSendsCommand() { var inputSubscription = nameof(ReceivesAndSendsCommand); await CreateEndToEndTestSubscriptionsAsync(inputSubscription); var services = new ServiceCollection(); services.AddHostedService <MessageBusHostedService>() .AddSingleton <IMessageTracker, MessageTracker>() .AddMessageBus(new AzureServiceBusClientBuilder(Configuration["Hostname"], Configuration["Topic"], inputSubscription, Configuration["TenantId"])) .SubscribeToMessage <SetAutopilot, SetAutopilotHandler>(); _serviceProvider = services.BuildServiceProvider(); await StartMessageBusHostedServiceAsync(_serviceProvider); var setAutopilotCommand = new SetAutopilot { AutopilotId = Guid.NewGuid().ToString() }; await SendMessagesAsync(setAutopilotCommand, nameof(SetAutopilot)); await Task.Delay(TimeSpan.FromSeconds(4)); Assert.DoesNotContain(await ReceiveMessagesForSubscriptionAsync(inputSubscription), m => m.Body.ToObjectFromJson <CreateNewFlightPlan>().Destination == setAutopilotCommand.AutopilotId); Assert.Single(await ReceiveMessagesForSubscriptionAsync($"{inputSubscription}-Output"), m => m.Subject == nameof(MonitorAutopilot) && m.Body.ToObjectFromJson <MonitorAutopilot>().AutopilotIdentifider == setAutopilotCommand.AutopilotId); }
public async Task SendsCommand() { var subscription = nameof(SendsCommand); await CreateEndToEndTestSubscriptionsAsync(subscription); var services = new ServiceCollection(); services.AddHostedService <MessageBusHostedService>() .AddSingleton <IMessageTracker, MessageTracker>() .AddSingleton <ISendingService, SendingService>() .AddMessageBus(new AzureServiceBusClientBuilder(Configuration["Hostname"], Configuration["Topic"], subscription, Configuration["TenantId"])); _serviceProvider = services.BuildServiceProvider(); var setAutopilotCommand = new SetAutopilot { AutopilotId = Guid.NewGuid().ToString() }; await _serviceProvider.GetRequiredService <ISendingService>().SendAsync(setAutopilotCommand); Assert.Single(await ReceiveMessagesForSubscriptionAsync($"{subscription}-Output"), m => m.Subject == nameof(SetAutopilot) && m.Body.ToObjectFromJson <SetAutopilot>().AutopilotId == setAutopilotCommand.AutopilotId); }
public async Task SendsCommandWithScheduledEnqueueTime() { var subscription = nameof(SendsCommandWithScheduledEnqueueTime); await CreateEndToEndTestSubscriptionsAsync(subscription); var services = new ServiceCollection(); services.AddHostedService <MessageBusHostedService>() .AddSingleton <IMessageTracker, MessageTracker>() .AddSingleton <ISendingService, SendingServiceWithDelay>() .AddMessageBus(new AzureServiceBusClientBuilder(Configuration["Hostname"], Configuration["Topic"], subscription, Configuration["TenantId"])); _serviceProvider = services.BuildServiceProvider(); var setAutopilotCommand = new SetAutopilot { AutopilotId = Guid.NewGuid().ToString() }; await _serviceProvider.GetRequiredService <ISendingService>().SendAsync(setAutopilotCommand); Assert.Empty(await FindSetAutopilotCommandsAsync(subscription, setAutopilotCommand)); await Task.Delay(TimeSpan.FromSeconds(11)); Assert.Single(await FindSetAutopilotCommandsAsync(subscription, setAutopilotCommand)); }