public void SetUp()
        {
            InitializeDataSets();
            MockRepository   = new Mock <IRepository>();
            MockGroupService = new Mock <IGroupService>();
            MockUserService  = new Mock <IUserService>();
            MockRoleService  = new Mock <IRoleService>();

            MockRepository.Setup(m => m.GetSet <User>()).Returns(() => UserSet);
            MockRepository.Setup(m => m.GetSet <Group>()).Returns(() => GroupSet);
            MockRepository.Setup(m => m.GetSet <Role>()).Returns(() => RoleSet);
            MockRepository.Setup(m => m.GetSet <Project>()).Returns(() => ProjectSet);
            MockRepository.Setup(m => m.GetSet <ProjectUser>()).Returns(() => ProjectUserSet);
            MockRepository.Setup(m => m.GetSet <ProjectRole>()).Returns(() => ProjectRoleSet);
            MockRepository.Setup(m => m.GetSet <ProjectGroup>()).Returns(() => ProjectGroupSet);
            MockRepository.Setup(m => m.GetSet <ProjectUserRole>()).Returns(() => ProjectUserRoleSet);

            MockUserService.Setup(m => m.FindUser(1)).Returns(() => UserSet.FirstOrDefault(u => u.Id == 1));
            MockUserService.Setup(m => m.FindUser(2)).Returns(() => UserSet.FirstOrDefault(u => u.Id == 2));
            MockUserService.Setup(m => m.FindUser(3)).Throws <NotFoundException>();

            MockRoleService.Setup(m => m.FindRole(1)).Returns(() => RoleSet.First(r => r.Id == 1));
            MockRoleService.Setup(m => m.FindRole(2)).Returns(() => RoleSet.First(r => r.Id == 2));
            MockRoleService.Setup(m => m.FindRole(3)).Throws <NotFoundException>();

            MockGroupService.Setup(m => m.FindGroup(1)).Returns(() => GroupSet.First(g => g.Id == 1));
            MockGroupService.Setup(m => m.FindGroup(2)).Returns(() => GroupSet.First(g => g.Id == 2));
            MockGroupService.Setup(m => m.FindGroup(3)).Throws <NotFoundException>();
        }
        public void SetUp()
        {
            var userList = new List <User>();

            userList.Add(new User()
            {
                Id = 1, Name = "User1", Password = "******"
            });
            userList.Add(new User()
            {
                Id = 2, Name = "User2", Password = "******"
            });
            UserSet = userList;
            var roleList = new List <Role>();

            roleList.Add(new Role()
            {
                Id = 1, Name = "Role1", Description = "Any1"
            });
            roleList.Add(new Role()
            {
                Id = 2, Name = "Role2", Description = "Any2"
            });
            RoleSet = roleList;
            var groupList = new List <Group>();

            groupList.Add(new Group()
            {
                Id = 1, Name = "Group1"
            });
            groupList.Add(new Group()
            {
                Id = 2, Name = "Group2"
            });
            GroupSet        = groupList;
            MockTransaction = new Mock <ITransaction>();
            MockRepository  = new Mock <IRepository>();
            MockRepository.Setup(repo => repo.BeginTransaction()).Returns(() => Transaction);
            MockUserService = new Mock <IUserService>();
            MockUserService.Setup(u => u.FindUser(1)).Returns(() => UserSet.First(u => u.Id == 1));
            MockUserService.Setup(u => u.FindUser(2)).Returns(() => UserSet.First(u => u.Id == 2));
            MockRoleService = new Mock <IRoleService>();
            MockRoleService.Setup(r => r.FindRole(1)).Returns(() => RoleSet.First(r => r.Id == 1));
            MockRoleService.Setup(r => r.FindRole(2)).Returns(() => RoleSet.First(r => r.Id == 2));
            MockRepository.Setup(repo => repo.GetSet <Group>()).Returns(() => GroupSet);
        }
        public void TestUpdateRole()
        {
            MockRepository.Setup(repo => repo.Update <Role>(It.IsAny <Role>())).Returns(() => RoleSet.First(r => r.Id == 1));
            var role = RoleService.UpdateRole(1, "Role3", "Any");

            Assert.AreEqual(1, role.Id);
            Assert.AreEqual("Role3", role.Name);
        }