public void CreateUser() { var context = new Context(); var user = context.Users.FirstOrDefault(i => i.Name == "Stan") ?? new User { Name = "Stan" }; if (context.Users.Any(i => i.Id == user.Id) == false) context.Users.Add(user); context.SaveChanges(); }
public void CreateTasks() { var context = new Context(); var task = context.Tasks.FirstOrDefault(i => i.Description == "Lev1") ?? new Task { Description = "Lev1" }; if (context.Tasks.Any(i => i.Id == task.Id) == false) context.Tasks.Add(task); var sub1 = context.Tasks.FirstOrDefault(i => i.Description == "Lev2-1") ?? new Task { Description = "Lev2-1" }; if (context.Tasks.Any(i => i.Id == sub1.Id) == false) context.Tasks.Add(sub1); context.SaveChanges(); }
public void RemoveRole() { var context = new Context(); var user = context.Users.FirstOrDefault(i => i.Name == "Stan"); Assert.IsNotNull(user); var firstRole = user.Roles.LastOrDefault(); if (firstRole == null) return; user.Roles.Remove(firstRole); var x = context.SaveChanges(); Assert.IsTrue(x > 0); }
public void ChangeOrder() { var context = new Context(); var user = context.Users.FirstOrDefault(i => i.Name == "Stan"); Assert.IsNotNull(user); var order = 1; foreach (var o in user.Roles.OrderByDescending(i => i.Order)) { o.Order = order++; } var x = context.SaveChanges(); Assert.IsTrue(x > 0); }
public void InsertSubTasks2() { var context = new Context(); var task = context.Tasks.FirstOrDefault(i => i.Description == "Lev1"); Assert.IsNotNull(task); var sub1 = context.Tasks.FirstOrDefault(i => i.Description == "Lev2-1"); Assert.IsNotNull(sub1); if (task.SubTasks.Any(i => i.TaskId == sub1.Id) == false) { var ot = new OrderedTask { Parent = task, Task = sub1, Order = task.SubTasks.Count + 1 }; context.OrderedTasks.Add(ot); } context.SaveChanges(); }
public void CreateRole() { var context = new Context(); var role = context.Roles.FirstOrDefault(i => i.Name == "Admin") ?? new Role { Name = "Admin" }; if (context.Roles.Any(i => i.Id == role.Id) == false) context.Roles.Add(role); role = context.Roles.FirstOrDefault(i => i.Name == "User") ?? new Role { Name = "User" }; if (context.Roles.Any(i => i.Id == role.Id) == false) context.Roles.Add(role); role = context.Roles.FirstOrDefault(i => i.Name == "Guest") ?? new Role { Name = "Guest" }; if (context.Roles.Any(i => i.Id == role.Id) == false) context.Roles.Add(role); context.SaveChanges(); }
public void AddRoles() { var context = new Context(); var user = context.Users.FirstOrDefault(i => i.Name == "Stan"); Assert.IsNotNull(user); var role1 = context.Roles.FirstOrDefault(i => i.Name == "Admin"); Assert.IsNotNull(role1); var role2 = context.Roles.FirstOrDefault(i => i.Name == "User"); Assert.IsNotNull(role2); user.Roles.Clear(); user.Roles.Add(new OrderedRole{Order = user.Roles.Count() + 1, Role = role1}); user.Roles.Add(new OrderedRole { Order = user.Roles.Count() + 1, Role = role2 }); var x = context.SaveChanges(); Assert.IsTrue(x > 0); }