示例#1
0
        public void TestUserLoginIsUnique()
        {
            const string EMAIL = "*****@*****.**";

            RemoveByCriteria <User>(u => u.Email == EMAIL);

            var user1 = GraphLabsContext.Users.Create();

            user1.Name         = TEST_NAME;
            user1.Email        = EMAIL;
            user1.FatherName   = "FatherName";
            user1.PasswordHash = "PasswordHash";
            user1.Surname      = "Surname";
            GraphLabsContext.Users.Add(user1);
            GraphLabsContext.SaveChanges();

            var user2 = GraphLabsContext.Users.Create();

            user2.Name         = TEST_NAME;
            user2.Email        = EMAIL;
            user2.FatherName   = "FatherName";
            user2.PasswordHash = "PasswordHash";
            user2.Surname      = "Surname";
            GraphLabsContext.Users.Add(user2);

            Assert.Throws <SqlException>(() => GraphLabsContext.SaveChanges());
        }
示例#2
0
        private void RemoveByCriteria <T>(Expression <Func <T, bool> > predicate) where T : class
        {
            var set      = GraphLabsContext.Set <T>();
            var entities = set.Where(predicate);

            foreach (var entity in entities)
            {
                set.Remove(entity);
            }
            GraphLabsContext.SaveChanges();
        }
示例#3
0
        /// <summary> Устанавливает время системы </summary>
        public void SetDate(DateTime newDateTime)
        {
            var currentDate = GetDate();
            var newDate     = newDateTime.Date;

            Contract.Assume(newDate > currentDate, "Новая дата должна быть больше предыдущей.");

            var settings = _context.Settings.Single();

            settings.SystemDate = newDate;
            _context.SaveChanges();
        }
示例#4
0
        public TaskModulesController(GraphLabsContext context, InMemoryInitialData initialData)
        {
            _db = context;

            if (!context.TaskModules.Any())
            {
                foreach (var module in initialData.GetTaskModules())
                {
                    context.TaskModules.Add(module);
                }
                context.SaveChanges();
            }
        }
示例#5
0
        public void TestDoSmth()
        {
            RemoveByCriteria <User>(u => u.Name == TEST_NAME);

            Assert.AreEqual(0, GraphLabsContext.Users.Count(u => u.Name == TEST_NAME));

            var user = GraphLabsContext.Users.Create();

            user.Name         = TEST_NAME;
            user.Email        = "*****@*****.**";
            user.FatherName   = "FatherName";
            user.PasswordHash = "PasswordHash";
            user.Surname      = "Surname";
            GraphLabsContext.Users.Add(user);

            GraphLabsContext.SaveChanges();

            Assert.AreEqual(1, GraphLabsContext.Users.Count(u => u.Name == TEST_NAME));
        }
示例#6
0
 /// <summary> Сохранить все изменения </summary>
 public void SaveChanges()
 {
     _context.SaveChanges();
 }