Пример #1
0
        public async void Get()
        {
            Mock <ILogger <PetRepository> > loggerMoc = PetRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext            context   = PetRepositoryMoc.GetContext();
            var repository = new PetRepository(loggerMoc.Object, context);

            Pet entity = new Pet();

            context.Set <Pet>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.Id);

            record.Should().NotBeNull();
        }
Пример #2
0
        public async void Update_Entity_Is_Tracked()
        {
            Mock <ILogger <PetRepository> > loggerMoc = PetRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext            context   = PetRepositoryMoc.GetContext();
            var repository = new PetRepository(loggerMoc.Object, context);
            Pet entity     = new Pet();

            context.Set <Pet>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.Id);

            await repository.Update(record);

            var modifiedRecord = context.Set <Pet>().FirstOrDefaultAsync();

            modifiedRecord.Should().NotBeNull();
        }
Пример #3
0
        public async void Update_Entity_Is_Tracked()
        {
            Mock <ILogger <PetRepository> > loggerMoc = PetRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext            context   = PetRepositoryMoc.GetContext();
            var repository = new PetRepository(loggerMoc.Object, context);
            Pet entity     = new Pet();

            entity.SetProperties(default(int), 1, 2, "B", 2);
            context.Set <Pet>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.Id);

            await repository.Update(record);

            var records = await context.Set <Pet>().ToListAsync();

            records.Count.Should().Be(2);
        }