Exemplo n.º 1
0
        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 TransactionalBus(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 bus     = new TransactionalBus(Bus);

            await bus.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 bus     = new TransactionalBus(Bus);

            var sendEndpoint = await bus.GetSendEndpoint(InputQueueAddress);

            await sendEndpoint.Send(message);

            Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>());
        }
        public async Task Should_not_publish_properly()
        {
            var message           = new PingMessage();
            var transactionOutbox = new TransactionalBus(Bus);

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await transactionOutbox.Publish(message);
            }

            Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>());
        }
Exemplo n.º 5
0
        public void TestInitialize()
        {
            _messagePublisher = new Mock <IMessagePublisher>(MockBehavior.Strict);
            _messagePublisher.Setup(x => x.Publish(It.IsAny <string>(), It.IsAny <Type>()));
            _messagePublisher.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <Type>(), It.IsAny <IMessageQueue>()));

            _messageSerializer = new Mock <IMessageSerializer>(MockBehavior.Strict);
            _messageSerializer.Setup(x => x.Serialize(It.IsAny <object>())).Returns(SerializedMessage);

            _messageQueue = new Mock <IMessageQueue>(MockBehavior.Strict);

            _busUnderTest = new TransactionalBus(_messagePublisher.Object, _messageSerializer.Object, _messageQueue.Object);
        }
        public async Task Should_not_send_properly()
        {
            var message           = new PingMessage();
            var transactionOutbox = new TransactionalBus(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>());
        }
Exemplo n.º 7
0
        public async Task Should_not_publish_properly()
        {
            var message = new InitiateSimpleSaga();
            var product = new Product {
                Name = "Should_not_publish_properly"
            };
            var transactionOutbox = new TransactionalBus(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));
            }
        }