public Task InsertResponse(SafeRebusResponse response) { Logger.LogDebug($"Inserting response with id: {response.Id.ToString()}"); return(Insert.InsertResponse.Execute( DbProvider.GetDbTransaction().Connection, Configuration, response)); }
private static SafeRebusResponse HandleRequest(SafeRebusRequest request) { var response = new SafeRebusResponse { Id = request.Id, Response = GetRandomResponse() }; return(response); }
private static SafeRebusResponse HandleRequest(SafeRebusRequest request) { var response = new SafeRebusResponse { Id = request.Id, Response = "This is a response from the NServiceBus Host!" }; return(response); }
public static Task Execute( IDbConnection dbConnection, IConfiguration configuration, SafeRebusResponse response) { var @params = new DynamicParameters(); @params.Add(SafeRebus.Database.CommonColumns.Id, response.Id); @params.Add(Columns.Response, response.Response); var sql = string.Format(SqlTemplate, configuration.GetDbSchema(), Tables.ResponseTable); return(dbConnection.ExecuteAsync(sql, @params)); }
public Task SendFromNServiceBusToRebus_Success() { return(NServiceBusTestUtilities.ExecuteInNServiceBusScope(async(nServiceBusScope, rebusBus) => { var outputQueue = nServiceBusScope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqOutputQueue(); var endpointInstance = nServiceBusScope.ServiceProvider.GetService <IEndpointInstance>(); var repository = nServiceBusScope.ServiceProvider.GetService <IResponseRepository>(); var response = new SafeRebusResponse(); await endpointInstance.Send(outputQueue, response); await MessageHandler.Utilities.Tools.WaitUntilSuccess(async() => { (await repository.SelectResponse(response.Id)).Id.Should().Be(response.Id); }, TimeSpan.FromSeconds(3)); })); }
public async Task InsertAndCheckExists_Success() { var response = new SafeRebusResponse { Response = "some new random" }; await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await repository.InsertResponse(response); dbProvider.GetDbTransaction().Commit(); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var savedResponse = await repository.SelectResponse(response.Id); savedResponse.Response.Should().Be(response.Response); savedResponse.Id.Should().Be(response.Id); }); }
public async Task BeginTransactionAndNotCommit_ResendWithReplySuccess() { var response = new SafeRebusResponse(); var additionalOverrideConfig = new Dictionary <string, string>(); await TestServiceExecutor.ExecuteInScope(async scope => { var inputQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqInputQueue(); var outputQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqOutputQueue(); additionalOverrideConfig["rabbitMq:inputQueue"] = inputQueue; additionalOverrideConfig["rabbitMq:outputQueue"] = outputQueue; var bus = scope.ServiceProvider.GetService <IOutboxBus>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await bus.BeginTransaction(GetTransportMessage(inputQueue)); await bus.Reply(response); dbProvider.GetDbTransaction().Commit(); }, additionalOverrideConfig); await Task.Delay(TimeSpan.FromSeconds(1)); await TestServiceExecutor.ExecuteInScope(async scope => { var outboxMessageCleaner = scope.ServiceProvider.GetService <IOutboxMessageCleaner>(); await outboxMessageCleaner.CleanMessages(false); await Task.Delay(TimeSpan.FromSeconds(1)); }, additionalOverrideConfig); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var outboxMessageRepository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); await MessageHandler.Utilities.Tools.WaitUntilSuccess(async() => { (await repository.SelectResponse(response.Id)).Id.Should().Be(response.Id); }); var outboxMessages = await outboxMessageRepository.SelectOutboxMessagesBeforeThreshold(TimeSpan.Zero); outboxMessages.Should().BeEmpty(); }, additionalOverrideConfig); }
public async Task MultipleInsertAndCheckExists_Success() { var allResponseIds = new List <Guid>(); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); for (var i = 0; i < 10; i++) { var response = new SafeRebusResponse(); await repository.InsertResponse(response); allResponseIds.Add(response.Id); } dbProvider.GetDbTransaction().Commit(); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var savedResponseIds = (await repository.SelectResponses(allResponseIds)).Select(savedResponse => savedResponse.Id); allResponseIds.Select(responseId => savedResponseIds.Should().Contain(responseId)); }); }