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_Create_Check_Should_Succeed() { var roleModel = RoleTestData.GetUserRoleModel(); var role = RoleTestData.GetNullRole(); roleRepository.Setup(r => r.GetById(a => a.Name == roleModel.Name)).Returns(role); roleRepository.Setup(r => r.GetById(a => a.Code == roleModel.Code)).Returns(role); roleBusinessRules.CreateCheck(roleModel, roleRepository.Object); }
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 Should_Fail_To_Create_Role_When_SaveCheck_Throws_Excpetion() { // Arrange roleBusinessRules.Setup(x => x.CreateCheck(It.IsAny <RoleModel>(), It.IsAny <RoleRepository>())).Throws(new ResponseValidationException(ResponseMessage.ToError("Role Create throws exception."))); // 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.Never); roleBuilder.Verify(x => x.BuildModel(It.IsAny <Data.Role>()), Times.Never); unitOfWork.Verify(x => x.Save(), Times.Never); unitOfWork.Verify(x => x.Role.Insert(It.IsAny <Data.Role>()), Times.Never); unitOfWork.Verify(x => x.Role.GetById(It.IsAny <Expression <Func <Data.Role, bool> > >()), Times.Never); }
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); }