public void UserManagementLogic_ImportMerge_EntityWithEmptySamAccountName_ThrowsInsufficientDataException() { ClaimsPrincipal user = new ClaimsPrincipal(); ImportUsersActiveDirectoryMetadataModel entity = new ImportUsersActiveDirectoryMetadataModel() { MergeWith = Guid.NewGuid(), Merge = true, Users = new System.Collections.Generic.List <ActiveDirectoryMetadataAuthPrincipalQueryResultModel>() { new ActiveDirectoryMetadataAuthPrincipalQueryResultModel() { SamAccountName = string.Empty, UserPrincipalName = "TestUpn" } } }; Mock <IConfigurationRepository> configurationRepository = new Mock <IConfigurationRepository>(); configurationRepository.Setup(x => x.Exists <AuthenticablePrincipal>(It.IsAny <Expression <Func <AuthenticablePrincipal, bool> > >())).Returns(false); configurationRepository.Setup(x => x.Get <AuthenticablePrincipal>(It.IsAny <Guid>())).Returns(new AuthenticablePrincipal()); configurationRepository.Setup(x => x.Exists <ActiveDirectoryMetadata>(It.IsAny <Guid>())).Returns(true); UserManagementLogic userManagementLogic = new UserManagementLogic(configurationRepository.Object, new AuthorizeInitialSetup(configurationRepository.Object)); userManagementLogic.ImportUser(entity, user); }
public JsonResult ImportUsers(ImportUsersActiveDirectoryMetadataModel entity) { try { userManagement.ImportUser(entity, User); return(http.RespondSuccess()); } catch (Exception e) { return(http.RespondServerError(e.Message)); } }
public void UserManagementLogic_ImportUser_Unauthorized_ThrowsUnauthorizedAccessException() { ClaimsPrincipal user = new ClaimsPrincipal(); ImportUsersActiveDirectoryMetadataModel entity = GetImportUsersActiveDirectoryMetadataModelValid(); Mock <IAuthorizationLogic> authorizationLogic = new Mock <IAuthorizationLogic>(); authorizationLogic.Setup(x => x.IsAuthorizedThrowsException(AuthorizationScopes.ManageUsers, user, It.IsAny <ILoggableEntity>(), It.IsAny <EventCategory>())).Throws(new UnauthorizedAccessException()); Mock <IConfigurationRepository> configurationRepository = new Mock <IConfigurationRepository>(); UserManagementLogic userManagementLogic = new UserManagementLogic(configurationRepository.Object, authorizationLogic.Object); userManagementLogic.ImportUser(entity, user); }