private async Task PerformTest( PostSecurityResult access, Comment expectedContent, BlobSharedAccessInformation expectedFileSharedAccessInformation, BlobSharedAccessInformation expectedImageSharedAccessInformation) { var result = await this.target.ExecuteAsync(PostData, access, Expiry); Assert.AreEqual( new GetPostQueryResult( new GetPostQueryResult.FullPost( CreatorId, Creator, PostId, BlogId, Blog, ChannelId, Channel, expectedContent, PreviewWordCount, WordCount, ImageCount, FileCount, VideoCount, LiveDate, LikesCount, CommentsCount, true, access == PostSecurityResult.Denied, access == PostSecurityResult.FreePost), new List <GetPostQueryResult.File> { new GetPostQueryResult.File( new FileInformation(FileId1, ContainerName1), new FileSourceInformation(FileName1, FileExtension1, ContentType1, FileSize1, new RenderSize(FileWidth1, FileHeight1)), expectedFileSharedAccessInformation), new GetPostQueryResult.File( new FileInformation(FileId2, ContainerName2), new FileSourceInformation(FileName2, FileExtension2, ContentType2, FileSize2, new RenderSize(FileWidth2, FileHeight2)), expectedImageSharedAccessInformation), }), result); }
private async Task PerformReadTest( bool isPostSubscriberValue, bool isPostOwnerValue, bool isFreeAccessUserValue, bool isFreePostValue, PostSecurityResult expectedResult) { this.SetupReadingTest(isPostSubscriberValue, isPostOwnerValue, isFreeAccessUserValue, isFreePostValue); Assert.AreEqual(expectedResult, await this.target.IsReadAllowedAsync(UserId, PostId, Timestamp)); if (expectedResult != PostSecurityResult.Denied) { await this.target.AssertReadAllowedAsync(UserId, PostId, Timestamp); } else { await ExpectedException.AssertExceptionAsync <UnauthorizedException>(() => { return(this.target.AssertReadAllowedAsync(UserId, PostId, Timestamp)); }); } }
private async Task <GetPostQueryResult.File> ProcessFile(GetPostQueryResult.FullPost post, GetPostDbResult.PostFileDbResult file, PostSecurityResult access, AccessSignatureExpiryInformation expiry) { var fileInformation = await this.fileInformationAggregator.GetFileInformationAsync(post.ChannelId, file.FileId, file.Purpose); RenderSize renderSize = null; if (file.RenderWidth.HasValue && file.RenderHeight.HasValue) { renderSize = new RenderSize(file.RenderWidth.Value, file.RenderHeight.Value); } var fileSourceInformation = new FileSourceInformation( file.FileName, file.FileExtension, this.mimeTypeMap.GetMimeType(file.FileExtension), file.FileSize, renderSize); BlobSharedAccessInformation accessInformation = null; if (access == PostSecurityResult.Denied) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostPreviewImageThumbnailName, expiry.Private); } } else if (access == PostSecurityResult.FreePost) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostFeedImageThumbnailName, expiry.Private); } else if (file.Purpose == FilePurposes.PostFile) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid(), expiry.Private); } } var completeFile = new GetPostQueryResult.File(fileInformation, fileSourceInformation, accessInformation); return(completeFile); }
public async Task <GetPostQueryResult> ExecuteAsync(GetPostDbResult postData, PostSecurityResult access, AccessSignatureExpiryInformation expiry) { postData.AssertNotNull("postData"); expiry.AssertNotNull("expiry"); var post = await this.ProcessPost(postData.Post, access); var files = new List <GetPostQueryResult.File>(); foreach (var file in postData.Files) { var completeFile = await this.ProcessFile(post, file, access, expiry); files.Add(completeFile); } return(new GetPostQueryResult(post, files)); }
private async Task <GetPostQueryResult.FullPost> ProcessPost(PreviewNewsfeedPost post, PostSecurityResult access) { FileInformation profileImage = null; if (post.ProfileImageFileId != null) { profileImage = await this.fileInformationAggregator.GetFileInformationAsync( null, post.ProfileImageFileId, FilePurposes.ProfileImage); } FileInformation headerImage = null; if (post.HeaderImageFileId != null) { headerImage = await this.fileInformationAggregator.GetFileInformationAsync( null, post.HeaderImageFileId, FilePurposes.ProfileHeaderImage); } var postContent = post.Content.Value; if (access == PostSecurityResult.Denied) { postContent = this.getPostPreviewContent.Execute(postContent, post.PreviewText); } return(new GetPostQueryResult.FullPost( post.CreatorId, new GetPreviewNewsfeedQueryResult.PreviewPostCreator(new Username(post.Username), profileImage), post.PostId, post.BlogId, new GetPreviewNewsfeedQueryResult.PreviewPostBlog(new BlogName(post.BlogName), headerImage, post.Introduction), post.ChannelId, new GetPreviewNewsfeedQueryResult.PreviewPostChannel(new ChannelName(post.ChannelName)), new Comment(postContent), post.PreviewWordCount, post.WordCount, post.ImageCount, post.FileCount, post.VideoCount, post.LiveDate, post.LikesCount, post.CommentsCount, post.HasLikedPost, access == PostSecurityResult.Denied, access == PostSecurityResult.FreePost)); }