public void MedicalExaminerFound_ReturnsSuccess() { // Arrange var expectedResult = ValidationResult.Success; var userId = "1"; var expectedUser = new MeUser { UserId = userId, Permissions = new List <MEUserPermission>() { new MEUserPermission() { LocationId = "site", UserRole = UserRoles.MedicalExaminer, } } }; var expectedExamination = new Examination() { SiteLocationId = "site", }; SetupUserRetrievalByIdMock(userId, expectedUser); SetupExaminationValidationContextProvider(_serviceProvideMock, expectedExamination); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act var result = sut.GetValidationResult(userId, _context); // Assert Assert.Equal(expectedResult, result); }
public void MedicalExaminerWrongUserType_ReturnsFail() { // Arrange var userId = "1"; var expectedUser = new MeUser { UserId = userId, Permissions = new List <MEUserPermission>() }; var expectedExamination = new Examination() { SiteLocationId = "site", }; var expectedResult = new ValidationResult("The user is not a `Medical Examiner`."); SetupUserRetrievalByIdMock(userId, expectedUser); SetupExaminationValidationContextProvider(_serviceProvideMock, expectedExamination); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act var result = sut.GetValidationResult(userId, _context); // Assert Assert.NotNull(result); if (result != null) { Assert.Equal(expectedResult.ErrorMessage, result.ErrorMessage); } }
public void GetValidationResult_ShouldThrowInvalidOperationException_WhenExaminationValidationContextProviderNotSetupOnContext() { // Arrange var expectedUserId = "expectedUserId"; var serviceProvider = new Mock <IServiceProvider>(); var context = new ValidationContext(new object(), serviceProvider.Object, new Dictionary <object, object>()); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act Action act = () => sut.GetValidationResult(expectedUserId, context); // Assert act.Should().Throw <InvalidOperationException>(); }
public void GetValidationResult_Fails_WhenExaminationNotSet() { // Arrange SetupExaminationValidationContextProvider(_serviceProvideMock, null); var userId = "1"; var expectedResult = new ValidationResult("The examination was not present to confirm role validation."); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act var result = sut.GetValidationResult(userId, _context); // Assert Assert.NotNull(result); if (result != null) { Assert.Equal(expectedResult.ErrorMessage, result.ErrorMessage); } }
public void MedicalExaminerUserItemIsNotString_ReturnsFail() { // Arrange SetupExaminationValidationContextProvider(_serviceProvideMock, new Examination()); var expectedResult = new ValidationResult("Item not recognised as of type useritem for `Medical Examiner`."); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act var result = sut.GetValidationResult(new object(), _context); // Assert Assert.Null(result); if (result != null) { Assert.Equal(expectedResult.ErrorMessage, result.ErrorMessage); } }
public void MedicalExaminerNotFound_ReturnsFail() { // Arrange var userId = "1"; var expectedResult = new ValidationResult("The user with id `1` was not found."); SetupUserRetrievalByIdMock(userId, null); SetupExaminationValidationContextProvider(_serviceProvideMock, new Examination()); var sut = new ValidRoleOnExamination(UserRoles.MedicalExaminer); // Act var result = sut.GetValidationResult(userId, _context); // Assert Assert.NotNull(result); if (result != null) { Assert.Equal(expectedResult.ErrorMessage, result.ErrorMessage); } }