예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public AutoLotEntities() : base("name=AutoLotConnection")
        {
            //DbInterception.Add(new ConsoleWriterInterceptor());
            dbLogger.StartLogging();
            DbInterception.Add(dbLogger);

            var context = (this as IObjectContextAdapter).ObjectContext;

            context.SavingChanges += OnSavingChanges;
        }
예제 #4
0
        public void DatabaseLogger_can_append_to_a_file()
        {
            using (var context = new SimpleModelContext())
            {
                var output = CaptureFileOutput(
                    f =>
                {
                    using (var logger = new DatabaseLogger(f, append: false))
                    {
                        logger.StartLogging();

                        context.Categories.ToArray();
                    }

                    using (var logger = new DatabaseLogger(f, append: true))
                    {
                        logger.StartLogging();

                        context.Products.ToArray();
                    }
                });

                Assert.Contains("FROM [dbo].[Categories]", output);
                Assert.Contains("FROM [dbo].[Products]", output);
            }
        }
예제 #5
0
 public AutoLotEntities()
     : base("name=AutoLotConnection")
 {
     //DbInterception.Add(new ConsoleWriterInterceptor());
     DatabaseLogger.StartLogging();
     DbInterception.Add(DatabaseLogger);
 }
예제 #6
0
 public UserDataContext() : base("UserData")
 {
     if (DbLogger.IsActive)
     {
         DatabaseLogger.StartLogging();
         DbInterception.Add(DatabaseLogger);
     }
 }
예제 #7
0
 private void ConfigureLog()
 {
     if (LogConfig.DbLogger.IsActive)
     {
         DatabaseLogger.StartLogging();
         DbInterception.Add(DatabaseLogger);
     }
 }
예제 #8
0
 public AutoLotEntities()
     : base("name=AutoLotConnection")
 {
     DatabaseLogger.StartLogging();
     DbInterception.Add(DatabaseLogger);
     //var context = (this as IObjectContextAdapter).ObjectContext;
     //context.ObjectMaterialized += OnObjectMaterialized;
     //context.SavingChanges += OnSavingChanges;
 }
예제 #9
0
        public AutoLotEntities() : base("name=AutoLotConnection")
        {
            DbInterception.Add(new ConsoleWriterInterceptor());
            DatabaseLogger.StartLogging();
            DbInterception.Add(DatabaseLogger);

            var context = (this as IObjectContextAdapter).ObjectContext;

            context.ObjectMaterialized += Context_ObjectMaterialized;
            context.SavingChanges      += Context_SavingChanges;
        }
예제 #10
0
        public AutoLotEntities() : base("name=AutoLotConnection")
        {
            //DbInterception.Add(new ConsoleWriterlnterceptor());
            DatabaseLogger.StartLogging();
            DbInterception.Add(DatabaseLogger);

            // Код перехватчика.
            var context = (this as IObjectContextAdapter).ObjectContext;

            context.ObjectMaterialized += OnObjectMaterialized;
            context.SavingChanges      += OnSavingChanges;
        }
예제 #11
0
        public AutoLotDbContext()
            : base("name=AutoLotConnection")
        {
            DbInterception.Add(ConsoleWriterInterceptor);
            DatabseLogger.StartLogging();
            DbInterception.Add(DatabseLogger);

            var context = (this as IObjectContextAdapter).ObjectContext;

            //just after properties of object is set and before object returned from context
            context.ObjectMaterialized += OnObjectMaterialized;
            //just after starting to push values to DB but before update DB
            context.SavingChanges += OnSavingChanges;
        }
예제 #12
0
        public void DatabaseLogger_can_log_to_a_file()
        {
            Assert.Contains(
                "FROM [dbo].[Products]",
                CaptureFileOutput(
                    f =>
            {
                using (var logger = new DatabaseLogger(f))
                {
                    using (var context = new SimpleModelContext())
                    {
                        logger.StartLogging();

                        context.Products.ToArray();
                    }
                }
            }));
        }
예제 #13
0
        public void Dispose_stops_logging()
        {
            using (var context = new SimpleModelContext())
            {
                var output = CaptureConsoleOutput(
                    () =>
                {
                    using (var logger = new DatabaseLogger())
                    {
                        logger.StartLogging();

                        context.Categories.ToArray();
                    }

                    context.Products.ToArray();
                });

                Assert.Contains("FROM [dbo].[Categories]", output);
                Assert.DoesNotContain("FROM [dbo].[Products]", output);
            }
        }
예제 #14
0
        public AutoLotEntities() : base("name=AutoLotConnection")
        {
            ////Register the Interception.
            //DbInterception.Add(new ConsoleWriterInterceptor());

            //Use static DatabaseLogger field containing DatabaseLogger object, to invoking StartLogging().
            DatabaseLogger.StartLogging();

            //Register the DatabaseLogger.
            DbInterception.Add(DatabaseLogger);



            //Interceptor code
            var context = (this as IObjectContextAdapter).ObjectContext;

            context.ObjectMaterialized += OnObjectMaterialized;

            //SavingChanges fires after SaveChanges() is called(on the DbContext) but before the DB is updated.
            context.SavingChanges += OnSavingChanges;
        }
예제 #15
0
        [Fact] // CodePlex 2568
        public void DatabaseLogger_can_be_used_concurrently()
        {
            CaptureFileOutput(
                f =>
            {
                using (var logger = new DatabaseLogger(f))
                {
                    logger.StartLogging();

                    ExecuteInParallel(
                        () =>
                    {
                        using (var context = new SimpleModelContext())
                        {
                            for (var i = 0; i < 200; i++)
                            {
                                context.Products.AsNoTracking().Load();
                            }
                        }
                    }, 30);
                }
            });
        }
예제 #16
0
 protected override void Dispose(bool disposing)
 {
     logger.StartLogging();
     DbInterception.Remove(logger);
     base.Dispose(disposing);
 }