Exemplo n.º 1
0
        // Tests a repository can deal with an entity type which has nested child relationships
        // e.g. Grandparent -> Parent -> Child
        public async Task Repository_NestedChildRelation_Insert_GetByID()
        {
            base.ClearAll();

            var grandParentEntityIn  = _fixture.Create <GrandParentEntity>();
            var grandParentEntity2In = _fixture.Create <GrandParentEntity>();

            var repository = new GrandParentEntityRepository(_dataService);

            // Insert records
            await repository.InsertAsync(grandParentEntityIn);

            await repository.InsertAsync(grandParentEntity2In);

            // Get the first entity back by id
            var grandParentEntityOut = await repository.GetByIDAsync(grandParentEntityIn.ID);

            CheckEntityTreesAreSame(grandParentEntityIn, grandParentEntityOut);
        }
Exemplo n.º 2
0
        public async Task Repository_NestedChildRelation_InsertMany_GetAll()
        {
            base.ClearAll();

            var repository = new GrandParentEntityRepository(_dataService);

            // Insert records
            List <GrandParentEntity> grandParentEntitiesIn = _fixture.CreateMany <GrandParentEntity>().ToList();
            await repository.InsertAsync(grandParentEntitiesIn);

            // Get all the entities out
            var grandParentEntitiesOut = (await repository.GetAllAsync()).ToList();

            // Check that we got the same number of entities back out
            Assert.Equal(grandParentEntitiesIn.ToList().Count, grandParentEntitiesOut.ToList().Count);

            // Check down the hierarchy that property values line up
            for (int i = 0; i < grandParentEntitiesIn.Count; i++)
            {
                CheckEntityTreesAreSame(grandParentEntitiesIn[i], grandParentEntitiesOut[i]);
            }
        }
Exemplo n.º 3
0
        // Tests a repository can deal with an entity type which has nested child relationships
        // e.g. Grandparent -> Parent -> Child
        public async Task Repository_NestedChildRelation_DeleteAll()
        {
            base.ClearAll();

            var grandParentEntityIn = _fixture.Create <GrandParentEntity>();

            var repository = new GrandParentEntityRepository(_dataService);

            // Insert records
            await repository.InsertAsync(grandParentEntityIn);

            // DeleteAll
            await repository.DeleteAllAsync();

            var asyncConnection = _dataService.GetAsyncDBConnection();

            // Check the table and all its child tables are now empty
            Assert.Empty(await asyncConnection.Table <GrandParentEntity>().ToListAsync());
            Assert.Empty(await asyncConnection.Table <ParentEntity>().ToListAsync());
            Assert.Empty(await asyncConnection.Table <ChildEntity>().ToListAsync());
            Assert.Empty(await asyncConnection.Table <ChildEntity2>().ToListAsync());
            Assert.Empty(await asyncConnection.Table <SingleChildEntity>().ToListAsync());
        }