public void InsertIntoPostRepository(NewPost newPost, HttpResponse response) { PostDocument postDocument = null; "Given a new post".x(() => newPost = new NewPost { Body = "my new post", Title = "my title" }); "When I submit the post".x(async() => response = await ExecuteHttpAsync(new AddPostCommand { Post = newPost })); "Then the post is available in the repository".x(async() => { Post returnedPost = response.GetJson <Post>(); Guid postId = returnedPost.Id; IPostRepository postRepository = ServiceProvider.GetRequiredService <IPostRepository>(); postDocument = await postRepository.Get(postId); }); "And the body and title match the submitted post".x(() => { Assert.Equal("my new post", postDocument.Body); Assert.Equal("my title", postDocument.Title); }); }
public async Task <Post> ExecuteAsync(AddPostCommand command, Post previousResult) { PostDocument postDocument = CreatePostDocument(command); await AddPostDocumentToRepository(postDocument); return(CreatePostFromDocument(postDocument)); }
public async Task <Post> ExecuteAsync(GetPostQuery command, Post previousResult) { PostDocument postDocument = await _postRepository.Get(command.PostId); Post post = _mapper.Map <Post>(postDocument); return(post); }
public static void AddImage(PostDocument img, TagBuilder root, int size) { Debug.Assert(img.Type == DocumentType.IMAGE); TagBuilder image = new TagBuilder("img"); image.Attributes.Add("style", $"width:{size}px; height:{size}px;");; image.Attributes.Add("src", $"data:{img.DataType};base64,{Convert.ToBase64String(img.Data)}"); root.InnerHtml.AppendHtml(image); }
public static void AddVideo(PostDocument vid, TagBuilder root, int size) { Debug.Assert(vid.Type == DocumentType.VIDEO); TagBuilder video = new TagBuilder("video"); video.Attributes.Add("controls", ""); video.Attributes.Add("style", $"width:{size}px; height:{size}px;"); video.Attributes.Add("src", $"data:{vid.DataType};base64,{Convert.ToBase64String(vid.Data)}"); root.InnerHtml.AppendHtml(video); }
public override async Task PostDocumentAsync <T>(PostDocument <T> doc, CancellationToken ct = default) { var request = new SendMessageRequest(); request.QueueUrl = PostDocumentQueueUrl; request.MessageBody = JsonSerializer.Serialize(doc); request.MessageGroupId = CreateDocName(doc.Type, doc.Name); request.MessageDeduplicationId = Guid.NewGuid().ToString(); await _sqs.SendMessageAsync(request, ct); }
private Post CreatePostFromDocument(PostDocument postDocument) { return(new Post { Body = postDocument.Body, CreatedByUserId = postDocument.CreatedByUserId, Id = postDocument.Id, PostedAtUtc = postDocument.PostedAtUtc, Title = postDocument.Title }); }
public Task <PostDocument> Get(Guid postId) { PostDocument postDocument = _documents.SingleOrDefault(x => x.Id == postId); if (postDocument == null) { throw new PostNotFoundException(); } return(Task.FromResult(postDocument)); }
public async Task <Post> ExecuteAsync(GetPostQuery query, Post previousResult) { PostDocument postDocument = await _postRepository.Get(query.PostId); if (postDocument == null) { throw new PostNotFoundException(); } var post = _mapper.Map <Post>(postDocument); return(post); }
public async Task <ImageAnalysis> QueryService(PostDocument post) { ComputerVisionClient computerVision = new ComputerVisionClient( new ApiKeyServiceClientCredentials(_subscriptionKey), new System.Net.Http.DelegatingHandler[] { }); Stream stream = new MemoryStream(post.Image.ImageFile); ImageAnalysis analysis = await computerVision.AnalyzeImageInStreamAsync(stream, new List <VisualFeatureTypes>() { VisualFeatureTypes.Description, VisualFeatureTypes.Tags, VisualFeatureTypes.Objects }); return(analysis); }
protected async Task <PostDocument> CreateDocumentAsync(IFormFile document) { byte[] docData = null; using (var binaryReader = new BinaryReader(document.OpenReadStream())) { docData = binaryReader.ReadBytes((int)document.Length); } PostDocument doc = new PostDocument { DataType = document.ContentType, Type = document.IsImage() ? DocumentType.IMAGE : DocumentType.VIDEO, Data = docData }; return(doc); }
public void TestSerialization() { PostDocument <IPerson> postDoc = new PostDocument <IPerson>() { Type = "person", Name = "someone", Document = new Person() { Name = "firstname", } }; var doc = JsonSerializer.Serialize(postDoc); Assert.Equal("{\"type\":\"person\",\"name\":\"someone\",\"doc\":{\"name\":\"firstname\",\"Parent\":null,\"Parents\":null,\"Gender\":0,\"BirthYear\":null,\"Birthday\":\"0001-01-01T00:00:00\",\"PocketMoney\":0}}", doc); }
public void AddTheme(ThemeDocument theme) { if (theme != null) { var firstPost = new PostDocument(); firstPost.PostId = ObjectId.GenerateNewId(); firstPost.Author = theme.Author; firstPost.Date = theme.Date; firstPost.Details = theme.Details; theme.LastPostInfo = String.Format("{0}, {1}", firstPost.Date, firstPost.Author); theme.Posts = new List<PostDocument> { { firstPost } }; theme.TotalPosts = theme.Posts.Count; theme.Url = theme.Title.GenerateSlug(); _themes.Insert(theme); } }
public ActionResult AddPost(PostModel postModel) { ObjectId themeId = ObjectId.TryParse(postModel.ThemeId, out themeId) ? themeId : ObjectId.Empty; _themeDoc = _themeService.GetTheme(themeId); if (ModelState.IsValid) { var newPost = new PostDocument { PostId = ObjectId.GenerateNewId(), Author = User == null ? AnonymousName : User.Identity.Name, Date = DateTime.Now, Details = postModel.Details, }; _postService.AddPost(ObjectId.Parse(postModel.ThemeId), newPost); PostListItemModel postListItemModel = MapPost(newPost); return new JsonResult { Data = new { result = 1, postHtml = RenderPartialHelper.RenderPartialViewToString("PostListItem", postListItemModel, this), addHtml = RenderPartialHelper.RenderPartialViewToString("AddPost", new PostModel { ThemeId = postModel.ThemeId }, this), } }; } return new JsonResult { Data = new { result = 0, addHtml = RenderPartialHelper.RenderPartialViewToString("AddPost", postModel, this), } }; }
private async Task AddPostDocumentToRepository(PostDocument postDocument) { await _postRepository.Add(postDocument); }
private PostListItemModel MapPost(PostDocument postDocument) { return new PostListItemModel { PostId = postDocument.PostId, Author = postDocument.Author, Date = postDocument.Date, Details = postDocument.Details, ThemeId = _themeDoc != null ? _themeDoc.ThemeId : ObjectId.Empty, ThemeTitle = _themeDoc != null ? _themeDoc.Title : String.Empty, }; }
public Task Add(PostDocument postDocument) { _documents.Add(postDocument); return(Task.CompletedTask); }
public abstract Task PostDocumentAsync <T>(PostDocument <T> doc, CancellationToken ct = default);
public async Task UpdateDescription(PostDocument postDocument) { await _context.Post.ReplaceOneAsync( filter : (p) => p.PostId == postDocument.PostId, replacement : postDocument); }
private Post CreatePostFromDocument(PostDocument postDocument) { return(_mapper.Map <Post>(postDocument)); }