-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from CXuesong/net60-cleanup
Code re-format & cleanup
- Loading branch information
Showing
218 changed files
with
25,512 additions
and
26,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
using Xunit; | ||
|
||
// This is a work-around for #11. | ||
// This is a work-around for #11. | ||
// https://github.com/CXuesong/WikiClientLibrary/issues/11 | ||
// We are using Bot Password on CI, which may naturally evade the issue. | ||
|
||
// [assembly: CollectionBehavior(DisableTestParallelization = true)] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace WikiClientLibrary.Tests.UnitTestProject1 | ||
namespace WikiClientLibrary.Tests.UnitTestProject1; | ||
|
||
public enum CISkippedReason | ||
{ | ||
|
||
public enum CISkippedReason | ||
{ | ||
Unknown = 0, | ||
Unstable, | ||
Deprecated, | ||
AgentBlocked | ||
} | ||
Unknown = 0, | ||
Unstable, | ||
Deprecated, | ||
AgentBlocked | ||
|
||
/// <summary> | ||
/// Mark the unit test with <c>CI=Skipped</c> trait. | ||
/// This will cause the test not being executed in CI environment. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
[TraitDiscoverer("WikiClientLibrary.Tests.UnitTestProject1." + nameof(CISkippedTraitDiscoverer), "UnitTestProject1")] | ||
public class CISkippedAttribute : Attribute, ITraitAttribute | ||
{ | ||
} | ||
|
||
public CISkippedReason Reason { get; set; } | ||
/// <summary> | ||
/// Mark the unit test with <c>CI=Skipped</c> trait. | ||
/// This will cause the test not being executed in CI environment. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
[TraitDiscoverer("WikiClientLibrary.Tests.UnitTestProject1." + nameof(CISkippedTraitDiscoverer), "UnitTestProject1")] | ||
public class CISkippedAttribute : Attribute, ITraitAttribute | ||
{ | ||
|
||
} | ||
public CISkippedReason Reason { get; set; } | ||
|
||
public class CISkippedTraitDiscoverer : ITraitDiscoverer | ||
{ | ||
private static readonly KeyValuePair<string, string>[] traits = new[] { new KeyValuePair<string, string>("CI", "Skipped") }; | ||
} | ||
|
||
public class CISkippedTraitDiscoverer : ITraitDiscoverer | ||
{ | ||
|
||
private static readonly KeyValuePair<string, string>[] traits = new[] { new KeyValuePair<string, string>("CI", "Skipped") }; | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) | ||
{ | ||
return traits; | ||
} | ||
/// <inheritdoc /> | ||
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) | ||
{ | ||
return traits; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WikiClientLibrary; | ||
using WikiClientLibrary.Client; | ||
using WikiClientLibrary.Client; | ||
using WikiClientLibrary.Sites; | ||
|
||
namespace WikiClientLibrary.Tests.UnitTestProject1 | ||
namespace WikiClientLibrary.Tests.UnitTestProject1; | ||
|
||
internal static partial class CredentialManager | ||
{ | ||
internal static partial class CredentialManager | ||
{ | ||
/// <summary> | ||
/// The API EntryPoint used for performing page moving/deletion and file uploads. | ||
/// </summary> | ||
public static string? DirtyTestsEntryPointUrl { get; private set; } | ||
|
||
/// <summary> | ||
/// The API EntryPoint used for performing private wiki API tests. | ||
/// </summary> | ||
/// <remarks> | ||
/// A private wiki is a wiki with the following settings | ||
/// <code> | ||
/// $wgGroupPermissions['*']['read'] = false; | ||
/// $wgGroupPermissions['*']['edit'] = false; | ||
/// $wgGroupPermissions['*']['createaccount'] = false; | ||
/// </code> | ||
/// </remarks> | ||
public static string? PrivateWikiTestsEntryPointUrl { get; private set; } | ||
/// <summary> | ||
/// The API EntryPoint used for performing page moving/deletion and file uploads. | ||
/// </summary> | ||
public static string? DirtyTestsEntryPointUrl { get; private set; } | ||
|
||
/// <summary> | ||
/// When implemented in your own credential file, | ||
/// set this property to a function that can login into specific site. | ||
/// You can use <see cref="WikiSite.ApiEndpoint"/> to determine which site to login into. | ||
/// </summary> | ||
private static Func<WikiSite, Task> LoginCoreAsyncHandler { get; set; } = _ => | ||
throw new NotSupportedException( | ||
"To enable login feature, you should set `LoginCoreAsyncHandler` in `Initialize` private function. See http://github.com/cxuesong/WikiClientLibrary for more information."); | ||
/// <summary> | ||
/// The API EntryPoint used for performing private wiki API tests. | ||
/// </summary> | ||
/// <remarks> | ||
/// A private wiki is a wiki with the following settings | ||
/// <code> | ||
/// $wgGroupPermissions['*']['read'] = false; | ||
/// $wgGroupPermissions['*']['edit'] = false; | ||
/// $wgGroupPermissions['*']['createaccount'] = false; | ||
/// </code> | ||
/// </remarks> | ||
public static string? PrivateWikiTestsEntryPointUrl { get; private set; } | ||
|
||
/// <summary> | ||
/// When implemented in your own credential file, | ||
/// set this property to a function that can return a <see cref="WikiSite"/> instance | ||
/// using <see cref="WikiSite(IWikiClient,SiteOptions,string,string)"/> overload | ||
/// to login to the site during initialization. | ||
/// You can use <see cref="SiteOptions.ApiEndpoint"/> to determine which site to login into. | ||
/// </summary> | ||
private static Func<IWikiClient, SiteOptions, Task<WikiSite>> EarlyLoginCoreAsyncHandler { get; set; } = (_, __) => | ||
throw new NotSupportedException( | ||
"To enable login feature, you should set `EarlyLoginCoreAsyncHandler` in `Initialize` private function. See http://github.com/cxuesong/WikiClientLibrary for more information."); | ||
/// <summary> | ||
/// When implemented in your own credential file, | ||
/// set this property to a function that can login into specific site. | ||
/// You can use <see cref="WikiSite.ApiEndpoint"/> to determine which site to login into. | ||
/// </summary> | ||
private static Func<WikiSite, Task> LoginCoreAsyncHandler { get; set; } = _ => | ||
throw new NotSupportedException( | ||
"To enable login feature, you should set `LoginCoreAsyncHandler` in `Initialize` private function. See http://github.com/cxuesong/WikiClientLibrary for more information."); | ||
|
||
/// <summary> | ||
/// Initialize confidential information. | ||
/// </summary> | ||
/// <remarks>You can initialize <see cref="DirtyTestsEntryPointUrl"/> in this method.</remarks> | ||
static partial void Initialize(); | ||
/// <summary> | ||
/// When implemented in your own credential file, | ||
/// set this property to a function that can return a <see cref="WikiSite"/> instance | ||
/// using <see cref="WikiSite(IWikiClient,SiteOptions,string,string)"/> overload | ||
/// to login to the site during initialization. | ||
/// You can use <see cref="SiteOptions.ApiEndpoint"/> to determine which site to login into. | ||
/// </summary> | ||
private static Func<IWikiClient, SiteOptions, Task<WikiSite>> EarlyLoginCoreAsyncHandler { get; set; } = (_, __) => | ||
throw new NotSupportedException( | ||
"To enable login feature, you should set `EarlyLoginCoreAsyncHandler` in `Initialize` private function. See http://github.com/cxuesong/WikiClientLibrary for more information."); | ||
|
||
/// <summary> | ||
/// Use predefined credential routine, login to the specified site. | ||
/// </summary> | ||
public static async Task LoginAsync(WikiSite site) | ||
{ | ||
if (site == null) throw new ArgumentNullException(nameof(site)); | ||
await LoginCoreAsyncHandler(site); | ||
if (!site.AccountInfo.IsUser) | ||
throw new NotSupportedException("Failed to login into: " + site + " . Check your LoginCoreAsyncHandler implementation."); | ||
} | ||
/// <summary> | ||
/// Initialize confidential information. | ||
/// </summary> | ||
/// <remarks>You can initialize <see cref="DirtyTestsEntryPointUrl"/> in this method.</remarks> | ||
static partial void Initialize(); | ||
|
||
/// <summary> | ||
/// Use predefined credential routine, return a logged-in WikiSite instance. | ||
/// </summary> | ||
public static async Task<WikiSite> EarlyLoginAsync(IWikiClient wikiClient, SiteOptions options) | ||
{ | ||
if (wikiClient == null) throw new ArgumentNullException(nameof(wikiClient)); | ||
if (options == null) throw new ArgumentNullException(nameof(options)); | ||
var site = await EarlyLoginCoreAsyncHandler(wikiClient, options); | ||
if (!site.Initialization.IsCompleted) | ||
throw new InvalidOperationException("You forgot to await WikiSite.Initialization in your EarlyLoginCoreAsyncHandler implementation."); | ||
if (site == null) | ||
throw new NotSupportedException("Your EarlyLoginCoreAsyncHandler implementation returned null for site: " + options.ApiEndpoint + "."); | ||
if (!site.AccountInfo.IsUser) | ||
throw new NotSupportedException("Failed to login into: " + site + " . Check your EarlyLoginCoreAsyncHandler implementation."); | ||
return site; | ||
} | ||
/// <summary> | ||
/// Use predefined credential routine, login to the specified site. | ||
/// </summary> | ||
public static async Task LoginAsync(WikiSite site) | ||
{ | ||
if (site == null) throw new ArgumentNullException(nameof(site)); | ||
await LoginCoreAsyncHandler(site); | ||
if (!site.AccountInfo.IsUser) | ||
throw new NotSupportedException("Failed to login into: " + site + " . Check your LoginCoreAsyncHandler implementation."); | ||
} | ||
|
||
static CredentialManager() | ||
{ | ||
Initialize(); | ||
} | ||
/// <summary> | ||
/// Use predefined credential routine, return a logged-in WikiSite instance. | ||
/// </summary> | ||
public static async Task<WikiSite> EarlyLoginAsync(IWikiClient wikiClient, SiteOptions options) | ||
{ | ||
if (wikiClient == null) throw new ArgumentNullException(nameof(wikiClient)); | ||
if (options == null) throw new ArgumentNullException(nameof(options)); | ||
var site = await EarlyLoginCoreAsyncHandler(wikiClient, options); | ||
if (!site.Initialization.IsCompleted) | ||
throw new InvalidOperationException( | ||
"You forgot to await WikiSite.Initialization in your EarlyLoginCoreAsyncHandler implementation."); | ||
if (site == null) | ||
throw new NotSupportedException("Your EarlyLoginCoreAsyncHandler implementation returned null for site: " + | ||
options.ApiEndpoint + "."); | ||
if (!site.AccountInfo.IsUser) | ||
throw new NotSupportedException("Failed to login into: " + site + " . Check your EarlyLoginCoreAsyncHandler implementation."); | ||
return site; | ||
} | ||
|
||
static CredentialManager() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
namespace WikiClientLibrary.Tests.UnitTestProject1; | ||
|
||
namespace WikiClientLibrary.Tests.UnitTestProject1 | ||
public static class Endpoints | ||
{ | ||
public static class Endpoints | ||
{ | ||
|
||
public const string WikipediaTest2 = "https://test2.wikipedia.org/w/api.php"; | ||
public const string WikipediaTest2 = "https://test2.wikipedia.org/w/api.php"; | ||
|
||
/// <summary> | ||
/// WMF beta test site. We only apply the tests that cannot be performed in test2.wikipedia.org (e.g. Flow boards). | ||
/// </summary> | ||
public const string WikipediaBetaEn = "https://en.wikipedia.beta.wmflabs.org/w/api.php"; | ||
/// <summary> | ||
/// WMF beta test site. We only apply the tests that cannot be performed in test2.wikipedia.org (e.g. Flow boards). | ||
/// </summary> | ||
public const string WikipediaBetaEn = "https://en.wikipedia.beta.wmflabs.org/w/api.php"; | ||
|
||
/// <summary> | ||
/// This is NOT a test site so do not make modifications to the site. | ||
/// </summary> | ||
public const string WikipediaEn = "https://en.wikipedia.org/w/api.php"; | ||
/// <summary> | ||
/// This is NOT a test site so do not make modifications to the site. | ||
/// </summary> | ||
public const string WikipediaEn = "https://en.wikipedia.org/w/api.php"; | ||
|
||
/// <summary> | ||
/// This is NOT a test site so do not make modifications to the site. | ||
/// </summary> | ||
public const string WikipediaLzh = "https://zh-classical.wikipedia.org/w/api.php"; | ||
/// <summary> | ||
/// This is NOT a test site so do not make modifications to the site. | ||
/// </summary> | ||
public const string WikipediaLzh = "https://zh-classical.wikipedia.org/w/api.php"; | ||
|
||
public const string WikimediaCommonsBeta = "https://commons.wikimedia.beta.wmflabs.org/w/api.php"; | ||
public const string WikimediaCommonsBeta = "https://commons.wikimedia.beta.wmflabs.org/w/api.php"; | ||
|
||
public const string Wikidata = "https://www.wikidata.org/w/api.php"; | ||
public const string Wikidata = "https://www.wikidata.org/w/api.php"; | ||
|
||
public const string WikidataTest = "https://test.wikidata.org/w/api.php"; | ||
public const string WikidataTest = "https://test.wikidata.org/w/api.php"; | ||
|
||
public const string WikidataBeta = "https://wikidata.beta.wmflabs.org/w/api.php"; | ||
public const string WikidataBeta = "https://wikidata.beta.wmflabs.org/w/api.php"; | ||
|
||
// Suggested by KockaAdmiralac. | ||
// It's on MW 1.33 now. Well. | ||
public const string WikiaTest = "https://dman.fandom.com/api.php"; | ||
// Suggested by KockaAdmiralac. | ||
// It's on MW 1.33 now. Well. | ||
public const string WikiaTest = "https://dman.fandom.com/api.php"; | ||
|
||
// It's on MW 1.19 as of now. | ||
public const string TFWiki = "https://tfwiki.net/api.php"; | ||
// It's on MW 1.19 as of now. | ||
public const string TFWiki = "https://tfwiki.net/api.php"; | ||
|
||
public const string RuWarriorsWiki = "https://warriors-cats.fandom.com/ru/api.php"; | ||
public const string RuWarriorsWiki = "https://warriors-cats.fandom.com/ru/api.php"; | ||
|
||
public const string LolEsportsWiki = "https://lol.fandom.com/api.php"; | ||
public const string LolEsportsWiki = "https://lol.fandom.com/api.php"; | ||
|
||
} | ||
} |
Oops, something went wrong.