示例#1
0
            public void Executing_validates_arguments()
            {
                var logger = new DbCommandLogger(new StringWriter().Write);

                Assert.Equal(
                    "command",
                    Assert.Throws <ArgumentNullException>(() => logger.Executing(null, new DbCommandInterceptionContext <int>())).ParamName);
                Assert.Equal(
                    "interceptionContext",
                    Assert.Throws <ArgumentNullException>(() => logger.Executing(new Mock <DbCommand>().Object, null)).ParamName);
            }
示例#2
0
            public void Executing_filters_by_context_when_set()
            {
                var context1 = new Mock <DbContext>().Object;
                var context2 = new Mock <DbContext>().Object;

                var writer = new StringWriter();
                var logger = new DbCommandLogger(writer.Write);

                logger.Executing(CreateCommand("That Sam-I-am!"), new DbCommandInterceptionContext <int>().WithDbContext(context1));
                logger.Executing(CreateCommand("I do not like"), new DbCommandInterceptionContext <int>().WithDbContext(context2));
                logger.Executing(CreateCommand("that Sam-I-am"), new DbCommandInterceptionContext <int>());

                Assert.Equal("That Sam-I-am!", GetSingleLine(writer));
            }
示例#3
0
            public void Executing_logs_every_command_when_context_not_set()
            {
                var context1 = new Mock <DbContext>().Object;
                var context2 = new Mock <DbContext>().Object;

                var writer = new StringWriter();
                var logger = new DbCommandLogger(writer.Write);

                logger.Executing(CreateCommand("Do you like"), new DbCommandInterceptionContext <int>());
                logger.Executing(CreateCommand("Green eggs and ham?"), new DbCommandInterceptionContext <int>().WithDbContext(context1));
                logger.Executing(CreateCommand("I do not like them"), new DbCommandInterceptionContext <int>().WithDbContext(context2));

                var lines = GetLines(writer);

                Assert.Equal("Do you like", lines[0]);
                Assert.Equal("Green eggs and ham?", lines[2]);
                Assert.Equal("I do not like them", lines[4]);
            }