/// <summary> /// Publishes the post as a file. /// </summary> /// <param name="markdown">Content in Markdown format.</param> /// <param name="env"><see cref="IApplicationEnvironment"/> instance.</param> /// <param name="request"><see cref="HttpRequest"/> instance.</param> /// <returns>Returns the <see cref="PublishedPostPath"/> instance containing paths for published files.</returns> public async Task <PublishedPostPath> PublishPostAsync(string markdown, IApplicationEnvironment env, HttpRequest request) { if (string.IsNullOrWhiteSpace(markdown)) { throw new ArgumentNullException(nameof(markdown)); } if (env == null) { throw new ArgumentNullException(nameof(env)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } var publishedpath = new PublishedPostPath(); var markdownpath = await this.PublishMarkdownAsync(markdown, env).ConfigureAwait(false); publishedpath.Markdown = markdownpath; var html = await this.GetPublishedHtmlAsync(markdown, request).ConfigureAwait(false); var htmlpath = await this.PublishHtmlAsync(html, env).ConfigureAwait(false); publishedpath.Html = htmlpath; return(publishedpath); }
public async void Given_Model_Publish_ShouldReturn_ViewResult(string markdown, string html, string markdownpath, string htmlpath) { this._requestServices.Setup(p => p.GetService(typeof(IApplicationEnvironment))).Returns(this._applicationEnvironment.Object); this._httpContext.SetupGet(p => p.RequestServices).Returns(this._requestServices.Object); this._controller.ActionContext = this._actionContext; this._controller.TempData = this._tempData.Object; var publishedpath = new PublishedPostPath() { Markdown = markdownpath, Html = htmlpath }; this._publishService.Setup(p => p.PublishPostAsync(It.IsAny <string>(), It.IsAny <IApplicationEnvironment>(), It.IsAny <HttpRequest>())).Returns(Task.FromResult(publishedpath)); var model = new PostFormViewModel() { Title = "Title", Slug = "slug", Body = markdown }; var result = await this._controller.Publish(model).ConfigureAwait(false) as ViewResult; result.Should().NotBeNull(); var vm = result.ViewData.Model as PostPublishViewModel; vm.Should().NotBeNull(); vm.Theme.Should().Be(this._defaultThemeName); vm.MarkdownPath.Should().Be(markdownpath); vm.HtmlPath.Should().Be(htmlpath); }