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); } } }
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); } } }
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); } }
public void Count(MetricCollector collector) { using (var context = _fixture.CreateContext()) { collector.StartCollection(); var result = context.Products.Count(); collector.StopCollection(); Assert.Equal(1000, result); } }
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); } }
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); } }
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()); } }
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()) { } } } }
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()); }
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); } } }
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); } }
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); } } }
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); } }
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); } } }
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)); } }
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); } } }
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()); } }
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); } }
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); } } } }
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); } } } }