public void WrapsRollback()
        {
            var mockTx = new Mock<IDbTransaction>();
            var mockConn = new Mock<IDbConnection>();
            var mockPublisher = new Mock<ITimedMessagePublisher>();
            var connGuid = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);

            tx.Rollback();
            mockTx.Verify(p => p.Rollback(), Times.Once);
            mockPublisher.Verify(
                p => p.EmitStopMessage(
                    It.Is<TransactionRollbackMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                    Times.Once);
        }
        public void WrapsRollback()
        {
            var mockTx        = new Mock <IDbTransaction>();
            var mockConn      = new Mock <IDbConnection>();
            var mockPublisher = new Mock <ITimedMessagePublisher>();
            var connGuid      = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);

            tx.Rollback();
            mockTx.Verify(p => p.Rollback(), Times.Once);
            mockPublisher.Verify(
                p => p.EmitStopMessage(
                    It.Is <TransactionRollbackMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                Times.Once);
        }
        public void Constructor_SetsValuesAndEmitsStartMessage()
        {
            var mockTx = new Mock<IDbTransaction>();
            mockTx.SetupGet(p => p.IsolationLevel).Returns(IsolationLevel.Chaos);
            var mockConn = new Mock<IDbConnection>();
            var mockPublisher = new Mock<ITimedMessagePublisher>();
            var connGuid = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);
            Assert.That(tx.Connection, Is.EqualTo(mockConn.Object));
            Assert.That(tx.TransactionId, Is.Not.Null);
            Assert.That(tx.IsolationLevel, Is.EqualTo(IsolationLevel.Chaos));
            mockTx.Verify(p => p.IsolationLevel, Times.AtLeastOnce);
            mockPublisher.Verify(
                p => p.EmitStartMessage(
                    It.Is<TransactionBeganMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                    Times.Once);
        }
        public void WrapsDisposeOnNonCommitedTransactionPublishesRollback()
        {
            var mockTx = new Mock <IDbTransaction>();

            mockTx.SetupGet(p => p.IsolationLevel).Returns(IsolationLevel.Chaos);
            var mockConn      = new Mock <IDbConnection>();
            var mockPublisher = new Mock <ITimedMessagePublisher>();
            var connGuid      = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);

            tx.Dispose();

            mockTx.Verify(p => p.Dispose(), Times.Once);
            mockPublisher.Verify(
                p => p.EmitStopMessage(
                    It.Is <TransactionRollbackMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                Times.Once);
        }
        public void Constructor_SetsValuesAndEmitsStartMessage()
        {
            var mockTx = new Mock <IDbTransaction>();

            mockTx.SetupGet(p => p.IsolationLevel).Returns(IsolationLevel.Chaos);
            var mockConn      = new Mock <IDbConnection>();
            var mockPublisher = new Mock <ITimedMessagePublisher>();
            var connGuid      = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);

            Assert.That(tx.Connection, Is.EqualTo(mockConn.Object));
            Assert.That(tx.TransactionId, Is.Not.Null);
            Assert.That(tx.IsolationLevel, Is.EqualTo(IsolationLevel.Chaos));
            mockTx.Verify(p => p.IsolationLevel, Times.AtLeastOnce);
            mockPublisher.Verify(
                p => p.EmitStartMessage(
                    It.Is <TransactionBeganMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                Times.Once);
        }
        public void WrapsDisposeOnCommitedTransactionDoesNotPublishRollback()
        {
            var mockTx = new Mock<IDbTransaction>();
            mockTx.SetupGet(p => p.IsolationLevel).Returns(IsolationLevel.Chaos);
            var mockConn = new Mock<IDbConnection>();
            var mockPublisher = new Mock<ITimedMessagePublisher>();
            var connGuid = Guid.NewGuid();

            var tx = new GlimpseAdomdTransaction(mockTx.Object, mockConn.Object, connGuid, mockPublisher.Object);
            tx.Commit();
            tx.Dispose();

            mockTx.Verify(p => p.Dispose(), Times.Once);
            mockPublisher.Verify(
             p => p.EmitStopMessage(
                 It.Is<TransactionRollbackMessage>(s => s.ConnectionId == connGuid && s.TransactionId == tx.TransactionId)),
                 Times.Never);
        }