Exemple #1
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostHistoryTypeRepository> > loggerMoc = PostHistoryTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryTypeRepositoryMoc.GetContext();
            var             repository   = new PostHistoryTypeRepository(loggerMoc.Object, context);
            PostHistoryType entity       = new PostHistoryType();

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

            await repository.Update(new PostHistoryType());

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

            modifiedRecord.Should().NotBeNull();
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostHistoryTypeRepository> > loggerMoc = PostHistoryTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryTypeRepositoryMoc.GetContext();
            var             repository   = new PostHistoryTypeRepository(loggerMoc.Object, context);
            PostHistoryType entity       = new PostHistoryType();

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

            context.Entry(entity).State = EntityState.Detached;

            await repository.Update(entity);

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

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