public void InitializeAndSaveChanges_AdventureWorks(MetricCollector collector, int count)
            {
                using (collector.StartCollection())
                {
                    for (int i = 0; i < count; i++)
                    {
                        using (var context = AdventureWorksFixture.CreateContext())
                        {
                            context.Currency.Add(new Currency
                            {
                                CurrencyCode = "TMP",
                                Name         = "Temporary"
                            });

                            using (context.Database.BeginTransaction())
                            {
                                context.SaveChanges();

                                // Don't mesure transaction rollback
                                collector.StopCollection();
                            }
                            collector.StartCollection();
                        }
                    }
                }
            }
 public void Sleep100ms(MetricCollector collector)
 {
     using (collector.StartCollection())
     {
         Thread.Sleep(100);
     }
 }
        public void Mixed(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                using (context.Database.BeginTransaction())
                {
                    var customers = context.Customers.ToArray();

                    for (var i = 0; i < 333; i++)
                    {
                        context.Customers.Add(new Customer {
                            Name = "New Customer " + i
                        });
                    }

                    for (var i = 0; i < 1000; i += 3)
                    {
                        context.Customers.Remove(customers[i]);
                    }

                    for (var i = 1; i < 1000; i += 3)
                    {
                        customers[i].Name += " Modified";
                    }

                    collector.StartCollection();
                    var records = context.SaveChanges();
                    collector.StopCollection();

                    Assert.Equal(1000, records);
                }
            }
        }
Beispiel #4
0
        public void AddParents(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = new List <Customer>();
                for (var i = 0; i < 100; i++)
                {
                    customers.Add(new Customer {
                        CustomerId = i + 1
                    });
                    context.Orders.Add(new Order {
                        CustomerId = i + 1
                    });
                }

                foreach (var customer in customers)
                {
                    using (collector.StartCollection())
                    {
                        context.Customers.Add(customer);
                    }

                    Assert.Same(customer, customer.Orders.Single().Customer);
                }
            }
        }
Beispiel #5
0
        public void AttachParents(MetricCollector collector)
        {
            List <Customer> customers;

            using (var context = _fixture.CreateContext())
            {
                customers = context.Customers.ToList();
            }

            using (var context = _fixture.CreateContext())
            {
                var orders = context.Orders.ToList();
                Assert.Equal(100, orders.Count);
                Assert.Equal(100, customers.Count);

                foreach (var customer in customers)
                {
                    using (collector.StartCollection())
                    {
                        context.Customers.Attach(customer);
                    }

                    Assert.Same(customer, customer.Orders.Single().Customer);
                }
            }
        }
 public void Calibration_100ms_controlled(MetricCollector collector)
 {
     Thread.Sleep(100);
     using (collector.StartCollection())
     {
         Thread.Sleep(100);
     }
 }
Beispiel #7
0
 public void Count(MetricCollector collector)
 {
     using (var context = _fixture.CreateContext())
     {
         collector.StartCollection();
         var result = context.Products.Count();
         collector.StopCollection();
         Assert.Equal(1000, result);
     }
 }
Beispiel #8
0
 public void OrderBy(MetricCollector collector)
 {
     using (var context = _fixture.CreateContext())
     {
         collector.StartCollection();
         var result = context.Products.OrderBy(p => p.Retail).ToList();
         collector.StopCollection();
         Assert.Equal(1000, result.Count);
     }
 }
Beispiel #9
0
 public void Projection(MetricCollector collector)
 {
     using (var context = _fixture.CreateContext())
     {
         collector.StartCollection();
         var result = context.Products.Select(p => new { p.Name, p.Retail }).ToList();
         collector.StopCollection();
         Assert.Equal(1000, result.Count);
     }
 }
Beispiel #10
0
 public void Include(MetricCollector collector)
 {
     using (var context = _fixture.CreateContext())
     {
         collector.StartCollection();
         var result = context.Customers.Include(c => c.Orders).ToList();
         collector.StopCollection();
         Assert.Equal(1000, result.Count);
         Assert.Equal(2000, result.SelectMany(c => c.Orders).Count());
     }
 }
Beispiel #11
0
        public void LoadAll(MetricCollector collector, bool tracking, bool caching)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Products.ApplyTracking(tracking);

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(1000, result.Count);
            }
        }
 public void CreateAndDisposeUnusedContext(MetricCollector collector, int count)
 {
     using (collector.StartCollection())
     {
         for (int i = 0; i < count; i++)
         {
             using (var context = AdventureWorksFixture.CreateContext())
             {
             }
         }
     }
 }
Beispiel #13
0
        public void Count(MetricCollector collector, bool caching)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Products;

                collector.StartCollection();
                var result = query.Count();
                collector.StopCollection();
                Assert.Equal(1000, result);
            }
        }
 public void InitializeAndQuery_AdventureWorks(MetricCollector collector, int count)
 {
     using (collector.StartCollection())
     {
         for (int i = 0; i < count; i++)
         {
             using (var context = AdventureWorksFixture.CreateContext())
             {
                 context.Department.First();
             }
         }
     }
 }
        public void BuildModel_AdventureWorks(MetricCollector collector)
        {
            collector.StartCollection();

            var builder = new DbModelBuilder();

            AdventureWorksContext.ConfigureModel(builder);
            var model = builder.Build(new SqlConnection(AdventureWorksFixtureBase.ConnectionString));

            collector.StopCollection();

            Assert.Equal(67, model.ConceptualModel.EntityTypes.Count());
        }
Beispiel #16
0
        public void RemoveCollection(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = context.Customers.ToArray();
                Assert.Equal(1000, customers.Length);

                using (collector.StartCollection())
                {
                    context.Customers.RemoveRange(customers);
                }
            }
        }
Beispiel #17
0
        public void Projection(MetricCollector collector, bool caching)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Products
                            .Select(p => new { p.Name, p.Retail });

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(1000, result.Count);
            }
        }
Beispiel #18
0
        public void AttachCollection(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = GetAllCustomersFromDatabase();
                Assert.Equal(1000, customers.Length);

                using (collector.StartCollection())
                {
                    context.Customers.AttachRange(customers);
                }
            }
        }
Beispiel #19
0
        public void SkipTake(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                collector.StartCollection();
                var result = context.Products
                             .OrderBy(p => p.ProductId)
                             .Skip(500).Take(500)
                             .ToList();

                collector.StopCollection();
                Assert.Equal(500, result.Count);
            }
        }
Beispiel #20
0
        public void OrderBy(MetricCollector collector, bool tracking)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .ApplyTracking(tracking)
                            .OrderBy(p => p.Retail);

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(1000, result.Count);
            }
        }
        public void AttachCollection(MetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = GetAllCustomersFromDatabase();
                Assert.Equal(1000, customers.Length);

                using (collector.StartCollection())
                {
                    context.Customers.AttachRange(customers);
                }
            }
        }
Beispiel #22
0
        public void QueryParents(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Orders.ToList();

                collector.StartCollection();
                var customers = context.Customers.ToList();
                collector.StopCollection();

                Assert.Equal(100, context.ChangeTracker.Entries <Customer>().Count());
                Assert.Equal(100, context.ChangeTracker.Entries <Order>().Count());
                Assert.All(customers, c => Assert.Equal(1, c.Orders.Count));
            }
        }
Beispiel #23
0
        public void QueryChildren(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Customers.ToList();

                collector.StartCollection();
                var orders = context.Orders.ToList();
                collector.StopCollection();

                Assert.Equal(100, context.ChangeTracker.Entries <Customer>().Count());
                Assert.Equal(100, context.ChangeTracker.Entries <Order>().Count());
                Assert.All(orders, o => Assert.NotNull(o.Customer));
            }
        }
        public void RemoveCollection(MetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = context.Customers.ToArray();
                Assert.Equal(1000, customers.Length);

                using (collector.StartCollection())
                {
                    context.Customers.RemoveRange(customers);
                }
            }
        }
Beispiel #25
0
        public void Include(MetricCollector collector, bool tracking, bool caching)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Customers
                            .ApplyTracking(tracking)
                            .Include(c => c.Orders);

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(1000, result.Count);
                Assert.Equal(2000, result.SelectMany(c => c.Orders).Count());
            }
        }
Beispiel #26
0
        public void SkipTake(MetricCollector collector, bool tracking, bool caching)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Products
                            .ApplyTracking(tracking)
                            .OrderBy(p => p.ProductId)
                            .Skip(500).Take(500);

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(500, result.Count);
            }
        }
Beispiel #27
0
        public void Where(MetricCollector collector, bool tracking, bool caching)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .ApplyCaching(caching)
                            .ApplyTracking(tracking)
                            .Where(p => p.Retail < 15);

                collector.StartCollection();
                var result = query.ToList();
                collector.StopCollection();
                Assert.Equal(500, result.Count);
            }
        }
        public void ValueFromObject(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                using (collector.StartCollection())
                {
                    var valueHolder = new ValueHolder();
                    for (var i = 0; i < _funcletizationIterationCount; i++)
                    {
                        var result = context.Products.Where(p => p.ProductId < valueHolder.SecondLevelProperty).ToList();

                        Assert.Equal(10, result.Count);
                    }
                }
            }
        }
        public void NewQueryInstance(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                using (collector.StartCollection())
                {
                    var val = 11;
                    for (var i = 0; i < _funcletizationIterationCount; i++)
                    {
                        var result = context.Products.Where(p => p.ProductId < val).ToList();

                        Assert.Equal(10, result.Count);
                    }
                }
            }
        }
Beispiel #30
0
        public void Update(MetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = GetAllCustomersFromDatabase();
                Assert.Equal(1000, customers.Length);

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Update(customer);
                    }
                }
            }
        }