public async Task Search_NotFoundArtifact_ResourceNotFoundException() { // arrange ArtifactBasicDetails artifactBasicDetails = null; _sqlArtifactRepositoryMock.Setup(q => q.GetArtifactBasicDetails(ScopeId, UserId, null)).ReturnsAsync(artifactBasicDetails); _searchEngineRepositoryMock.Setup(q => q.GetCollectionContentSearchArtifactResults(ScopeId, _pagination, true, UserId, null)).ReturnsAsync(_searchArtifactsResult); var errorMessage = I18NHelper.FormatInvariant(ErrorMessages.ArtifactNotFound, ScopeId); var excectedResult = new ResourceNotFoundException(errorMessage, ErrorCodes.ResourceNotFound); ResourceNotFoundException exception = null; // act try { await _searchEngineService.Search(ScopeId, _pagination, ScopeType.Contents, true, UserId); } catch (ResourceNotFoundException ex) { exception = ex; } // assert Assert.IsNotNull(exception); Assert.AreEqual(excectedResult.Message, exception.Message); }
protected override void InternalCheckForOperationSupport(ArtifactBasicDetails artifactBasicDetails) { if (!IsWorkflowSupported((ItemTypePredefined)artifactBasicDetails.PrimitiveItemTypePredefined)) { throw ExceptionHelper.ArtifactDoesNotSupportOperation(artifactBasicDetails.ItemId); } }
private async Task LockReviewAsync(int reviewId, int userId, ArtifactBasicDetails reviewInfo) { if (reviewInfo.LockedByUserId.HasValue) { if (reviewInfo.LockedByUserId.Value != userId) { throw ExceptionHelper.ArtifactNotLockedException(reviewId, userId); } return; } if (!await _lockArtifactsRepository.LockArtifactAsync(reviewId, userId)) { throw ExceptionHelper.ArtifactNotLockedException(reviewId, userId); } }
private async Task <ReviewSettings> GetReviewSettingsFromReviewData(Review reviewData, ArtifactBasicDetails reviewInfo) { var reviewSettings = new ReviewSettings(reviewData.ReviewPackageRawData); // We never ignore folders for formal reviews - Jira Bug STOR-4636 reviewSettings.IgnoreFolders = reviewData.ReviewType != ReviewType.Formal && !reviewData.BaselineId.HasValue && reviewSettings.IgnoreFolders; reviewSettings.CanEditRequireESignature = reviewData.ReviewStatus == ReviewPackageStatus.Draft || (reviewData.ReviewStatus == ReviewPackageStatus.Active && reviewData.ReviewType != ReviewType.Formal); var projectPermissions = await _permissionsRepository.GetProjectPermissions(reviewInfo.ProjectId); reviewSettings.IsMeaningOfSignatureEnabledInProject = projectPermissions.HasFlag(ProjectPermissions.IsMeaningOfSignatureEnabled); reviewSettings.CanEditRequireMeaningOfSignature = reviewSettings.CanEditRequireESignature && reviewSettings.IsMeaningOfSignatureEnabledInProject; return(reviewSettings); }
protected virtual void InternalCheckForOperationSupport(ArtifactBasicDetails artifactBasicDetails) { // Do nothing }
public void Initialize() { _sqlHelperMock = new SqlHelperMock(); _collectionsRepository = new Mock <ICollectionsRepository>(); _artifactRepository = new Mock <IArtifactRepository>(); _lockArtifactsRepository = new Mock <ILockArtifactsRepository>(); _itemInfoRepository = new Mock <IItemInfoRepository>(); _artifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>(); _searchEngineService = new Mock <ISearchEngineService>(); _artifactListService = new Mock <IArtifactListService>(); _collectionService = new CollectionsService( _collectionsRepository.Object, _artifactRepository.Object, _lockArtifactsRepository.Object, _itemInfoRepository.Object, _artifactPermissionsRepository.Object, _sqlHelperMock, _searchEngineService.Object, _artifactListService.Object); _artifactIds = new HashSet <int> { 1, 2, 3 }; _collectionId = 1; _searchArtifactsResult = new SearchArtifactsResult { ArtifactIds = _artifactIds, Total = _artifactIds.Count }; _profileColumnsSettings = new ProfileColumns( new List <ProfileColumn> { new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Number, 2) }); _collectionPermissions = new Dictionary <int, RolePermissions> { { _collectionId, RolePermissions.Read | RolePermissions.Edit } }; _collectionDetails = new ArtifactBasicDetails { ArtifactId = _collectionId, ProjectId = 1, DraftDeleted = false, PrimitiveItemTypePredefined = (int)ItemTypePredefined.ArtifactCollection, LockedByUserId = _userId }; _artifacts = new List <ItemDetails> { new ItemDetails { Name = "Artifact1", ItemTypeId = 2, VersionProjectId = 1, EndRevision = int.MaxValue, PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor } }; _artifactPermissions = new Dictionary <int, RolePermissions>(); foreach (var itemDetails in _artifacts) { _artifactPermissions.Add(itemDetails.ItemTypeId, RolePermissions.Read); } _profileColumns = new ProfileColumns( new List <ProfileColumn> { new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2) }); _propertyTypeInfos = new List <PropertyTypeInfo> { new PropertyTypeInfo { Id = 2, Predefined = PropertyTypePredefined.CustomGroup, Name = "Custom", PrimitiveType = PropertyPrimitiveType.Number } }; _artifactRepository .Setup(r => r.GetArtifactBasicDetails(_collectionId, _userId, null)) .ReturnsAsync(_collectionDetails); _artifactPermissionsRepository .Setup(r => r.GetArtifactPermissions(_collectionId, _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null)) .ReturnsAsync(_collectionPermissions); _artifactPermissionsRepository .Setup(r => r.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null)) .ReturnsAsync(_artifactPermissions); _collectionsRepository .Setup(r => r.GetContentArtifactIdsAsync(_collectionId, _userId, It.IsAny <bool>())) .ReturnsAsync(_artifactIds.ToList()); _collectionsRepository .Setup(r => r.RemoveArtifactsFromCollectionAsync(_collectionId, It.IsAny <IEnumerable <int> >(), _userId, null)) .ReturnsAsync(_artifacts.Count); _itemInfoRepository .Setup(r => r.GetItemsDetails(It.IsAny <int>(), It.IsAny <List <int> >(), It.IsAny <bool>(), It.IsAny <int>(), null)) .ReturnsAsync(_artifacts); _searchEngineService .Setup(s => s.Search(It.IsAny <int>(), It.IsAny <Pagination>(), It.IsAny <ScopeType>(), It.IsAny <bool>(), It.IsAny <int>(), null)) .ReturnsAsync(_searchArtifactsResult); InitializeProfileColumnsAndPropertyTypeInfos(_profileColumnsSettings, _propertyTypeInfos); _reviewItemsRemovalParams = new ItemsRemovalParams { ItemIds = new List <int> { 1, 2, 3 }, SelectionType = SelectionType.Selected }; }