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()); }
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(); }
/// <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(); }
public TaskModulesController(GraphLabsContext context, InMemoryInitialData initialData) { _db = context; if (!context.TaskModules.Any()) { foreach (var module in initialData.GetTaskModules()) { context.TaskModules.Add(module); } context.SaveChanges(); } }
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)); }
/// <summary> Сохранить все изменения </summary> public void SaveChanges() { _context.SaveChanges(); }