示例#1
0
 protected TestBase()
 {
     using (ContextDb testDb = new ContextDb())
     {
         Database.SetInitializer(new DbInitializer());
         testDb.Database.Initialize(true);
     }
 }
示例#2
0
 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);
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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);
     }
 }
示例#5
0
 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);
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
        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));
            }
        }
示例#9
0
 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;
     }
 }