Exemple #1
0
            public void Executing_validates_arguments()
            {
                var formatter = new DatabaseLogFormatter(new StringWriter().Write);

                Assert.Equal(
                    "command",
                    Assert.Throws <ArgumentNullException>(() => formatter.Executing(null, new DbCommandInterceptionContext <int>())).ParamName);
                Assert.Equal(
                    "interceptionContext",
                    Assert.Throws <ArgumentNullException>(() => formatter.Executing <int>(new Mock <DbCommand>().Object, null)).ParamName);
            }
Exemple #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 formatter = new DatabaseLogFormatter(writer.Write);

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

                Assert.Equal("That Sam-I-am!", GetSingleLine(writer));
            }
Exemple #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 formatter = new DatabaseLogFormatter(writer.Write);

                formatter.Executing(CreateCommand("Do you like"), new DbCommandInterceptionContext <int>());
                formatter.Executing(CreateCommand("Green eggs and ham?"), new DbCommandInterceptionContext <int>().WithDbContext(context1));
                formatter.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]);
            }