コード例 #1
0
        public async Task Get_a_record_lazy_when_using_find_by_id_and_not_lazy_when_fetch_by_id()
        {
            //arrange
            AppDbContext      appDbContext = AppDbContextMocker.GetAppDbContext("test_1");
            IMeetUpRepository _repo        = new MeetUpRepository(appDbContext);

            //act
            var ent = await _repo.FindByIdAsync(1);

            var dto = ent.ConvertTo <MeetUpHeaderDto>();

            //assert
            Assert.True(ent.SeatGrid is null);
            Assert.True(dto.Id == 1);


            //act
            ent = await _repo.FetchByIdAsync(1);

            var dtof = ent.ConvertTo <MeetUpDto>();

            //assert
            Assert.True(ent.SeatGrid?.Seats != null);
            Assert.True(dtof.SeatGrid?.Seats != null);
            Assert.True(ent.SeatGrid?.Seats[0].SeatLabel == "A1");
            Assert.True(ent.SeatGrid?.Seats[99]?.SeatLabel == "J10");

            //clean up otherwise the other test will complain about key tracking.
            await appDbContext.DisposeAsync();
        }
コード例 #2
0
        public async Task Removing_record_should_remove_all_children()
        {
            //arrange
            MeetUp meetUp = new MeetUp()
            {
                Id          = 1,
                CostPerSeat = 0M,
                Location    = "Delete Record",
                Date        = DateTime.Now.AddDays(2)
            };
            AppDbContext      appDbContext = AppDbContextMocker.GetAppDbContext("test_4");
            IMeetUpRepository _repo        = new MeetUpRepository(appDbContext);

            //act
            _repo.Delete(meetUp); // delete by entity
            await _repo.SaveChangesAsync();

            var delEnt = await _repo.FindByIdAsync(meetUp.Id);

            _repo.Delete(2);
            await _repo.SaveChangesAsync();

            var delEnt2 = await _repo.FindByIdAsync(2);

            var all = await _repo.FindByExpressionAsync(m => m.Id > 0);

            var anyGrids = appDbContext.SeatGrids.Where(x => x.Id > 0);

            //assert
            Assert.Null(delEnt);
            Assert.Null(delEnt2);
            Assert.True(all.Count() == 0);
            Assert.True(anyGrids.Count() == 0);

            await appDbContext.DisposeAsync();
        }