public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
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); }
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); } }
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); } }
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); } }
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); }
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); } }
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()); } }
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()); }
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); }
public ActionResult Edit(TestDB testdb) { if (ModelState.IsValid) { db.Entry(testdb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testdb)); }
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(); }
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); }
public void SetUp() { using (context = new TestingContext()) { TearDownData(); SetUpData(); } context = new TestingContext(); model = context.Set <Role>().Single(); entry = context.Entry <BaseModel>(model); }
public LoggableEntityTests() { using (context = new TestingContext()) { context.DropData(); SetUpData(); } context = new TestingContext(); model = context.Set <Role>().Single(); entry = context.Entry <BaseModel>(model); }
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(); }
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); }
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()); }
public void Update(OpenAnswersGivenByStutent item) { db.Entry(item).State = EntityState.Modified; }
public void Update(ExamOpenAnswerByStd item) { db.Entry(item).State = EntityState.Modified; }
public void Update(ExamQuestion item) { db.Entry(item).State = EntityState.Modified; }
public void Update(Subject item) { db.Entry(item).State = EntityState.Modified; }