Example #1
0
        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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        public BaseController(BlogClient blogClient, IConfiguration configuration)
        {
            BlogClient = blogClient;

            AccountName = configuration["BlobStorage:accountname"];

            StorageCredentials = new StorageCredentials(AccountName, configuration["BlobStorage:key"]);
            StorageAccount     = new CloudStorageAccount(StorageCredentials, true);
        }
Example #6
0
        private static async Task ShowAllArticles(BlogClient blogClient)
        {
            var articles = await blogClient.GetAllArticles();

            foreach (var art in articles)
            {
                Console.WriteLine(art.Title);
            }
        }
Example #7
0
 //- @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));
     }
 }
Example #8
0
 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));
     }
 }
Example #9
0
 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));
     }
 }
Example #10
0
 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));
     }
 }
Example #11
0
 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);
     }
 }
Example #12
0
 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));
     }
 }
Example #13
0
 //- @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));
     }
 }
Example #14
0
 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);
     }
 }
Example #15
0
 //- @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));
     }
 }
Example #16
0
 public async Task RefreshKeywords()
 {
     try
     {
         _settings.Keywords = await BlogClient.GetKeywords(_settings.HostBlogId);
     }
     catch (BlogClientOperationCancelledException)
     {
     }
 }
Example #17
0
 //- @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));
     }
 }
Example #18
0
 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));
     }
 }
Example #19
0
 public async Task RefreshCategories()
 {
     try
     {
         _settings.Categories = await BlogClient.GetCategories(_settings.HostBlogId);
     }
     catch (BlogClientOperationCancelledException)
     {
     }
 }
Example #20
0
 //- @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));
     }
 }
Example #21
0
 //- @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));
     }
 }
Example #22
0
 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);
     }
 }
Example #23
0
 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));
     }
 }
Example #24
0
 //- @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));
     }
 }
Example #25
0
 //- @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));
     }
 }
Example #26
0
 //- @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));
     }
 }
Example #27
0
 //- @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));
     }
 }
Example #28
0
        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);
        }
Example #29
0
 public void DeletePost(string postId, bool isPage, bool publish)
 {
     if (isPage)
     {
         BlogClient.DeletePage(_settings.HostBlogId, postId);
     }
     else
     {
         BlogClient.DeletePost(_settings.HostBlogId, postId, publish);
     }
 }
Example #30
0
        public ActionResult AllBlog()
        {
            if (Check())
            {
                return(RedirectToAction("Index", "Login"));
            }
            BlogClient service = new BlogClient();

            MyBlog[] arr = service.GetAllBlog();
            return(View(arr));
        }