public async Task TestDbQueryReadManyDirectOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); context.ExecuteScriptFileInTransaction(TestData.GetFilePath("ReplaceTableWithView.sql")); context.Add(new Parent { Children = new List <Child> { new Child { MyString = "Hello" }, new Child { MyString = "Goodbye" } } }); context.SaveChanges(); context.ChangeTracker.Clear(); var utData = context.SetupEntitiesDirect(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var entities = await service.ReadManyNoTracked <ChildReadOnly>().ToListAsync(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); entities.Count.ShouldEqual(2); } }
public async Task TestDbQueryReadManyViaDtoOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); context.Add(new Parent { Children = new List <Child> { new Child { MyString = "Hello" }, new Child { MyString = "Goodbye" } } }); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupSingleDtoAndEntities <ChildDbQueryDto>(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var entities = await service.ReadManyNoTracked <ChildDbQueryDto>().ToListAsync(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); entities.Count.ShouldEqual(2); } }
public async Task TestProjectBookTitleManyOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <BookTitle>(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var list = await service.ReadManyNoTracked <BookTitle>().ToListAsync(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); list.Count.ShouldEqual(4); list.Select(x => x.Title).ShouldEqual(new [] { "Refactoring", "Patterns of Enterprise Application Architecture", "Domain-Driven Design", "Quantum Networking" }); } }
public async Task TestManyOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupEntitiesDirect(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var books = await service.ReadManyNoTracked <Book>().ToListAsync(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); books.Count.ShouldEqual(4); context.Entry(books.ToList().First()).State.ShouldEqual(EntityState.Detached); } }
public async Task TestDbQueryReadManyViaDtoOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); #if NETCOREAPP3_0 context.ExecuteScriptFileInTransaction(TestData.GetFilePath("ReplaceTableWithView.sql")); #endif context.Add(new Parent { Children = new List <Child> { new Child { MyString = "Hello" }, new Child { MyString = "Goodbye" } } }); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupSingleDtoAndEntities <ChildDbQueryDto>(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper, new CreateNewDBContextHelper(() => new TestDbContext(options))); //ATTEMPT var entities = await service.ReadManyNoTracked <ChildDbQueryDto>().ToListAsync(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); entities.Count.ShouldEqual(2); } }