Example #1
0
        public void DiscardChanges_ChangesAddedEntityState_ToDetached()
        {
            using (var dbContext = new EntityDbContext())
            {
                var entity = new User {
                    Name = Guid.NewGuid().ToString()
                };
                dbContext.Create(entity);

                dbContext.Entry(entity).State.ShouldEqual(EntityState.Added);
                dbContext.DiscardChanges();
                dbContext.Entry(entity).State.ShouldEqual(EntityState.Detached);
            }
        }
Example #2
0
        public void DiscardChanges_ChangesDeletedEntityState_ToUnchanged()
        {
            using (var dbContext = new EntityDbContext())
            {
                var entity = new User {
                    Name = Guid.NewGuid().ToString()
                };
                dbContext.Create(entity);
                var affectedRows = dbContext.SaveChangesAsync().Result;

                affectedRows.ShouldEqual(1);
                dbContext.Entry(entity).State.ShouldEqual(EntityState.Unchanged);
                dbContext.Delete(entity);
                dbContext.Entry(entity).State.ShouldEqual(EntityState.Deleted);
                dbContext.DiscardChanges();
                dbContext.Entry(entity).State.ShouldEqual(EntityState.Unchanged);
            }
        }