Ejemplo n.º 1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Ejemplo n.º 2
0
        public void Insert_AddsModelToDbSet()
        {
            unitOfWork.Insert(model);

            BaseModel actual   = context.ChangeTracker.Entries <TestModel>().Single().Entity;
            BaseModel expected = model;

            Assert.Equal(EntityState.Added, context.Entry(model).State);
            Assert.Same(expected, actual);
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     using (TestingContext context = new TestingContext())
     {
         TestModel model = new TestModel();
         context.Set <TestModel>().Add(model);
         context.Entry(model).State = EntityState.Modified;
         entry = context.Entry(model).Property(property => property.Text);
     }
 }
Ejemplo n.º 4
0
        public void LoggableEntity_SetsEntityTypeNameFromProxy()
        {
            DbEntityEntry <BaseModel> proxy = context.Entry <BaseModel>(context.Set <Role>().Single());

            String actual   = new LoggableEntity(proxy).Name;
            String expected = typeof(Role).Name;

            Assert.Equal("System.Data.Entity.DynamicProxies", proxy.Entity.GetType().Namespace);
            Assert.Equal(expected, actual);
        }
        public LoggablePropertyTests()
        {
            using (TestingContext context = new TestingContext())
            {
                Role model = ObjectFactory.CreateRole();

                context.Set <Role>().Add(model);
                context.Entry(model).State = EntityState.Modified;
                textProperty = context.Entry(model).Property(prop => prop.Title);
                dateProperty = context.Entry(model).Property(prop => prop.CreationDate);
            }
        }
Ejemplo n.º 6
0
        public LoggablePropertyTests()
        {
            using (TestingContext context = new TestingContext())
            {
                TestModel model = new TestModel();

                context.Set <TestModel>().Attach(model);
                context.Entry(model).State = EntityState.Modified;
                textProperty = context.Entry(model).Property(prop => prop.Title);
                dateProperty = context.Entry(model).Property(prop => prop.CreationDate);
            }
        }
Ejemplo n.º 7
0
        public void Insert_AddsModelToDbSet()
        {
            TestModel model = ObjectFactory.CreateTestModel();

            unitOfWork.Insert(model);

            TestModel actual   = context.Set <TestModel>().Local.Single();
            TestModel expected = model;

            Assert.Equal(EntityState.Added, context.Entry(model).State);
            Assert.Same(expected, actual);
        }
Ejemplo n.º 8
0
        public void InsertRange_AddsModelsToDbSet()
        {
            IEnumerable <Role> models = new[] { ObjectFactory.CreateRole(1), ObjectFactory.CreateRole(2) };

            unitOfWork.InsertRange(models);

            IEnumerator <Role> actual   = context.ChangeTracker.Entries <Role>().Select(entry => entry.Entity).GetEnumerator();
            IEnumerator <Role> expected = models.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.Equal(EntityState.Added, context.Entry(actual.Current).State);
                Assert.Same(expected.Current, actual.Current);
            }
        }
Ejemplo n.º 9
0
        public void LoggableEntity_CreatesPropertiesForAttachedEntity()
        {
            context.Dispose();
            String roleName = model.Name;

            context = new TestingContext();
            context.Set <Role>().Attach(model);

            entry = context.Entry <BaseModel>(model);
            entry.OriginalValues["Name"] = "Role";
            entry.CurrentValues["Name"]  = "Role";
            entry.State = EntityState.Modified;

            IEnumerator <LoggableProperty> expected = new List <LoggableProperty>()
            {
                new LoggableProperty(entry.Property("Name"), roleName)
            }.GetEnumerator();
            IEnumerator <LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.AreEqual(expected.Current.IsModified, actual.Current.IsModified);
                Assert.AreEqual(expected.Current.ToString(), actual.Current.ToString());
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> PutTesting(int id, Testing testing)
        {
            if (id != testing.EID)
            {
                return(BadRequest());
            }

            _context.Entry(testing).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TestingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 11
0
        public void LoggableEntity_SetsEntityTypeName()
        {
            entry = context.Entry <BaseModel>(context.Set <Role>().Add(new Role()));

            String actual   = new LoggableEntity(entry).Name;
            String expected = typeof(Role).Name;

            Assert.NotEqual("System.Data.Entity.DynamicProxies", entry.Entity.GetType().Namespace);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 12
0
 public ActionResult Edit(TestDB testdb)
 {
     if (ModelState.IsValid)
     {
         db.Entry(testdb).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(testdb));
 }
Ejemplo n.º 13
0
        public AuditLoggerTests()
        {
            context = new TestingContext();
            logger  = new AuditLogger(context, 1);
            TestingContext dataContext = new TestingContext();
            TestModel      model       = ObjectsFactory.CreateTestModel();

            entry = dataContext.Entry <BaseModel>(dataContext.Add(model).Entity);
            dataContext.SaveChanges();
        }
Ejemplo n.º 14
0
        public AuditLoggerTests()
        {
            context = new TestingContext();
            logger  = new AuditLogger(context, 1);
            TestModel      model       = ObjectFactory.CreateTestModel();
            TestingContext dataContext = new TestingContext();

            entry = dataContext.Entry <BaseModel>(dataContext.Set <TestModel>().Add(model));
            dataContext.Set <AuditLog>().RemoveRange(dataContext.Set <AuditLog>());
            dataContext.DropData();
        }
        public LoggableEntityTests()
        {
            using (context = new TestingContext())
            {
                context.Add(model = ObjectsFactory.CreateTestModel());
                context.SaveChanges();
            }

            context = new TestingContext(context);
            entry   = context.Entry <BaseModel>(model);
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            using (context = new TestingContext())
            {
                TearDownData();
                SetUpData();
            }

            context = new TestingContext();
            model   = context.Set <Role>().Single();
            entry   = context.Entry <BaseModel>(model);
        }
Ejemplo n.º 17
0
        public LoggableEntityTests()
        {
            using (context = new TestingContext())
            {
                context.DropData();
                SetUpData();
            }

            context = new TestingContext();
            model   = context.Set <Role>().Single();
            entry   = context.Entry <BaseModel>(model);
        }
Ejemplo n.º 18
0
        public AuditLoggerTests()
        {
            context     = new TestingContext();
            dataContext = new TestingContext();
            TestModel model = ObjectFactory.CreateTestModel();

            logger = Substitute.ForPartsOf <AuditLogger>(context);

            entry = dataContext.Entry <BaseModel>(dataContext.Set <TestModel>().Add(model));
            dataContext.Set <TestModel>().RemoveRange(dataContext.Set <TestModel>());
            dataContext.SaveChanges();
        }
Ejemplo n.º 19
0
        public LoggableEntityTests()
        {
            using (context = new TestingContext())
            {
                context.Set <TestModel>().RemoveRange(context.Set <TestModel>());
                context.Set <TestModel>().Add(ObjectFactory.CreateTestModel());
                context.Set <Role>().Add(ObjectFactory.CreateRole());
                context.DropData();
            }

            context = new TestingContext();
            model   = context.Set <TestModel>().Single();
            entry   = context.Entry <BaseModel>(model);
        }
Ejemplo n.º 20
0
        public void LoggableEntity_CreatesPropertiesForAttachedEntity()
        {
            context.Dispose();
            String title = model.Title;

            context = new TestingContext();
            context.Set <TestModel>().Attach(model);

            entry = context.Entry <BaseModel>(model);
            entry.OriginalValues["Title"] = "Role";
            entry.CurrentValues["Title"]  = "Role";
            entry.State = EntityState.Modified;

            LoggableProperty expected = new LoggableProperty(entry.Property("Title"), title);
            LoggableProperty actual   = new LoggableEntity(entry).Properties.Single();

            Assert.Equal(expected.IsModified, actual.IsModified);
            Assert.Equal(expected.ToString(), actual.ToString());
        }
Ejemplo n.º 21
0
 public void Update(OpenAnswersGivenByStutent item)
 {
     db.Entry(item).State = EntityState.Modified;
 }
Ejemplo n.º 22
0
 public void Update(ExamOpenAnswerByStd item)
 {
     db.Entry(item).State = EntityState.Modified;
 }
Ejemplo n.º 23
0
 public void Update(ExamQuestion item)
 {
     db.Entry(item).State = EntityState.Modified;
 }
Ejemplo n.º 24
0
 public void Update(Subject item)
 {
     db.Entry(item).State = EntityState.Modified;
 }