public async Task GivenSuccessResponseFromServer_WhenArticlesRequests_ThenArticlesAreReturned() { var response = @"[{ ""title"": ""THE TITLE"", ""description"": ""THE DESCRIPTION"", ""id"": 1 }, { ""title"": ""THE TITLE 2"", ""description"": ""THE DESCRIPTION"", ""id"": 2 }, { ""title"": ""THE TITLE 3"", ""description"": ""THE DESCRIPTION"", ""id"": 3 }]"; var messageHandler = new MockHttpMessageHandler(response, HttpStatusCode.OK); var httpClient = new HttpClient(messageHandler) { BaseAddress = new Uri("http://not-important.com") }; var sut = new BlogClient(httpClient); var result = await sut.GetAllArticles(); result.Should().HaveCount(3); }
/// <summary> /// Get the version of the post currently residing on the server /// </summary> /// <param name="blogPost"></param> /// <returns></returns> public async Task <BlogPost> GetPost(string postId, bool isPage) { BlogPost blogPost = null; if (isPage) { // get the page blogPost = await BlogClient.GetPage(_settings.HostBlogId, postId); // ensure it is marked as a page blogPost.IsPage = true; } else { blogPost = await BlogClient.GetPost(_settings.HostBlogId, postId); // if there is no permalink then attempt to construct one EnsurePermalink(blogPost); } // apply content filters blogPost.Contents = ContentFilterApplier.ApplyContentFilters(ClientOptions.ContentFilter, blogPost.Contents, ContentFilterMode.Open); // return the blog post return(blogPost); }
public async Task GivenSuccessResponseFromServer_WhenArticlePosted_ThenSuccessMessageIsReturned() { var response = @"{ ""title"": ""THE TITLE"", ""description"": ""THE DESCRIPTION"", ""id"": 101 }"; var messageHandler = new MockHttpMessageHandler(); MockHttpMessageHandler.RegisterResponse(HttpStatusCode.OK, response); var httpClient = new HttpClient(messageHandler) { BaseAddress = new Uri("http://not-important.com") }; var sut = new BlogClient(httpClient); var result = await sut.CreateArticle(new Article { Title = "THE TITLE", Description = "THE DESCRIPTION" }); result.Success.Should().BeTrue(); result.Message.Should().Be("Article 'THE TITLE' created with id 101"); messageHandler.Input.Should().Be(@"{""title"":""THE TITLE"",""description"":""THE DESCRIPTION"",""canonical_url"":null}"); messageHandler.NumberOfCalls.Should().Be(1); }
public BaseController(BlogClient blogClient, IConfiguration configuration) { BlogClient = blogClient; IConfigurationSection section = configuration.GetSection("BlobStorage"); StorageCredentials = new StorageCredentials(section.GetValue <string>("accountname"), section.GetValue <string>("key")); StorageAccount = new CloudStorageAccount(StorageCredentials, true); }
public BaseController(BlogClient blogClient, IConfiguration configuration) { BlogClient = blogClient; AccountName = configuration["BlobStorage:accountname"]; StorageCredentials = new StorageCredentials(AccountName, configuration["BlobStorage:key"]); StorageAccount = new CloudStorageAccount(StorageCredentials, true); }
private static async Task ShowAllArticles(BlogClient blogClient) { var articles = await blogClient.GetAllArticles(); foreach (var art in articles) { Console.WriteLine(art.Title); } }
//- @GetBlogMetaData -// public static BlogMetaData GetBlogMetaData(String blogGuid) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; blogClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(blogClient.GetBlogMetaData(blogGuid)); } }
public static List <BlogEntry> GetBlogEntryList(String blogGuid, Int32 maxEntryCount, Boolean ignoreFooter, BlogEntryRetreivalType blogEntryRetreivalType, String username, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.GetBlogEntryList(blogGuid, maxEntryCount, true, ignoreFooter, blogEntryRetreivalType)); } }
public static String PostBlogEntry(String blogGuid, List <Author> authorList, String title, String content, DateTime dateTime, String blogEntryTypeGuid, List <Label> labelList, Boolean publish, String username, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.PostBlogEntry(blogGuid, authorList, title, content, dateTime, blogEntryTypeGuid, labelList, publish)); } }
public static BlogEntry GetSingleBlogEntry(String blogEntryGuid, Boolean metaDataOnly, String username, String password) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.GetSingleBlogEntry(blogEntryGuid, metaDataOnly)); } }
public static void DisableBlogEntry(String blogEntryGuid, String username, String password) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ blogClient.DisableBlogEntry(blogEntryGuid); } }
internal static List <BlogEntry> GetBlogEntryListByDateRange(string blogGuid, DateTime startDateTime, DateTime endDateTime, Boolean metaDataOnly) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; blogClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(blogClient.GetBlogEntryListByDateRange(blogGuid, startDateTime, endDateTime, metaDataOnly)); } }
//- @GetArchivedEntryList -// public static List <ArchiveCount> GetArchivedEntryList(String blogGuid) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; blogClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(blogClient.GetArchivedEntryList(blogGuid)); } }
public static void UpdateBlogEntry(String blogEntryGuid, String title, String content, String blogEntryTypeGuid, List <Label> labelList, DateTime dateTime, Boolean publish, String username, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ blogClient.UpdateBlogEntry(blogEntryGuid, title, content, blogEntryTypeGuid, labelList, dateTime, publish); } }
//- @GetNetBlogEntryList -// public static List <BlogEntry> GetNetBlogEntryList(String blogGuid, String label, String archive, String link, Int32 maxBlogEntryCount, Boolean ignoreFooter) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; blogClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(blogClient.GetNetBlogEntryList(blogGuid, label, archive, link, maxBlogEntryCount, ignoreFooter)); } }
public async Task RefreshKeywords() { try { _settings.Keywords = await BlogClient.GetKeywords(_settings.HostBlogId); } catch (BlogClientOperationCancelledException) { } }
//- @GetNetBlogEntryList -// public static List <BlogEntry> GetNetBlogEntryList(String blogGuid, String label, String archive, String link, Int32 maxBlogEntryCount) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; blogClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(blogClient.GetNetBlogEntryList(blogGuid, label, archive, link, maxBlogEntryCount)); } }
public static List <BlogEntry> GetBlogEntryList(String blogGuid, Int32 maxEntryCount, BlogEntryRetreivalType blogEntryRetreivalType, String username, String password) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.GetBlogEntryList(blogGuid, maxEntryCount, true, blogEntryRetreivalType)); } }
public async Task RefreshCategories() { try { _settings.Categories = await BlogClient.GetCategories(_settings.HostBlogId); } catch (BlogClientOperationCancelledException) { } }
//- @GetArchivedEntryList -// public static List <ArchiveCount> GetArchivedEntryList(String blogGuid) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; blogClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(blogClient.GetArchivedEntryList(blogGuid)); } }
//- @GetBlogMetaData -// public static BlogMetaData GetBlogMetaData(String blogGuid) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; blogClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(blogClient.GetBlogMetaData(blogGuid)); } }
public static void DisableBlogEntry(String blogEntryGuid, String username, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ blogClient.DisableBlogEntry(blogEntryGuid); } }
public static BlogEntry GetSingleBlogEntryByLink(String blogGuid, String link, Boolean ignoreFooter, Boolean metaDataOnly, String username, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = username; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.GetSingleBlogEntryByLink(blogGuid, link, ignoreFooter, metaDataOnly)); } }
//- @GetBlogListForAssociatedAuthor -// public static List <BlogMetaData> GetBlogListForAssociatedAuthor(String emailAddress, String password) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = emailAddress; blogClient.ClientCredentials.UserName.Password = password; //+ return(blogClient.GetBlogListForAssociatedAuthor(emailAddress)); } }
//- @GetBlogEntryTypeList -// internal static List <BlogEntryType> GetBlogEntryTypeList(String blogGuid, List <String> guidList) { using (BlogClient blogClient = new BlogClient(MinimaConfiguration.ActiveBlogServiceEndpoint)) { blogClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; blogClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(blogClient.GetBlogEntryTypeList(blogGuid, guidList)); } }
//- @GetBlogEntryListByDateRange -// public static List <BlogEntry> GetBlogEntryListByDateRange(string blogGuid, DateTime startDateTime, DateTime endDateTime, Boolean ignoreFooter, Boolean metaDataOnly) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; blogClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(blogClient.GetBlogEntryListByDateRange(blogGuid, startDateTime, endDateTime, ignoreFooter, metaDataOnly)); } }
//- @GetBlogEntryTypeList -// public static List <BlogEntryType> GetBlogEntryTypeList(String blogGuid, List <String> guidList) { using (BlogClient blogClient = new BlogClient(BlogSection.GetConfigSection().Service.Endpoint.Blog)) { blogClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; blogClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(blogClient.GetBlogEntryTypeList(blogGuid, guidList)); } }
public async Task <PostResult> EditPost(BlogPost post, INewCategoryContext newCategoryContext, bool publish) { // initialize result (for edits the id never changes) PostResult result = new PostResult(); var editpostResult = new EditPostResult(); result.PostId = post.Id; try { //apply any publishing filters and make the post using (new ContentFilterApplier(post, ClientOptions, ContentFilterMode.Publish)) { // make the post if (post.IsPage) { await BlogClient.EditPage(_settings.HostBlogId, post, publish, result.ETag, result.AtomRemotePost); } else { await BlogClient.EditPost(_settings.HostBlogId, post, newCategoryContext, publish, editpostResult); } } // note success _settings.LastPublishFailed = false; } catch (BlogClientProviderException ex) { if (ErrorIsInvalidPostId(ex)) { return(await NewPost(post, newCategoryContext, publish)); } else { throw; } } catch { _settings.LastPublishFailed = true; throw; } // determine the date-published based on whether there was an override if (post.HasDatePublishedOverride) { result.DatePublished = post.DatePublishedOverride; } else { result.DatePublished = DateTime.UtcNow; } // return result return(result); }
public void DeletePost(string postId, bool isPage, bool publish) { if (isPage) { BlogClient.DeletePage(_settings.HostBlogId, postId); } else { BlogClient.DeletePost(_settings.HostBlogId, postId, publish); } }
public ActionResult AllBlog() { if (Check()) { return(RedirectToAction("Index", "Login")); } BlogClient service = new BlogClient(); MyBlog[] arr = service.GetAllBlog(); return(View(arr)); }