Beispiel #1
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <CommentRepository> > loggerMoc = CommentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = CommentRepositoryMoc.GetContext();
            var     repository           = new CommentRepository(loggerMoc.Object, context);
            Comment entity = new Comment();

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

            await repository.Update(new Comment());

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

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

            entity.SetProperties(default(int), DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 2, "B", 1);
            context.Set <Comment>().Add(entity);
            await context.SaveChangesAsync();

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

            await repository.Update(entity);

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

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