public void TestDbQueryChildReadOnlyOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptionsWithLogging <TestDbContext>(log => _output.WriteLine(log.ToString()));

            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))
            {
                //ATTEMPT
                var children = context.Children.ToList();

                //VERIFY
                children.Count.ShouldEqual(2);
            }
        }
        public void TestDbQueryReadManyViaDtoOk()
        {
            //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.SetupSingleDtoAndEntities <ChildDbQueryDto>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var entities = service.ReadManyNoTracked <ChildDbQueryDto>().ToList();

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                entities.Count.ShouldEqual(2);
            }
        }
        public void TestDbQueryReadSingleWhereDirectOk()
        {
            //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 CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var entity = service.ReadSingle <ChildReadOnly>(x => x.ChildId == 1);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                entity.ShouldNotBeNull();
            }
        }
Example #4
0
        public async Task TestDbQueryReadManyDirectOk()
        {
            //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.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);
            }
        }
Example #5
0
        public async Task TestDbQueryReadSingleWhereViaDtoOk()
        {
            //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);

                //ATTEMPT
                var entity = await service.ReadSingleAsync <ChildDbQueryDto>(x => x.ChildId == 1);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                entity.ShouldNotBeNull();
            }
        }