public async Task Should_publish_after_db_create() { var message = new InitiateSimpleSaga(); var product = new Product { Name = "Should_publish_after_db_create" }; var transactionOutbox = new TransactionalEnlistmentBus(Bus); using (var dbContext = GetDbContext()) using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); await transactionOutbox.Publish(message); // Hasn't published yet Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); transaction.Complete(); } // Now has published await _received; using (var dbContext = GetDbContext()) { Assert.IsTrue(await dbContext.Products.AnyAsync(x => x.Id == product.Id)); } }
public async Task Should_not_publish_properly() { var message = new PingMessage(); var transactionOutbox = new TransactionalEnlistmentBus(Bus); using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await transactionOutbox.Publish(message); } Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); }
public async Task Should_not_send_properly() { var message = new PingMessage(); var transactionOutbox = new TransactionalEnlistmentBus(Bus); using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var sendEndpoint = await transactionOutbox.GetSendEndpoint(InputQueueAddress); await sendEndpoint.Send(message); } Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); }
public static async Task Main(string[] args) { var containerBuilder = new ContainerBuilder(); containerBuilder.ConfigureMasstransit(); containerBuilder.RegisterType <MyHorribleDomainService>().As <IHorribleDomainService>(); var container = containerBuilder.Build(); var busControl = container.Resolve <IBusControl>(); var busHandle = await busControl.StartAsync(); var bus = container.Resolve <IBus>(); try { var transactionalBus = new TransactionalEnlistmentBus(bus); using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); for (int i = 0; i < 5; i++) { await transactionalBus.Publish(new AMessage(Guid.NewGuid().ToString())); } var domainService = container.Resolve <IHorribleDomainService>(); domainService.MyMethodThatAlwaysFails(); transaction.Complete(); } catch (Exception) { Console.WriteLine("An exception occured. Hopefully no Consumers has printed out anything!"); } Console.WriteLine("Press any key to exit"); await Task.Run(() => Console.ReadKey()); await busHandle.StopAsync(); }
public async Task Should_not_publish_properly() { var message = new InitiateSimpleSaga(); var product = new Product { Name = "Should_not_publish_properly" }; var transactionOutbox = new TransactionalEnlistmentBus(Bus); using (var dbContext = GetDbContext()) using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { EntityEntry <Product> entity = dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); await transactionOutbox.Publish(message); } Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); using (var dbContext = GetDbContext()) { Assert.IsFalse(await dbContext.Products.AnyAsync(x => x.Id == product.Id)); } }