Exemplo n.º 1
0
        public static void LogCommandExecuting_WhenNoConnectionProvided_ThrowsArgumentNullException()
        {
            var connectionMock = new Mock <ISchematicConnection>();

            connectionMock.Setup(c => c.DbConnection).Returns(Mock.Of <IDbConnectionFactory>());
            var            logger   = Mock.Of <ILogger>();
            const LogLevel logLevel = LogLevel.Information;

            Logging.AddLogging(connectionMock.Object, logger, logLevel);
            Assert.That(() => Logging.LogCommandExecuting(null, Guid.NewGuid(), "test_query", null), Throws.ArgumentNullException);
        }
Exemplo n.º 2
0
        public static void RemoveLogging_WhenLoggingConfigured_ThrowsNothing()
        {
            var connectionMock = new Mock <ISchematicConnection>();

            connectionMock.Setup(c => c.DbConnection).Returns(Mock.Of <IDbConnectionFactory>());
            var            logger   = Mock.Of <ILogger>();
            const LogLevel logLevel = LogLevel.Information;

            Logging.AddLogging(connectionMock.Object, logger, logLevel);
            Assert.That(() => Logging.RemoveLogging(connectionMock.Object), Throws.Nothing);
        }
        public static void Stop_WhenNotStarted_ShouldDoNothing()
        {
            var          connectionFactory = Mock.Of <IDbConnectionFactory>(MockBehavior.Strict);
            var          logger            = Mock.Of <ILogger>();
            const string sql = "select 1";

            var connection = new SchematicConnection(connectionFactory, Mock.Of <IDatabaseDialect>());

            Logging.AddLogging(connection, logger, LogLevel.Information);

            var loggingContext = new QueryLoggingContext(connectionFactory, sql, null);

            Assert.That(() => loggingContext.Stop(), Throws.Nothing);
        }
Exemplo n.º 4
0
        public static void LogCommandExecuting_WhenValidConnectionProvided_PerformsLogging()
        {
            var          connectionId = Guid.NewGuid();
            var          commandId    = Guid.NewGuid();
            const string sql          = "test_query";
            var          parameters   = new { ParamA = "test_param_1", ParamB = "test_param_2" };

            var connectionMock = new Mock <ISchematicConnection>();

            connectionMock.Setup(c => c.DbConnection).Returns(Mock.Of <IDbConnectionFactory>());
            connectionMock.Setup(c => c.ConnectionId).Returns(connectionId);
            var            loggerMock = new Mock <ILogger>();
            var            logger     = loggerMock.Object;
            const LogLevel logLevel   = LogLevel.Information;

            Logging.AddLogging(connectionMock.Object, logger, logLevel);
            Assert.That(() => Logging.LogCommandExecuting(connectionMock.Object.DbConnection, commandId, sql, parameters), Throws.Nothing);
        }
Exemplo n.º 5
0
        public static void LogCommandExecuting_WhenValidConnectionWithNoParamsProvided_PerformsLogging()
        {
            var          connectionId = Guid.NewGuid();
            var          commandId    = Guid.NewGuid();
            const string sql          = "test_query";

            var connectionMock = new Mock <ISchematicConnection>();

            connectionMock.Setup(c => c.DbConnection).Returns(Mock.Of <IDbConnectionFactory>());
            connectionMock.Setup(c => c.ConnectionId).Returns(connectionId);
            var            loggerMock = new Mock <ILogger>();
            var            logger     = loggerMock.Object;
            const LogLevel logLevel   = LogLevel.Information;

            Logging.AddLogging(connectionMock.Object, logger, logLevel);

            Assert.Multiple(() =>
            {
                Assert.That(() => Logging.LogCommandExecuting(connectionMock.Object.DbConnection, commandId, sql, null), Throws.Nothing);
                Assert.That(() => Logging.LogCommandExecuting(connectionMock.Object.DbConnection, commandId, sql, new object()), Throws.Nothing);
            });
        }