示例#1
0
 private void TearDownData()
 {
     dataContext.Set <TestModel>().RemoveRange(dataContext.Set <TestModel>());
     context.Set <Log>().RemoveRange(context.Set <Log>());
     context.SaveChanges();
     dataContext.SaveChanges();
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public void SetUp()
        {
            context = new TestingContext();
            TearDownData();
            SetUpData();

            context     = new TestingContext();
            entry       = context.Entry(context.Set <Role>().SingleOrDefault());
            entry.State = EntityState.Modified;
        }
示例#5
0
        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));
        }
示例#6
0
        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;
                }
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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();
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
 public virtual void Log(String message)
 {
     context.Set <Log>().Add(new Log(message));
     context.SaveChanges();
 }
示例#12
0
        public void ElementType_IsRepositoryModelType()
        {
            Type expected = (context.Set <TestModel>() as IQueryable).ElementType;
            Type actual   = (repository as IQueryable).ElementType;

            Assert.AreSame(expected, actual);
        }
示例#13
0
        public void Log_DoesNotLogModifiedEntitiesWithoutChanges()
        {
            entry.State = EntityState.Modified;

            Assert.IsFalse(context.Set <Log>().Any());
        }
 public IEnumerable <T> List()
 {
     return(_aContext.Set <T>().ToList());
 }