diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml
index a58b17b..232a9b6 100644
--- a/.github/workflows/integration-tests.yml
+++ b/.github/workflows/integration-tests.yml
@@ -26,8 +26,10 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
+ - name: Dotnet Restore
+ run: dotnet restore ${{ env.solution }} --disable-parallel
- name: Build Solution
- run: dotnet build ${{ env.solution }} -c Release
+ run: dotnet build ${{ env.solution }} -c Release --no-restore
- name: Create dockerzied WordPress
run: |
diff --git a/WordPressPCL.Tests.Hosted/Basic_Tests.cs b/WordPressPCL.Tests.Hosted/Basic_Tests.cs
index b0c18ae..d1abcbe 100644
--- a/WordPressPCL.Tests.Hosted/Basic_Tests.cs
+++ b/WordPressPCL.Tests.Hosted/Basic_Tests.cs
@@ -25,7 +25,7 @@ public async Task Hosted_BasicSetupTest()
Assert.IsNotNull(_client);
// Posts
var posts = await _client.Posts.GetAllAsync();
- Assert.AreNotEqual(posts.Count(), 0);
+ Assert.AreNotEqual(posts.Count, 0);
Assert.IsNotNull(posts);
}
@@ -73,7 +73,7 @@ public async Task Hosted_GetPostsByTag()
// Initialize
var posts = await _client.Posts.GetPostsByTagAsync(tagId);
- Assert.AreNotEqual(0, posts.Count());
+ Assert.AreNotEqual(0, posts.Count);
foreach (Post post in posts)
{
Assert.IsTrue(post.Tags.ToList().Contains(tagId));
@@ -87,7 +87,7 @@ public async Task Hosted_GetPostsByAuthor()
int author = 3722200;
// Initialize
var posts = await _client.Posts.GetPostsByAuthorAsync(author);
- Assert.AreNotEqual(0, posts.Count());
+ Assert.AreNotEqual(0, posts.Count);
foreach (Post post in posts)
{
Assert.IsTrue(post.Author == author);
@@ -101,7 +101,7 @@ public async Task Hosted_GetPostsBySearch()
string search = "hello";
// Initialize
var posts = await _client.Posts.GetPostsBySearchAsync(search);
- Assert.AreNotEqual(0, posts.Count());
+ Assert.AreNotEqual(0, posts.Count);
foreach (Post post in posts)
{
bool containsOnContentOrTitle = false;
diff --git a/WordPressPCL.Tests.Hosted/Utility/ClientHelper.cs b/WordPressPCL.Tests.Hosted/Utility/ClientHelper.cs
index 7bc11e1..84d4f2d 100644
--- a/WordPressPCL.Tests.Hosted/Utility/ClientHelper.cs
+++ b/WordPressPCL.Tests.Hosted/Utility/ClientHelper.cs
@@ -1,7 +1,4 @@
-using System.Threading.Tasks;
-using WordPressPCL.Models;
-
-namespace WordPressPCL.Tests.Hosted.Utility;
+namespace WordPressPCL.Tests.Hosted.Utility;
public static class ClientHelper
{
diff --git a/WordPressPCL.Tests.Hosted/Utility/HttpHelper_Tests.cs b/WordPressPCL.Tests.Hosted/Utility/HttpHelper_Tests.cs
index 2a67632..9158886 100644
--- a/WordPressPCL.Tests.Hosted/Utility/HttpHelper_Tests.cs
+++ b/WordPressPCL.Tests.Hosted/Utility/HttpHelper_Tests.cs
@@ -38,7 +38,7 @@ public async Task Hosted_HttpHelper_InvalidPreProcessing()
// We call Get tag list without pre processing
var tags = await client.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
// Now we add a PreProcessing task
@@ -73,7 +73,7 @@ public async Task Hosted_HttpHelper_ValidPreProcessing() {
// We call Get tag list without pre processing
var tags = await client.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
// Now we add a PreProcessing task
@@ -84,7 +84,7 @@ public async Task Hosted_HttpHelper_ValidPreProcessing() {
tags = await client.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
}
}
diff --git a/WordPressPCL.Tests.Hosted/WordPressPCL.Tests.Hosted.csproj b/WordPressPCL.Tests.Hosted/WordPressPCL.Tests.Hosted.csproj
index f17e625..a03ae72 100644
--- a/WordPressPCL.Tests.Hosted/WordPressPCL.Tests.Hosted.csproj
+++ b/WordPressPCL.Tests.Hosted/WordPressPCL.Tests.Hosted.csproj
@@ -7,9 +7,9 @@
-
-
-
+
+
+
diff --git a/WordPressPCL.Tests.Selfhosted/ApplicationPasswords_Tests.cs b/WordPressPCL.Tests.Selfhosted/ApplicationPasswords_Tests.cs
index 34d0c11..360ed1e 100644
--- a/WordPressPCL.Tests.Selfhosted/ApplicationPasswords_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/ApplicationPasswords_Tests.cs
@@ -1,6 +1,5 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Diagnostics;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
using System.Threading.Tasks;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
@@ -21,7 +20,7 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Application_Passwords_Create()
{
- var password = await _clientAuth.Users.CreateApplicationPasswordAsync(System.Guid.NewGuid().ToString());
+ ApplicationPassword password = await _clientAuth.Users.CreateApplicationPasswordAsync(System.Guid.NewGuid().ToString());
Assert.IsNotNull(password.Password);
}
@@ -29,7 +28,7 @@ public async Task Application_Passwords_Create()
public async Task Read()
{
await _clientAuth.Users.CreateApplicationPasswordAsync(System.Guid.NewGuid().ToString());
- var passwords = await _clientAuth.Users.GetApplicationPasswords();
+ List passwords = await _clientAuth.Users.GetApplicationPasswords();
Assert.IsNotNull(passwords);
Assert.AreNotEqual(0, passwords.Count);
@@ -38,16 +37,16 @@ public async Task Read()
[TestMethod]
public async Task Application_Password_Auth()
{
- var appPassword = await _clientAuth.Users.CreateApplicationPasswordAsync(System.Guid.NewGuid().ToString());
- var appPasswordClient = new WordPressClient(ApiCredentials.WordPressUri);
+ ApplicationPassword appPassword = await _clientAuth.Users.CreateApplicationPasswordAsync(System.Guid.NewGuid().ToString());
+ WordPressClient appPasswordClient = new(ApiCredentials.WordPressUri);
appPasswordClient.Auth.UseBasicAuth(ApiCredentials.Username, appPassword.Password);
- var post = new Post()
+ Post post = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate")
};
- var postCreated = await appPasswordClient.Posts.CreateAsync(post);
+ Post postCreated = await appPasswordClient.Posts.CreateAsync(post);
Assert.IsNotNull(postCreated);
Assert.AreEqual("Title 1", postCreated.Title.Raw);
}
diff --git a/WordPressPCL.Tests.Selfhosted/Basic_Tests.cs b/WordPressPCL.Tests.Selfhosted/Basic_Tests.cs
index 8565de1..2c54d66 100644
--- a/WordPressPCL.Tests.Selfhosted/Basic_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Basic_Tests.cs
@@ -1,9 +1,9 @@
-using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordPressPCL.Tests.Selfhosted.Utility;
using System.Threading.Tasks;
using WordPressPCL.Models;
using System.Linq;
+using System.Collections.Generic;
namespace WordPressPCL.Tests.Selfhosted;
@@ -28,11 +28,11 @@ public async Task BasicSetupTest()
// Initialize
Assert.IsNotNull(_client);
// Posts
- var posts = await _client.Posts.GetAllAsync();
+ List posts = await _client.Posts.GetAllAsync();
Assert.IsNotNull(posts);
// Test Auth Client
- var postsAuth = await _clientAuth.Posts.GetAllAsync();
+ List postsAuth = await _clientAuth.Posts.GetAllAsync();
Assert.IsNotNull(postsAuth);
}
@@ -40,8 +40,8 @@ public async Task BasicSetupTest()
public async Task GetFirstPostTest()
{
// Initialize
- var posts = await _client.Posts.GetAllAsync();
- var post = await _client.Posts.GetByIDAsync(posts.First().Id);
+ List posts = await _client.Posts.GetAllAsync();
+ Post post = await _client.Posts.GetByIDAsync(posts.First().Id);
Assert.IsTrue(posts.First().Id == post.Id);
Assert.IsTrue(!string.IsNullOrEmpty(posts.First().Content.Rendered));
}
@@ -50,7 +50,7 @@ public async Task GetFirstPostTest()
public async Task GetStickyPosts()
{
// Initialize
- var posts = await _client.Posts.GetStickyPostsAsync();
+ List posts = await _client.Posts.GetStickyPostsAsync();
foreach (Post post in posts)
{
@@ -64,7 +64,7 @@ public async Task GetPostsByCategory()
// This CategoryID MUST exists at ApiCredentials.WordPressUri
int category = 1;
// Initialize
- var posts = await _client.Posts.GetPostsByCategoryAsync(category);
+ List posts = await _client.Posts.GetPostsByCategoryAsync(category);
foreach (Post post in posts)
{
@@ -78,7 +78,7 @@ public async Task GetPostsByTag()
// This TagID MUST exists at ApiCredentials.WordPressUri
int tag = 12;
// Initialize
- var posts = await _client.Posts.GetPostsByTagAsync(tag);
+ List posts = await _client.Posts.GetPostsByTagAsync(tag);
foreach (Post post in posts)
{
@@ -92,7 +92,7 @@ public async Task GetPostsByAuthor()
// This AuthorID MUST exists at ApiCredentials.WordPressUri
int author = 2;
// Initialize
- var posts = await _client.Posts.GetPostsByAuthorAsync(author);
+ List posts = await _client.Posts.GetPostsByAuthorAsync(author);
foreach (Post post in posts)
{
@@ -106,7 +106,7 @@ public async Task GetPostsBySearch()
// This search term MUST be used at least once
string search = "hello";
// Initialize
- var posts = await _client.Posts.GetPostsBySearchAsync(search);
+ List posts = await _client.Posts.GetPostsBySearchAsync(search);
foreach (Post post in posts)
{
@@ -124,7 +124,7 @@ public async Task GetPostsBySearch()
[TestMethod]
public async Task Authorize()
{
- var validToken = await _clientAuth.Auth.IsValidJWTokenAsync();
+ bool validToken = await _clientAuth.Auth.IsValidJWTokenAsync();
Assert.IsTrue(validToken);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Categories_Tests.cs b/WordPressPCL.Tests.Selfhosted/Categories_Tests.cs
index 80f6429..15708fd 100644
--- a/WordPressPCL.Tests.Selfhosted/Categories_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Categories_Tests.cs
@@ -1,9 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
-using System.Diagnostics;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using WordPressPCL;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
using WordPressPCL.Utility;
@@ -27,8 +26,8 @@ public static async Task Init(TestContext testContext)
public async Task Categories_Create()
{
Random random = new();
- var name = $"TestCategory {random.Next(0, 10000)}";
- var category = await _clientAuth.Categories.CreateAsync(new Category()
+ string name = $"TestCategory {random.Next(0, 10000)}";
+ Category category = await _clientAuth.Categories.CreateAsync(new Category()
{
Name = name,
Description = "Test"
@@ -41,30 +40,30 @@ public async Task Categories_Create()
[TestMethod]
public async Task Categories_Read()
{
- var categories = await _client.Categories.GetAllAsync();
+ List categories = await _client.Categories.GetAllAsync();
Assert.IsNotNull(categories);
- Assert.AreNotEqual(categories.Count(), 0);
+ Assert.AreNotEqual(categories.Count, 0);
CollectionAssert.AllItemsAreUnique(categories.Select(tag => tag.Id).ToList());
}
[TestMethod]
public async Task Categories_Get()
{
- var categories = await _client.Categories.GetAsync();
+ List categories = await _client.Categories.GetAsync();
Assert.IsNotNull(categories);
- Assert.AreNotEqual(categories.Count(), 0);
+ Assert.AreNotEqual(categories.Count, 0);
CollectionAssert.AllItemsAreUnique(categories.Select(tag => tag.Id).ToList());
}
[TestMethod]
public async Task Categories_Update()
{
- var categories = await _clientAuth.Categories.GetAllAsync();
- var category = categories.First();
+ List categories = await _clientAuth.Categories.GetAllAsync();
+ Category category = categories.First();
Random random = new();
- var name = $"UpdatedCategory {random.Next(0, 10000)}";
+ string name = $"UpdatedCategory {random.Next(0, 10000)}";
category.Name = name;
- var updatedCategory = await _clientAuth.Categories.UpdateAsync(category);
+ Category updatedCategory = await _clientAuth.Categories.UpdateAsync(category);
Assert.AreEqual(updatedCategory.Name, name);
Assert.AreEqual(updatedCategory.Id, category.Id);
}
@@ -73,8 +72,8 @@ public async Task Categories_Update()
public async Task Categories_Delete()
{
Random random = new();
- var name = $"TestCategory {random.Next(0, 10000)}";
- var category = await _clientAuth.Categories.CreateAsync(new Category()
+ string name = $"TestCategory {random.Next(0, 10000)}";
+ Category category = await _clientAuth.Categories.CreateAsync(new Category()
{
Name = name,
Description = "Test"
@@ -84,26 +83,26 @@ public async Task Categories_Delete()
{
Assert.Inconclusive();
}
- var response = await _clientAuth.Categories.DeleteAsync(category.Id);
+ bool response = await _clientAuth.Categories.DeleteAsync(category.Id);
Assert.IsTrue(response);
- var categories = await _clientAuth.Categories.GetAllAsync();
- var c = categories.Where(x => x.Id == category.Id).ToList();
+ List categories = await _clientAuth.Categories.GetAllAsync();
+ List c = categories.Where(x => x.Id == category.Id).ToList();
Assert.AreEqual(c.Count, 0);
}
[TestMethod]
public async Task Categories_Query()
{
- var queryBuilder = new CategoriesQueryBuilder()
+ CategoriesQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
OrderBy = TermsOrderBy.Id,
Order = Order.DESC,
};
- var queryresult = await _clientAuth.Categories.QueryAsync(queryBuilder);
+ List queryresult = await _clientAuth.Categories.QueryAsync(queryBuilder);
Assert.AreEqual("?page=1&per_page=15&orderby=id&order=desc&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs b/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs
index a944b78..06f4d94 100644
--- a/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs
@@ -1,10 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Diagnostics;
using System.Threading.Tasks;
using WordPressPCL.Models;
using WordPressPCL.Utility;
using WordPressPCL.Tests.Selfhosted.Utility;
using System.Linq;
+using System.Collections.Generic;
namespace WordPressPCL.Tests.Selfhosted;
@@ -24,46 +24,46 @@ public class CommentsThreaded_Tests
public static async Task CommentsThreaded_SetupAsync(TestContext testContext)
{
_clientAuth = await ClientHelper.GetAuthenticatedWordPressClient(testContext);
- var IsValidToken = await _clientAuth.Auth.IsValidJWTokenAsync();
+ bool IsValidToken = await _clientAuth.Auth.IsValidJWTokenAsync();
Assert.IsTrue(IsValidToken);
- var post = await _clientAuth.Posts.CreateAsync(new Post()
+ Post post = await _clientAuth.Posts.CreateAsync(new Post()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate")
});
await Task.Delay(1000);
- var comment0 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment0 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
Content = new Content("orem ipsum dolor sit amet")
});
- var comment00 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment00 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
Content = new Content("r sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam non")
});
- var comment1 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment1 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
ParentId = comment0.Id,
Content = new Content("onsetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna ali")
});
- var comment2 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment2 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
ParentId = comment1.Id,
Content = new Content("ro eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem i")
});
- var comment3 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment3 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
ParentId = comment2.Id,
Content = new Content("tetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam e")
});
- var comment4 = await _clientAuth.Comments.CreateAsync(new Comment()
+ Comment comment4 = await _clientAuth.Comments.CreateAsync(new Comment()
{
PostId = post.Id,
ParentId = comment1.Id,
@@ -81,38 +81,38 @@ public static async Task CommentsThreaded_SetupAsync(TestContext testContext)
[TestMethod]
public async Task CommentsThreaded_Sort()
{
- var allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
+ List allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
- var threaded = ThreadedCommentsHelper.GetThreadedComments(allComments);
+ List threaded = ThreadedCommentsHelper.GetThreadedComments(allComments);
Assert.IsNotNull(threaded);
- var ct0 = threaded.Find(x => x.Id == comment0id);
+ CommentThreaded ct0 = threaded.Find(x => x.Id == comment0id);
Assert.AreEqual(ct0.Depth, 0);
- var ct1 = threaded.Find(x => x.Id == comment1id);
+ CommentThreaded ct1 = threaded.Find(x => x.Id == comment1id);
Assert.AreEqual(ct1.Depth, 1);
- var ct2 = threaded.Find(x => x.Id == comment2id);
+ CommentThreaded ct2 = threaded.Find(x => x.Id == comment2id);
Assert.AreEqual(ct2.Depth, 2);
- var ct3 = threaded.Find(x => x.Id == comment3id);
+ CommentThreaded ct3 = threaded.Find(x => x.Id == comment3id);
Assert.AreEqual(ct3.Depth, 3);
- var ct4 = threaded.Find(x => x.Id == comment4id);
+ CommentThreaded ct4 = threaded.Find(x => x.Id == comment4id);
Assert.AreEqual(ct4.Depth, 2);
- var ct00 = threaded.Find(x => x.Id == comment00id);
+ CommentThreaded ct00 = threaded.Find(x => x.Id == comment00id);
Assert.AreEqual(ct00.Depth, 0);
for (int i = 0; i < threaded.Count - 1; i++)
{
// The following comment depth has to be the lower, equal or +1
- var ni = i + 1;
- var id = threaded[i].Depth;
- var nid = threaded[ni].Depth;
- var validDepth = (id >= nid || id + 1 == nid);
+ int ni = i + 1;
+ int id = threaded[i].Depth;
+ int nid = threaded[ni].Depth;
+ bool validDepth = (id >= nid || id + 1 == nid);
Assert.IsTrue(validDepth);
- var idate = threaded[i].Date;
- var nidate = threaded[ni].Date;
+ System.DateTime idate = threaded[i].Date;
+ System.DateTime nidate = threaded[ni].Date;
// The following comment date has to be
- var validDate = (
+ bool validDate = (
// newer
idate <= nidate
// or older and a child comment
@@ -124,63 +124,63 @@ public async Task CommentsThreaded_Sort()
[TestMethod]
public async Task CommentsThreaded_MaxDepth()
{
- var allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
+ List allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
- var threaded = ThreadedCommentsHelper.GetThreadedComments(allComments, 1);
+ List threaded = ThreadedCommentsHelper.GetThreadedComments(allComments, 1);
Assert.IsNotNull(threaded);
- var ct0 = threaded.Find(x => x.Id == comment0id);
+ CommentThreaded ct0 = threaded.Find(x => x.Id == comment0id);
Assert.AreEqual(ct0.Depth, 0);
- var ct1 = threaded.Find(x => x.Id == comment1id);
+ CommentThreaded ct1 = threaded.Find(x => x.Id == comment1id);
Assert.AreEqual(ct1.Depth, 1);
- var ct2 = threaded.Find(x => x.Id == comment2id);
+ CommentThreaded ct2 = threaded.Find(x => x.Id == comment2id);
Assert.AreEqual(ct2.Depth, 1);
- var ct3 = threaded.Find(x => x.Id == comment3id);
+ CommentThreaded ct3 = threaded.Find(x => x.Id == comment3id);
Assert.AreEqual(ct3.Depth, 1);
- var ct4 = threaded.Find(x => x.Id == comment4id);
+ CommentThreaded ct4 = threaded.Find(x => x.Id == comment4id);
Assert.AreEqual(ct4.Depth, 1);
- var ct00 = threaded.Find(x => x.Id == comment00id);
+ CommentThreaded ct00 = threaded.Find(x => x.Id == comment00id);
Assert.AreEqual(ct00.Depth, 0);
}
[TestMethod]
public async Task CommentsThreaded_Sort_Extension()
{
- var allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
+ List allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
Assert.IsTrue(allComments.Any());
//ExtensionMethod
- var threaded = ThreadedCommentsHelper.ToThreaded(allComments);
+ List threaded = ThreadedCommentsHelper.ToThreaded(allComments);
Assert.IsNotNull(threaded);
- var ct0 = threaded.Find(x => x.Id == comment0id);
+ CommentThreaded ct0 = threaded.Find(x => x.Id == comment0id);
Assert.AreEqual(ct0.Depth, 0);
- var ct1 = threaded.Find(x => x.Id == comment1id);
+ CommentThreaded ct1 = threaded.Find(x => x.Id == comment1id);
Assert.AreEqual(ct1.Depth, 1);
- var ct2 = threaded.Find(x => x.Id == comment2id);
+ CommentThreaded ct2 = threaded.Find(x => x.Id == comment2id);
Assert.AreEqual(ct2.Depth, 2);
- var ct3 = threaded.Find(x => x.Id == comment3id);
+ CommentThreaded ct3 = threaded.Find(x => x.Id == comment3id);
Assert.AreEqual(ct3.Depth, 3);
- var ct4 = threaded.Find(x => x.Id == comment4id);
+ CommentThreaded ct4 = threaded.Find(x => x.Id == comment4id);
Assert.AreEqual(ct4.Depth, 2);
- var ct00 = threaded.Find(x => x.Id == comment00id);
+ CommentThreaded ct00 = threaded.Find(x => x.Id == comment00id);
Assert.AreEqual(ct00.Depth, 0);
//Assert.AreEqual(threaded.Count, threaded.IndexOf(ct00) + 1);
for (int i = 0; i < threaded.Count - 1; i++)
{
// The following comment depth has to be the lower, equal or +1
- var ni = i + 1;
- var id = threaded[i].Depth;
- var nid = threaded[ni].Depth;
- var validDepth = (id >= nid || id + 1 == nid);
+ int ni = i + 1;
+ int id = threaded[i].Depth;
+ int nid = threaded[ni].Depth;
+ bool validDepth = (id >= nid || id + 1 == nid);
Assert.IsTrue(validDepth);
- var idate = threaded[i].Date;
- var nidate = threaded[ni].Date;
+ System.DateTime idate = threaded[i].Date;
+ System.DateTime nidate = threaded[ni].Date;
// The following comment date has to be
- var validDate = (
+ bool validDate = (
// newer
idate <= nidate
// or older and a child comment
@@ -192,42 +192,42 @@ public async Task CommentsThreaded_Sort_Extension()
[TestMethod]
public async Task CommentsThreaded_Sort_Extension_Desc()
{
- var allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
+ List allComments = await _clientAuth.Comments.GetAllCommentsForPostAsync(postid);
Assert.IsTrue(allComments.Any());
- var threaded = ThreadedCommentsHelper.ToThreaded(allComments, true);
+ List threaded = ThreadedCommentsHelper.ToThreaded(allComments, true);
// Depth should be the same regardless of desc or asc
Assert.IsNotNull(threaded);
- var ct0 = threaded.Find(x => x.Id == comment0id);
+ CommentThreaded ct0 = threaded.Find(x => x.Id == comment0id);
Assert.AreEqual(ct0.Depth, 0);
- var ct1 = threaded.Find(x => x.Id == comment1id);
+ CommentThreaded ct1 = threaded.Find(x => x.Id == comment1id);
Assert.AreEqual(ct1.Depth, 1);
- var ct2 = threaded.Find(x => x.Id == comment2id);
+ CommentThreaded ct2 = threaded.Find(x => x.Id == comment2id);
Assert.AreEqual(ct2.Depth, 2);
- var ct3 = threaded.Find(x => x.Id == comment3id);
+ CommentThreaded ct3 = threaded.Find(x => x.Id == comment3id);
Assert.AreEqual(ct3.Depth, 3);
- var ct4 = threaded.Find(x => x.Id == comment4id);
+ CommentThreaded ct4 = threaded.Find(x => x.Id == comment4id);
Assert.AreEqual(ct4.Depth, 2);
- var ct00 = threaded.Find(x => x.Id == comment00id);
+ CommentThreaded ct00 = threaded.Find(x => x.Id == comment00id);
Assert.AreEqual(ct00.Depth, 0);
for (int i = 0; i < threaded.Count - 1; i++)
{
// The following comment depth has to be the lower, equal or +1 at most
- var ni = i + 1;
- var idepth = threaded[i].Depth;
- var nidepth = threaded[ni].Depth;
- var niparent = threaded[ni].ParentId;
- var validDepth = (idepth >= nidepth || idepth + 1 == nidepth);
+ int ni = i + 1;
+ int idepth = threaded[i].Depth;
+ int nidepth = threaded[ni].Depth;
+ int niparent = threaded[ni].ParentId;
+ bool validDepth = (idepth >= nidepth || idepth + 1 == nidepth);
Assert.IsTrue(validDepth);
- var idate = threaded[i].Date;
- var nidate = threaded[ni].Date;
+ System.DateTime idate = threaded[i].Date;
+ System.DateTime nidate = threaded[ni].Date;
// The following comment date has to be
- var validDate = (
+ bool validDate = (
// older
idate >= nidate
// or newer, if it's a direct child comment
@@ -239,13 +239,13 @@ public async Task CommentsThreaded_Sort_Extension_Desc()
}
// Comments with depth 0 must be ordered desc
- var firstLvl = threaded.FindAll(x => x.Depth == 0);
+ List firstLvl = threaded.FindAll(x => x.Depth == 0);
for (int i = 0; i < firstLvl.Count - 1; i++)
{
// The following comment depth has to be the lower, equal or +1
- var ni = i + 1;
- var idate = threaded[i].Date;
- var nidate = threaded[ni].Date;
+ int ni = i + 1;
+ System.DateTime idate = threaded[i].Date;
+ System.DateTime nidate = threaded[ni].Date;
// The following comment date has to be older
Assert.IsTrue(threaded[i].Id > threaded[ni].Id);
diff --git a/WordPressPCL.Tests.Selfhosted/Comments_Tests.cs b/WordPressPCL.Tests.Selfhosted/Comments_Tests.cs
index 1df8701..5158739 100644
--- a/WordPressPCL.Tests.Selfhosted/Comments_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Comments_Tests.cs
@@ -26,14 +26,14 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Comments_Create()
{
- var posts = await _clientAuth.Posts.GetAllAsync();
- var postId = posts.First().Id;
+ List posts = await _clientAuth.Posts.GetAllAsync();
+ int postId = posts.First().Id;
- var me = await _clientAuth.Users.GetCurrentUserAsync();
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
// Create random content to prevent duplicate commment errors
- var content = $"TestComment {System.Guid.NewGuid()}";
- var comment = new Comment()
+ string content = $"TestComment {System.Guid.NewGuid()}";
+ Comment comment = new()
{
Content = new Content(content),
PostId = postId,
@@ -41,26 +41,26 @@ public async Task Comments_Create()
AuthorEmail = "test@test.com",
AuthorName = me.Name
};
- var resultComment = await _clientAuth.Comments.CreateAsync(comment);
+ Comment resultComment = await _clientAuth.Comments.CreateAsync(comment);
Assert.IsNotNull(resultComment);
// Posting same comment twice should fail
await Assert.ThrowsExceptionAsync(async () =>
{
- var secondResultComment = await _clientAuth.Comments.CreateAsync(comment);
+ Comment secondResultComment = await _clientAuth.Comments.CreateAsync(comment);
});
}
[TestMethod]
public async Task Comments_Read()
{
- var comments = await _client.Comments.GetAllAsync();
+ List comments = await _client.Comments.GetAllAsync();
if (!comments.Any())
{
Assert.Inconclusive("no comments to test");
}
- foreach (var comment in comments)
+ foreach (Comment comment in comments)
{
// test Date parsing was successfull
Assert.IsNotNull(comment.Date);
@@ -78,7 +78,7 @@ public async Task Comments_Read()
[TestMethod]
public async Task Comments_Get()
{
- var comments = await _client.Comments.GetAsync();
+ List comments = await _client.Comments.GetAsync();
if (!comments.Any())
{
@@ -91,33 +91,33 @@ public async Task Comments_Get()
[TestMethod]
public async Task Comments_Update()
{
- var me = await _clientAuth.Users.GetCurrentUserAsync();
- var queryBuilder = new CommentsQueryBuilder()
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
+ CommentsQueryBuilder queryBuilder = new()
{
Authors = new List { me.Id }
};
- var comments = await _clientAuth.Comments.QueryAsync(queryBuilder, true);
- var comment = comments.FirstOrDefault();
+ List comments = await _clientAuth.Comments.QueryAsync(queryBuilder, true);
+ Comment comment = comments.FirstOrDefault();
if (comment == null)
{
Assert.Inconclusive();
}
- var title = $"TestComment {System.Guid.NewGuid()}";
+ string title = $"TestComment {System.Guid.NewGuid()}";
comment.Content.Raw = title;
- var commentUpdated = await _clientAuth.Comments.UpdateAsync(comment);
+ Comment commentUpdated = await _clientAuth.Comments.UpdateAsync(comment);
Assert.AreEqual(commentUpdated.Content.Raw, title);
}
[TestMethod]
public async Task Comments_Delete()
{
- var posts = await _clientAuth.Posts.GetAllAsync();
- var postId = posts.First().Id;
+ List posts = await _clientAuth.Posts.GetAllAsync();
+ int postId = posts.First().Id;
- var me = await _clientAuth.Users.GetCurrentUserAsync();
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
// Create random content to prevent duplicate commment errors
- var comment = new Comment()
+ Comment comment = new()
{
Content = new Content($"Testcomment {System.Guid.NewGuid()}"),
PostId = postId,
@@ -125,9 +125,9 @@ public async Task Comments_Delete()
AuthorEmail = "test@test.com",
AuthorName = me.Name
};
- var resultComment = await _clientAuth.Comments.CreateAsync(comment);
+ Comment resultComment = await _clientAuth.Comments.CreateAsync(comment);
- var response = await _clientAuth.Comments.DeleteAsync(resultComment.Id);
+ bool response = await _clientAuth.Comments.DeleteAsync(resultComment.Id);
Assert.IsTrue(response);
}
@@ -135,17 +135,17 @@ public async Task Comments_Delete()
[TestMethod]
public async Task Comments_Query()
{
- var queryBuilder = new CommentsQueryBuilder()
+ CommentsQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
OrderBy = CommentsOrderBy.Id,
Order = Order.DESC,
};
- var queryresult = await _clientAuth.Comments.QueryAsync(queryBuilder);
+ List queryresult = await _clientAuth.Comments.QueryAsync(queryBuilder);
Assert.AreEqual("?page=1&per_page=15&orderby=id&order=desc&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
// TODO: Can't create pending comment from Admin Account
@@ -153,13 +153,13 @@ public async Task Comments_Query()
public async Task Comments_Query_Pending()
{
// Create new pending comment
- var posts = await _clientAuth.Posts.GetAllAsync();
- var postId = posts.First().Id;
- var me = await _clientAuth.Users.GetCurrentUserAsync();
+ List posts = await _clientAuth.Posts.GetAllAsync();
+ int postId = posts.First().Id;
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
// Create random content to prevent duplicate commment errors
- var content = $"TestComment {System.Guid.NewGuid()}";
- var comment = new Comment()
+ string content = $"TestComment {System.Guid.NewGuid()}";
+ Comment comment = new()
{
Content = new Content(content),
PostId = postId,
@@ -168,12 +168,12 @@ public async Task Comments_Query_Pending()
AuthorName = me.Name,
Status = CommentStatus.Pending
};
- var resultComment = await _clientAuth.Comments.CreateAsync(comment);
+ Comment resultComment = await _clientAuth.Comments.CreateAsync(comment);
Assert.IsNotNull(resultComment);
Assert.AreEqual(CommentStatus.Pending, resultComment.Status);
// this test needs a pending comment added manually for now.
- var queryBuilder = new CommentsQueryBuilder()
+ CommentsQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
@@ -181,11 +181,11 @@ public async Task Comments_Query_Pending()
Order = Order.DESC,
Statuses = new List { CommentStatus.Pending }
};
- var queryresult = await _clientAuth.Comments.QueryAsync(queryBuilder, true);
- var querystring = "page=1&per_page=15&orderby=id&status=hold";
+ List queryresult = await _clientAuth.Comments.QueryAsync(queryBuilder, true);
+ string querystring = "page=1&per_page=15&orderby=id&status=hold";
Assert.AreEqual(querystring, queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotEqual(queryresult.Count(), 0);
+ Assert.AreNotEqual(queryresult.Count, 0);
// Delete Pending comment
await _clientAuth.Comments.DeleteAsync(resultComment.Id);
@@ -194,22 +194,22 @@ public async Task Comments_Query_Pending()
[TestMethod]
public async Task Comments_GetAllForPost()
{
- var me = await _clientAuth.Users.GetCurrentUserAsync();
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
// create test post and add comments
- var post = new Post()
+ Post post = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate")
};
- var createdPost = await _clientAuth.Posts.CreateAsync(post);
+ Post createdPost = await _clientAuth.Posts.CreateAsync(post);
Assert.IsNotNull(createdPost);
for (int i = 0; i < 30; i++)
{
// Create random content to prevent duplicate commment errors
- var content = $"TestComment {System.Guid.NewGuid()}";
- var comment = new Comment()
+ string content = $"TestComment {System.Guid.NewGuid()}";
+ Comment comment = new()
{
Content = new Content(content),
PostId = createdPost.Id,
@@ -217,20 +217,20 @@ public async Task Comments_GetAllForPost()
AuthorEmail = "test@test.com",
AuthorName = me.Name
};
- var resultComment = await _clientAuth.Comments.CreateAsync(comment);
+ Comment resultComment = await _clientAuth.Comments.CreateAsync(comment);
Assert.IsNotNull(resultComment);
}
// shoud work without auth
- var nonauthclient = ClientHelper.GetWordPressClient();
- var comments = await nonauthclient.Comments.GetCommentsForPostAsync(createdPost.Id);
- Assert.IsTrue(comments.Count() <= 10);
+ WordPressClient nonauthclient = ClientHelper.GetWordPressClient();
+ List comments = await nonauthclient.Comments.GetCommentsForPostAsync(createdPost.Id);
+ Assert.IsTrue(comments.Count <= 10);
- var allComments = await nonauthclient.Comments.GetAllCommentsForPostAsync(createdPost.Id);
- Assert.IsTrue(allComments.Count() > 20);
+ List allComments = await nonauthclient.Comments.GetAllCommentsForPostAsync(createdPost.Id);
+ Assert.IsTrue(allComments.Count > 20);
// cleanup
- var result = await _clientAuth.Posts.DeleteAsync(createdPost.Id);
+ bool result = await _clientAuth.Posts.DeleteAsync(createdPost.Id);
Assert.IsTrue(result);
}
diff --git a/WordPressPCL.Tests.Selfhosted/CustomRequests_Tests.cs b/WordPressPCL.Tests.Selfhosted/CustomRequests_Tests.cs
index 66a8dc7..abd08fe 100644
--- a/WordPressPCL.Tests.Selfhosted/CustomRequests_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/CustomRequests_Tests.cs
@@ -1,9 +1,9 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Newtonsoft.Json;
using WordPressPCL.Tests.Selfhosted.Utility;
namespace WordPressPCL.Tests.Selfhosted;
@@ -35,17 +35,17 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task CustomRequests_Read()
{
- var forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
+ List forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
Assert.IsNotNull(forms);
- Assert.AreNotEqual(forms.Count(), 0);
+ Assert.AreNotEqual(forms.Count, 0);
}
// TODO: check why this isn't returning the form
//[TestMethod]
public async Task CustomRequests_Create()
{
- var title = $"Test Form {Guid.NewGuid()}";
- var form = await _clientAuth.CustomRequest.CreateAsync("contact-form-7/v1/contact-forms", new ContactFormItem() { Title = title, Locale = "en-US" });
+ string title = $"Test Form {Guid.NewGuid()}";
+ ContactFormItem form = await _clientAuth.CustomRequest.CreateAsync("contact-form-7/v1/contact-forms", new ContactFormItem() { Title = title, Locale = "en-US" });
Assert.IsNotNull(form);
Assert.IsNotNull(form.Id);
Assert.AreEqual(form.Title, title);
@@ -55,15 +55,15 @@ public async Task CustomRequests_Create()
//[TestMethod]
public async Task CustomRequests_Update()
{
- var title = $"Test Form {Guid.NewGuid()}";
- var form = await _clientAuth.CustomRequest.CreateAsync("contact-form-7/v1/contact-forms", new ContactFormItem() { Title = title, Locale = "en-US" });
+ string title = $"Test Form {Guid.NewGuid()}";
+ ContactFormItem form = await _clientAuth.CustomRequest.CreateAsync("contact-form-7/v1/contact-forms", new ContactFormItem() { Title = title, Locale = "en-US" });
- var forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
+ List forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
Assert.IsNotNull(forms);
- Assert.AreNotEqual(forms.Count(), 0);
- var editform = forms.First();
+ Assert.AreNotEqual(forms.Count, 0);
+ ContactFormItem editform = forms.First();
editform.Title += "test";
- var form2 = await _clientAuth.CustomRequest.UpdateAsync($"contact-form-7/v1/contact-forms/{editform.Id.Value}", editform);
+ ContactFormItem form2 = await _clientAuth.CustomRequest.UpdateAsync($"contact-form-7/v1/contact-forms/{editform.Id.Value}", editform);
Assert.IsNotNull(form2);
Assert.AreEqual(form.Title, editform.Title);
}
@@ -72,11 +72,11 @@ public async Task CustomRequests_Update()
//[TestMethod]
public async Task CustomRequests_Delete()
{
- var forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
+ List forms = await _clientAuth.CustomRequest.GetAsync>("contact-form-7/v1/contact-forms", false, true);
Assert.IsNotNull(forms);
- Assert.AreNotEqual(forms.Count(), 0);
- var deleteform = forms.First();
- var result = await _clientAuth.CustomRequest.DeleteAsync($"contact-form-7/v1/contact-forms/{deleteform.Id.Value}");
+ Assert.AreNotEqual(forms.Count, 0);
+ ContactFormItem deleteform = forms.First();
+ bool result = await _clientAuth.CustomRequest.DeleteAsync($"contact-form-7/v1/contact-forms/{deleteform.Id.Value}");
Assert.IsTrue(result);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/ExceptionTests.cs b/WordPressPCL.Tests.Selfhosted/ExceptionTests.cs
index a5c0ff1..6155d95 100644
--- a/WordPressPCL.Tests.Selfhosted/ExceptionTests.cs
+++ b/WordPressPCL.Tests.Selfhosted/ExceptionTests.cs
@@ -28,7 +28,7 @@ public async Task Exception_JWTAuthExceptionTest()
await Assert.ThrowsExceptionAsync(async () =>
{
- var settings = await _client.Settings.GetSettingsAsync();
+ Settings settings = await _client.Settings.GetSettingsAsync();
});
}
@@ -71,7 +71,7 @@ public async Task Exception_PostCreateExceptionTest()
// Create empty post
try
{
- var post = await _clientAuth.Posts.CreateAsync(new Post());
+ Post post = await _clientAuth.Posts.CreateAsync(new Post());
}
catch (WPException wpex)
{
@@ -88,7 +88,7 @@ public async Task Exception_DeleteExceptionTest()
// Delete nonexisted post
try
{
- var result = await _clientAuth.Posts.DeleteAsync(int.MaxValue);
+ bool result = await _clientAuth.Posts.DeleteAsync(int.MaxValue);
}
catch (WPException wpex)
{
diff --git a/WordPressPCL.Tests.Selfhosted/HttpClient_Tests.cs b/WordPressPCL.Tests.Selfhosted/HttpClient_Tests.cs
index ed39372..cc56c65 100644
--- a/WordPressPCL.Tests.Selfhosted/HttpClient_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/HttpClient_Tests.cs
@@ -1,8 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
+using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
namespace WordPressPCL.Tests.Selfhosted;
@@ -14,7 +16,7 @@ public class HttpClient_Tests
public async Task CustomHttpClient_WithBaseAddress()
{
// Initialize
- var httpClient = new HttpClient
+ HttpClient httpClient = new()
{
BaseAddress = new Uri(ApiCredentials.WordPressUri)
};
@@ -26,23 +28,19 @@ public async Task CustomHttpClient_WithBaseAddress()
public async Task CustomHttpClient_WithoutBaseAddress()
{
// Initialize
- var httpClient = new HttpClient();
- var wordPressClient = new WordPressClient(httpClient, uri: new Uri(ApiCredentials.WordPressUri));
+ HttpClient httpClient = new();
+ WordPressClient wordPressClient = new(httpClient, uri: new Uri(ApiCredentials.WordPressUri));
await CustomHttpClientBase(httpClient, wordPressClient);
}
- private async Task CustomHttpClientBase(HttpClient httpClient, WordPressClient client)
+ private static async Task CustomHttpClientBase(HttpClient httpClient, WordPressClient client)
{
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0");
httpClient.DefaultRequestHeaders.Add("Referer", "https://github.com/wp-net/WordPressPCL");
- var posts = await client.Posts.GetAllAsync();
- var post = await client.Posts.GetByIDAsync(posts.First().Id);
+ List posts = await client.Posts.GetAllAsync();
+ Post post = await client.Posts.GetByIDAsync(posts.First().Id);
Assert.IsTrue(posts.First().Id == post.Id);
Assert.IsTrue(!string.IsNullOrEmpty(posts.First().Content.Rendered));
-
- await client.Auth.RequestJWTokenAsync(ApiCredentials.Username, ApiCredentials.Password);
- var validToken = await client.Auth.IsValidJWTokenAsync();
- Assert.IsTrue(validToken);
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL.Tests.Selfhosted/ListPosts_QueryBuilder_Tests.cs b/WordPressPCL.Tests.Selfhosted/ListPosts_QueryBuilder_Tests.cs
index 26ee26e..bd1fb38 100644
--- a/WordPressPCL.Tests.Selfhosted/ListPosts_QueryBuilder_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/ListPosts_QueryBuilder_Tests.cs
@@ -1,9 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordPressPCL.Tests.Selfhosted.Utility;
-using WordPressPCL;
using System.Threading.Tasks;
using WordPressPCL.Utility;
using System.Linq;
+using System.Collections.Generic;
+using WordPressPCL.Models;
namespace WordPressPCL.Tests.Selfhosted;
@@ -23,20 +24,20 @@ public static void Init(TestContext testContext)
public async Task List_Posts_QueryBuilder_Test_Pagination()
{
// Posts
- var postsA = await _client.Posts.QueryAsync(new PostsQueryBuilder()
+ List postsA = await _client.Posts.QueryAsync(new PostsQueryBuilder()
{
Page = 1,
PerPage = 2
});
- var postsB = await _client.Posts.QueryAsync(new PostsQueryBuilder()
+ List postsB = await _client.Posts.QueryAsync(new PostsQueryBuilder()
{
Page = 2,
PerPage = 2
});
Assert.IsNotNull(postsA);
Assert.IsNotNull(postsB);
- Assert.AreNotEqual(postsA.Count(), 0);
- Assert.AreNotEqual(postsB.Count(), 0);
+ Assert.AreNotEqual(postsA.Count, 0);
+ Assert.AreNotEqual(postsB.Count, 0);
CollectionAssert.AreNotEqual(postsA.Select(post => post.Id).ToList(), postsB.Select(post => post.Id).ToList());
}
@@ -45,7 +46,7 @@ public async Task List_Posts_QueryBuilder_Test_Pagination()
public async Task List_Posts_QueryBuilder_After()
{
// Posts
- var posts = await _client.Posts.QueryAsync(new PostsQueryBuilder { After = System.DateTime.Parse("2017-05-22T13:41:09") });
+ List posts = await _client.Posts.QueryAsync(new PostsQueryBuilder { After = System.DateTime.Parse("2017-05-22T13:41:09") });
Assert.IsNotNull(posts);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Media_Tests.cs b/WordPressPCL.Tests.Selfhosted/Media_Tests.cs
index a4677a1..ceb39f8 100644
--- a/WordPressPCL.Tests.Selfhosted/Media_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Media_Tests.cs
@@ -1,16 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
-using WordPressPCL;
using WordPressPCL.Tests.Selfhosted.Utility;
using System.Linq;
using WordPressPCL.Utility;
using WordPressPCL.Models;
using System.IO;
using Newtonsoft.Json;
-using System.Diagnostics;
+using System.Collections.Generic;
namespace WordPressPCL.Tests.Selfhosted;
@@ -30,28 +26,28 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Media_Create()
{
- var path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
+ string path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
Stream s = File.OpenRead(path);
- var mediaitem = await _clientAuth.Media.CreateAsync(s,"cat.jpg");
+ MediaItem mediaitem = await _clientAuth.Media.CreateAsync(s,"cat.jpg");
Assert.IsNotNull(mediaitem);
}
[TestMethod]
public async Task Media_Create_2_0()
{
- var path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
-
- var mediaitem = await _clientAuth.Media.CreateAsync(path, "cat.jpg");
+ string path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
+
+ MediaItem mediaitem = await _clientAuth.Media.CreateAsync(path, "cat.jpg");
Assert.IsNotNull(mediaitem);
// Create a new post with media item as featured image
- var post = new Post()
+ Post post = new()
{
Title = new Title("Post with Featured Image"),
Content = new Content("Content PostCreate"),
FeaturedMedia = mediaitem.Id
};
- var createdPost = await _clientAuth.Posts.CreateAsync(post);
+ Post createdPost = await _clientAuth.Posts.CreateAsync(post);
Assert.AreEqual(createdPost.FeaturedMedia, mediaitem.Id);
}
@@ -59,7 +55,7 @@ public async Task Media_Create_2_0()
[TestMethod]
public async Task Media_With_Exif_Error_Should_Deserialize_Without_Exception()
{
- var path = Directory.GetCurrentDirectory() + "/Assets/img_exif_error.jpg";
+ string path = Directory.GetCurrentDirectory() + "/Assets/img_exif_error.jpg";
MediaItem mediaItem = null;
try {
mediaItem = await _clientAuth.Media.CreateAsync(path, "img_exif_error.jpg");
@@ -72,34 +68,34 @@ public async Task Media_With_Exif_Error_Should_Deserialize_Without_Exception()
[TestMethod]
public async Task Media_Read()
{
- var media = await _client.Media.GetAllAsync();
+ List media = await _client.Media.GetAllAsync();
Assert.IsNotNull(media);
- Assert.AreNotEqual(media.Count(), 0);
+ Assert.AreNotEqual(media.Count, 0);
}
[TestMethod]
public async Task Media_Get()
{
- var media = await _client.Media.GetAsync();
+ List media = await _client.Media.GetAsync();
Assert.IsNotNull(media);
- Assert.AreNotEqual(media.Count(), 0);
+ Assert.AreNotEqual(media.Count, 0);
}
[TestMethod]
public async Task Media_Update()
{
- var media = await _clientAuth.Media.GetAllAsync();
- var file = media.FirstOrDefault();
+ List media = await _clientAuth.Media.GetAllAsync();
+ MediaItem file = media.FirstOrDefault();
Assert.IsNotNull(file);
- var title = $"New Title {System.Guid.NewGuid()}";
+ string title = $"New Title {System.Guid.NewGuid()}";
Assert.AreNotEqual(title, file.Title.Raw);
file.Title.Raw = title;
- var desc = $"This is a nice cat! {System.Guid.NewGuid()}";
+ string desc = $"This is a nice cat! {System.Guid.NewGuid()}";
file.Description.Raw = desc;
- var fileUpdated = await _clientAuth.Media.UpdateAsync(file);
+ MediaItem fileUpdated = await _clientAuth.Media.UpdateAsync(file);
Assert.IsNotNull(fileUpdated);
Assert.AreEqual(fileUpdated.Title.Raw, title);
Assert.AreEqual(fileUpdated.Description.Raw, desc);
@@ -109,42 +105,42 @@ public async Task Media_Update()
public async Task Media_Delete()
{
// Create file
- var path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
+ string path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
Stream s = File.OpenRead(path);
- var mediaitem = await _clientAuth.Media.CreateAsync(s, "cat.jpg");
+ MediaItem mediaitem = await _clientAuth.Media.CreateAsync(s, "cat.jpg");
Assert.IsNotNull(mediaitem);
// Delete file
- var response = await _clientAuth.Media.DeleteAsync(mediaitem.Id);
+ bool response = await _clientAuth.Media.DeleteAsync(mediaitem.Id);
Assert.IsTrue(response);
}
[TestMethod]
public async Task Media_Query()
{
- var queryBuilder = new MediaQueryBuilder()
+ MediaQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
OrderBy = MediaOrderBy.Date,
Order = Order.ASC,
};
- var queryresult = await _clientAuth.Media.QueryAsync(queryBuilder);
+ List queryresult = await _clientAuth.Media.QueryAsync(queryBuilder);
Assert.AreEqual("?page=1&per_page=15&orderby=date&order=asc&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
[TestMethod]
public async Task MediaSizesInEmbeddedPost()
{
- var posts = await _client.Posts.GetAllAsync(true);
- var i = 0;
- foreach (var post in posts) {
+ List posts = await _client.Posts.GetAllAsync(true);
+ int i = 0;
+ foreach (Post post in posts) {
if (post.Embedded.WpFeaturedmedia != null && post.Embedded.WpFeaturedmedia.Any())
{
i++;
- var img = post.Embedded.WpFeaturedmedia.First();
+ MediaItem img = post.Embedded.WpFeaturedmedia.First();
Assert.IsFalse(string.IsNullOrEmpty(img.MediaDetails.Sizes["full"].SourceUrl));
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/MimeTypeHelper_Tests.cs b/WordPressPCL.Tests.Selfhosted/MimeTypeHelper_Tests.cs
index 89c7ab3..d24f433 100644
--- a/WordPressPCL.Tests.Selfhosted/MimeTypeHelper_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/MimeTypeHelper_Tests.cs
@@ -10,7 +10,7 @@ public void MimeType_Defaults_To_Application_Octet_Stream_For_Unknown_Extension(
const string unknownExtension = "unknown";
const string expectedMimeType = "application/octet-stream";
- var resultMimeType = MimeTypeHelper.GetMIMETypeFromExtension(unknownExtension);
+ string resultMimeType = MimeTypeHelper.GetMIMETypeFromExtension(unknownExtension);
Assert.AreEqual(expectedMimeType, resultMimeType);
}
diff --git a/WordPressPCL.Tests.Selfhosted/Pages_Tests.cs b/WordPressPCL.Tests.Selfhosted/Pages_Tests.cs
index 37f6447..15e101e 100644
--- a/WordPressPCL.Tests.Selfhosted/Pages_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Pages_Tests.cs
@@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
using System.Threading.Tasks;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
@@ -26,12 +25,12 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Pages_Create()
{
- var page = new Page()
+ Page page = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate")
};
- var createdPage = await _clientAuth.Pages.CreateAsync(page);
+ Page createdPage = await _clientAuth.Pages.CreateAsync(page);
Assert.AreEqual(page.Content.Raw, createdPage.Content.Raw);
Assert.IsTrue(createdPage.Content.Rendered.Contains(page.Content.Rendered));
@@ -40,29 +39,29 @@ public async Task Pages_Create()
[TestMethod]
public async Task Pages_Read()
{
- var pages = await _client.Pages.QueryAsync(new PagesQueryBuilder());
+ List pages = await _client.Pages.QueryAsync(new PagesQueryBuilder());
Assert.IsNotNull(pages);
- Assert.AreNotEqual(pages.Count(), 0);
+ Assert.AreNotEqual(pages.Count, 0);
}
[TestMethod]
public async Task Pages_Get()
{
- var pages = await _client.Pages.GetAsync();
+ List pages = await _client.Pages.GetAsync();
Assert.IsNotNull(pages);
- Assert.AreNotEqual(pages.Count(), 0);
+ Assert.AreNotEqual(pages.Count, 0);
}
[TestMethod]
public async Task Pages_Update()
{
- var testContent = $"Test {System.Guid.NewGuid()}";
- var pages = await _client.Pages.GetAllAsync();
- Assert.IsTrue(pages.Count() > 0);
+ string testContent = $"Test {System.Guid.NewGuid()}";
+ List pages = await _client.Pages.GetAllAsync();
+ Assert.IsTrue(pages.Count > 0);
- var page = pages.FirstOrDefault();
+ Page page = pages.FirstOrDefault();
page.Content.Raw = testContent;
- var updatedPage = await _clientAuth.Pages.UpdateAsync(page);
+ Page updatedPage = await _clientAuth.Pages.UpdateAsync(page);
Assert.AreEqual(testContent, updatedPage.Content.Raw);
}
@@ -70,26 +69,26 @@ public async Task Pages_Update()
[TestMethod]
public async Task Pages_Delete()
{
- var page = new Page()
+ Page page = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate")
};
- var createdPage = await _clientAuth.Pages.CreateAsync(page);
+ Page createdPage = await _clientAuth.Pages.CreateAsync(page);
Assert.IsNotNull(createdPage);
- var response = await _clientAuth.Pages.Delete(createdPage.Id);
+ bool response = await _clientAuth.Pages.Delete(createdPage.Id);
Assert.IsTrue(response);
await Assert.ThrowsExceptionAsync(async () =>
{
- var pageById = await _client.Pages.GetByIDAsync(createdPage.Id);
+ Page pageById = await _client.Pages.GetByIDAsync(createdPage.Id);
});
}
[TestMethod]
public async Task Pages_Query()
{
- var queryBuilder = new PagesQueryBuilder()
+ PagesQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
@@ -98,9 +97,9 @@ public async Task Pages_Query()
Statuses = new List { Status.Publish },
Embed = true
};
- var queryresult = await _client.Pages.QueryAsync(queryBuilder);
+ List queryresult = await _client.Pages.QueryAsync(queryBuilder);
Assert.AreEqual("?page=1&per_page=15&orderby=title&status=publish&order=asc&_embed=true&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Plugins_Tests.cs b/WordPressPCL.Tests.Selfhosted/Plugins_Tests.cs
index fe95bc7..6c8b42a 100644
--- a/WordPressPCL.Tests.Selfhosted/Plugins_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Plugins_Tests.cs
@@ -1,10 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Diagnostics;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using WordPressPCL;
-using WordPressPCL.Client;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
using WordPressPCL.Utility;
@@ -26,27 +23,27 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Plugins_Install_Activate_Deactivate_Delete()
{
- var plugin = await _clientAuth.Plugins.InstallAsync(PluginId);
+ Plugin plugin = await _clientAuth.Plugins.InstallAsync(PluginId);
Assert.IsNotNull(plugin);
Assert.AreEqual(PluginId, plugin.Id);
//Activate plugin
- var activePlugin = await _clientAuth.Plugins.ActivateAsync(plugin);
+ Plugin activePlugin = await _clientAuth.Plugins.ActivateAsync(plugin);
Assert.AreEqual(activePlugin.Status, ActivationStatus.Active);
Assert.AreEqual(activePlugin.Id, plugin.Id);
//Deactivate plugin
- var deactivatedPlugin = await _clientAuth.Plugins.DeactivateAsync(plugin);
+ Plugin deactivatedPlugin = await _clientAuth.Plugins.DeactivateAsync(plugin);
Assert.AreEqual(deactivatedPlugin.Status, ActivationStatus.Inactive);
Assert.AreEqual(deactivatedPlugin.Id, plugin.Id);
//Delete plugin
- var response = await _clientAuth.Plugins.DeleteAsync(plugin);
+ bool response = await _clientAuth.Plugins.DeleteAsync(plugin);
Assert.IsTrue(response);
- var plugins = await _clientAuth.Plugins.GetAllAsync(useAuth: true);
- var c = plugins.Where(x => x.Id == plugin.Id).ToList();
+ List plugins = await _clientAuth.Plugins.GetAllAsync(useAuth: true);
+ List c = plugins.Where(x => x.Id == plugin.Id).ToList();
Assert.AreEqual(c.Count, 0);
}
@@ -54,34 +51,34 @@ public async Task Plugins_Install_Activate_Deactivate_Delete()
public async Task Plugins_GetActive()
{
//Active plugin
- var plugins = await _clientAuth.Plugins.QueryAsync(new PluginsQueryBuilder { Status = ActivationStatus.Active }, useAuth:true);
+ List plugins = await _clientAuth.Plugins.QueryAsync(new PluginsQueryBuilder { Status = ActivationStatus.Active }, useAuth:true);
Assert.IsNotNull(plugins);
- Assert.AreNotEqual(plugins.Count(), 0);
+ Assert.AreNotEqual(plugins.Count, 0);
}
[TestMethod]
public async Task Plugins_Search ()
{
//Active plugin
- var plugins = await _clientAuth.Plugins.QueryAsync(new PluginsQueryBuilder { Search="jwt" }, useAuth:true);
+ List plugins = await _clientAuth.Plugins.QueryAsync(new PluginsQueryBuilder { Search="jwt" }, useAuth:true);
Assert.IsNotNull(plugins);
- Assert.AreNotEqual(plugins.Count(), 0);
+ Assert.AreNotEqual(plugins.Count, 0);
}
[TestMethod]
public async Task Plugins_Get()
{
- var plugins = await _clientAuth.Plugins.GetAsync (useAuth: true);
+ List plugins = await _clientAuth.Plugins.GetAsync (useAuth: true);
Assert.IsNotNull(plugins);
- Assert.AreNotEqual(plugins.Count(), 0);
+ Assert.AreNotEqual(plugins.Count, 0);
CollectionAssert.AllItemsAreUnique(plugins.Select(tag => tag.Id).ToList());
}
[TestMethod]
public async Task Plugins_GetByID()
{
- var plugin = await _clientAuth.Plugins.GetByIDAsync("jwt-auth/jwt-auth", useAuth: true);
+ Plugin plugin = await _clientAuth.Plugins.GetByIDAsync("jwt-auth/jwt-auth", useAuth: true);
Assert.IsNotNull(plugin);
}
diff --git a/WordPressPCL.Tests.Selfhosted/PostRevisions_Tests.cs b/WordPressPCL.Tests.Selfhosted/PostRevisions_Tests.cs
index 8046d83..04f07a2 100644
--- a/WordPressPCL.Tests.Selfhosted/PostRevisions_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/PostRevisions_Tests.cs
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using WordPressPCL;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
@@ -21,44 +21,44 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task PostRevisions_Read()
{
- var id = await CreatePostWithRevision();
- var revisionsclient = _clientAuth.Posts.Revisions(id);
- var revisions = await revisionsclient.GetAllAsync();
- Assert.AreNotEqual(revisions.Count(), 0);
+ int id = await CreatePostWithRevision();
+ Client.PostRevisions revisionsclient = _clientAuth.Posts.Revisions(id);
+ List revisions = await revisionsclient.GetAllAsync();
+ Assert.AreNotEqual(revisions.Count, 0);
}
[TestMethod]
public async Task PostRevisions_Get()
{
- var id = await CreatePostWithRevision();
- var revisionsclient = _clientAuth.Posts.Revisions(id);
- var revisions = await revisionsclient.GetAsync();
- Assert.AreNotEqual(revisions.Count(), 0);
+ int id = await CreatePostWithRevision();
+ Client.PostRevisions revisionsclient = _clientAuth.Posts.Revisions(id);
+ List revisions = await revisionsclient.GetAsync();
+ Assert.AreNotEqual(revisions.Count, 0);
}
// TODO: check why revision can't be deleted
//[TestMethod]
public async Task PostRevisions_Delete()
{
- var id = await CreatePostWithRevision();
+ int id = await CreatePostWithRevision();
- var revisionsclient = _clientAuth.Posts.Revisions(id);
- var revisions = await revisionsclient.GetAllAsync();
- Assert.AreNotEqual(revisions.Count(), 0);
- var res = await revisionsclient.DeleteAsync(revisions.First().Id);
+ Client.PostRevisions revisionsclient = _clientAuth.Posts.Revisions(id);
+ List revisions = await revisionsclient.GetAllAsync();
+ Assert.AreNotEqual(revisions.Count, 0);
+ bool res = await revisionsclient.DeleteAsync(revisions.First().Id);
Assert.IsTrue(res);
}
private async Task CreatePostWithRevision()
{
- var post = new Post()
+ Post post = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate"),
};
- var createdPost = await _clientAuth.Posts.CreateAsync(post);
+ Post createdPost = await _clientAuth.Posts.CreateAsync(post);
createdPost.Content.Raw = "Updated Content";
- var updatedPost = await _clientAuth.Posts.UpdateAsync(createdPost);
+ Post updatedPost = await _clientAuth.Posts.UpdateAsync(createdPost);
return updatedPost.Id;
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/PostStatuses_Tests.cs b/WordPressPCL.Tests.Selfhosted/PostStatuses_Tests.cs
index 93a0068..fa2537d 100644
--- a/WordPressPCL.Tests.Selfhosted/PostStatuses_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/PostStatuses_Tests.cs
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
+using System.Collections.Generic;
using System.Threading.Tasks;
-using WordPressPCL;
+using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
namespace WordPressPCL.Tests.Selfhosted;
@@ -20,16 +20,16 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task PostStatuses_Read()
{
- var poststatuses = await _clientAuth.PostStatuses.GetAllAsync();
+ List poststatuses = await _clientAuth.PostStatuses.GetAllAsync();
Assert.IsNotNull(poststatuses);
- Assert.AreNotEqual(poststatuses.Count(), 0);
+ Assert.AreNotEqual(poststatuses.Count, 0);
}
[TestMethod]
public async Task PostStatuses_Get()
{
- var poststatuses = await _clientAuth.PostStatuses.GetAsync();
+ List poststatuses = await _clientAuth.PostStatuses.GetAsync();
Assert.IsNotNull(poststatuses);
- Assert.AreNotEqual(poststatuses.Count(), 0);
+ Assert.AreNotEqual(poststatuses.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/PostTypes_Tests.cs b/WordPressPCL.Tests.Selfhosted/PostTypes_Tests.cs
index 0df9518..c89f299 100644
--- a/WordPressPCL.Tests.Selfhosted/PostTypes_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/PostTypes_Tests.cs
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
+using System.Collections.Generic;
using System.Threading.Tasks;
-using WordPressPCL;
+using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
namespace WordPressPCL.Tests.Selfhosted;
@@ -22,16 +22,16 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task PostTypes_Read()
{
- var posttypes = await _clientAuth.PostTypes.GetAllAsync();
+ List posttypes = await _clientAuth.PostTypes.GetAllAsync();
Assert.IsNotNull(posttypes);
- Assert.AreNotEqual(posttypes.Count(), 0);
+ Assert.AreNotEqual(posttypes.Count, 0);
}
[TestMethod]
public async Task PostTypes_Get()
{
- var posttypes = await _clientAuth.PostTypes.GetAsync();
+ List posttypes = await _clientAuth.PostTypes.GetAsync();
Assert.IsNotNull(posttypes);
- Assert.AreNotEqual(posttypes.Count(), 0);
+ Assert.AreNotEqual(posttypes.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/QueryBuilder_Tests.cs b/WordPressPCL.Tests.Selfhosted/QueryBuilder_Tests.cs
index d8bc449..55c77c0 100644
--- a/WordPressPCL.Tests.Selfhosted/QueryBuilder_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/QueryBuilder_Tests.cs
@@ -13,7 +13,7 @@ public class QueryBuilder_Tests
public void Multi_Parameter_Query_Works_Test()
{
// Initialize
- var builder = new PostsQueryBuilder() {
+ PostsQueryBuilder builder = new() {
Page = 1,
PerPage = 15,
OrderBy = PostsOrderBy.Title,
diff --git a/WordPressPCL.Tests.Selfhosted/Settings_Tests.cs b/WordPressPCL.Tests.Selfhosted/Settings_Tests.cs
index 5bb6bbd..9702054 100644
--- a/WordPressPCL.Tests.Selfhosted/Settings_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Settings_Tests.cs
@@ -1,11 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
+using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
-using System.Linq;
-using WordPressPCL;
namespace WordPressPCL.Tests.Selfhosted;
@@ -23,7 +19,7 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Get_Settings_Test()
{
- var settings = await _clientAuth.Settings.GetSettingsAsync();
+ Settings settings = await _clientAuth.Settings.GetSettingsAsync();
Assert.IsNotNull(settings);
Assert.IsNotNull(settings.Title);
}
diff --git a/WordPressPCL.Tests.Selfhosted/Tag_Tests.cs b/WordPressPCL.Tests.Selfhosted/Tag_Tests.cs
index 76cf5b7..c84a6e4 100644
--- a/WordPressPCL.Tests.Selfhosted/Tag_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Tag_Tests.cs
@@ -1,11 +1,10 @@
-using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordPressPCL.Tests.Selfhosted.Utility;
-using WordPressPCL;
using System.Threading.Tasks;
using WordPressPCL.Models;
using WordPressPCL.Utility;
using System.Linq;
+using System.Collections.Generic;
namespace WordPressPCL.Tests.Selfhosted;
@@ -21,7 +20,7 @@ public static async Task Init(TestContext testContext)
_client = ClientHelper.GetWordPressClient();
_clientAuth = await ClientHelper.GetAuthenticatedWordPressClient(testContext);
- var tagname = $"Test {System.Guid.NewGuid()}";
+ string tagname = $"Test {System.Guid.NewGuid()}";
await _clientAuth.Tags.CreateAsync(new Tag()
{
Name = tagname,
@@ -32,8 +31,8 @@ await _clientAuth.Tags.CreateAsync(new Tag()
[TestMethod]
public async Task Tags_Create()
{
- var tagname = $"Test {System.Guid.NewGuid()}";
- var tag = await _clientAuth.Tags.CreateAsync(new Tag()
+ string tagname = $"Test {System.Guid.NewGuid()}";
+ Tag tag = await _clientAuth.Tags.CreateAsync(new Tag()
{
Name = tagname,
Description = "Test Description"
@@ -46,35 +45,35 @@ public async Task Tags_Create()
[TestMethod]
public async Task Tags_Read()
{
- var tags = await _clientAuth.Tags.GetAllAsync();
+ List tags = await _clientAuth.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(tag => tag.Id).ToList());
}
[TestMethod]
public async Task Tags_Get()
{
- var tags = await _client.Tags.GetAsync();
+ List tags = await _client.Tags.GetAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(tag => tag.Id).ToList());
}
[TestMethod]
public async Task Tags_Update()
{
- var tags = await _clientAuth.Tags.GetAllAsync();
- var tag = tags.FirstOrDefault();
+ List tags = await _clientAuth.Tags.GetAllAsync();
+ Tag tag = tags.FirstOrDefault();
if(tag == null)
{
Assert.Inconclusive();
}
- var tagname = $"Testname {System.Guid.NewGuid()}";
- var tagdesc = "Test Description";
+ string tagname = $"Testname {System.Guid.NewGuid()}";
+ string tagdesc = "Test Description";
tag.Name = tagname;
tag.Description = tagdesc;
- var tagUpdated = await _clientAuth.Tags.UpdateAsync(tag);
+ Tag tagUpdated = await _clientAuth.Tags.UpdateAsync(tag);
Assert.AreEqual(tagname, tagUpdated.Name);
Assert.AreEqual(tagdesc, tagUpdated.Description);
}
@@ -82,33 +81,33 @@ public async Task Tags_Update()
[TestMethod]
public async Task Tags_Delete()
{
- var tags = await _clientAuth.Tags.GetAllAsync();
- var tag = tags.FirstOrDefault();
+ List tags = await _clientAuth.Tags.GetAllAsync();
+ Tag tag = tags.FirstOrDefault();
if (tag == null)
{
Assert.Inconclusive();
}
- var tagId = tag.Id;
- var response = await _clientAuth.Tags.DeleteAsync(tagId);
+ int tagId = tag.Id;
+ bool response = await _clientAuth.Tags.DeleteAsync(tagId);
Assert.IsTrue(response);
tags = await _clientAuth.Tags.GetAllAsync();
- var tagsWithId = tags.Where(x => x.Id == tagId).ToList();
+ List tagsWithId = tags.Where(x => x.Id == tagId).ToList();
Assert.AreEqual(tagsWithId.Count, 0);
}
[TestMethod]
public async Task Tags_Query()
{
- var queryBuilder = new TagsQueryBuilder()
+ TagsQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
OrderBy = TermsOrderBy.Id,
Order = Order.DESC,
};
- var queryresult = await _clientAuth.Tags.QueryAsync(queryBuilder);
+ List queryresult = await _clientAuth.Tags.QueryAsync(queryBuilder);
Assert.AreEqual("?page=1&per_page=15&orderby=id&order=desc&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Taxonomies_Tests.cs b/WordPressPCL.Tests.Selfhosted/Taxonomies_Tests.cs
index d64e406..f4af59b 100644
--- a/WordPressPCL.Tests.Selfhosted/Taxonomies_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Taxonomies_Tests.cs
@@ -1,9 +1,9 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
using System.Threading.Tasks;
-using WordPressPCL;
using WordPressPCL.Utility;
using WordPressPCL.Tests.Selfhosted.Utility;
+using WordPressPCL.Models;
+using System.Collections.Generic;
namespace WordPressPCL.Tests.Selfhosted;
@@ -21,29 +21,29 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Taxonomies_Read()
{
- var taxonomies = await _clientAuth.Taxonomies.GetAllAsync();
+ List taxonomies = await _clientAuth.Taxonomies.GetAllAsync();
Assert.IsNotNull(taxonomies);
- Assert.AreNotEqual(taxonomies.Count(), 0);
+ Assert.AreNotEqual(taxonomies.Count, 0);
}
[TestMethod]
public async Task Taxonomies_Get()
{
- var taxonomies = await _clientAuth.Taxonomies.GetAsync();
+ List taxonomies = await _clientAuth.Taxonomies.GetAsync();
Assert.IsNotNull(taxonomies);
- Assert.AreNotEqual(taxonomies.Count(), 0);
+ Assert.AreNotEqual(taxonomies.Count, 0);
}
[TestMethod]
public async Task Taxonomies_Query()
{
- var queryBuilder = new TaxonomiesQueryBuilder()
+ TaxonomiesQueryBuilder queryBuilder = new()
{
Type = "post"
};
- var queryresult = await _clientAuth.Taxonomies.QueryAsync(queryBuilder);
+ List queryresult = await _clientAuth.Taxonomies.QueryAsync(queryBuilder);
Assert.AreEqual("?type=post&order=desc&context=view", queryBuilder.BuildQuery());
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Themes_Tests.cs b/WordPressPCL.Tests.Selfhosted/Themes_Tests.cs
index f5abe87..1715140 100644
--- a/WordPressPCL.Tests.Selfhosted/Themes_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Themes_Tests.cs
@@ -1,10 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Diagnostics;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using WordPressPCL;
-using WordPressPCL.Client;
using WordPressPCL.Models;
using WordPressPCL.Tests.Selfhosted.Utility;
using WordPressPCL.Utility;
@@ -25,24 +22,24 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Themes_GetActive()
{
- var themes = await _clientAuth.Themes.QueryAsync(new ThemesQueryBuilder { Status = ActivationStatus.Active }, useAuth:true);
+ List themes = await _clientAuth.Themes.QueryAsync(new ThemesQueryBuilder { Status = ActivationStatus.Active }, useAuth:true);
Assert.IsNotNull(themes);
- Assert.AreNotEqual(themes.Count(), 0);
+ Assert.AreNotEqual(themes.Count, 0);
}
[TestMethod]
public async Task Themes_Get()
{
- var themes = await _clientAuth.Themes.GetAsync (useAuth: true);
+ List themes = await _clientAuth.Themes.GetAsync (useAuth: true);
Assert.IsNotNull(themes);
- Assert.AreNotEqual(themes.Count(), 0);
+ Assert.AreNotEqual(themes.Count, 0);
CollectionAssert.AllItemsAreUnique(themes.Select(tag => tag.Stylesheet).ToList());
}
[TestMethod]
public async Task Themes_GetByID()
{
- var theme = await _clientAuth.Themes.GetByIDAsync("twentytwentythree", useAuth: true);
+ Theme theme = await _clientAuth.Themes.GetByIDAsync("twentytwentyfour", useAuth: true);
Assert.IsNotNull(theme);
}
diff --git a/WordPressPCL.Tests.Selfhosted/User_Tests.cs b/WordPressPCL.Tests.Selfhosted/User_Tests.cs
index 18b4659..fee5fd1 100644
--- a/WordPressPCL.Tests.Selfhosted/User_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/User_Tests.cs
@@ -1,11 +1,10 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordPressPCL.Models;
-using WordPressPCL.Utility;
using WordPressPCL.Tests.Selfhosted.Utility;
-using WordPressPCL.Models.Exceptions;
+using WordPressPCL.Utility;
using Guid = System.Guid;
namespace WordPressPCL.Tests.Selfhosted;
@@ -26,15 +25,15 @@ public static async Task Init(TestContext testContext)
[TestMethod]
public async Task Users_Create()
{
- var username = Guid.NewGuid().ToString();
- var nickname = $"Nickname{username}";
- var email = $"{username}@test.com";
- var firstname = $"Firstname{username}";
- var lastname = $"Lastname{username}";
- var password = $"testpassword{username}";
- var name = $"{firstname} {lastname}";
-
- var user = await _clientAuth.Users.CreateAsync(new User(username, email, password)
+ string username = Guid.NewGuid().ToString();
+ string nickname = $"Nickname{username}";
+ string email = $"{username}@test.com";
+ string firstname = $"Firstname{username}";
+ string lastname = $"Lastname{username}";
+ string password = $"testpassword{username}";
+ string name = $"{firstname} {lastname}";
+
+ User user = await _clientAuth.Users.CreateAsync(new User(username, email, password)
{
NickName = nickname,
Name = name,
@@ -53,10 +52,10 @@ public async Task Users_Create()
[TestMethod]
public async Task Users_Read()
{
- var users = await _client.Users.GetAllAsync();
+ List users = await _client.Users.GetAllAsync();
Assert.IsNotNull(users);
- Assert.IsTrue(users.Count() >= 1);
- var user = await _client.Users.GetByIDAsync(users.First().Id);
+ Assert.IsTrue(users.Count >= 1);
+ User user = await _client.Users.GetByIDAsync(users.First().Id);
Assert.IsNotNull(user);
Assert.AreEqual(user.Id, users.First().Id);
}
@@ -64,10 +63,10 @@ public async Task Users_Read()
[TestMethod]
public async Task Users_Get()
{
- var users = await _client.Users.GetAsync();
+ List users = await _client.Users.GetAsync();
Assert.IsNotNull(users);
- Assert.IsTrue(users.Count() >= 1);
- var user = await _client.Users.GetByIDAsync(users.First().Id);
+ Assert.IsTrue(users.Count >= 1);
+ User user = await _client.Users.GetByIDAsync(users.First().Id);
Assert.IsNotNull(user);
Assert.AreEqual(user.Id, users.First().Id);
}
@@ -75,16 +74,16 @@ public async Task Users_Get()
[TestMethod]
public async Task Users_Update()
{
- var user = await CreateRandomUser();
+ User user = await CreateRandomUser();
Assert.IsNotNull(user);
- var name = $"TestuserUpdate";
+ string name = $"TestuserUpdate";
user.Name = name;
user.NickName = name;
user.FirstName = name;
user.LastName = name;
- var updatedUser = await _clientAuth.Users.UpdateAsync(user);
+ User updatedUser = await _clientAuth.Users.UpdateAsync(user);
Assert.IsNotNull(updatedUser);
Assert.AreEqual(updatedUser.Name, name);
Assert.AreEqual(updatedUser.NickName, name);
@@ -95,10 +94,10 @@ public async Task Users_Update()
[TestMethod]
public async Task Users_Delete()
{
- var user = await CreateRandomUser();
+ User user = await CreateRandomUser();
Assert.IsNotNull(user);
- var me = await _clientAuth.Users.GetCurrentUserAsync();
- var response = await _clientAuth.Users.Delete(user.Id, me.Id);
+ User me = await _clientAuth.Users.GetCurrentUserAsync();
+ bool response = await _clientAuth.Users.Delete(user.Id, me.Id);
Assert.IsTrue(response);
}
@@ -106,36 +105,36 @@ public async Task Users_Delete()
public async Task Users_Delete_And_Reassign_Posts()
{
// Create new user
- var user1 = await CreateRandomUser();
+ User user1 = await CreateRandomUser();
Assert.IsNotNull(user1);
- var user2 = await CreateRandomUser();
+ User user2 = await CreateRandomUser();
Assert.IsNotNull(user2);
// Create post for user
- var post = new Post()
+ Post post = new()
{
Title = new Title("Title 1"),
Content = new Content("Content PostCreate"),
Author = user1.Id
};
- var postCreated = await _clientAuth.Posts.CreateAsync(post);
+ Post postCreated = await _clientAuth.Posts.CreateAsync(post);
Assert.IsNotNull(post);
Assert.AreEqual(postCreated.Author, user1.Id);
// Delete User1 and reassign posts to user2
- var response = await _clientAuth.Users.Delete(user1.Id, user2.Id);
+ bool response = await _clientAuth.Users.Delete(user1.Id, user2.Id);
Assert.IsTrue(response);
// Get posts for user 2 and check if ID of postCreated is in there
- var postsOfUser2 = await _clientAuth.Posts.GetPostsByAuthorAsync(user2.Id);
- var postsById = postsOfUser2.Where(x => x.Id == postCreated.Id).ToList();
+ List postsOfUser2 = await _clientAuth.Posts.GetPostsByAuthorAsync(user2.Id);
+ List postsById = postsOfUser2.Where(x => x.Id == postCreated.Id).ToList();
Assert.AreEqual(postsById.Count, 1);
}
[TestMethod]
public async Task Users_Query()
{
- var queryBuilder = new UsersQueryBuilder()
+ UsersQueryBuilder queryBuilder = new()
{
Page = 1,
PerPage = 15,
@@ -145,18 +144,38 @@ public async Task Users_Query()
};
Assert.AreEqual("?page=1&per_page=15&orderby=registered_date&order=desc&context=edit", queryBuilder.BuildQuery());
- var queryresult = await _clientAuth.Users.QueryAsync(queryBuilder, true);
+ List queryresult = await _clientAuth.Users.QueryAsync(queryBuilder, true);
Assert.IsNotNull(queryresult);
- Assert.AreNotSame(queryresult.Count(), 0);
+ Assert.AreNotSame(queryresult.Count, 0);
+ }
+
+ [TestMethod]
+ public async Task Users_GetRoles()
+ {
+ UsersQueryBuilder queryBuilder = new()
+ {
+ // required for roles to be loaded
+ Context = Context.Edit
+ };
+
+ List users = await _clientAuth.Users.QueryAsync(queryBuilder, true);
+ Assert.IsNotNull(users);
+ Assert.IsTrue(users.Count >= 1);
+
+ foreach (User user in users)
+ {
+ Assert.IsNotNull(user.Roles);
+ Assert.IsTrue(user.Roles.Count >= 1);
+ }
}
#region Utils
private Task CreateRandomUser()
{
- var username = Guid.NewGuid().ToString();
- var email = $"{username}@test.com";
- var password = $"testpassword{username}";
+ string username = Guid.NewGuid().ToString();
+ string email = $"{username}@test.com";
+ string password = $"testpassword{username}";
return _clientAuth.Users.CreateAsync(new User(username, email, password));
}
diff --git a/WordPressPCL.Tests.Selfhosted/Utility/CapabilitiesJsonConverter_Tests.cs b/WordPressPCL.Tests.Selfhosted/Utility/CapabilitiesJsonConverter_Tests.cs
index b0950b8..8193131 100644
--- a/WordPressPCL.Tests.Selfhosted/Utility/CapabilitiesJsonConverter_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Utility/CapabilitiesJsonConverter_Tests.cs
@@ -9,13 +9,13 @@ namespace WordPressPCL.Tests.Selfhosted.Utility;
[TestClass]
public class CapabilitiesJsonConverter_Tests
{
- private const string testData1 = "{ \"switch_themes\": true, \"edit_themes\": true, \"activate_plugins\": true, \"edit_plugins\": true, \"edit_users\": true, \"edit_files\": true, \"manage_options\": true, \"moderate_comments\": true, \"manage_categories\": true, \"manage_links\": true, \"upload_files\": true, \"import\": true, \"unfiltered_html\": true, \"edit_posts\": true, \"edit_others_posts\": true, \"edit_published_posts\": true, \"publish_posts\": true, \"edit_pages\": true, \"read\": true, \"level_10\": true, \"level_9\": true, \"level_8\": true, \"level_7\": true, \"level_6\": true, \"level_5\": true, \"level_4\": true, \"level_3\": true, \"level_2\": true, \"level_1\": true, \"level_0\": true, \"edit_others_pages\": true, \"edit_published_pages\": true, \"publish_pages\": true, \"delete_pages\": true, \"delete_others_pages\": true, \"delete_published_pages\": true, \"delete_posts\": true, \"delete_others_posts\": true, \"delete_published_posts\": true, \"delete_private_posts\": true, \"edit_private_posts\": true, \"read_private_posts\": true, \"delete_private_pages\": true, \"edit_private_pages\": true, \"read_private_pages\": true, \"delete_users\": true, \"create_users\": true, \"unfiltered_upload\": true, \"edit_dashboard\": true, \"update_plugins\": true, \"delete_plugins\": true, \"install_plugins\": true, \"update_themes\": true, \"install_themes\": true, \"update_core\": true, \"list_users\": true, \"remove_users\": true, \"promote_users\": true, \"edit_theme_options\": true, \"delete_themes\": true, \"export\": true, \"manage_polls\": true, \"NextGEN Manage tags\": true, \"NextGEN Manage others gallery\": true, \"MailPress_edit_dashboard\": true, \"MailPress_manage_options\": true, \"MailPress_edit_mails\": true, \"MailPress_edit_others_mails\": true, \"MailPress_send_mails\": true, \"MailPress_delete_mails\": true, \"MailPress_archive_mails\": true, \"MailPress_mail_custom_fields\": true, \"MailPress_switch_themes\": true, \"MailPress_edit_users\": true, \"MailPress_delete_users\": true, \"MailPress_user_custom_fields\": true, \"MailPress_manage_addons\": true, \"MailPress_manage_autoresponders\": true, \"MailPress_manage_newsletters\": true, \"MailPress_test_newsletters\": true, \"picasa_dialog\": true, \"wysija_newsletters\": true, \"wysija_subscribers\": true, \"wysija_config\": true, \"wysija_theme_tab\": true, \"wysija_style_tab\": true, \"wysija_stats_dashboard\": true, \"aiosp_manage_seo\": true, \"see_snap_box\": true, \"make_snap_posts\": true, \"wpseo_bulk_edit\": true, \"wpseo_manage_options\": true, \"haveown_snap_accss\": true, \"administrator\": \"1\" }";
- private const string badTestData1 = "{ \"switch_themes\": \"lalala\", \"edit_themes\": true, \"activate_plugins\": true, \"edit_plugins\": true, \"edit_users\": true, \"edit_files\": true, \"manage_options\": true, \"moderate_comments\": true, \"manage_categories\": true, \"manage_links\": true, \"upload_files\": true, \"import\": true, \"unfiltered_html\": true, \"edit_posts\": true, \"edit_others_posts\": true, \"edit_published_posts\": true, \"publish_posts\": true, \"edit_pages\": true, \"read\": true, \"level_10\": true, \"level_9\": true, \"level_8\": true, \"level_7\": true, \"level_6\": true, \"level_5\": true, \"level_4\": true, \"level_3\": true, \"level_2\": true, \"level_1\": true, \"level_0\": true, \"edit_others_pages\": true, \"edit_published_pages\": true, \"publish_pages\": true, \"delete_pages\": true, \"delete_others_pages\": true, \"delete_published_pages\": true, \"delete_posts\": true, \"delete_others_posts\": true, \"delete_published_posts\": true, \"delete_private_posts\": true, \"edit_private_posts\": true, \"read_private_posts\": true, \"delete_private_pages\": true, \"edit_private_pages\": true, \"read_private_pages\": true, \"delete_users\": true, \"create_users\": true, \"unfiltered_upload\": true, \"edit_dashboard\": true, \"update_plugins\": true, \"delete_plugins\": true, \"install_plugins\": true, \"update_themes\": true, \"install_themes\": true, \"update_core\": true, \"list_users\": true, \"remove_users\": true, \"promote_users\": true, \"edit_theme_options\": true, \"delete_themes\": true, \"export\": true, \"manage_polls\": true, \"NextGEN Manage tags\": true, \"NextGEN Manage others gallery\": true, \"MailPress_edit_dashboard\": true, \"MailPress_manage_options\": true, \"MailPress_edit_mails\": true, \"MailPress_edit_others_mails\": true, \"MailPress_send_mails\": true, \"MailPress_delete_mails\": true, \"MailPress_archive_mails\": true, \"MailPress_mail_custom_fields\": true, \"MailPress_switch_themes\": true, \"MailPress_edit_users\": true, \"MailPress_delete_users\": true, \"MailPress_user_custom_fields\": true, \"MailPress_manage_addons\": true, \"MailPress_manage_autoresponders\": true, \"MailPress_manage_newsletters\": true, \"MailPress_test_newsletters\": true, \"picasa_dialog\": true, \"wysija_newsletters\": true, \"wysija_subscribers\": true, \"wysija_config\": true, \"wysija_theme_tab\": true, \"wysija_style_tab\": true, \"wysija_stats_dashboard\": true, \"aiosp_manage_seo\": true, \"see_snap_box\": true, \"make_snap_posts\": true, \"wpseo_bulk_edit\": true, \"wpseo_manage_options\": true, \"haveown_snap_accss\": true, \"administrator\": \"1\" }";
+ private const string TestData1 = "{ \"switch_themes\": true, \"edit_themes\": true, \"activate_plugins\": true, \"edit_plugins\": true, \"edit_users\": true, \"edit_files\": true, \"manage_options\": true, \"moderate_comments\": true, \"manage_categories\": true, \"manage_links\": true, \"upload_files\": true, \"import\": true, \"unfiltered_html\": true, \"edit_posts\": true, \"edit_others_posts\": true, \"edit_published_posts\": true, \"publish_posts\": true, \"edit_pages\": true, \"read\": true, \"level_10\": true, \"level_9\": true, \"level_8\": true, \"level_7\": true, \"level_6\": true, \"level_5\": true, \"level_4\": true, \"level_3\": true, \"level_2\": true, \"level_1\": true, \"level_0\": true, \"edit_others_pages\": true, \"edit_published_pages\": true, \"publish_pages\": true, \"delete_pages\": true, \"delete_others_pages\": true, \"delete_published_pages\": true, \"delete_posts\": true, \"delete_others_posts\": true, \"delete_published_posts\": true, \"delete_private_posts\": true, \"edit_private_posts\": true, \"read_private_posts\": true, \"delete_private_pages\": true, \"edit_private_pages\": true, \"read_private_pages\": true, \"delete_users\": true, \"create_users\": true, \"unfiltered_upload\": true, \"edit_dashboard\": true, \"update_plugins\": true, \"delete_plugins\": true, \"install_plugins\": true, \"update_themes\": true, \"install_themes\": true, \"update_core\": true, \"list_users\": true, \"remove_users\": true, \"promote_users\": true, \"edit_theme_options\": true, \"delete_themes\": true, \"export\": true, \"manage_polls\": true, \"NextGEN Manage tags\": true, \"NextGEN Manage others gallery\": true, \"MailPress_edit_dashboard\": true, \"MailPress_manage_options\": true, \"MailPress_edit_mails\": true, \"MailPress_edit_others_mails\": true, \"MailPress_send_mails\": true, \"MailPress_delete_mails\": true, \"MailPress_archive_mails\": true, \"MailPress_mail_custom_fields\": true, \"MailPress_switch_themes\": true, \"MailPress_edit_users\": true, \"MailPress_delete_users\": true, \"MailPress_user_custom_fields\": true, \"MailPress_manage_addons\": true, \"MailPress_manage_autoresponders\": true, \"MailPress_manage_newsletters\": true, \"MailPress_test_newsletters\": true, \"picasa_dialog\": true, \"wysija_newsletters\": true, \"wysija_subscribers\": true, \"wysija_config\": true, \"wysija_theme_tab\": true, \"wysija_style_tab\": true, \"wysija_stats_dashboard\": true, \"aiosp_manage_seo\": true, \"see_snap_box\": true, \"make_snap_posts\": true, \"wpseo_bulk_edit\": true, \"wpseo_manage_options\": true, \"haveown_snap_accss\": true, \"administrator\": \"1\" }";
+ private const string BadTestData1 = "{ \"switch_themes\": \"lalala\", \"edit_themes\": true, \"activate_plugins\": true, \"edit_plugins\": true, \"edit_users\": true, \"edit_files\": true, \"manage_options\": true, \"moderate_comments\": true, \"manage_categories\": true, \"manage_links\": true, \"upload_files\": true, \"import\": true, \"unfiltered_html\": true, \"edit_posts\": true, \"edit_others_posts\": true, \"edit_published_posts\": true, \"publish_posts\": true, \"edit_pages\": true, \"read\": true, \"level_10\": true, \"level_9\": true, \"level_8\": true, \"level_7\": true, \"level_6\": true, \"level_5\": true, \"level_4\": true, \"level_3\": true, \"level_2\": true, \"level_1\": true, \"level_0\": true, \"edit_others_pages\": true, \"edit_published_pages\": true, \"publish_pages\": true, \"delete_pages\": true, \"delete_others_pages\": true, \"delete_published_pages\": true, \"delete_posts\": true, \"delete_others_posts\": true, \"delete_published_posts\": true, \"delete_private_posts\": true, \"edit_private_posts\": true, \"read_private_posts\": true, \"delete_private_pages\": true, \"edit_private_pages\": true, \"read_private_pages\": true, \"delete_users\": true, \"create_users\": true, \"unfiltered_upload\": true, \"edit_dashboard\": true, \"update_plugins\": true, \"delete_plugins\": true, \"install_plugins\": true, \"update_themes\": true, \"install_themes\": true, \"update_core\": true, \"list_users\": true, \"remove_users\": true, \"promote_users\": true, \"edit_theme_options\": true, \"delete_themes\": true, \"export\": true, \"manage_polls\": true, \"NextGEN Manage tags\": true, \"NextGEN Manage others gallery\": true, \"MailPress_edit_dashboard\": true, \"MailPress_manage_options\": true, \"MailPress_edit_mails\": true, \"MailPress_edit_others_mails\": true, \"MailPress_send_mails\": true, \"MailPress_delete_mails\": true, \"MailPress_archive_mails\": true, \"MailPress_mail_custom_fields\": true, \"MailPress_switch_themes\": true, \"MailPress_edit_users\": true, \"MailPress_delete_users\": true, \"MailPress_user_custom_fields\": true, \"MailPress_manage_addons\": true, \"MailPress_manage_autoresponders\": true, \"MailPress_manage_newsletters\": true, \"MailPress_test_newsletters\": true, \"picasa_dialog\": true, \"wysija_newsletters\": true, \"wysija_subscribers\": true, \"wysija_config\": true, \"wysija_theme_tab\": true, \"wysija_style_tab\": true, \"wysija_stats_dashboard\": true, \"aiosp_manage_seo\": true, \"see_snap_box\": true, \"make_snap_posts\": true, \"wpseo_bulk_edit\": true, \"wpseo_manage_options\": true, \"haveown_snap_accss\": true, \"administrator\": \"1\" }";
[TestMethod]
public void CapabilitiesJsonConverterRead_Test()
{
- var result = JsonConvert.DeserializeObject>(testData1, new CustomCapabilitiesJsonConverter());
+ Dictionary result = JsonConvert.DeserializeObject>(TestData1, new CustomCapabilitiesJsonConverter());
Assert.IsNotNull(result);
Assert.IsTrue(result["administrator"]);
Assert.IsTrue(result["level_0"]);
@@ -24,17 +24,17 @@ public void CapabilitiesJsonConverterRead_Test()
[TestMethod]
public void MUST_FAIL_CapabilitiesJsonConverterRead_Test()
{
- Assert.ThrowsException(() => JsonConvert.DeserializeObject>(badTestData1, new CustomCapabilitiesJsonConverter()));
+ Assert.ThrowsException(() => JsonConvert.DeserializeObject>(BadTestData1, new CustomCapabilitiesJsonConverter()));
}
[TestMethod]
public void CapabilitiesJsonConverterWrite_Test()
{
- var data = new Dictionary() {
+ Dictionary data = new() {
{ "administrator", true },
{ "level_0", true }
};
- var result = JsonConvert.SerializeObject(data, new CustomCapabilitiesJsonConverter());
+ string result = JsonConvert.SerializeObject(data, new CustomCapabilitiesJsonConverter());
Assert.AreEqual("{\"administrator\":true,\"level_0\":true}", result);
}
}
diff --git a/WordPressPCL.Tests.Selfhosted/Utility/ClientHelper.cs b/WordPressPCL.Tests.Selfhosted/Utility/ClientHelper.cs
index 0d1df70..1364f0f 100644
--- a/WordPressPCL.Tests.Selfhosted/Utility/ClientHelper.cs
+++ b/WordPressPCL.Tests.Selfhosted/Utility/ClientHelper.cs
@@ -1,6 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
-using System.Diagnostics;
using System.Threading.Tasks;
using WordPressPCL.Models;
@@ -10,7 +9,7 @@ public static class ClientHelper
{
public static async Task GetAuthenticatedWordPressClient(TestContext context)
{
- var clientAuth = new WordPressClient(ApiCredentials.WordPressUri);
+ WordPressClient clientAuth = new(ApiCredentials.WordPressUri);
Console.WriteLine($"Auth Plugin: {context?.Properties["authplugin"]}");
if (context?.Properties["authplugin"]?.ToString() == "jwtAuthByUsefulTeam")
diff --git a/WordPressPCL.Tests.Selfhosted/Utility/HttpHelper_Tests.cs b/WordPressPCL.Tests.Selfhosted/Utility/HttpHelper_Tests.cs
index ba4ff93..e825847 100644
--- a/WordPressPCL.Tests.Selfhosted/Utility/HttpHelper_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Utility/HttpHelper_Tests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -22,8 +23,8 @@ public static async Task Init(TestContext testContext)
public async Task HttpHelper_InvalidPreProcessing()
{
// Create a random tag , must works:
- var tagname = $"Test {System.Guid.NewGuid()}";
- var tag = await _clientAuth.Tags.CreateAsync(new Tag()
+ string tagname = $"Test {System.Guid.NewGuid()}";
+ Tag tag = await _clientAuth.Tags.CreateAsync(new Tag()
{
Name = tagname,
Description = "Test Description"
@@ -34,9 +35,9 @@ public async Task HttpHelper_InvalidPreProcessing()
Assert.AreEqual("Test Description", tag.Description);
// We call Get tag list without pre processing
- var tags = await _clientAuth.Tags.GetAllAsync();
+ List tags = await _clientAuth.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
// Now we add a PreProcessing task
@@ -57,9 +58,9 @@ public async Task HttpHelper_ValidPreProcessing()
_clientAuth.HttpResponsePreProcessing = null;
// Create a random tag
- var random = new Random();
- var tagname = $"Test {System.Guid.NewGuid()}";
- var tag = await _clientAuth.Tags.CreateAsync(new Tag()
+ Random random = new();
+ string tagname = $"Test {System.Guid.NewGuid()}";
+ Tag tag = await _clientAuth.Tags.CreateAsync(new Tag()
{
Name = tagname,
Description = "Test Description"
@@ -70,9 +71,9 @@ public async Task HttpHelper_ValidPreProcessing()
Assert.AreEqual("Test Description", tag.Description);
// We call Get tag list without pre processing
- var tags = await _clientAuth.Tags.GetAllAsync();
+ List tags = await _clientAuth.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
// Now we add a PreProcessing task
@@ -83,7 +84,7 @@ public async Task HttpHelper_ValidPreProcessing()
tags = await _clientAuth.Tags.GetAllAsync();
Assert.IsNotNull(tags);
- Assert.AreNotEqual(tags.Count(), 0);
+ Assert.AreNotEqual(tags.Count, 0);
CollectionAssert.AllItemsAreUnique(tags.Select(e => e.Id).ToList());
_clientAuth.HttpResponsePreProcessing = null;
}
diff --git a/WordPressPCL.Tests.Selfhosted/Utility/UrlHelper_Tests.cs b/WordPressPCL.Tests.Selfhosted/Utility/UrlHelper_Tests.cs
index f5c1cf9..2d103a7 100644
--- a/WordPressPCL.Tests.Selfhosted/Utility/UrlHelper_Tests.cs
+++ b/WordPressPCL.Tests.Selfhosted/Utility/UrlHelper_Tests.cs
@@ -12,7 +12,7 @@ public class UrlHelper_Tests
public void SetQueryParam_Test()
{
string test = "test";
- var result = test.SetQueryParam("param", "value");
+ string result = test.SetQueryParam("param", "value");
Assert.AreEqual("test", test);
Assert.AreEqual("test?param=value", result);
diff --git a/WordPressPCL.Tests.Selfhosted/WordPressPCL.Tests.Selfhosted.csproj b/WordPressPCL.Tests.Selfhosted/WordPressPCL.Tests.Selfhosted.csproj
index b01b9dc..2382e31 100644
--- a/WordPressPCL.Tests.Selfhosted/WordPressPCL.Tests.Selfhosted.csproj
+++ b/WordPressPCL.Tests.Selfhosted/WordPressPCL.Tests.Selfhosted.csproj
@@ -5,9 +5,9 @@
-
-
-
+
+
+
diff --git a/WordPressPCL/Client/Auth.cs b/WordPressPCL/Client/Auth.cs
index 2ac1929..ea6c21f 100644
--- a/WordPressPCL/Client/Auth.cs
+++ b/WordPressPCL/Client/Auth.cs
@@ -1,14 +1,13 @@
using Newtonsoft.Json.Linq;
-using System;
using System.Collections.Generic;
using System.Net.Http;
-using System.Text;
using System.Threading.Tasks;
using WordPressPCL.Models;
using WordPressPCL.Models.Exceptions;
using WordPressPCL.Utility;
-namespace WordPressPCL.Client {
+namespace WordPressPCL.Client
+{
///
/// Client class for interaction with Auth endpoints of WP REST API
diff --git a/WordPressPCL/Client/CRUDOperation.cs b/WordPressPCL/Client/CRUDOperation.cs
index c22517f..1f95ee8 100644
--- a/WordPressPCL/Client/CRUDOperation.cs
+++ b/WordPressPCL/Client/CRUDOperation.cs
@@ -100,14 +100,14 @@ public async Task> GetAllAsync(bool embed = false, bool useAuth = f
{
//100 - Max posts per page in WordPress REST API, so this is hack with multiple requests
string url = MethodPath.SetQueryParam("per_page", "100").SetQueryParam("page", "1");
- List entities = (await HttpHelper.GetRequestAsync>(url, embed, useAuth).ConfigureAwait(false))?.ToList();
+ List entities = await HttpHelper.GetRequestAsync>(url, embed, useAuth).ConfigureAwait(false);
if (HttpHelper.LastResponseHeaders.Contains("X-WP-TotalPages") && Convert.ToInt32(HttpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture) > 1)
{
int totalpages = Convert.ToInt32(HttpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture);
for (int page = 2; page <= totalpages; page++)
{
url = MethodPath.SetQueryParam("per_page", "100").SetQueryParam("page", page.ToString());
- entities.AddRange((await HttpHelper.GetRequestAsync>(url, embed, useAuth).ConfigureAwait(false))?.ToList());
+ entities.AddRange(await HttpHelper.GetRequestAsync>(url, embed, useAuth).ConfigureAwait(false));
}
}
return entities;
@@ -148,4 +148,4 @@ public async Task UpdateAsync(TClass Entity)
return (await HttpHelper.PostRequestAsync($"{MethodPath}/{(Entity as Base)?.Id}", postBody).ConfigureAwait(false)).Item1;
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Comments.cs b/WordPressPCL/Client/Comments.cs
index 024806d..965389f 100644
--- a/WordPressPCL/Client/Comments.cs
+++ b/WordPressPCL/Client/Comments.cs
@@ -36,9 +36,9 @@ public Comments(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
/// include embed info
/// Send request with authentication header
/// List of comments for post
- public Task> GetCommentsForPostAsync(int PostID, bool embed = false, bool useAuth = false)
+ public Task> GetCommentsForPostAsync(int PostID, bool embed = false, bool useAuth = false)
{
- return HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}", embed, useAuth);
+ return HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}", embed, useAuth);
}
///
@@ -48,17 +48,17 @@ public Task> GetCommentsForPostAsync(int PostID, bool embed
/// include embed info
/// Send request with authentication header
/// List of comments for post
- public async Task> GetAllCommentsForPostAsync(int PostID, bool embed = false, bool useAuth = false)
+ public async Task> GetAllCommentsForPostAsync(int PostID, bool embed = false, bool useAuth = false)
{
//100 - Max comments per page in WordPress REST API, so this is hack with multiple requests
- List comments = (await HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}&per_page=100&page=1", embed, useAuth).ConfigureAwait(false))?.ToList();
+ List comments = await HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}&per_page=100&page=1", embed, useAuth).ConfigureAwait(false);
if (HttpHelper.LastResponseHeaders.Contains("X-WP-TotalPages") &&
int.TryParse(HttpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), out int totalPages) &&
totalPages > 1)
{
for (int page = 2; page <= totalPages; page++)
{
- comments.AddRange((await HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}&per_page=100&page={page}", embed, useAuth).ConfigureAwait(false))?.ToList());
+ comments.AddRange(await HttpHelper.GetRequestAsync>($"{_methodPath}?post={PostID}&per_page=100&page={page}", embed, useAuth).ConfigureAwait(false));
}
}
return comments;
@@ -77,4 +77,4 @@ public Task DeleteAsync(int ID, bool force = false)
#endregion Custom
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Media.cs b/WordPressPCL/Client/Media.cs
index 71add5e..31b1a1a 100644
--- a/WordPressPCL/Client/Media.cs
+++ b/WordPressPCL/Client/Media.cs
@@ -132,13 +132,13 @@ public Task> GetAsync(bool embed = false, bool useAuth = false)
public async Task> GetAllAsync(bool embed = false, bool useAuth = false)
{
//100 - Max posts per page in WordPress REST API, so this is hack with multiple requests
- List entities = (await _httpHelper.GetRequestAsync>($"{_methodPath}?per_page=100&page=1", embed, useAuth).ConfigureAwait(false))?.ToList();
+ List entities = await _httpHelper.GetRequestAsync>($"{_methodPath}?per_page=100&page=1", embed, useAuth).ConfigureAwait(false);
if (_httpHelper.LastResponseHeaders.Contains("X-WP-TotalPages") && Convert.ToInt32(_httpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture) > 1)
{
int totalpages = Convert.ToInt32(_httpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture);
for (int page = 2; page <= totalpages; page++)
{
- entities.AddRange((await _httpHelper.GetRequestAsync>($"{_methodPath}?per_page=100&page={page}", embed, useAuth).ConfigureAwait(false))?.ToList());
+ entities.AddRange(await _httpHelper.GetRequestAsync>($"{_methodPath}?per_page=100&page={page}", embed, useAuth).ConfigureAwait(false));
}
}
return entities;
@@ -179,4 +179,4 @@ public async Task UpdateAsync(MediaItem Entity)
return (await _httpHelper.PostRequestAsync($"{_methodPath}/{Entity?.Id}", postBody).ConfigureAwait(false)).Item1;
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Pages.cs b/WordPressPCL/Client/Pages.cs
index ca92f4d..5a86628 100644
--- a/WordPressPCL/Client/Pages.cs
+++ b/WordPressPCL/Client/Pages.cs
@@ -34,11 +34,11 @@ public Pages(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
/// include embed info
/// Send request with authentication header
/// List of pages
- public Task> GetPagesByAuthorAsync(int authorId, bool embed = false, bool useAuth = false)
+ public Task> GetPagesByAuthorAsync(int authorId, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>($"{_methodPath}?author={authorId}", embed, useAuth);
+ return HttpHelper.GetRequestAsync>($"{_methodPath}?author={authorId}", embed, useAuth);
}
///
@@ -48,11 +48,11 @@ public Task> GetPagesByAuthorAsync(int authorId, bool embed =
/// include embed info
/// Send request with authentication header
/// List of pages
- public Task> GetPagesBySearchAsync(string searchTerm, bool embed = false, bool useAuth = false)
+ public Task> GetPagesBySearchAsync(string searchTerm, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>($"{_methodPath}?search={searchTerm}", embed, useAuth);
+ return HttpHelper.GetRequestAsync>($"{_methodPath}?search={searchTerm}", embed, useAuth);
}
///
@@ -68,4 +68,4 @@ public Task Delete(int ID, bool force = false)
#endregion Custom
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Plugins.cs b/WordPressPCL/Client/Plugins.cs
index e2f840c..4a6b162 100644
--- a/WordPressPCL/Client/Plugins.cs
+++ b/WordPressPCL/Client/Plugins.cs
@@ -1,12 +1,8 @@
-using Newtonsoft.Json;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
using System.Net.Http;
-using System.Runtime;
using System.Text;
using System.Threading.Tasks;
-using WordPressPCL.Interfaces;
+using Newtonsoft.Json;
using WordPressPCL.Models;
using WordPressPCL.Utility;
@@ -43,8 +39,8 @@ public Plugins(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
public async Task InstallAsync(Plugin Plugin)
{
- using var postBody = new StringContent(JsonConvert.SerializeObject(new { slug = Plugin.Id }), Encoding.UTF8, "application/json");
- var (plugin, _) = await _httpHelper.PostRequestAsync("plugins", postBody).ConfigureAwait(false);
+ using StringContent postBody = new StringContent(JsonConvert.SerializeObject(new { slug = Plugin.Id }), Encoding.UTF8, "application/json");
+ (Plugin plugin, HttpResponseMessage _) = await _httpHelper.PostRequestAsync("plugins", postBody).ConfigureAwait(false);
return plugin;
}
@@ -57,8 +53,8 @@ public async Task InstallAsync(Plugin Plugin)
public async Task InstallAsync(string Id)
{
- using var postBody = new StringContent(JsonConvert.SerializeObject(new { slug=Id }), Encoding.UTF8, "application/json");
- var (plugin, _) = await _httpHelper.PostRequestAsync("plugins", postBody).ConfigureAwait(false);
+ using StringContent postBody = new StringContent(JsonConvert.SerializeObject(new { slug = Id }), Encoding.UTF8, "application/json");
+ (Plugin plugin, HttpResponseMessage _) = await _httpHelper.PostRequestAsync("plugins", postBody).ConfigureAwait(false);
return plugin;
}
@@ -69,8 +65,8 @@ public async Task InstallAsync(string Id)
///
public async Task ActivateAsync(Plugin Plugin)
{
- using var postBody = new StringContent(JsonConvert.SerializeObject(new { status = "active" }), Encoding.UTF8, "application/json");
- var (plugin, _) = await _httpHelper.PostRequestAsync($"plugins/{Plugin.PluginFile}", postBody).ConfigureAwait(false);
+ using StringContent postBody = new StringContent(JsonConvert.SerializeObject(new { status = "active" }), Encoding.UTF8, "application/json");
+ (Plugin plugin, HttpResponseMessage _) = await _httpHelper.PostRequestAsync($"plugins/{Plugin.PluginFile}", postBody).ConfigureAwait(false);
return plugin;
}
@@ -82,8 +78,8 @@ public async Task ActivateAsync(Plugin Plugin)
public async Task DeactivateAsync(Plugin Plugin)
{
- using var postBody = new StringContent(JsonConvert.SerializeObject(new { status = "inactive" }), Encoding.UTF8, "application/json");
- var (plugin, _) = await _httpHelper.PostRequestAsync($"plugins/{Plugin.PluginFile}", postBody).ConfigureAwait(false);
+ using StringContent postBody = new(JsonConvert.SerializeObject(new { status = "inactive" }), Encoding.UTF8, "application/json");
+ (Plugin plugin, HttpResponseMessage _) = await _httpHelper.PostRequestAsync($"plugins/{Plugin.PluginFile}", postBody).ConfigureAwait(false);
return plugin;
}
@@ -93,11 +89,11 @@ public async Task DeactivateAsync(Plugin Plugin)
/// Search term
/// include embed info
/// List of posts
- public Task> GetPluginsBySearchAsync(string searchTerm, bool embed = false)
+ public Task> GetPluginsBySearchAsync(string searchTerm, bool embed = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("search", searchTerm), embed,true);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("search", searchTerm), embed, true);
}
///
@@ -106,11 +102,11 @@ public Task> GetPluginsBySearchAsync(string searchTerm, bool
/// active or inactive
/// include embed info
/// List of posts
- public Task> GetPluginsByActivationStatusAsync(ActivationStatus activationStatus, bool embed = false)
+ public Task> GetPluginsByActivationStatusAsync(ActivationStatus activationStatus, bool embed = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("status", activationStatus.ToString().ToLower()), embed, true);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("status", activationStatus.ToString().ToLower()), embed, true);
}
@@ -128,4 +124,4 @@ public Task DeleteAsync(Plugin Plugin)
#endregion Custom
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Posts.cs b/WordPressPCL/Client/Posts.cs
index 9a8e505..c8463bf 100644
--- a/WordPressPCL/Client/Posts.cs
+++ b/WordPressPCL/Client/Posts.cs
@@ -35,11 +35,11 @@ public Posts(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
/// include embed info
/// Send request with authentication header
/// List of posts
- public Task> GetStickyPostsAsync(bool embed = false, bool useAuth = false)
+ public Task> GetStickyPostsAsync(bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("sticky", "true"), embed, useAuth);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("sticky", "true"), embed, useAuth);
}
///
@@ -49,11 +49,11 @@ public Task> GetStickyPostsAsync(bool embed = false, bool useA
/// include embed info
/// Send request with authentication header
/// List of posts
- public Task> GetPostsByCategoryAsync(int categoryId, bool embed = false, bool useAuth = false)
+ public Task> GetPostsByCategoryAsync(int categoryId, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("categories", categoryId), embed, useAuth);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("categories", categoryId), embed, useAuth);
}
///
@@ -63,11 +63,11 @@ public Task> GetPostsByCategoryAsync(int categoryId, bool embe
/// include embed info
/// Send request with authentication header
/// List of posts
- public Task> GetPostsByTagAsync(int tagId, bool embed = false, bool useAuth = false)
+ public Task> GetPostsByTagAsync(int tagId, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("tags", tagId), embed, useAuth);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("tags", tagId), embed, useAuth);
}
///
@@ -77,11 +77,11 @@ public Task> GetPostsByTagAsync(int tagId, bool embed = false,
/// include embed info
/// Send request with authentication header
/// List of posts
- public Task> GetPostsByAuthorAsync(int authorId, bool embed = false, bool useAuth = false)
+ public Task> GetPostsByAuthorAsync(int authorId, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("author", authorId), embed, useAuth);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("author", authorId), embed, useAuth);
}
///
@@ -91,18 +91,18 @@ public Task> GetPostsByAuthorAsync(int authorId, bool embed =
/// include embed info
/// Send request with authentication header
/// List of posts
- public Task> GetPostsBySearchAsync(string searchTerm, bool embed = false, bool useAuth = false)
+ public Task> GetPostsBySearchAsync(string searchTerm, bool embed = false, bool useAuth = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("search", searchTerm), embed, useAuth);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("search", searchTerm), embed, useAuth);
}
///
/// Get count of posts
///
/// Result of operation
- public async Task GetCountAsync()
+ public async Task GetCountAsync()
{
var responseHeaders = await HttpHelper.HeadRequestAsync(_methodPath).ConfigureAwait(false);
var totalHeaderVal = responseHeaders.GetValues("X-WP-Total").First();
@@ -136,4 +136,4 @@ public PostRevisions Revisions(int postId)
#endregion Custom
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Themes.cs b/WordPressPCL/Client/Themes.cs
index 5ab1196..c729b8f 100644
--- a/WordPressPCL/Client/Themes.cs
+++ b/WordPressPCL/Client/Themes.cs
@@ -1,12 +1,5 @@
-using Newtonsoft.Json;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Net.Http;
-using System.Runtime;
-using System.Text;
using System.Threading.Tasks;
-using WordPressPCL.Interfaces;
using WordPressPCL.Models;
using WordPressPCL.Utility;
@@ -35,7 +28,7 @@ public Themes(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
#region Custom
-
+
///
/// Get themes by search term
@@ -43,15 +36,15 @@ public Themes(HttpHelper HttpHelper) : base(HttpHelper, _methodPath)
/// active or inactive
/// include embed info
/// List of posts
- public Task> GetThemesByActivationStatusAsync(ActivationStatus activationStatus, bool embed = false)
+ public Task> GetThemesByActivationStatusAsync(ActivationStatus activationStatus, bool embed = false)
{
// default values
// int page = 1, int per_page = 10, int offset = 0, Post.OrderBy orderby = Post.OrderBy.date
- return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("status", activationStatus.ToString().ToLower()), embed, true);
+ return HttpHelper.GetRequestAsync>(_methodPath.SetQueryParam("status", activationStatus.ToString().ToLower()), embed, true);
}
#endregion Custom
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Client/Users.cs b/WordPressPCL/Client/Users.cs
index d45b376..d8e9844 100644
--- a/WordPressPCL/Client/Users.cs
+++ b/WordPressPCL/Client/Users.cs
@@ -41,8 +41,8 @@ public Users(HttpHelper HttpHelper)
/// Created object
public virtual async Task CreateAsync(User Entity)
{
- var entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(Entity) : JsonConvert.SerializeObject(Entity, _httpHelper.JsonSerializerSettings);
- using var postBody = new StringContent(entity, Encoding.UTF8, "application/json");
+ string entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(Entity) : JsonConvert.SerializeObject(Entity, _httpHelper.JsonSerializerSettings);
+ using StringContent postBody = new(entity, Encoding.UTF8, "application/json");
return (await _httpHelper.PostRequestAsync($"{METHOD_PATH}", postBody).ConfigureAwait(false)).Item1;
}
@@ -66,13 +66,13 @@ public Task> GetAsync(bool embed = false, bool useAuth = false)
public async Task> GetAllAsync(bool embed = false, bool useAuth = false)
{
//100 - Max posts per page in WordPress REST API, so this is hack with multiple requests
- var entities = (await _httpHelper.GetRequestAsync>($"{METHOD_PATH}?per_page=100&page=1", embed, useAuth).ConfigureAwait(false))?.ToList();
+ List entities = await _httpHelper.GetRequestAsync>($"{METHOD_PATH}?per_page=100&page=1", embed, useAuth).ConfigureAwait(false);
if (_httpHelper.LastResponseHeaders.Contains("X-WP-TotalPages") && Convert.ToInt32(_httpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture) > 1)
{
int totalpages = Convert.ToInt32(_httpHelper.LastResponseHeaders.GetValues("X-WP-TotalPages").FirstOrDefault(), CultureInfo.InvariantCulture);
for (int page = 2; page <= totalpages; page++)
{
- entities.AddRange((await _httpHelper.GetRequestAsync>($"{METHOD_PATH}?per_page=100&page={page}", embed, useAuth).ConfigureAwait(false))?.ToList());
+ entities.AddRange(await _httpHelper.GetRequestAsync>($"{METHOD_PATH}?per_page=100&page={page}", embed, useAuth).ConfigureAwait(false));
}
}
return entities;
@@ -108,8 +108,8 @@ public Task> QueryAsync(UsersQueryBuilder queryBuilder, bool useAuth
/// Updated object
public async Task UpdateAsync(User Entity)
{
- var entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(Entity) : JsonConvert.SerializeObject(Entity, _httpHelper.JsonSerializerSettings);
- using var postBody = new StringContent(entity, Encoding.UTF8, "application/json");
+ string entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(Entity) : JsonConvert.SerializeObject(Entity, _httpHelper.JsonSerializerSettings);
+ using StringContent postBody = new(entity, Encoding.UTF8, "application/json");
return (await _httpHelper.PostRequestAsync($"{METHOD_PATH}/{Entity?.Id}", postBody).ConfigureAwait(false)).Item1;
}
@@ -159,8 +159,8 @@ public Task Delete(int ID, User ReassignUser)
public async Task CreateApplicationPasswordAsync(string applicationName, string userId = "me")
{
var body = new { name = applicationName };
- var entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(body) : JsonConvert.SerializeObject(body, _httpHelper.JsonSerializerSettings);
- using var postBody = new StringContent(entity, Encoding.UTF8, "application/json");
+ string entity = _httpHelper.JsonSerializerSettings == null ? JsonConvert.SerializeObject(body) : JsonConvert.SerializeObject(body, _httpHelper.JsonSerializerSettings);
+ using StringContent postBody = new(entity, Encoding.UTF8, "application/json");
return (await _httpHelper.PostRequestAsync($"{METHOD_PATH}/{userId}/{APPLICATION_PASSWORDS_PATH}", postBody, true).ConfigureAwait(false)).Item1;
}
@@ -176,4 +176,4 @@ public Task> GetApplicationPasswords(string userId = "
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Models/Embedded.cs b/WordPressPCL/Models/Embedded.cs
index 74955ac..5e137e5 100644
--- a/WordPressPCL/Models/Embedded.cs
+++ b/WordPressPCL/Models/Embedded.cs
@@ -1,5 +1,5 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using Newtonsoft.Json;
namespace WordPressPCL.Models
{
@@ -12,29 +12,29 @@ public class Embedded
/// Post Author
///
[JsonProperty("author")]
- public IEnumerable Author { get; set; }
+ public List Author { get; set; }
///
/// Comments on the post
///
[JsonProperty("replies")]
- public IEnumerable> Replies { get; set; }
+ public List> Replies { get; set; }
///
/// Featured images for the post
///
[JsonProperty("wp:featuredmedia")]
- public IEnumerable WpFeaturedmedia { get; set; }
+ public List WpFeaturedmedia { get; set; }
///
/// Terms for the post (categories, tags etc.)
///
[JsonProperty("wp:term")]
- public IEnumerable> WpTerm { get; set; }
+ public List> WpTerm { get; set; }
///
/// Parent page
///
[JsonProperty("up")]
- public IEnumerable Up { get; set; }
+ public List Up { get; set; }
}
}
diff --git a/WordPressPCL/Models/JWTData.cs b/WordPressPCL/Models/JWTData.cs
index 1462740..a19fb4d 100644
--- a/WordPressPCL/Models/JWTData.cs
+++ b/WordPressPCL/Models/JWTData.cs
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
-using System;
namespace WordPressPCL.Models
{
diff --git a/WordPressPCL/Models/Links.cs b/WordPressPCL/Models/Links.cs
index 632932c..1b822a4 100644
--- a/WordPressPCL/Models/Links.cs
+++ b/WordPressPCL/Models/Links.cs
@@ -1,5 +1,5 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using Newtonsoft.Json;
namespace WordPressPCL.Models
{
@@ -12,58 +12,68 @@ public class Links
/// Self link
///
[JsonProperty("self")]
- public IEnumerable Self { get; set; }
+ public List Self { get; set; }
+
///
/// Collection of links
///
///
[JsonProperty("collection")]
- public IEnumerable Collection { get; set; }
+ public List Collection { get; set; }
+
///
/// About info
///
///
[JsonProperty("about")]
- public IEnumerable About { get; set; }
+ public List About { get; set; }
+
///
/// WordPress post Type
///
[JsonProperty("wp:post_type")]
- public IEnumerable WpPostType { get; set; }
+ public List WpPostType { get; set; }
+
///
/// Curries
///
[JsonProperty("curies")]
- public IEnumerable Curies { get; set; }
+ public List Curies { get; set; }
+
///
/// Author
///
[JsonProperty("author")]
- public IEnumerable Author { get; set; }
+ public List Author { get; set; }
+
///
/// Replies
///
[JsonProperty("replies")]
- public IEnumerable Replies { get; set; }
+ public List Replies { get; set; }
+
///
/// Versions
///
[JsonProperty("version-history")]
- public IEnumerable Versions { get; set; }
+ public List Versions { get; set; }
+
///
/// Attachment
///
[JsonProperty("wp:attachment")]
- public IEnumerable Attachment { get; set; }
+ public List Attachment { get; set; }
+
///
/// Featured media
///
[JsonProperty("wp:featuredmedia")]
- public IEnumerable FeaturedMedia { get; set; }
+ public List FeaturedMedia { get; set; }
+
///
/// Featured media
///
[JsonProperty("wp:term")]
- public IEnumerable Term { get; set; }
+ public List Term { get; set; }
}
}
diff --git a/WordPressPCL/Models/PostType.cs b/WordPressPCL/Models/PostType.cs
index eb4d606..7549252 100644
--- a/WordPressPCL/Models/PostType.cs
+++ b/WordPressPCL/Models/PostType.cs
@@ -1,5 +1,5 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using Newtonsoft.Json;
namespace WordPressPCL.Models
{
@@ -34,7 +34,7 @@ public class PostType
///
/// Context: edit
[JsonProperty("labels")]
- public IEnumerable Labels { get; set; }
+ public List Labels { get; set; }
///
/// The title for the taxonomy.
@@ -62,7 +62,7 @@ public class PostType
///
/// Context: edit
[JsonProperty("taxonomies")]
- public IEnumerable Taxonomies { get; set; }
+ public List Taxonomies { get; set; }
///
/// REST base route for the taxonomy.
@@ -84,4 +84,4 @@ public PostType()
{
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Models/Taxonomy.cs b/WordPressPCL/Models/Taxonomy.cs
index 7a780ee..c54b0dc 100644
--- a/WordPressPCL/Models/Taxonomy.cs
+++ b/WordPressPCL/Models/Taxonomy.cs
@@ -1,5 +1,5 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using Newtonsoft.Json;
namespace WordPressPCL.Models
{
@@ -34,7 +34,7 @@ public class Taxonomy
///
/// Context: edit
[JsonProperty("labels")]
- public IEnumerable Labels { get; set; }
+ public List Labels { get; set; }
///
/// The title for the taxonomy.
@@ -62,7 +62,7 @@ public class Taxonomy
///
/// Context: view, edit
[JsonProperty("types")]
- public IEnumerable Types { get; set; }
+ public List Types { get; set; }
///
/// REST base route for the taxonomy.
@@ -84,4 +84,4 @@ public Taxonomy()
{
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Models/Theme.cs b/WordPressPCL/Models/Theme.cs
index 3018b12..477c396 100644
--- a/WordPressPCL/Models/Theme.cs
+++ b/WordPressPCL/Models/Theme.cs
@@ -1,7 +1,5 @@
using Newtonsoft.Json;
using System;
-using System.Collections.Generic;
-using System.Text;
namespace WordPressPCL.Models
{
diff --git a/WordPressPCL/Models/User.cs b/WordPressPCL/Models/User.cs
index e7290eb..5597e8b 100644
--- a/WordPressPCL/Models/User.cs
+++ b/WordPressPCL/Models/User.cs
@@ -1,6 +1,6 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
+using Newtonsoft.Json;
using WordPressPCL.Utility;
namespace WordPressPCL.Models
@@ -104,7 +104,7 @@ public class User : Base
///
/// Context: edit
[JsonProperty("roles", DefaultValueHandling = DefaultValueHandling.Ignore)]
- public IEnumerable Roles { get; set; }
+ public List Roles { get; set; }
///
/// Password for the user (never included).
@@ -124,7 +124,7 @@ public class User : Base
/// Any extra capabilities assigned to the user.
///
/// Context: edit
- [JsonProperty("extra_capabilities", DefaultValueHandling = DefaultValueHandling.Ignore, ItemConverterType = typeof (CustomCapabilitiesJsonConverter))]
+ [JsonProperty("extra_capabilities", DefaultValueHandling = DefaultValueHandling.Ignore, ItemConverterType = typeof(CustomCapabilitiesJsonConverter))]
public IDictionary ExtraCapabilities { get; set; }
///
@@ -170,4 +170,4 @@ public User()
{
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Utility/CommentsQueryBuilder.cs b/WordPressPCL/Utility/CommentsQueryBuilder.cs
index 3070aa2..7c16ca6 100644
--- a/WordPressPCL/Utility/CommentsQueryBuilder.cs
+++ b/WordPressPCL/Utility/CommentsQueryBuilder.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Text;
using WordPressPCL.Models;
namespace WordPressPCL.Utility
diff --git a/WordPressPCL/Utility/HttpHelper.cs b/WordPressPCL/Utility/HttpHelper.cs
index 10156b3..8d71881 100644
--- a/WordPressPCL/Utility/HttpHelper.cs
+++ b/WordPressPCL/Utility/HttpHelper.cs
@@ -1,10 +1,10 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Newtonsoft.Json;
using WordPressPCL.Models;
using WordPressPCL.Models.Exceptions;
@@ -98,30 +98,37 @@ public HttpHelper(HttpClient httpClient, string defaultPath, Uri wordpressURI =
internal async Task GetRequestAsync(string route, bool embed, bool isAuthRequired = false, bool ignoreDefaultPath = false)
where TClass : class
- {
+ {
route = BuildRoute(ignoreDefaultPath, route);
string embedParam = "";
if (embed)
{
if (route.Contains("?"))
+ {
embedParam = "&_embed";
+ }
else
+ {
embedParam = "?_embed";
+ }
}
route += embedParam;
HttpResponseMessage response;
- using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, route))
+ using (HttpRequestMessage requestMessage = new(HttpMethod.Get, route))
{
SetAuthHeader(isAuthRequired, requestMessage);
response = await _httpClient.SendAsync(requestMessage).ConfigureAwait(false);
}
LastResponseHeaders = response.Headers;
- var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ string responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
if (HttpResponsePreProcessing != null)
+ {
responseString = HttpResponsePreProcessing(responseString);
+ }
+
return DeserializeJsonResponse(response, responseString);
}
else
@@ -132,10 +139,10 @@ internal async Task GetRequestAsync(string route, bool embed, bo
internal async Task<(TClass, HttpResponseMessage)> PostRequestAsync(string route, HttpContent postBody, bool isAuthRequired = true, bool ignoreDefaultPath = false)
where TClass : class
- {
+ {
route = BuildRoute(ignoreDefaultPath, route);
HttpResponseMessage response;
- using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, route))
+ using (HttpRequestMessage requestMessage = new(HttpMethod.Post, route))
{
SetAuthHeader(isAuthRequired, requestMessage);
requestMessage.Content = postBody;
@@ -143,11 +150,14 @@ internal async Task GetRequestAsync(string route, bool embed, bo
}
LastResponseHeaders = response.Headers;
- var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ string responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
if (HttpResponsePreProcessing != null)
+ {
responseString = HttpResponsePreProcessing(responseString);
+ }
+
return (DeserializeJsonResponse(response, responseString), response);
}
else
@@ -160,14 +170,14 @@ internal async Task DeleteRequestAsync(string route, bool isAuthRequired =
{
route = BuildRoute(ignoreDefaultPath, route);
HttpResponseMessage response;
- using (var requestMessage = new HttpRequestMessage(HttpMethod.Delete, route))
+ using (HttpRequestMessage requestMessage = new(HttpMethod.Delete, route))
{
SetAuthHeader(isAuthRequired, requestMessage);
response = await _httpClient.SendAsync(requestMessage).ConfigureAwait(false);
}
LastResponseHeaders = response.Headers;
- var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ string responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
return true;
@@ -182,7 +192,7 @@ internal async Task HeadRequestAsync(string route, bool isA
{
route = BuildRoute(ignoreDefaultPath, route);
HttpResponseMessage response;
- using (var requestMessage = new HttpRequestMessage(HttpMethod.Head, route))
+ using (HttpRequestMessage requestMessage = new(HttpMethod.Head, route))
{
SetAuthHeader(isAuthRequired, requestMessage);
response = await _httpClient.SendAsync(requestMessage).ConfigureAwait(false);
@@ -207,7 +217,7 @@ private void SetAuthHeader(bool isAuthRequired, HttpRequestMessage requestMessag
}
else if (AuthMethod == AuthMethod.Basic)
{
- var authToken = Encoding.ASCII.GetBytes($"{UserName}:{ApplicationPassword}");
+ byte[] authToken = Encoding.ASCII.GetBytes($"{UserName}:{ApplicationPassword}");
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
}
else
@@ -220,12 +230,16 @@ private void SetAuthHeader(bool isAuthRequired, HttpRequestMessage requestMessag
private string BuildRoute(bool ignoreDefaultPath, string route)
{
if (string.IsNullOrEmpty(route))
+ {
return route;
+ }
- var processedRoute = ignoreDefaultPath ? route : $"{_defaultPath}{route}";
+ string processedRoute = ignoreDefaultPath ? route : $"{_defaultPath}{route}";
if (_baseUri != null)
+ {
processedRoute = $"{_baseUri.AbsoluteUri.TrimEnd('/')}/{processedRoute.TrimStart('/')}";
+ }
return processedRoute;
}
@@ -242,7 +256,7 @@ private TClass DeserializeJsonResponse(HttpResponseMessage response, str
}
catch (JsonReaderException)
{
- var (success, sanitizedResponse) = TryGetResponseFromMalformedResponse(responseString);
+ (bool success, string sanitizedResponse) = TryGetResponseFromMalformedResponse(responseString);
if (!success)
{
throw new WPUnexpectedException(response, responseString);
@@ -259,13 +273,13 @@ private TClass DeserializeJsonResponse(HttpResponseMessage response, str
private static (bool, string) TryGetResponseFromMalformedResponse(string responseString)
{
responseString = responseString.Trim();
- var jsonSingleItemRegex = @"\{""id"":.+\}$";
- var match = Regex.Match(responseString, jsonSingleItemRegex);
+ string jsonSingleItemRegex = @"\{""id"":.+\}$";
+ Match match = Regex.Match(responseString, jsonSingleItemRegex);
if (match.Success)
{
return (true, match.Value);
}
- var jsonCollectionRegex = @"\[({""id"":.+},?)*\]$";
+ string jsonCollectionRegex = @"\[({""id"":.+},?)*\]$";
match = Regex.Match(responseString, jsonCollectionRegex);
if (match.Success)
{
@@ -290,4 +304,4 @@ private static Exception CreateUnexpectedResponseException(HttpResponseMessage r
return new WPException(badrequest.Message, badrequest);
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Utility/PluginsQueryBuilder.cs b/WordPressPCL/Utility/PluginsQueryBuilder.cs
index 7005c82..d046900 100644
--- a/WordPressPCL/Utility/PluginsQueryBuilder.cs
+++ b/WordPressPCL/Utility/PluginsQueryBuilder.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using WordPressPCL.Models;
+using WordPressPCL.Models;
namespace WordPressPCL.Utility
{
diff --git a/WordPressPCL/Utility/QueryBuilder.cs b/WordPressPCL/Utility/QueryBuilder.cs
index 1829edd..40f1baa 100644
--- a/WordPressPCL/Utility/QueryBuilder.cs
+++ b/WordPressPCL/Utility/QueryBuilder.cs
@@ -42,14 +42,14 @@ public abstract class QueryBuilder
/// query HTTP string
public string BuildQuery()
{
- var query = HttpUtility.ParseQueryString(string.Empty);
- foreach (var property in GetType().GetRuntimeProperties())
+ NameValueCollection query = HttpUtility.ParseQueryString(string.Empty);
+ foreach (PropertyInfo property in GetType().GetRuntimeProperties())
{
- var attribute = property.GetCustomAttribute();
- var exclusionAttribute = property.GetCustomAttribute();
+ QueryTextAttribute attribute = property.GetCustomAttribute();
+ ExcludeQueryTextAttribute exclusionAttribute = property.GetCustomAttribute();
if (attribute != null)
{
- var value = GetPropertyValue(property);
+ object value = GetPropertyValue(property);
if (value is null) continue;
if (exclusionAttribute != null && value.ToString().ToLowerInvariant() == exclusionAttribute.ExclusionValue) continue;
@@ -62,8 +62,8 @@ public string BuildQuery()
query.Add(attribute.Text, value.ToString().ToLowerInvariant());
}
}
- var queryString = query.ToString();
- if(queryString.Length > 0)
+ string queryString = query.ToString();
+ if (queryString.Length > 0)
{
queryString = "?" + queryString;
}
@@ -82,17 +82,19 @@ private object GetPropertyValue(object property)
{
if (pi.PropertyType.GetTypeInfo().IsEnum)
{
- var attribute = pi.PropertyType.GetRuntimeField(((Enum)pi.GetValue(this)).ToString()).GetCustomAttribute();
+ EnumMemberAttribute attribute = pi.PropertyType.GetRuntimeField(((Enum)pi.GetValue(this)).ToString()).GetCustomAttribute();
return attribute.Value;
}
- if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) {
- var genericParamOfList = pi.PropertyType.GetGenericArguments()[0];
- var finalListType = typeof(List<>).MakeGenericType(genericParamOfList);
+ if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
+ {
+ Type genericParamOfList = pi.PropertyType.GetGenericArguments()[0];
+ Type finalListType = typeof(List<>).MakeGenericType(genericParamOfList);
dynamic list = Convert.ChangeType(pi.GetValue(this), finalListType, CultureInfo.InvariantCulture);
if (list == null) return null;
- var sb = new StringBuilder();
- foreach (var item in list) {
+ StringBuilder sb = new();
+ foreach (dynamic item in list)
+ {
sb.Append(GetPropertyValue((object)item)).Append(',');
}
return sb.ToString().TrimEnd(',');
@@ -112,7 +114,7 @@ private object GetPropertyValue(object property)
{
if (property.GetType().GetTypeInfo().IsEnum)
{
- var attribute = property.GetType().GetRuntimeField(((Enum)property).ToString()).GetCustomAttribute();
+ EnumMemberAttribute attribute = property.GetType().GetRuntimeField(((Enum)property).ToString()).GetCustomAttribute();
return attribute.Value;
}
if (property.GetType() == typeof(DateTime))
@@ -127,4 +129,4 @@ private object GetPropertyValue(object property)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/WordPressPCL/Utility/ThemesQueryBuilder.cs b/WordPressPCL/Utility/ThemesQueryBuilder.cs
index df920eb..013b68e 100644
--- a/WordPressPCL/Utility/ThemesQueryBuilder.cs
+++ b/WordPressPCL/Utility/ThemesQueryBuilder.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using WordPressPCL.Models;
+using WordPressPCL.Models;
namespace WordPressPCL.Utility
{
diff --git a/WordPressPCL/Utility/ThreadedCommentsHelper.cs b/WordPressPCL/Utility/ThreadedCommentsHelper.cs
index c7f6673..aa803fe 100644
--- a/WordPressPCL/Utility/ThreadedCommentsHelper.cs
+++ b/WordPressPCL/Utility/ThreadedCommentsHelper.cs
@@ -18,25 +18,27 @@ public static class ThreadedCommentsHelper
/// list of comments which will be ordered
/// max hierarchy depth
/// order by descending
- public static List GetThreadedComments(IEnumerable comments, int maxDepth = int.MaxValue, bool isDescending = false)
+ public static List GetThreadedComments(List comments, int maxDepth = int.MaxValue, bool isDescending = false)
{
if (comments == null)
+ {
return null;
+ }
- var threadedCommentsFinal = new List();
- var dateSortedThreadedComments = DateSortedWithDepth(comments, maxDepth, isDescending);
+ List threadedCommentsFinal = new();
+ List dateSortedThreadedComments = DateSortedWithDepth(comments, maxDepth, isDescending);
int lastrun = int.MaxValue;
while (dateSortedThreadedComments.Count > 0)
{
- var thisrun = dateSortedThreadedComments.Count;
+ int thisrun = dateSortedThreadedComments.Count;
if (thisrun == lastrun)
{
// no comments could be moved, abort
break;
}
lastrun = thisrun;
- foreach (var comment in dateSortedThreadedComments)
+ foreach (CommentThreaded comment in dateSortedThreadedComments)
{
if (comment.ParentId == 0)
{
@@ -45,19 +47,19 @@ public static List GetThreadedComments(IEnumerable com
else
{
// is parent already in threadedComments?
- var parentComment = threadedCommentsFinal.Find(x => x.Id == comment.ParentId);
+ CommentThreaded parentComment = threadedCommentsFinal.Find(x => x.Id == comment.ParentId);
if (parentComment != null)
{
- var index = threadedCommentsFinal.IndexOf(parentComment);
+ int index = threadedCommentsFinal.IndexOf(parentComment);
threadedCommentsFinal.Insert(index + 1, comment);
}
}
}
// remove all comments that have been moved to the new sorted list
- foreach (var comment in threadedCommentsFinal)
+ foreach (CommentThreaded comment in threadedCommentsFinal)
{
- var c = dateSortedThreadedComments.Find(x => x.Id == comment.Id);
+ CommentThreaded c = dateSortedThreadedComments.Find(x => x.Id == comment.Id);
if (c != null)
{
dateSortedThreadedComments.Remove(c);
@@ -71,14 +73,14 @@ public static List GetThreadedComments(IEnumerable com
return threadedCommentsFinal;
}
- private static List DateSortedWithDepth(IEnumerable comments, int maxDepth, bool isDescending = false)
+ private static List DateSortedWithDepth(List comments, int maxDepth, bool isDescending = false)
{
- var dateSortedComments = isDescending ? comments.OrderByDescending(x => x.Date).ToList()
+ List dateSortedComments = isDescending ? comments.OrderByDescending(x => x.Date).ToList()
: comments.OrderBy(x => x.Date).ToList();
- var dateSortedthreadedComments = new List();
- foreach (var c in dateSortedComments)
+ List dateSortedthreadedComments = new();
+ foreach (Comment c in dateSortedComments)
{
- var serialized = JsonConvert.SerializeObject(c);
+ string serialized = JsonConvert.SerializeObject(c);
CommentThreaded commentThreaded = JsonConvert.DeserializeObject