public void Executed_validates_arguments() { var logger = new DbCommandLogger(new StringWriter().Write); Assert.Equal( "command", Assert.Throws <ArgumentNullException>(() => logger.Executed(null, null, new DbCommandInterceptionContext <int>())) .ParamName); Assert.Equal( "interceptionContext", Assert.Throws <ArgumentNullException>(() => logger.Executed(new Mock <DbCommand>().Object, null, null)).ParamName); }
public void Executed_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.Executed(CreateCommand(""), "Sam-I-am", new DbCommandInterceptionContext <int>().WithDbContext(context1)); logger.Executed(CreateCommand(""), "I do not like", new DbCommandInterceptionContext <int>().WithDbContext(context2)); logger.Executed(CreateCommand(""), "Green eggs and ham", new DbCommandInterceptionContext <int>()); Assert.Equal(Strings.CommandLogComplete(0, "Sam-I-am", ""), GetSingleLine(writer)); }
public void Executed_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.Executed(CreateCommand(""), "Would you like them", new DbCommandInterceptionContext <int>()); logger.Executed(CreateCommand(""), "Here or there?", new DbCommandInterceptionContext <int>().WithDbContext(context1)); logger.Executed(CreateCommand(""), "I would not like them", new DbCommandInterceptionContext <int>().WithDbContext(context2)); var lines = GetLines(writer); Assert.Equal(Strings.CommandLogComplete(0, "Would you like them", ""), lines[0]); Assert.Equal(Strings.CommandLogComplete(0, "Here or there?", ""), lines[2]); Assert.Equal(Strings.CommandLogComplete(0, "I would not like them", ""), lines[4]); }