public void Role_Should_Be_Updated_By_RoleModel() { var role = RoleTestData.GetUserRole(); var roleModel = RoleTestData.GetUpdateUserRoleModel(); roleAdapter.Update(role, roleModel); Assert.AreEqual(role.Name, roleModel.Name); Assert.AreEqual(role.Code, roleModel.Code); }
public void Role_Create_Check_Should_Fail_If_Role_Name_Already_Exist() { var roleModel = RoleTestData.GetUserRoleModel(); var role = RoleTestData.GetUserRole(); roleRepository.Setup(r => r.GetById(It.Is <Expression <Func <Data.Role, bool> > >(e => AreEqual(e, "roleModel.Name")))).Returns(role); roleBusinessRules.CreateCheck(roleModel, roleRepository.Object); roleRepository.Verify(r => r.GetById(It.IsAny <Expression <Func <Data.Role, bool> > >()), Times.Once); }
public void Role_Update_Check_Should_Throw_Exception_Role_Code_Already_Exists() { var roleModel = RoleTestData.GetUserRoleModel(); var role = RoleTestData.GetUserRole(); roleRepository.Setup(r => r.GetById(It.Is <Expression <Func <Data.Role, bool> > >(e => AreEqual <Data.Role, bool>(e, "roleModel.Id")))).Returns(role); roleRepository.Setup(r => r.GetById(It.Is <Expression <Func <Data.Role, bool> > >(e => AreEqual <Data.Role, bool>(e, "roleModel.Code")))).Returns(role); roleRepository.Setup(r => r.GetById(It.Is <Expression <Func <Data.Role, bool> > >(e => AreEqual <Data.Role, bool>(e, "roleModel.Name")))).Returns(RoleTestData.GetNullRole()); roleBusinessRules.UpdateCheck(roleModel, roleRepository.Object); }
public void Role_Add_Unique_Role_Should_Succeed() { using (var context = new PayrollContext(IntergrationTestsSetup.ContextOptions)) { var unitOfWork = new UnitOfWork(context); var role = RoleTestData.GetUserRole(); unitOfWork.Role.Insert(role); unitOfWork.Save(); Assert.IsTrue(role.Id > 0); } }
public void Should_Create_Role() { // Arrange unitOfWork.Setup(x => x.Save()).Verifiable(); unitOfWork.Setup(x => x.Role.Insert(It.IsAny <Data.Role>())).Verifiable(); roleBusinessRules.Setup(x => x.CreateCheck(It.IsAny <RoleModel>(), It.IsAny <RoleRepository>())).Verifiable(); roleBuilder.Setup(x => x.Build(It.IsAny <RoleModel>())).Returns(RoleTestData.GetEmptyRole()); roleBuilder.Setup(x => x.BuildModel(It.IsAny <Data.Role>())).Returns(new RoleModel()); unitOfWork.Setup(x => x.Role.GetById(It.IsAny <Expression <Func <Data.Role, bool> > >())).Returns(RoleTestData.GetUserRole()); // Act var result = roleService.Create(RoleTestData.GetUserRoleModel()); // Assert roleBusinessRules.Verify(x => x.CreateCheck(It.IsAny <RoleModel>(), It.IsAny <RoleRepository>()), Times.Once); roleBuilder.Verify(x => x.Build(It.IsAny <RoleModel>()), Times.Once); unitOfWork.Verify(x => x.Role.GetById(It.IsAny <Expression <Func <Data.Role, bool> > >()), Times.Once); roleBuilder.Verify(x => x.BuildModel(It.IsAny <Data.Role>()), Times.Once); }
public void Role_Update_Should_Throw_Exception_When_RoleModel_Null() { var role = RoleTestData.GetUserRole(); roleAdapter.Update(role, null); }