public void Can_create_csv_from_Customers() { NorthwindData.LoadData(false); var csv = CsvSerializer.SerializeToCsv(NorthwindData.Customers); Log(csv); Assert.That(csv, Is.Not.Null); }
public void Can_create_csv_from_Customers_pipe_row_separator() { CsvConfig.RowSeparatorString = "|"; NorthwindData.LoadData(false); var csv = CsvSerializer.SerializeToCsv(NorthwindData.Customers); Log(csv); Assert.That(csv, Is.Not.Null); }
public NorthwindQueryInMemoryFixture() { _options = BuildOptions(); using (var context = CreateContext()) { NorthwindData.Seed(context); } }
public void Can_insert_Northwind_Data() { using (var db = OpenDbConnection()) { CreateNorthwindTables(db); NorthwindData.LoadData(false); LoadNorthwindData(db); } }
public void Can_create_csv_from_Categories() { NorthwindData.LoadData(false); var category = NorthwindFactory.Category(1, "between \"quotes\" here", "with, comma", null); var categories = new[] { category, category }; var csv = CsvSerializer.SerializeToCsv(categories); Log(csv); Assert.That(csv, Is.EqualTo("Id,CategoryName,Description,Picture\r\n1,\"between \"\"quotes\"\" here\",\"with, comma\",\r\n1,\"between \"\"quotes\"\" here\",\"with, comma\",\r\n")); }
public void Can_insert_Northwind_Data_with_images() { using (var db = ConnectionString.OpenDbConnection()) { CreateNorthwindTables(db); NorthwindData.LoadData(true); LoadNorthwindData(db); } }
public void Can_insert_Northwind_Data() { using (var db = ConnectionString.OpenDbConnection()) using (var dbCmd = db.CreateCommand()) { CreateNorthwindTables(dbCmd); NorthwindData.LoadData(false); LoadNorthwindData(dbCmd); } }
private int AssertQuery <TItem>( Func <IQueryable <TItem>, IQueryable <IQueryable <object> > > query, bool assertOrder = false) where TItem : class { using (var context = CreateContext()) { return(AssertResults( query(NorthwindData.Set <TItem>()).ToArray(), query(context.Set <TItem>()).ToArray(), assertOrder)); } }
private NorthwindContext CreateContext(bool enableFilter) { var ctx = new NorthwindContext(_options); ctx.IsSoftDeleteFilterEnabled = enableFilter; //ctx.Database.EnsureDeleted(); if (ctx.Database.EnsureCreated()) { NorthwindData.Seed(ctx); } return(ctx); }
private async Task <int> AssertQueryAsync <TItem>( Func <IQueryable <TItem>, IQueryable <object> > query, bool assertOrder = false) where TItem : class { using (var context = new DbContext(Configuration)) { return(AssertResults( query(NorthwindData.Set <TItem>()).ToArray(), await((IAsyncEnumerable <object>)query(context.Set <TItem>())).ToArray(), assertOrder)); } }
private int AssertQuery <TItem>( Func <IQueryable <TItem>, IQueryable <bool> > query, bool assertOrder = false) where TItem : class { using (var context = new DbContext(Configuration)) { return(AssertResults( query(NorthwindData.Set <TItem>()).ToArray(), query(context.Set <TItem>()).ToArray(), assertOrder)); } }
private async Task <int> AssertQueryAsync <TItem>( Func <IQueryable <TItem>, Task <bool> > query, bool assertOrder = false) where TItem : class { using (var context = new DbContext(Configuration)) { return(AssertResults( new[] { await query(NorthwindData.Set <TItem>()) }, new[] { await query(context.Set <TItem>()) }, assertOrder)); } }
private int AssertQuery <TItem>( Func <IQueryable <TItem>, TItem> query, bool assertOrder = false) where TItem : class { using (var context = CreateContext()) { return(AssertResults( new[] { query(NorthwindData.Set <TItem>()) }, new[] { query(context.Set <TItem>()) }, assertOrder)); } }
public void Can_create_csv_from_Categories_long_delimiter() { CsvConfig.ItemDelimiterString = "~^~"; NorthwindData.LoadData(false); var category = NorthwindFactory.Category(1, "between \"quotes\" here", "with, comma", null); var categories = new[] { category, category }; var csv = CsvSerializer.SerializeToCsv(categories); Log(csv); Assert.That(csv, Is.EqualTo( "Id,CategoryName,Description,Picture\r\n" + "1,between \"quotes\" here,~^~with, comma~^~,\r\n" + "1,between \"quotes\" here,~^~with, comma~^~,\r\n" )); }
private int AssertQuery <TItem1, TItem2, TItem3>( Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TItem3>, IQueryable <int> > query, bool assertOrder = false) where TItem1 : class where TItem2 : class where TItem3 : class { using (var context = CreateContext()) { return(AssertResults( query(NorthwindData.Set <TItem1>(), NorthwindData.Set <TItem2>(), NorthwindData.Set <TItem3>()).ToArray(), query(context.Set <TItem1>(), context.Set <TItem2>(), context.Set <TItem3>()).ToArray(), assertOrder)); } }
public void Can_create_csv_from_Categories_pipe_separator() { CsvConfig.ItemSeperatorString = "|"; NorthwindData.LoadData(false); var category = NorthwindFactory.Category(1, "between \"quotes\" here", "with, comma", null); var categories = new[] { category, category }; var csv = CsvSerializer.SerializeToCsv(categories); Log(csv); Assert.That(csv, Is.EqualTo( "Id|CategoryName|Description|Picture\r\n" + "1|\"between \"\"quotes\"\" here\"|with, comma|\r\n" + "1|\"between \"\"quotes\"\" here\"|with, comma|\r\n" )); }
private async Task <int> AssertQuery <TItem>( Func <DbSet <TItem>, IQueryable <object> > relationalQuery, Func <IQueryable <TItem>, IQueryable <object> > l2oQuery, bool assertOrder = false, Action <IList <object>, IList <object> > asserter = null) where TItem : class { using (var context = CreateContext()) { return(TestHelpers.AssertResults( l2oQuery(NorthwindData.Set <TItem>()).ToArray(), await relationalQuery(context.Set <TItem>()).ToArrayAsync(), assertOrder, asserter)); } }
private int AssertQuery <TItem1, TItem2>( Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <object> > query, bool assertOrder = false, Action <IList <object>, IList <object> > asserter = null) where TItem1 : class where TItem2 : class { using (var context = new DbContext(Configuration)) { return(AssertResults( query(NorthwindData.Set <TItem1>(), NorthwindData.Set <TItem2>()).ToArray(), query(context.Set <TItem1>(), context.Set <TItem2>()).ToArray(), assertOrder, asserter)); } }
public override NorthwindContext CreateContext( QueryTrackingBehavior queryTrackingBehavior = QueryTrackingBehavior.TrackAll, bool enableFilters = false) { if (!IsSeeded) { using (var context = base.CreateContext(queryTrackingBehavior, enableFilters)) { NorthwindData.Seed(context); } IsSeeded = true; } return(base.CreateContext(queryTrackingBehavior, enableFilters)); }
public void Load_Northwind_database_with_redis() { NorthwindData.LoadData(false); GC.Collect(); var stopWatch = new Stopwatch(); stopWatch.Start(); using (var client = new RedisClient(TestConfig.SingleHost)) { LoadNorthwindData(client); } Debug.WriteLine("stopWatch.ElapsedMilliseconds: " + stopWatch.ElapsedMilliseconds); }
public NorthwindQueryInMemoryFixture() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .AddSingleton(TestInMemoryModelSource.GetFactory(OnModelCreating)) .AddSingleton <ILoggerFactory>(_testLoggerFactory) .BuildServiceProvider(); _options = new DbContextOptionsBuilder() .UseInMemoryDatabase() .UseInternalServiceProvider(serviceProvider).Options; using (var context = CreateContext()) { NorthwindData.Seed(context); } }
private void AssertQuery <TItem>( Func <DbSet <TItem>, IQueryable <object> > relationalQuery, Func <IQueryable <TItem>, IQueryable <object> > l2oQuery, bool assertOrder = false, int entryCount = 0) where TItem : class { using (var context = CreateContext()) { TestHelpers.AssertResults( l2oQuery(NorthwindData.Set <TItem>()).ToArray(), relationalQuery(context.Set <TItem>()).ToArray(), assertOrder); Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); } }
protected void AssertQuery <TItem, TResult>( Func <IQueryable <TItem>, IQueryable <TResult> > efQuery, Func <IQueryable <TItem>, IQueryable <TResult> > l2oQuery, bool assertOrder = false, int entryCount = 0, Action <IList <TResult>, IList <TResult> > asserter = null) where TItem : class { using (var context = CreateContext()) { TestHelpers.AssertResults( l2oQuery(NorthwindData.Set <TItem>()).ToArray(), efQuery(context.Set <TItem>()).ToArray(), assertOrder, asserter); } }
private static void CreateTestData(DbContext context, Model model) { var titleProperty = model.GetEntityType(typeof(Employee)).GetProperty("Title"); foreach (var employee in NorthwindData.CreateEmployees()) { context.Set <Employee>().Add(employee); context.ChangeTracker.Entry(employee).StateEntry[titleProperty] = employee.Title; } context.Set <Customer>().AddRange(NorthwindData.CreateCustomers()); context.Set <Order>().AddRange(NorthwindData.CreateOrders()); context.Set <Product>().AddRange(NorthwindData.CreateProducts()); context.Set <OrderDetail>().AddRange(NorthwindData.CreateOrderDetails()); context.SaveChanges(); }
public InMemoryNorthwindQueryFixture() { _serviceProvider = new ServiceCollection() .AddEntityFramework() .AddInMemoryStore() .ServiceCollection .AddTestModelSource(OnModelCreating) .BuildServiceProvider(); _options = new DbContextOptions(); _options.UseInMemoryStore(); using (var context = CreateContext()) { NorthwindData.Seed(context); } }
public virtual void From_sql_annotations_do_not_modify_successive_calls() { using (var context = CreateContext()) { TestHelpers.AssertResults( NorthwindData.Set <Customer>().Where(c => c.ContactName.Contains("z")).ToArray(), context.Customers.FromSql("SELECT * FROM Customers WHERE Customers.ContactName LIKE '%z%'").ToArray(), assertOrder: false); Assert.Equal(14, context.ChangeTracker.Entries().Count()); TestHelpers.AssertResults( NorthwindData.Set <Customer>().ToArray(), context.Customers.ToArray(), assertOrder: false); Assert.Equal(91, context.ChangeTracker.Entries().Count()); } }
protected async Task AssertQuery <TItem>( Func <IQueryable <TItem>, IQueryable <object> > efQuery, Func <IQueryable <TItem>, IQueryable <object> > l2oQuery, bool assertOrder = false, int entryCount = 0, Action <IList <object>, IList <object> > asserter = null) where TItem : class { using (var context = CreateContext()) { TestHelpers.AssertResults( l2oQuery(NorthwindData.Set <TItem>()).ToArray(), await efQuery(context.Set <TItem>()).ToArrayAsync(), assertOrder, asserter); Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); } }
protected override void ImportData() { var data = new NorthwindData(); this.Regions.InsertAllOnSubmit(data.regions); this.Employees.InsertAllOnSubmit(data.employees); this.Territories.InsertAllOnSubmit(data.territories); this.EmployeeTerritories.InsertAllOnSubmit(data.employeeTerritories.Select(o => new EmployeeTerritory { EmployeeID = o.EmployeeID - 1, TerritoryID = o.TerritoryID })); this.Customers.InsertAllOnSubmit(data.customers); this.Shippers.InsertAllOnSubmit(data.shippers); this.Categories.InsertAllOnSubmit(data.categories); this.Suppliers.InsertAllOnSubmit(data.suppliers); foreach (var product in data.products) { product.SupplierID = product.SupplierID - 1; } this.Products.InsertAllOnSubmit(data.products); foreach (var order in data.orders) { if (order.ShipVia == null) { continue; } order.EmployeeID = order.EmployeeID - 1; order.ShipVia = order.ShipVia - 1; } this.Orders.InsertAllOnSubmit(data.orders); foreach (var orderDetail in data.orderDetails) { orderDetail.ProductID = orderDetail.ProductID - 1; } this.OrderDetails.InsertAllOnSubmit(data.orderDetails); /**/ this.SubmitChanges(); }
protected void AssertQuery <TItem1, TItem2, TResult>( Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TResult> > efQuery, Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TResult> > l2oQuery, bool assertOrder = false, int entryCount = 0, Action <IList <TResult>, IList <TResult> > asserter = null) where TItem1 : class where TItem2 : class { using (var context = CreateContext()) { TestHelpers.AssertResults( l2oQuery(NorthwindData.Set <TItem1>(), NorthwindData.Set <TItem2>()).ToArray(), efQuery(context.Set <TItem1>(), context.Set <TItem2>()).ToArray(), assertOrder, asserter); Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); } }
public static void LoadData() { NorthwindData.LoadData(); Instance = new NorthwindDtoData { Categories = NorthwindData.Categories.ConvertAll(x => ToCategoryDto(x)), Customers = NorthwindData.Customers.ConvertAll(x => ToCustomerDto(x)), Employees = NorthwindData.Employees.ConvertAll(x => ToEmployeeDto(x)), Shippers = NorthwindData.Shippers.ConvertAll(x => ToShipperDto(x)), Suppliers = NorthwindData.Suppliers.ConvertAll(x => ToSupplierDto(x)), Orders = NorthwindData.Orders.ConvertAll(x => ToOrderDto(x)), Products = NorthwindData.Products.ConvertAll(x => ToProduct(x)), OrderDetails = NorthwindData.OrderDetails.ConvertAll(x => ToOrderDetailDto(x)), CustomerCustomerDemos = NorthwindData.CustomerCustomerDemos.ConvertAll(x => ToCustomerCustomerDemoDto(x)), Regions = NorthwindData.Regions.ConvertAll(x => ToRegionDto(x)), Territories = NorthwindData.Territories.ConvertAll(x => ToTerritoryDto(x)), EmployeeTerritories = NorthwindData.EmployeeTerritories.ConvertAll(x => ToEmployeeTerritoryDto(x)), }; }