public void Logging_can_be_started_and_stopped() { using (var context = new SimpleModelContext()) { var output = CaptureConsoleOutput( () => { using (var logger = new DatabaseLogger()) { context.Products.ToArray(); logger.StartLogging(); logger.StopLogging(); context.Products.ToArray(); logger.StartLogging(); context.Categories.ToArray(); logger.StopLogging(); context.Products.ToArray(); } }); var foundIndex = output.IndexOf("FROM [dbo].[Categories]"); Assert.True(foundIndex > 0); foundIndex = output.IndexOf("FROM [dbo].[Categories]", foundIndex + 1); Assert.Equal(-1, foundIndex); Assert.DoesNotContain("FROM [dbo].[Products]", output); } }
public void Starting_is_no_op_if_already_started_and_likewise_for_stopping() { using (var context = new SimpleModelContext()) { var output = CaptureConsoleOutput( () => { using (var logger = new DatabaseLogger()) { logger.StopLogging(); context.Products.ToArray(); logger.StartLogging(); logger.StartLogging(); context.Categories.ToArray(); logger.StopLogging(); logger.StopLogging(); context.Products.ToArray(); } }); Assert.Contains("FROM [dbo].[Categories]", output); Assert.DoesNotContain("FROM [dbo].[Products]", output); } }