private void TearDownData() { dataContext.Set <TestModel>().RemoveRange(dataContext.Set <TestModel>()); context.Set <Log>().RemoveRange(context.Set <Log>()); context.SaveChanges(); dataContext.SaveChanges(); }
public void Log_LogsMessage() { logger.Log(new String('L', 10000)); String actual = context.Set <Log>().Single().Message; String expected = new String('L', 10000); Assert.AreEqual(1, context.Set <Log>().Count()); Assert.AreEqual(expected, actual); }
public void Expression_IsContextSetsExpression() { DbSet <TestModel> databaseSet = Substitute.For <DbSet <TestModel>, IQueryable>(); (databaseSet as IQueryable).Expression.Returns(Expression.Add(Expression.Constant(0), Expression.Constant(0))); AContext context = Substitute.For <AContext>(); context.Set <TestModel>().Returns(databaseSet); repository = new Repository <TestModel>(context); Expression expected = (context.Set <TestModel>() as IQueryable).Expression; Expression actual = (repository as IQueryable).Expression; Assert.AreSame(expected, actual); }
public void SetUp() { context = new TestingContext(); TearDownData(); SetUpData(); context = new TestingContext(); entry = context.Entry(context.Set <Role>().SingleOrDefault()); entry.State = EntityState.Modified; }
public void RollBack_RollbacksChanges() { Account model = ObjectFactory.CreateAccount(); context.Set <Account>().Add(model); unitOfWork.Rollback(); unitOfWork.Commit(); Assert.IsNull(unitOfWork.Repository <Account>().GetById(model.Id)); }
public virtual void Log(IEnumerable <DbEntityEntry> entries) { foreach (DbEntityEntry entry in entries) { switch (entry.State) { case EntityState.Added: case EntityState.Deleted: context.Set <Log>().Add(new Log(new LoggableEntry(entry).ToString())); break; case EntityState.Modified: LoggableEntry loggableEntry = new LoggableEntry(entry); if (loggableEntry.HasChanges) { context.Set <Log>().Add(new Log(loggableEntry.ToString())); } break; } } }
public void LoggableEntry_HasChangesIfAnyAttachedPropertyIsModified() { context.Dispose(); context = new TestingContext(); model.Name += "1"; context.Set <Role>().Attach(model); entry = context.Entry <Role>(model); entry.State = EntityState.Modified; Assert.IsTrue(new LoggableEntry(entry).HasChanges); }
public void SetUp() { context = new TestingContext(); dataContext = new TestingContext(); logger = new EntityLogger(context); HttpContext.Current = new HttpMock().HttpContext; TearDownData(); TestModel model = ObjectFactory.CreateTestModel(); dataContext.Set <TestModel>().Add(model); entry = dataContext.Entry(model); dataContext.SaveChanges(); }
public void LoggableEntry_SetsEntityTypeThenEntityIsNotProxied() { entry = context.Entry(context.Set <Role>().Add(new Role())); Type actual = new LoggableEntry(entry).EntityType; Type expected = model.GetType(); Assert.AreNotEqual("System.Data.Entity.DynamicProxies", entry.Entity.GetType().Namespace); Assert.AreEqual(expected, actual); }
public void Update_UpdatesNotAttachedModel() { TestModel expected = ObjectFactory.CreateTestModel(); context.Set <TestModel>().Add(expected); context.SaveChanges(); expected.Text += "Test"; context = new TestingContext(); repository = new Repository <TestModel>(context); repository.Update(expected); context.SaveChanges(); TestModel actual = context.Set <TestModel>().SingleOrDefault(); TestHelper.PropertyWiseEqual(expected, actual); }
public virtual void Log(String message) { context.Set <Log>().Add(new Log(message)); context.SaveChanges(); }
public void ElementType_IsRepositoryModelType() { Type expected = (context.Set <TestModel>() as IQueryable).ElementType; Type actual = (repository as IQueryable).ElementType; Assert.AreSame(expected, actual); }
public void Log_DoesNotLogModifiedEntitiesWithoutChanges() { entry.State = EntityState.Modified; Assert.IsFalse(context.Set <Log>().Any()); }
public IEnumerable <T> List() { return(_aContext.Set <T>().ToList()); }