protected TestBase() { using (ContextDb testDb = new ContextDb()) { Database.SetInitializer(new DbInitializer()); testDb.Database.Initialize(true); } }
public void RoleShouldBeDeleted() { using (ContextDb testDb = new ContextDb()) { testDb.Roles.Attach(expectedRole); testDb.Roles.Remove(expectedRole); testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { Role actualRole = testDb.Roles.Find(expectedRole.Id); Assert.IsNull(actualRole); } }
public void RoleShouldBeCreated() { using (ContextDb testDb = new ContextDb()) { testDb.Roles.Add(expectedRole); testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { Role actualRole = testDb.Roles.Find(expectedRole.Id); Assert.IsFalse(ReferenceEquals(expectedRole, actualRole)); Assert.AreEqual(expectedRole, actualRole); } }
public void UserShouldBeDeleted() { using (ContextDb testDb = new ContextDb()) { testDb.Users.Attach(expectedUser); testDb.Users.Remove(expectedUser); testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { User actualUser = testDb.Users.Find(expectedUser.Id); Assert.IsNull(actualUser); } }
public void UserShouldBeCreated() { using (ContextDb testDb = new ContextDb()) { testDb.Users.Add(expectedUser); testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { User actualUser = testDb.Users.Find(expectedUser.Id); Assert.IsFalse(ReferenceEquals(expectedUser, actualUser)); Assert.AreEqual(expectedUser, actualUser); } }
public void RoleShouldBeUpdated() { using (ContextDb testDb = new ContextDb()) { testDb.Roles.Attach(expectedRole); testDb.Entry(expectedRole).State = EntityState.Modified; testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { Role actualRole = testDb.Roles.Find(expectedRole.Id); Assert.IsFalse(ReferenceEquals(expectedRole, actualRole)); Assert.AreEqual(expectedRole, actualRole); } }
public void UserShouldBeUpdated() { using(ContextDb testDb = new ContextDb()) { testDb.Users.Attach(expectedUser); testDb.Entry(expectedUser).State = EntityState.Modified; testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { User actualUser = testDb.Users.Find(expectedUser.Id); Assert.IsFalse(ReferenceEquals(expectedUser, actualUser)); Assert.AreEqual(expectedUser, actualUser); } }
public void RelationshipShouldBeSaved() { using (ContextDb testDb = new ContextDb()) { testDb.Users.Attach(expectedUser); testDb.Roles.Attach(userRole); testDb.Roles.Attach(moderatorRole); testDb.Roles.Attach(adminRole); expectedUser.Roles.Add(userRole); expectedUser.Roles.Add(moderatorRole); expectedUser.Roles.Add(adminRole); testDb.SaveChanges(); } using (ContextDb testDb = new ContextDb()) { User actualUser = testDb.Users.Include(x => x.Roles).Single(x => x.Id == expectedUser.Id); Assert.AreEqual(expectedUser.Roles.Count(), actualUser.Roles.Count()); List<int> expectedIdList = expectedUser.Roles.Select(x => x.Id).ToList(); List<int> actualIdList = actualUser.Roles.Select(x => x.Id).ToList(); Assert.IsTrue(expectedIdList.SequenceEqual(actualIdList)); } }
public List<User> GetUsers(string filter) { using (ContextDb context = new ContextDb()) { List<User> listUserFiltered = context.Users.Include(x => x.Roles).Where(user => user.FirstName.Contains(filter) || user.LastName.Contains(filter)).ToList(); return listUserFiltered; } }