diff --git a/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj b/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj index 905f922..b0aa591 100644 --- a/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj +++ b/src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj @@ -8,13 +8,13 @@ true - - - - - - - - + + + + + + + + diff --git a/src/CrossWikiEditor.Core/GlobalUsings.cs b/src/CrossWikiEditor.Core/GlobalUsings.cs index 9140024..270ac56 100644 --- a/src/CrossWikiEditor.Core/GlobalUsings.cs +++ b/src/CrossWikiEditor.Core/GlobalUsings.cs @@ -2,7 +2,6 @@ global using System.Collections.Immutable; global using System.Collections.ObjectModel; global using System.Collections.Specialized; - global using System.ComponentModel; global using System.Globalization; global using System.Security.Cryptography; @@ -11,12 +10,10 @@ global using System.Web; global using System.Xml; global using System.Xml.Serialization; - global using CommunityToolkit.Mvvm.ComponentModel; global using CommunityToolkit.Mvvm.Input; global using CommunityToolkit.Mvvm.Messaging; global using CommunityToolkit.Mvvm.Messaging.Messages; - global using CrossWikiEditor.Core.ListProviders; global using CrossWikiEditor.Core.ListProviders.BaseListProviders; global using CrossWikiEditor.Core.Messages; @@ -33,10 +30,8 @@ global using CrossWikiEditor.Core.ViewModels.ReportViewModels; global using CrossWikiEditor.Core.WikiClientLibraryUtils; global using CrossWikiEditor.Core.WikiClientLibraryUtils.Generators; - global using HtmlAgilityPack; global using Serilog; - global using WikiClientLibrary; global using WikiClientLibrary.Client; global using WikiClientLibrary.Generators; diff --git a/src/CrossWikiEditor.Core/IDialog.cs b/src/CrossWikiEditor.Core/IDialog.cs index 679ec8a..2ffa37f 100644 --- a/src/CrossWikiEditor.Core/IDialog.cs +++ b/src/CrossWikiEditor.Core/IDialog.cs @@ -2,8 +2,8 @@ public interface IDialog { - void Close(object? dialogResult); object? DataContext { get; set; } + void Close(object? dialogResult); } public interface IOwner; \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllCategoriesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllCategoriesListProvider.cs index a6f2a01..b2ea040 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllCategoriesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllCategoriesListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllCategoriesListProvider(ICategoryService categoryService, +public sealed class AllCategoriesListProvider( + ICategoryService categoryService, IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { @@ -8,6 +9,8 @@ public sealed class AllCategoriesListProvider(ICategoryService categoryService, public override string ParamTitle => "Start from"; public override bool CanMake => true; - public override async Task>> MakeList(int limit) => - await categoryService.GetAllCategories(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await categoryService.GetAllCategories(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllFilesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllFilesListProvider.cs index 079145e..061a497 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllFilesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllFilesListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllFilesListProvider(IDialogService dialogService, +public sealed class AllFilesListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { @@ -8,6 +9,8 @@ public sealed class AllFilesListProvider(IDialogService dialogService, public override string ParamTitle => "Start from"; public override bool CanMake => true; - public override async Task>> MakeList(int limit) => - await pageService.GetAllFiles(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetAllFiles(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllPagesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllPagesListProvider.cs index 057adc1..43b1f4a 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllPagesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllPagesListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllPagesListProvider(IDialogService dialogService, +public sealed class AllPagesListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService) { public override string Title => "All Pages"; - public override async Task>> MakeList(int limit) => - await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.Disable); + public override async Task>> MakeList(int limit) + { + return await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.Disable); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllPagesNoRedirectsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllPagesNoRedirectsListProvider.cs index 6d008dd..922323d 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllPagesNoRedirectsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllPagesNoRedirectsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllPagesNoRedirectsListProvider(IDialogService dialogService, +public sealed class AllPagesNoRedirectsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService) { public override string Title => "All Pages (no redirects)"; - public override async Task>> MakeList(int limit) => - await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.Disable); + public override async Task>> MakeList(int limit) + { + return await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.Disable); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllPagesWithPrefixListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllPagesWithPrefixListProvider.cs index fd0c7ae..df7ec97 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllPagesWithPrefixListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllPagesWithPrefixListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllPagesWithPrefixListProvider(IDialogService dialogService, +public sealed class AllPagesWithPrefixListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedNamespacesListProvider @@ -8,10 +9,15 @@ public sealed class AllPagesWithPrefixListProvider(IDialogService dialogService, private int[]? _namespaces; public override string Title => "All Pages with prefix (Prefixindex)"; public override string ParamTitle => "Prefix"; - public override bool CanMake => _namespaces is { Length: 1 }; + public override bool CanMake => _namespaces is {Length: 1}; - public async Task GetAdditionalParams() => _namespaces = await this.GetNamespaces(isMultiselect: false, DialogService, viewModelFactory); + public async Task GetAdditionalParams() + { + _namespaces = await this.GetNamespaces(false, DialogService, viewModelFactory); + } - public override async Task>> MakeList(int limit) => - await pageService.GetAllPagesWithPrefix(settingsService.CurrentApiUrl, Param, _namespaces![0], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetAllPagesWithPrefix(settingsService.CurrentApiUrl, Param, _namespaces![0], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllRedirectsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllRedirectsListProvider.cs index feca780..97a2af7 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllRedirectsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllRedirectsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllRedirectsListProvider(IDialogService dialogService, +public sealed class AllRedirectsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService) { public override string Title => "All Redirects"; - public override async Task>> MakeList(int limit) => - await MakeListBase(limit, PropertyFilterOption.WithProperty, PropertyFilterOption.Disable); + public override async Task>> MakeList(int limit) + { + return await MakeListBase(limit, PropertyFilterOption.WithProperty, PropertyFilterOption.Disable); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/AllUsersListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/AllUsersListProvider.cs index 3d4138a..9714ede 100644 --- a/src/CrossWikiEditor.Core/ListProviders/AllUsersListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/AllUsersListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class AllUsersListProvider(IDialogService dialogService, +public sealed class AllUsersListProvider( + IDialogService dialogService, ISettingsService settingsService, IUserService userService) : LimitedListProviderBase(dialogService) { public override string Title => "All Users"; public override string ParamTitle => "Start from"; - public override async Task>> MakeList(int limit) => - await userService.GetAllUsers(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await userService.GetAllUsers(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/AllPagesListProviderBase.cs b/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/AllPagesListProviderBase.cs index 19736d7..617e891 100644 --- a/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/AllPagesListProviderBase.cs +++ b/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/AllPagesListProviderBase.cs @@ -8,13 +8,17 @@ public abstract class AllPagesListProviderBase( { private int[]? _namespaces; public override string ParamTitle => "Start from"; - public override bool CanMake => _namespaces is { Length: 1 }; - public async Task GetAdditionalParams() => _namespaces = await this.GetNamespaces(isMultiselect: false, DialogService, viewModelFactory); + public override bool CanMake => _namespaces is {Length: 1}; + + public async Task GetAdditionalParams() + { + _namespaces = await this.GetNamespaces(false, DialogService, viewModelFactory); + } protected async Task>> MakeListBase(int limit, PropertyFilterOption redirectsFilter, PropertyFilterOption langLinksFilter) { return await pageService.GetAllPages(settingsService.CurrentApiUrl, Param, _namespaces![0], - redirectsFilter: redirectsFilter, langLinksFilter: langLinksFilter, limit); + redirectsFilter, langLinksFilter, limit); } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/LimitedListProviderBase.cs b/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/LimitedListProviderBase.cs index 27327bb..88f033f 100644 --- a/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/LimitedListProviderBase.cs +++ b/src/CrossWikiEditor.Core/ListProviders/BaseListProviders/LimitedListProviderBase.cs @@ -9,6 +9,7 @@ public interface ILimitedListProvider : IListProvider public abstract class LimitedListProviderBase(IDialogService dialogService) : ListProviderBase, ILimitedListProvider { protected IDialogService DialogService => dialogService; + public async Task GetLimit() { return await dialogService.ShowDialog(new PromptViewModel("How many page", "Limit: ") diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageListProvider.cs index 64ee59f..06ead61 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageListProvider.cs @@ -10,6 +10,8 @@ public class CategoriesOnPageListProvider( public override string Title => "Categories on page"; public override string ParamTitle => "Page"; - public override async Task>> MakeList(int limit) => - await categoryService.GetCategoriesOf(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await categoryService.GetCategoriesOf(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageNoHiddenCategoriesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageNoHiddenCategoriesListProvider.cs index ab58504..bbbeebf 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageNoHiddenCategoriesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageNoHiddenCategoriesListProvider.cs @@ -7,6 +7,8 @@ public sealed class CategoriesOnPageNoHiddenCategoriesListProvider( { public override string Title => "Categories on page (no hidden categories)"; - public override async Task>> MakeList(int limit) => - await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, includeHidden: false); + public override async Task>> MakeList(int limit) + { + return await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, false); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProvider.cs index ad532bc..0a57e92 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProvider.cs @@ -7,6 +7,8 @@ public sealed class CategoriesOnPageOnlyHiddenCategoriesListProvider( { public override string Title => "Categories on page (only hidden categories)"; - public override async Task>> MakeList(int limit) => - await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, onlyHidden: true); + public override async Task>> MakeList(int limit) + { + return await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, onlyHidden: true); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoryListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoryListProvider.cs index ae3a3f4..e2982e0 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoryListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoryListProvider.cs @@ -1,11 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class CategoryListProvider(ICategoryService categoryService, - IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) +public sealed class CategoryListProvider( + ICategoryService categoryService, + IDialogService dialogService, + ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Category"; public override string ParamTitle => "Category"; - public override async Task>> MakeList(int limit) => - await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursive1LevelListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursive1LevelListProvider.cs index 3fe2722..d1f38af 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursive1LevelListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursive1LevelListProvider.cs @@ -1,11 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class CategoryRecursive1LevelListProvider(ICategoryService categoryService, - IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) +public sealed class CategoryRecursive1LevelListProvider( + ICategoryService categoryService, + IDialogService dialogService, + ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Category (recursive 1 level)"; public override string ParamTitle => "Category"; - public override async Task>> MakeList(int limit) => - await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, 1); + public override async Task>> MakeList(int limit) + { + return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, 1); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveListProvider.cs index ac5b74b..64c5965 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveListProvider.cs @@ -1,11 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class CategoryRecursiveListProvider(ICategoryService categoryService, - IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) +public sealed class CategoryRecursiveListProvider( + ICategoryService categoryService, + IDialogService dialogService, + ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Category (recursive)"; public override string ParamTitle => "Category"; - public override async Task>> MakeList(int limit) => - await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, Int32.MaxValue); + public override async Task>> MakeList(int limit) + { + return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, int.MaxValue); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveUserDefinedLevelListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveUserDefinedLevelListProvider.cs index 4483d8b..dcba188 100644 --- a/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveUserDefinedLevelListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/CategoryRecursiveUserDefinedLevelListProvider.cs @@ -1,8 +1,9 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class CategoryRecursiveUserDefinedLevelListProvider(ICategoryService categoryService, - IDialogService dialogService, - ISettingsService settingsService) +public sealed class CategoryRecursiveUserDefinedLevelListProvider( + ICategoryService categoryService, + IDialogService dialogService, + ISettingsService settingsService) : LimitedListProviderBase(dialogService), INeedAdditionalParamsListProvider { private int? _recursionLevel; @@ -11,19 +12,6 @@ public sealed class CategoryRecursiveUserDefinedLevelListProvider(ICategoryServi public override string ParamTitle => "Category"; public override bool CanMake => _recursionLevel is not null && !string.IsNullOrWhiteSpace(Param); - public override async Task>> MakeList(int limit) - { - if (_recursionLevel is null) - { - return new Exception("Please select recursive level."); - } - - UserSettings userSettings = settingsService.GetCurrentSettings(); - Result> result = await categoryService.GetPagesOfCategory(userSettings.GetApiUrl(), Param, limit, (int) _recursionLevel); - _recursionLevel = null; - return result; - } - public async Task GetAdditionalParams() { int? result = await DialogService.ShowDialog(new PromptViewModel("Number", "Recursion depth: ") @@ -36,4 +24,17 @@ public async Task GetAdditionalParams() _recursionLevel = result; } } + + public override async Task>> MakeList(int limit) + { + if (_recursionLevel is null) + { + return new Exception("Please select recursive level."); + } + + UserSettings userSettings = settingsService.GetCurrentSettings(); + Result> result = await categoryService.GetPagesOfCategory(userSettings.GetApiUrl(), Param, limit, (int) _recursionLevel); + _recursionLevel = null; + return result; + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/DisambiguationPagesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/DisambiguationPagesListProvider.cs index fdc7ae9..1a643d3 100644 --- a/src/CrossWikiEditor.Core/ListProviders/DisambiguationPagesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/DisambiguationPagesListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class DisambiguationPagesListProvider(IDialogService dialogService, +public sealed class DisambiguationPagesListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { @@ -8,6 +9,8 @@ public sealed class DisambiguationPagesListProvider(IDialogService dialogService public override string ParamTitle => ""; public override bool CanMake => true; - public override async Task>> MakeList(int limit) => - await pageService.GetPagesWithProp(settingsService.CurrentApiUrl, "disambiguation", limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetPagesWithProp(settingsService.CurrentApiUrl, "disambiguation", limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/FilesOnPageListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/FilesOnPageListProvider.cs index eda1f75..105e325 100644 --- a/src/CrossWikiEditor.Core/ListProviders/FilesOnPageListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/FilesOnPageListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class FilesOnPageListProvider(IDialogService dialogService, +public sealed class FilesOnPageListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Files on page"; public override string ParamTitle => "Files on"; - public override async Task>> MakeList(int limit) => - await pageService.FilesOnPage(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.FilesOnPage(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/HTMLScraperListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/HTMLScraperListProvider.cs index dfd54f5..0e3f716 100644 --- a/src/CrossWikiEditor.Core/ListProviders/HTMLScraperListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/HTMLScraperListProvider.cs @@ -1,6 +1,9 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class HtmlScraperListProvider(HtmlAgilityPackParser htmlAgilityPackParser, IHttpClientFactory httpClientFactory, ILogger logger, +public sealed class HtmlScraperListProvider( + HtmlAgilityPackParser htmlAgilityPackParser, + IHttpClientFactory httpClientFactory, + ILogger logger, SimpleHtmlParser simpleHtmlParser) : UnlimitedListProviderBase { public override string Title => "HTML Scraper"; diff --git a/src/CrossWikiEditor.Core/ListProviders/ImageFileLinksListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/ImageFileLinksListProvider.cs index dd01a5a..8af4b7a 100644 --- a/src/CrossWikiEditor.Core/ListProviders/ImageFileLinksListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/ImageFileLinksListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class ImageFileLinksListProvider(IDialogService dialogService, +public sealed class ImageFileLinksListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Image file links"; public override string ParamTitle => "File"; - public override async Task>> MakeList(int limit) => - await pageService.GetPagesByFileUsage(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetPagesByFileUsage(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/LinkSearchListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/LinkSearchListProvider.cs index 5318647..ce9e891 100644 --- a/src/CrossWikiEditor.Core/ListProviders/LinkSearchListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/LinkSearchListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class LinkSearchListProvider(IDialogService dialogService, +public sealed class LinkSearchListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Link search"; public override string ParamTitle => "URL"; - public override async Task>> MakeList(int limit) => - await pageService.LinkSearch(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.LinkSearch(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageBlueListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageBlueListProvider.cs index 6f1a5b8..bcc4ce4 100644 --- a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageBlueListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageBlueListProvider.cs @@ -1,8 +1,9 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class LinksOnPageBlueListProvider(IDialogService dialogService, - IPageService pageService, - ISettingsService settingsService) +public sealed class LinksOnPageBlueListProvider( + IDialogService dialogService, + IPageService pageService, + ISettingsService settingsService) : LinksOnPageListProvider(dialogService, pageService, settingsService) { public override string Title => "Links on page (only bluelinks)"; @@ -10,7 +11,7 @@ public sealed class LinksOnPageBlueListProvider(IDialogService dialogService, public override async Task>> MakeList(int limit) { Result> result = await base.MakeList(limit); - if (result is not { IsSuccessful: true, Value: not null }) + if (result is not {IsSuccessful: true, Value: not null}) { return result; } diff --git a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageListProvider.cs index eb7932b..d44a496 100644 --- a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public class LinksOnPageListProvider(IDialogService dialogService, +public class LinksOnPageListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Links on page"; public override string ParamTitle => "Links on"; - public override async Task>> MakeList(int limit) => - await pageService.LinksOnPage(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.LinksOnPage(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageRedListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageRedListProvider.cs index 47923dd..1c365c1 100644 --- a/src/CrossWikiEditor.Core/ListProviders/LinksOnPageRedListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/LinksOnPageRedListProvider.cs @@ -1,8 +1,9 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class LinksOnPageRedListProvider(IDialogService dialogService, - IPageService pageService, - ISettingsService settingsService) +public sealed class LinksOnPageRedListProvider( + IDialogService dialogService, + IPageService pageService, + ISettingsService settingsService) : LinksOnPageListProvider(dialogService, pageService, settingsService) { public override string Title => "Links on page (only redlinks)"; @@ -10,7 +11,7 @@ public sealed class LinksOnPageRedListProvider(IDialogService dialogService, public override async Task>> MakeList(int limit) { Result> result = await base.MakeList(limit); - if (result is not { IsSuccessful: true, Value: not null }) + if (result is not {IsSuccessful: true, Value: not null}) { return result; } diff --git a/src/CrossWikiEditor.Core/ListProviders/MyWatchlistListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/MyWatchlistListProvider.cs index cebda2f..cc6b22c 100644 --- a/src/CrossWikiEditor.Core/ListProviders/MyWatchlistListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/MyWatchlistListProvider.cs @@ -6,5 +6,8 @@ public sealed class MyWatchlistListProvider(IDialogService dialogService, IUserS public override string ParamTitle => string.Empty; public override bool CanMake => true; - public override async Task>> MakeList(int limit) => await userService.GetWatchlistPages(limit); + public override async Task>> MakeList(int limit) + { + return await userService.GetWatchlistPages(limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/NewPagesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/NewPagesListProvider.cs index 6dd3eae..1bd566f 100644 --- a/src/CrossWikiEditor.Core/ListProviders/NewPagesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/NewPagesListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class NewPagesListProvider(IDialogService dialogService, +public sealed class NewPagesListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedNamespacesListProvider @@ -8,10 +9,15 @@ public sealed class NewPagesListProvider(IDialogService dialogService, private int[]? _namespaces; public override string Title => "New pages"; public override string ParamTitle => string.Empty; - public override bool CanMake => _namespaces is { Length: > 0 }; + public override bool CanMake => _namespaces is {Length: > 0}; - public async Task GetAdditionalParams() => _namespaces = await this.GetNamespaces(true, DialogService, viewModelFactory); + public async Task GetAdditionalParams() + { + _namespaces = await this.GetNamespaces(true, DialogService, viewModelFactory); + } - public override async Task>> MakeList(int limit) => - await pageService.GetNewPages(settingsService.CurrentApiUrl, _namespaces!, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetNewPages(settingsService.CurrentApiUrl, _namespaces!, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/PagesWithPropListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/PagesWithPropListProvider.cs index 55f6e48..a64493d 100644 --- a/src/CrossWikiEditor.Core/ListProviders/PagesWithPropListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/PagesWithPropListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class PagesWithPropListProvider(IDialogService dialogService, +public sealed class PagesWithPropListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Pages with a page property"; public override string ParamTitle => "Property name"; - public override async Task>> MakeList(int limit) => - await pageService.GetPagesWithProp(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetPagesWithProp(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksListProvider.cs index 6b7c8fc..3edf768 100644 --- a/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class PagesWithoutLanguageLinksListProvider(IDialogService dialogService, +public sealed class PagesWithoutLanguageLinksListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService) { public override string Title => "Pages without language links"; - public override async Task>> MakeList(int limit) => - await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.WithoutProperty); + public override async Task>> MakeList(int limit) + { + return await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.WithoutProperty); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProvider.cs index 3b5abd4..c3c6484 100644 --- a/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProvider.cs @@ -1,11 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class PagesWithoutLanguageLinksNoRedirectsListProvider(IDialogService dialogService, +public sealed class PagesWithoutLanguageLinksNoRedirectsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService) { public override string Title => "Pages without language links (no redirects)"; - public override async Task>> MakeList(int limit) => - await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty); + + public override async Task>> MakeList(int limit) + { + return await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/PetscanListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/PetscanListProvider.cs index c1fee69..99daf9f 100644 --- a/src/CrossWikiEditor.Core/ListProviders/PetscanListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/PetscanListProvider.cs @@ -1,9 +1,11 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class PetscanListProvider(IHttpClientFactory httpClientFactory, ISettingsService settingsService, IWikiClientCache wikiClientCache) : UnlimitedListProviderBase +public sealed class PetscanListProvider(IHttpClientFactory httpClientFactory, ISettingsService settingsService, IWikiClientCache wikiClientCache) + : UnlimitedListProviderBase { public override string Title => "Petscan"; public override string ParamTitle => "PSID"; + public override async Task>> MakeList() { try diff --git a/src/CrossWikiEditor.Core/ListProviders/ProtectedPagesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/ProtectedPagesListProvider.cs index 8d6bfbf..016f005 100644 --- a/src/CrossWikiEditor.Core/ListProviders/ProtectedPagesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/ProtectedPagesListProvider.cs @@ -1,20 +1,25 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class ProtectedPagesListProvider(IDialogService dialogService, - IPageService pageService, ISettingsService settingsService, +public sealed class ProtectedPagesListProvider( + IDialogService dialogService, + IPageService pageService, + ISettingsService settingsService, IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedAdditionalParamsListProvider { - private string _protectionType = string.Empty; private string _protectionLevel = string.Empty; + private string _protectionType = string.Empty; public override string Title => "Protected pages"; public override string ParamTitle => ""; public override bool CanMake => !string.IsNullOrWhiteSpace(_protectionType) && !string.IsNullOrWhiteSpace(_protectionLevel); public async Task GetAdditionalParams() { - (_protectionType, _protectionLevel) = await DialogService.ShowDialog<(string, string)>(viewModelFactory.GetSelectProtectionSelectionPageViewModel()); + (_protectionType, _protectionLevel) = + await DialogService.ShowDialog<(string, string)>(viewModelFactory.GetSelectProtectionSelectionPageViewModel()); } - public override async Task>> MakeList(int limit) => - await pageService.GetProtectedPages(settingsService.CurrentApiUrl, _protectionType, _protectionLevel, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetProtectedPages(settingsService.CurrentApiUrl, _protectionType, _protectionLevel, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/RandomListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/RandomListProvider.cs index b597f94..58d32c6 100644 --- a/src/CrossWikiEditor.Core/ListProviders/RandomListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/RandomListProvider.cs @@ -1,9 +1,10 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class RandomListProvider(IDialogService dialogService, - IPageService pageService, - ISettingsService settingsService, - IViewModelFactory viewModelFactory) +public sealed class RandomListProvider( + IDialogService dialogService, + IPageService pageService, + ISettingsService settingsService, + IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedAdditionalParamsListProvider { private NamespacesAndRedirectFilterOptions? _options; @@ -15,24 +16,25 @@ public async Task GetAdditionalParams() { NamespacesAndRedirectFilterOptions? result = await DialogService.ShowDialog( - await viewModelFactory.GetSelectNamespacesAndRedirectFilterViewModel(isIncludeRedirectsVisible: false)); + await viewModelFactory.GetSelectNamespacesAndRedirectFilterViewModel(false)); if (result is not null) { _options = result; } } + public override async Task>> MakeList(int limit) { return await pageService.GetRandomPages( settingsService.CurrentApiUrl, _options!.Namespaces, - filterRedirects: _options.RedirectFilter switch + _options.RedirectFilter switch { RedirectFilter.All => null, RedirectFilter.Redirects => true, RedirectFilter.NoRedirects => false, _ => null }, - limit: limit); + limit); } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/RecentChangesListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/RecentChangesListProvider.cs index 0c43516..ee7d5ab 100644 --- a/src/CrossWikiEditor.Core/ListProviders/RecentChangesListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/RecentChangesListProvider.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class RecentChangesListProvider(IDialogService dialogService, +public sealed class RecentChangesListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService, IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedNamespacesListProvider @@ -8,13 +9,15 @@ public sealed class RecentChangesListProvider(IDialogService dialogService, private int[]? _namespaces; public override string Title => "Recent Changes"; public override string ParamTitle => ""; - public override bool CanMake => _namespaces is { Length: > 0 }; + public override bool CanMake => _namespaces is {Length: > 0}; public async Task GetAdditionalParams() { _namespaces = await this.GetNamespaces(true, DialogService, viewModelFactory); } - public override async Task>> MakeList(int limit) => - await pageService.GetRecentlyChangedPages(settingsService.CurrentApiUrl, _namespaces, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetRecentlyChangedPages(settingsService.CurrentApiUrl, _namespaces, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/TextFileListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/TextFileListProvider.cs index f83ee2f..be72ebf 100644 --- a/src/CrossWikiEditor.Core/ListProviders/TextFileListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/TextFileListProvider.cs @@ -1,9 +1,10 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class TextFileListProvider(IFileDialogService fileDialogService, - ISystemService systemService, - ISettingsService settingsService, - IWikiClientCache wikiClientCache) +public sealed class TextFileListProvider( + IFileDialogService fileDialogService, + ISystemService systemService, + ISettingsService settingsService, + IWikiClientCache wikiClientCache) : UnlimitedListProviderBase, INeedAdditionalParamsListProvider { private readonly List _textFiles = []; @@ -12,6 +13,15 @@ public sealed class TextFileListProvider(IFileDialogService fileDialogService, public override string ParamTitle => string.Empty; public override bool CanMake => _textFiles.Count != 0; + public async Task GetAdditionalParams() + { + string[]? result = await fileDialogService.OpenFilePickerAsync("Select text files to extract pages", true); + if (result is not null) + { + _textFiles.AddRange(result); + } + } + public override async Task>> MakeList() { var titles = new List(); @@ -28,7 +38,7 @@ public override async Task>> MakeList() } else { - titles.AddRange(pageText.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries) + titles.AddRange(pageText.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries) .Where(s => s.Trim().Length != 0) .Select(Tools.RemoveSyntax)); } @@ -39,13 +49,4 @@ public override async Task>> MakeList() _textFiles.Clear(); return result; } - - public async Task GetAdditionalParams() - { - string[]? result = await fileDialogService.OpenFilePickerAsync("Select text files to extract pages", true); - if (result is not null) - { - _textFiles.AddRange(result); - } - } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/TransclusionsOnPageListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/TransclusionsOnPageListProvider.cs index a0e84cd..9c9274a 100644 --- a/src/CrossWikiEditor.Core/ListProviders/TransclusionsOnPageListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/TransclusionsOnPageListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class TransclusionsOnPageListProvider(IDialogService dialogService, +public sealed class TransclusionsOnPageListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Transclusions on page"; public override string ParamTitle => "Transclusions on"; - public override async Task>> MakeList(int limit) => - await pageService.GetTransclusionsOn(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetTransclusionsOn(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/UserContributionsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/UserContributionsListProvider.cs index 3470c9a..1252db6 100644 --- a/src/CrossWikiEditor.Core/ListProviders/UserContributionsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/UserContributionsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class UserContributionsListProvider(IDialogService dialogService, +public sealed class UserContributionsListProvider( + IDialogService dialogService, ISettingsService settingsService, IUserService userService) : LimitedListProviderBase(dialogService) { public override string Title => "User contribs"; public override string ParamTitle => "User"; - public override async Task>> MakeList(int limit) => - await userService.GetUserContributionsPages(settingsService.CurrentApiUrl, Param, limit); + public override async Task>> MakeList(int limit) + { + return await userService.GetUserContributionsPages(settingsService.CurrentApiUrl, Param, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WhatLinksHereListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WhatLinksHereListProvider.cs index a33a97e..1118ee4 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WhatLinksHereListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WhatLinksHereListProvider.cs @@ -1,7 +1,9 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WhatLinksHereListProvider(IDialogService dialogService, - IPageService pageService, ISettingsService settingsService, +public sealed class WhatLinksHereListProvider( + IDialogService dialogService, + IPageService pageService, + ISettingsService settingsService, IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedAdditionalParamsListProvider { private NamespacesAndRedirectFilterOptions? _options; @@ -9,6 +11,17 @@ public sealed class WhatLinksHereListProvider(IDialogService dialogService, public override string ParamTitle => "What links to"; public override bool CanMake => !string.IsNullOrWhiteSpace(Param) && _options is not null; + public async Task GetAdditionalParams() + { + NamespacesAndRedirectFilterOptions? result = + await DialogService.ShowDialog(await viewModelFactory + .GetSelectNamespacesAndRedirectFilterViewModel()); + if (result is not null) + { + _options = result; + } + } + public override async Task>> MakeList(int limit) { return await pageService.GetPagesLinkedTo( @@ -25,14 +38,4 @@ public override async Task>> MakeList(int limit) allowRedirectLinks: _options.IncludeRedirects, limit: limit); } - - public async Task GetAdditionalParams() - { - NamespacesAndRedirectFilterOptions? result = - await DialogService.ShowDialog(await viewModelFactory.GetSelectNamespacesAndRedirectFilterViewModel()); - if (result is not null) - { - _options = result; - } - } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereAllNsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereAllNsListProvider.cs index 7285fe6..f945496 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereAllNsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereAllNsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WhatTranscludesHereAllNsListProvider(IDialogService dialogService, +public sealed class WhatTranscludesHereAllNsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "What transcludes page (all NS)"; public override string ParamTitle => "What embeds"; - public override async Task>> MakeList(int limit) => - await pageService.GetTransclusionsOf(settingsService.CurrentApiUrl, Param, null, limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetTransclusionsOf(settingsService.CurrentApiUrl, Param, null, limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereListProvider.cs index e4563d4..39d6a0e 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WhatTranscludesHereListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WhatTranscludesHereListProvider(IDialogService dialogService, +public sealed class WhatTranscludesHereListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "What transcludes page"; public override string ParamTitle => "What embeds"; - public override async Task>> MakeList(int limit) => - await pageService.GetTransclusionsOf(settingsService.CurrentApiUrl, Param, [0], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.GetTransclusionsOf(settingsService.CurrentApiUrl, Param, [0], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextAllNsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextAllNsListProvider.cs index e3d418e..10d6438 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextAllNsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextAllNsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WikiSearchInTextAllNsListProvider(IDialogService dialogService, +public sealed class WikiSearchInTextAllNsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Wiki search (text) (all NS)"; public override string ParamTitle => "Wiki search"; - public override async Task>> MakeList(int limit) => - await pageService.WikiSearch(settingsService.CurrentApiUrl, Param, [], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.WikiSearch(settingsService.CurrentApiUrl, Param, [], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextListProvider.cs index 10eec49..68d9c5f 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTextListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WikiSearchInTextListProvider(IDialogService dialogService, +public sealed class WikiSearchInTextListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Wiki search (text)"; public override string ParamTitle => "Wiki search"; - public override async Task>> MakeList(int limit) => - await pageService.WikiSearch(settingsService.CurrentApiUrl, Param, [0], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.WikiSearch(settingsService.CurrentApiUrl, Param, [0], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleAllNsListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleAllNsListProvider.cs index f9d08ae..08bd565 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleAllNsListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleAllNsListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WikiSearchInTitleAllNsListProvider(IDialogService dialogService, +public sealed class WikiSearchInTitleAllNsListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Wiki search (title) (all NS)"; public override string ParamTitle => "Wiki search"; - public override async Task>> MakeList(int limit) => - await pageService.WikiSearch(settingsService.CurrentApiUrl, $"intitle:{Param}", [], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.WikiSearch(settingsService.CurrentApiUrl, $"intitle:{Param}", [], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleListProvider.cs b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleListProvider.cs index eb51221..aa97885 100644 --- a/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleListProvider.cs +++ b/src/CrossWikiEditor.Core/ListProviders/WikiSearchInTitleListProvider.cs @@ -1,12 +1,15 @@ namespace CrossWikiEditor.Core.ListProviders; -public sealed class WikiSearchInTitleListProvider(IDialogService dialogService, +public sealed class WikiSearchInTitleListProvider( + IDialogService dialogService, IPageService pageService, ISettingsService settingsService) : LimitedListProviderBase(dialogService) { public override string Title => "Wiki search (title)"; public override string ParamTitle => "Wiki search"; - public override async Task>> MakeList(int limit) => - await pageService.WikiSearch(settingsService.CurrentApiUrl, $"intitle:{Param}", [0], limit); + public override async Task>> MakeList(int limit) + { + return await pageService.WikiSearch(settingsService.CurrentApiUrl, $"intitle:{Param}", [0], limit); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Messages/CurrentSettingsUpdatedMessage.cs b/src/CrossWikiEditor.Core/Messages/CurrentSettingsUpdatedMessage.cs index 81c0f03..85088d8 100644 --- a/src/CrossWikiEditor.Core/Messages/CurrentSettingsUpdatedMessage.cs +++ b/src/CrossWikiEditor.Core/Messages/CurrentSettingsUpdatedMessage.cs @@ -1,4 +1,5 @@ namespace CrossWikiEditor.Core.Messages; + public sealed class CurrentSettingsUpdatedMessage(UserSettings newSettings) : ValueChangedMessage(newSettings) { -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessedMessage.cs b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessedMessage.cs index f7b314e..207586e 100644 --- a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessedMessage.cs +++ b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessedMessage.cs @@ -1,7 +1,7 @@ namespace CrossWikiEditor.Core; /// -/// Message is fired when the local processing is finished and the page is ready to be saved. +/// Message is fired when the local processing is finished and the page is ready to be saved. /// /// public sealed class PageProcessedMessage(WikiPageModel wikiPageModel, bool isSuccessful) diff --git a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessingMessage.cs b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessingMessage.cs index 00c82c6..a584740 100644 --- a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessingMessage.cs +++ b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageProcessingMessage.cs @@ -1,9 +1,9 @@ namespace CrossWikiEditor.Core; /// -/// This message is fired the program starts processing the page (local changes, before saving). +/// This message is fired the program starts processing the page (local changes, before saving). /// public sealed class PageProcessingMessage(WikiPageModel wikiPageModel) { public WikiPageModel Page { get; } = wikiPageModel; -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavedMessage.cs b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavedMessage.cs index 1f78d76..40ba02e 100644 --- a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavedMessage.cs +++ b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavedMessage.cs @@ -1,7 +1,7 @@ namespace CrossWikiEditor.Core; /// -/// Message is fired when the page has been saved. +/// Message is fired when the page has been saved. /// /// public sealed class PageSavedMessage(WikiPageModel wikiPageModel, bool isSuccessful, Exception? exception = null) diff --git a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavingMessage.cs b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavingMessage.cs index 66d32c8..c714856 100644 --- a/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavingMessage.cs +++ b/src/CrossWikiEditor.Core/Messages/PageProcessingMessages/PageSavingMessage.cs @@ -1,9 +1,9 @@ namespace CrossWikiEditor.Core; /// -/// This message is fired the program starts saving the page. +/// This message is fired the program starts saving the page. /// public sealed class PageSavingMessage(WikiPageModel wikiPageModel) { public WikiPageModel Page { get; } = wikiPageModel; -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Models/FilterOptions.cs b/src/CrossWikiEditor.Core/Models/FilterOptions.cs index f7ee6fa..bc139df 100644 --- a/src/CrossWikiEditor.Core/Models/FilterOptions.cs +++ b/src/CrossWikiEditor.Core/Models/FilterOptions.cs @@ -6,7 +6,8 @@ public enum SetOperations Intersection } -public class FilterOptions(IReadOnlyCollection namespacesToKeep, +public class FilterOptions( + IReadOnlyCollection namespacesToKeep, string removeTitlesContaining, string keepTitlesContaining, bool useRegex, @@ -36,7 +37,9 @@ public List PerNamespacesToKeep(IEnumerable pages) public List PerRemoveTitlesContaining(IEnumerable pages) { - return RemoveTitlesContaining != string.Empty ? pages.Where(p => !p.Title.Contains(RemoveTitlesContaining, UseRegex)).ToList() : pages.ToList(); + return RemoveTitlesContaining != string.Empty + ? pages.Where(p => !p.Title.Contains(RemoveTitlesContaining, UseRegex)).ToList() + : pages.ToList(); } public List PerKeepTitlesContaining(IEnumerable pages) @@ -50,15 +53,18 @@ public List PerSetOperation(List pages) { return pages; } + var list = new HashSet(pages); if (SetOperation == SetOperations.SymmetricDifference) { list.ExceptWith(FilterPages); } + if (SetOperation == SetOperations.Intersection) { list.IntersectWith(FilterPages); } + return new List(list); } diff --git a/src/CrossWikiEditor.Core/Models/WikiPageModel.cs b/src/CrossWikiEditor.Core/Models/WikiPageModel.cs index d2a62c9..71036bb 100644 --- a/src/CrossWikiEditor.Core/Models/WikiPageModel.cs +++ b/src/CrossWikiEditor.Core/Models/WikiPageModel.cs @@ -4,6 +4,8 @@ public sealed class WikiPageModel : IEquatable, IComparable _initAsync ??= InitializeAsync(Title, _apiRoot, _wikiClientCache!); + + public int CompareTo(WikiPageModel? other) + { + if (ReferenceEquals(this, other)) + { + return 0; + } + + return ReferenceEquals(null, other) ? 1 : string.CompareOrdinal(Title, other.Title); + } + + public bool Equals(WikiPageModel? other) + { + return this == other; + } + private async Task InitializeAsync(string title, string apiRoot, IWikiClientCache wikiClientCache) { WikiSite site = await wikiClientCache.GetWikiSite(apiRoot); @@ -31,14 +54,6 @@ private async Task InitializeAsync(string title, string apiRoot, IWikiClientCach NamespaceId = _wikiPage.NamespaceId; } - private Task? _initAsync = null; - - public Task InitAsync => _initAsync ??= InitializeAsync(Title, _apiRoot, _wikiClientCache!); - - public string Title { get; } - - public int NamespaceId { get; set; } = 0; - public async Task GetContent() { await InitAsync; @@ -52,7 +67,8 @@ public async Task EditAsync(string content, string summary = "", bool isBo { return false; } - return await _wikiPage.EditAsync(new WikiPageEditOptions() + + return await _wikiPage.EditAsync(new WikiPageEditOptions { Content = content, Summary = summary, @@ -88,11 +104,6 @@ public void Deconstruct(out string title, out int namespaceId) namespaceId = NamespaceId; } - public bool Equals(WikiPageModel? other) - { - return this == other; - } - public override bool Equals(object? obj) { if (obj is WikiPageModel wikiPageModel) @@ -132,14 +143,4 @@ public override string ToString() { return !(left == right); } - - public int CompareTo(WikiPageModel? other) - { - if (ReferenceEquals(this, other)) - { - return 0; - } - - return ReferenceEquals(null, other) ? 1 : string.CompareOrdinal(Title, other.Title); - } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/PageListProcessor.cs b/src/CrossWikiEditor.Core/PageListProcessor.cs index 3a4747e..ba14002 100644 --- a/src/CrossWikiEditor.Core/PageListProcessor.cs +++ b/src/CrossWikiEditor.Core/PageListProcessor.cs @@ -3,9 +3,9 @@ public sealed class PageListProcessor { private readonly IMessengerWrapper _messenger; + private readonly List _pages; private readonly ISettingsService _settingsService; private readonly UserSettings _userSettings; - private readonly List _pages; private bool _isAlive = true; private TaskCompletionSource? _shouldSaveTaskCompletionSource; @@ -40,7 +40,7 @@ public async Task Start() private async Task TreatPage(WikiPageModel page) { - var (initialContent, newContent, replacements) = await ProcessPage(page); + (string? initialContent, string? newContent, List>? replacements) = await ProcessPage(page); if (initialContent is null || newContent is null || replacements is null) { _messenger.Send(new PageSkippedMessage(page, SkipReason.ErrorProcessing)); @@ -91,12 +91,14 @@ private async Task TreatPage(WikiPageModel page) newContent = regex.Replace(newContent, match => { string replacedValue = normalFindAndReplaceRule.ReplaceWith; - replacedValue = Regex.Replace(replacedValue, @"\$([1-9])", groupReference => match.Groups[int.Parse(groupReference.Groups[1].Value)].Value); + replacedValue = Regex.Replace(replacedValue, @"\$([1-9])", + groupReference => match.Groups[int.Parse(groupReference.Groups[1].Value)].Value); replacements.Add(Tuple.Create(match.Value, replacedValue)); return replacedValue; }); } } + _messenger.Send(new PageProcessedMessage(page, true)); return (initialContent, newContent, replacements); } @@ -127,10 +129,8 @@ private string GetSummary(List> replacements) { return string.Join(", ", replacements.Select(tp => $"{tp.Item1} \u2192 {tp.Item2}")) + ", օգտվելով CWE"; } - else - { - return "օգտվելով CWE"; - } + + return "օգտվելով CWE"; } public void Stop() diff --git a/src/CrossWikiEditor.Core/Repositories/SimpleJsonProfileRepository.cs b/src/CrossWikiEditor.Core/Repositories/SimpleJsonProfileRepository.cs index 4f173db..b9408a4 100644 --- a/src/CrossWikiEditor.Core/Repositories/SimpleJsonProfileRepository.cs +++ b/src/CrossWikiEditor.Core/Repositories/SimpleJsonProfileRepository.cs @@ -42,8 +42,9 @@ public static Profile JsonProfileToProfile(JsonProfile realmProfile, IStringEncr } /// -/// Realm is great but we use a tiny fraction of its capabilities and it is responsible for 30% of the final filesize of the app. -/// Write the content on a file instead for now. +/// Realm is great but we use a tiny fraction of its capabilities and it is responsible for 30% of the final filesize +/// of the app. +/// Write the content on a file instead for now. /// public sealed class SimpleJsonProfileRepository(IStringEncryptionService stringEncryptionService) : IProfileRepository { @@ -74,6 +75,7 @@ public void Update(Profile profile) profiles.Remove(p); profiles.Add(profile); } + SaveAll(profiles); } @@ -85,33 +87,35 @@ public List GetAll() { SaveAll([]); } + string json = File.ReadAllText(JsonName); List? jsonProfiles = JsonSerializer.Deserialize>(json); return jsonProfiles is null ? [] : jsonProfiles.ConvertAll(p => Mapper.JsonProfileToProfile(p, stringEncryptionService)); } } + public void Delete(int id) + { + List profiles = GetAll(); + Profile? p = profiles.Find(p => p.Id == id); + if (p is not null) + { + profiles.Remove(p); + } + + SaveAll(profiles); + } + private void SaveAll(List profiles) { lock (_profileJsonLock) { List jsonProfiles = profiles.ConvertAll(p => Mapper.ProfileToJsonProfile(p, stringEncryptionService)); - string json = JsonSerializer.Serialize(jsonProfiles, new JsonSerializerOptions() + string json = JsonSerializer.Serialize(jsonProfiles, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(JsonName, json); } } - - public void Delete(int id) - { - List profiles = GetAll(); - Profile? p = profiles.Find(p => p.Id == id); - if (p is not null) - { - profiles.Remove(p); - } - SaveAll(profiles); - } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Services/HtmlParsers/SimpleHtmlParser.cs b/src/CrossWikiEditor.Core/Services/HtmlParsers/SimpleHtmlParser.cs index 37d5e0f..70636a0 100644 --- a/src/CrossWikiEditor.Core/Services/HtmlParsers/SimpleHtmlParser.cs +++ b/src/CrossWikiEditor.Core/Services/HtmlParsers/SimpleHtmlParser.cs @@ -1,9 +1,11 @@ namespace CrossWikiEditor.Core.Services.HtmlParsers; -public sealed class SimpleHtmlParser(ILogger logger, ISettingsService settingsService, +public sealed class SimpleHtmlParser( + ILogger logger, + ISettingsService settingsService, IWikiClientCache wikiClientCache) { - readonly char[] _terminationChars = [' ', '\t', '\n', '"', '<', '>', '{', '}', '&']; + private readonly char[] _terminationChars = [' ', '\t', '\n', '"', '<', '>', '{', '}', '&']; public async Task> GetPages(string html) { @@ -47,8 +49,10 @@ private async Task TryGetWikiPageModel(string urlStart) { return page; } + return new WikiPageModel(Tools.GetPageTitleFromUrl(baseUrl + url), apiUrl, wikiClientCache); } + return new WikiPageModel(Tools.GetPageTitleFromUrl(baseUrl + url), apiUrl, wikiClientCache); } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Services/IDialogService.cs b/src/CrossWikiEditor.Core/Services/IDialogService.cs index b81baa6..4ac4adb 100644 --- a/src/CrossWikiEditor.Core/Services/IDialogService.cs +++ b/src/CrossWikiEditor.Core/Services/IDialogService.cs @@ -4,4 +4,4 @@ public interface IDialogService { Task ShowDialog(ViewModelBase viewModel); Task Alert(string title, string content); -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Services/SettingsService.cs b/src/CrossWikiEditor.Core/Services/SettingsService.cs index 64f33e9..62a4538 100644 --- a/src/CrossWikiEditor.Core/Services/SettingsService.cs +++ b/src/CrossWikiEditor.Core/Services/SettingsService.cs @@ -1,23 +1,22 @@ using System.Text.Json; -using CommunityToolkit.Mvvm.Messaging; namespace CrossWikiEditor.Core.Services; public interface ISettingsService { + string CurrentApiUrl { get; } UserSettings GetDefaultSettings(); UserSettings? GetSettingsByPath(string path); UserSettings GetCurrentSettings(); void SaveCurrentSettings(); void SetCurrentSettings(UserSettings userSettings); - string CurrentApiUrl { get; } } public sealed class SettingsService : ISettingsService { + private readonly string _currentSettingsPath; private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IMessengerWrapper _messenger; - private string _currentSettingsPath; private UserSettings _currentSettings; public SettingsService(IMessengerWrapper messenger) @@ -32,6 +31,7 @@ public SettingsService(IMessengerWrapper messenger) _currentSettings = temp; } } + _currentSettings ??= GetDefaultSettings(); _jsonSerializerOptions = new JsonSerializerOptions { @@ -41,7 +41,10 @@ public SettingsService(IMessengerWrapper messenger) messenger.Register(this, (r, m) => _currentSettings.UserWiki!.Project = m.Value); } - public UserSettings GetDefaultSettings() => UserSettings.GetDefaultUserSettings(); + public UserSettings GetDefaultSettings() + { + return UserSettings.GetDefaultUserSettings(); + } public UserSettings? GetSettingsByPath(string path) { @@ -49,6 +52,7 @@ public SettingsService(IMessengerWrapper messenger) { return null; } + string json = File.ReadAllText(path, Encoding.UTF8); return JsonSerializer.Deserialize(json); } @@ -61,10 +65,12 @@ public void SaveCurrentSettings() { Directory.CreateDirectory("./oldSettings"); } + // Just in case. This is just a json file, so no big deal, they can delete it themself. File.Move(_currentSettingsPath, $"./oldSettings/{DateTime.Now:yyyyMMdd_HHmmss}_settings.json"); } - var json = JsonSerializer.Serialize(_currentSettings, options: _jsonSerializerOptions); + + string? json = JsonSerializer.Serialize(_currentSettings, _jsonSerializerOptions); File.WriteAllText(_currentSettingsPath, json); } diff --git a/src/CrossWikiEditor.Core/Services/ViewModelFactory.cs b/src/CrossWikiEditor.Core/Services/ViewModelFactory.cs index 44ae86f..763a360 100644 --- a/src/CrossWikiEditor.Core/Services/ViewModelFactory.cs +++ b/src/CrossWikiEditor.Core/Services/ViewModelFactory.cs @@ -11,14 +11,15 @@ public interface IViewModelFactory DatabaseScannerViewModel GetDatabaseScannerViewModel(); } -public sealed class ViewModelFactory(IFileDialogService fileDialogService, - IDialogService dialogService, - IProfileRepository profileRepository, - IWikiClientCache wikiClientCache, - IUserService userService, - ISettingsService settingsService, - IMessengerWrapper messenger, - TextFileListProvider textFileListProvider) +public sealed class ViewModelFactory( + IFileDialogService fileDialogService, + IDialogService dialogService, + IProfileRepository profileRepository, + IWikiClientCache wikiClientCache, + IUserService userService, + ISettingsService settingsService, + IMessengerWrapper messenger, + TextFileListProvider textFileListProvider) : IViewModelFactory { public ProfilesViewModel GetProfilesViewModel() diff --git a/src/CrossWikiEditor.Core/Services/WikiServices/CategoryService.cs b/src/CrossWikiEditor.Core/Services/WikiServices/CategoryService.cs index 600925c..e2bd3ad 100644 --- a/src/CrossWikiEditor.Core/Services/WikiServices/CategoryService.cs +++ b/src/CrossWikiEditor.Core/Services/WikiServices/CategoryService.cs @@ -32,7 +32,8 @@ public async Task>> GetCategoriesOf(string apiRoot, s } catch (Exception e) { - logger.Fatal(e, "Failed to get pages. Site: {Site}, page: {Page}, includeHidden: {IncludeHidden}, onlyHidden: {OnlyHidden}, limit: {Limit}", + logger.Fatal(e, + "Failed to get pages. Site: {Site}, page: {Page}, includeHidden: {IncludeHidden}, onlyHidden: {OnlyHidden}, limit: {Limit}", apiRoot, pageName, includeHidden, onlyHidden, limit); return e; } @@ -62,6 +63,7 @@ public async Task>> GetPagesOfCategory(string apiRoot { continue; } + catGen = new CategoryMembersGenerator(new WikiPage(site, subCat.Title)); temp.AddRange(await catGen.EnumPagesAsync().Take(limit).Take(limit).ToListAsync()); } diff --git a/src/CrossWikiEditor.Core/Services/WikiServices/IPageService.cs b/src/CrossWikiEditor.Core/Services/WikiServices/IPageService.cs index 2d9acb2..efae7f0 100644 --- a/src/CrossWikiEditor.Core/Services/WikiServices/IPageService.cs +++ b/src/CrossWikiEditor.Core/Services/WikiServices/IPageService.cs @@ -9,10 +9,16 @@ public interface IPageService Task>> GetNewPages(string apiRoot, int[] namespaces, int limit); Task>> GetTransclusionsOn(string apiRoot, string pageName, int limit); Task>> GetTransclusionsOf(string apiRoot, string pageName, int[]? namespaces, int limit); - Task>> GetPagesLinkedTo(string apiRoot, string title, int[]? namespaces, bool allowRedirectLinks, bool? filterRedirects, int limit); + + Task>> GetPagesLinkedTo(string apiRoot, string title, int[]? namespaces, bool allowRedirectLinks, + bool? filterRedirects, int limit); + Task>> GetPagesWithProp(string apiRoot, string param, int limit); Task>> GetAllFiles(string apiRoot, string startTitle, int limit); - Task>> GetAllPages(string apiRoot, string startTitle, int namespaceId, PropertyFilterOption redirectsFilter, PropertyFilterOption langLinksFilter, int limit); + + Task>> GetAllPages(string apiRoot, string startTitle, int namespaceId, PropertyFilterOption redirectsFilter, + PropertyFilterOption langLinksFilter, int limit); + Task>> GetAllPagesWithPrefix(string apiRoot, string prefix, int namespaceId, int limit); Task>> GetProtectedPages(string apiRoot, string protectType, string protectLevel, int limit); Task>> WikiSearch(string apiRoot, string keyword, int[] namespaces, int limit); diff --git a/src/CrossWikiEditor.Core/Services/WikiServices/PageService.cs b/src/CrossWikiEditor.Core/Services/WikiServices/PageService.cs index 8effbac..2229fc7 100644 --- a/src/CrossWikiEditor.Core/Services/WikiServices/PageService.cs +++ b/src/CrossWikiEditor.Core/Services/WikiServices/PageService.cs @@ -137,7 +137,8 @@ public async Task>> GetTransclusionsOf(string apiRoot } catch (Exception e) { - logger.Fatal(e, "Failed to get pages. Site {Site}, page: {Page}, namespaces: {Namespaces}, limit: {Limit}", apiRoot, pageName, namespaces, limit); + logger.Fatal(e, "Failed to get pages. Site {Site}, page: {Page}, namespaces: {Namespaces}, limit: {Limit}", apiRoot, pageName, namespaces, + limit); return e; } } @@ -192,16 +193,19 @@ public async Task>> GetPagesWithProp(string apiRoot, } } - public async Task>> GetAllFiles(string apiRoot, string startTitle, int limit) => - await GetAllPages( - apiRoot: apiRoot, - startTitle: startTitle, - namespaceId: 6, - redirectsFilter: PropertyFilterOption.Disable, - langLinksFilter: PropertyFilterOption.Disable, - limit: limit); + public async Task>> GetAllFiles(string apiRoot, string startTitle, int limit) + { + return await GetAllPages( + apiRoot, + startTitle, + 6, + PropertyFilterOption.Disable, + PropertyFilterOption.Disable, + limit); + } - public async Task>> GetAllPages(string apiRoot, string startTitle, int namespaceId, PropertyFilterOption redirectsFilter, PropertyFilterOption langLinksFilter, int limit) + public async Task>> GetAllPages(string apiRoot, string startTitle, int namespaceId, + PropertyFilterOption redirectsFilter, PropertyFilterOption langLinksFilter, int limit) { return await GetAllPages(apiRoot, namespaceId, redirectsFilter, langLinksFilter, limit, startTitle); } @@ -248,7 +252,8 @@ public async Task>> WikiSearch(string apiRoot, string } catch (Exception e) { - logger.Fatal(e, "Failed to get pages. Site {Site}, keyword: {Keyword}, namespaces: {Namespaces}, limit: {Limit}", apiRoot, keyword, namespaces, limit); + logger.Fatal(e, "Failed to get pages. Site {Site}, keyword: {Keyword}, namespaces: {Namespaces}, limit: {Limit}", apiRoot, keyword, + namespaces, limit); return e; } } @@ -279,7 +284,7 @@ public async Task>> LinkSearch(string apiRoot, string WikiSite wikiSite = await wikiClientCache.GetWikiSite(apiRoot); var gen = new ExternalUrlUsageGenerator(wikiSite) { - Url = url, + Url = url }; List result = await gen.EnumItemsAsync().Take(limit).ToListAsync(); @@ -292,6 +297,28 @@ public async Task>> LinkSearch(string apiRoot, string } } + public Result> ConvertToSubject(List pages) + { + List result = (from wikiPageModel in pages + select ConvertToSubject(wikiPageModel) + into subjectPageResult + where subjectPageResult is {IsSuccessful: true, Value: not null} + select subjectPageResult.Value).ToList(); + + return result; + } + + public Result> ConvertToTalk(List pages) + { + var result = (from wikiPageModel in pages + select ConvertToTalk(wikiPageModel) + into talkPageResult + where talkPageResult is {IsSuccessful: true, Value: not null} + select talkPageResult.Value).ToList(); + + return result; + } + private async Task>> GetAllPages( string apiRoot, int namespaceId, @@ -320,39 +347,20 @@ private async Task>> GetAllPages( { gen.Prefix = prefix; } + List result = await gen.EnumPagesAsync().Take(limit).ToListAsync(); return result.ConvertAll(x => new WikiPageModel(x)); } catch (Exception e) { - logger.Fatal(e, "Failed to get pages. Site {Site}, start title: {StartTitle}, prefix: {Prefix}, namespace: {NamespaceId}, redirectsFilter {RedirectsFilter}, limit: {Limit}", apiRoot, + logger.Fatal(e, + "Failed to get pages. Site {Site}, start title: {StartTitle}, prefix: {Prefix}, namespace: {NamespaceId}, redirectsFilter {RedirectsFilter}, limit: {Limit}", + apiRoot, startTitle, prefix, namespaceId, redirectsFilter, limit); return e; } } - public Result> ConvertToSubject(List pages) - { - List result = (from wikiPageModel in pages - select ConvertToSubject(wikiPageModel) - into subjectPageResult - where subjectPageResult is { IsSuccessful: true, Value: not null } - select subjectPageResult.Value).ToList(); - - return result; - } - - public Result> ConvertToTalk(List pages) - { - var result = (from wikiPageModel in pages - select ConvertToTalk(wikiPageModel) - into talkPageResult - where talkPageResult is { IsSuccessful: true, Value: not null } - select talkPageResult.Value).ToList(); - - return result; - } - private Result ConvertToSubject(WikiPageModel page) { try diff --git a/src/CrossWikiEditor.Core/Services/WikiServices/UserService.cs b/src/CrossWikiEditor.Core/Services/WikiServices/UserService.cs index 9241344..dfe76af 100644 --- a/src/CrossWikiEditor.Core/Services/WikiServices/UserService.cs +++ b/src/CrossWikiEditor.Core/Services/WikiServices/UserService.cs @@ -65,7 +65,7 @@ public async Task>> GetUserContributionsPages(string try { WikiSite site = await wikiClientCache.GetWikiSite(apiRoot); - var gen = new UserContributionsGenerator(site, new List { username }) + var gen = new UserContributionsGenerator(site, new List {username}) { IncludeTitle = true, IncludeIds = true diff --git a/src/CrossWikiEditor.Core/Services/WikiServices/WikiClientCache.cs b/src/CrossWikiEditor.Core/Services/WikiServices/WikiClientCache.cs index e9a351e..ba98a49 100644 --- a/src/CrossWikiEditor.Core/Services/WikiServices/WikiClientCache.cs +++ b/src/CrossWikiEditor.Core/Services/WikiServices/WikiClientCache.cs @@ -19,6 +19,7 @@ public WikiClient GetWikiClient(string apiRoot, bool forceNew = false) client = new WikiClient(); _wikiClients[apiRoot] = client; } + return client; } diff --git a/src/CrossWikiEditor.Core/Settings/GeneralOptions.cs b/src/CrossWikiEditor.Core/Settings/GeneralOptions.cs index 406ef51..a69c08d 100644 --- a/src/CrossWikiEditor.Core/Settings/GeneralOptions.cs +++ b/src/CrossWikiEditor.Core/Settings/GeneralOptions.cs @@ -1,7 +1,7 @@ namespace CrossWikiEditor.Core.Settings; /// -/// Corresponds to the +/// Corresponds to the /// public sealed class GeneralOptions { @@ -14,4 +14,4 @@ public sealed class GeneralOptions public bool RegexTypoFixing { get; set; } public bool SkipIfNoTypoFixed { get; set; } public NormalFindAndReplaceRules NormalFindAndReplaceRules { get; set; } = []; -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Settings/MoreOptions.cs b/src/CrossWikiEditor.Core/Settings/MoreOptions.cs index 6eac8eb..7c1a70e 100644 --- a/src/CrossWikiEditor.Core/Settings/MoreOptions.cs +++ b/src/CrossWikiEditor.Core/Settings/MoreOptions.cs @@ -1,7 +1,7 @@ namespace CrossWikiEditor.Core.Settings; /// -/// Corresponds to the +/// Corresponds to the /// public sealed class MoreOptions { @@ -45,4 +45,4 @@ public sealed class CategoryTask(CategoryTaskType type) public string ReplaceCategory { get; set; } = string.Empty; public bool SkipIfNoChanged { get; set; } public bool RemoveSortkey { get; set; } -} +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRule.cs b/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRule.cs index 3ac85c1..01ca953 100644 --- a/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRule.cs +++ b/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRule.cs @@ -1,6 +1,7 @@ namespace CrossWikiEditor.Core.Settings; -public partial class NormalFindAndReplaceRule(string find, +public partial class NormalFindAndReplaceRule( + string find, string replaceWith, bool caseSensitive, bool regex, @@ -15,15 +16,25 @@ public NormalFindAndReplaceRule() : this("", "", false, false, false, false, fal { } - [ObservableProperty] private string _find = find; - [ObservableProperty] private string _replaceWith = replaceWith; - [ObservableProperty] private bool _caseSensitive = caseSensitive; - [ObservableProperty] private bool _regex = regex; - [ObservableProperty] private bool _multiLine = multiLine; - [ObservableProperty] private bool _singleLine = singleLine; - [ObservableProperty] private bool _minor = minor; - [ObservableProperty] private bool _afterFixes = afterFixes; - [ObservableProperty] private bool _enabled = enabled; - [ObservableProperty] private string _comment = comment; + [ObservableProperty] public partial string Find { get; set; } = find; + + [ObservableProperty] public partial string ReplaceWith { get; set; } = replaceWith; + + [ObservableProperty] public partial bool CaseSensitive { get; set; } = caseSensitive; + + [ObservableProperty] public partial bool Regex { get; set; } = regex; + + [ObservableProperty] public partial bool MultiLine { get; set; } = multiLine; + + [ObservableProperty] public partial bool SingleLine { get; set; } = singleLine; + + [ObservableProperty] public partial bool Minor { get; set; } = minor; + + [ObservableProperty] public partial bool AfterFixes { get; set; } = afterFixes; + + [ObservableProperty] public partial bool Enabled { get; set; } = enabled; + + [ObservableProperty] public partial string Comment { get; set; } = comment; + public bool IsEmpty => string.IsNullOrEmpty(Find); } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRules.cs b/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRules.cs index c5ab04a..3e3f996 100644 --- a/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRules.cs +++ b/src/CrossWikiEditor.Core/Settings/NormalFindAndReplaceRules.cs @@ -2,9 +2,13 @@ public sealed class NormalFindAndReplaceRules : List { - public NormalFindAndReplaceRules() : base() { } + public NormalFindAndReplaceRules() + { + } - public NormalFindAndReplaceRules(IEnumerable collection) : base(collection) { } + public NormalFindAndReplaceRules(IEnumerable collection) : base(collection) + { + } public bool IgnoreLinks { get; set; } diff --git a/src/CrossWikiEditor.Core/Settings/UserSettings.cs b/src/CrossWikiEditor.Core/Settings/UserSettings.cs index b9310b2..d961aa0 100644 --- a/src/CrossWikiEditor.Core/Settings/UserSettings.cs +++ b/src/CrossWikiEditor.Core/Settings/UserSettings.cs @@ -2,15 +2,36 @@ namespace CrossWikiEditor.Core.Settings; public sealed class UserSettings { - public UserWiki UserWiki { get; set; } = new UserWiki("hy", ProjectEnum.Wikipedia); + public UserWiki UserWiki { get; set; } = new("hy", ProjectEnum.Wikipedia); public SkipOptions SkipOptions { get; set; } = new(); public GeneralOptions GeneralOptions { get; set; } = new(); public MoreOptions MoreOptions { get; set; } = new(); public bool IsBotMode { get; set; } public string DefaultSummary { get; set; } = string.Empty; - public string GetApiUrl() => UserWiki.GetApiUrl(); - public string GetBaseUrl() => UserWiki.GetBaseUrl(); - public string GetLongBaseUrl() => UserWiki.GetLongBaseUrl(); - public string GetIndexUrl() => UserWiki.GetIndexUrl(); - public static UserSettings GetDefaultUserSettings() => new(); // TODO: For now + + public string GetApiUrl() + { + return UserWiki.GetApiUrl(); + } + + public string GetBaseUrl() + { + return UserWiki.GetBaseUrl(); + } + + public string GetLongBaseUrl() + { + return UserWiki.GetLongBaseUrl(); + } + + public string GetIndexUrl() + { + return UserWiki.GetIndexUrl(); + } + + public static UserSettings GetDefaultUserSettings() + { + return new UserSettings(); + // TODO: For now + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Utils/LanguageSpecificRegexes.cs b/src/CrossWikiEditor.Core/Utils/LanguageSpecificRegexes.cs index a460f31..92bcba9 100644 --- a/src/CrossWikiEditor.Core/Utils/LanguageSpecificRegexes.cs +++ b/src/CrossWikiEditor.Core/Utils/LanguageSpecificRegexes.cs @@ -18,6 +18,9 @@ public LanguageSpecificRegexes( messenger.Register(this, (_, _) => InitAsync = InitializeAsync()); } + public Regex? ExtractTitle { get; private set; } + public Task InitAsync { get; private set; } + private async Task InitializeAsync() { string apiRoot = _settingsService.CurrentApiUrl; @@ -36,7 +39,4 @@ private void MakeRegexes() + Regex.Escape(url[pos..]) + "/wiki/)"; ExtractTitle = new Regex("^" + s + "([^?&]*)$"); } - - public Regex? ExtractTitle { get; private set; } - public Task InitAsync { get; private set; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Utils/Result.cs b/src/CrossWikiEditor.Core/Utils/Result.cs index 044bea2..70903b4 100644 --- a/src/CrossWikiEditor.Core/Utils/Result.cs +++ b/src/CrossWikiEditor.Core/Utils/Result.cs @@ -20,10 +20,10 @@ public Result(Exception exception) ErrorMessage = Exception.Message; } - [MemberNotNullWhen(returnValue: true, nameof(Value))] + [MemberNotNullWhen(true, nameof(Value))] public bool IsSuccessful { get; } - [MemberNotNullWhen(returnValue: true, nameof(ErrorMessage))] + [MemberNotNullWhen(true, nameof(ErrorMessage))] public bool IsError => !IsSuccessful; public TResult? Value { get; } @@ -31,12 +31,38 @@ public Result(Exception exception) public Exception? Exception { get; } public string ErrorMessage { get; } - public bool Equals(Result other) => IsSuccessful && other.IsSuccessful && Equals(Value, other.Value); - public override bool Equals(object? obj) => obj is Result result && Equals(result); - public static bool operator ==(Result left, Result right) => left.Equals(right); - public static bool operator !=(Result left, Result right) => !(left == right); - public override int GetHashCode() => HashCode.Combine(IsSuccessful, Value, Exception, ErrorMessage); + public bool Equals(Result other) + { + return IsSuccessful && other.IsSuccessful && Equals(Value, other.Value); + } + + public override bool Equals(object? obj) + { + return obj is Result result && Equals(result); + } - public static implicit operator Result(TResult value) => new(value); - public static implicit operator Result(Exception value) => new(value); + public static bool operator ==(Result left, Result right) + { + return left.Equals(right); + } + + public static bool operator !=(Result left, Result right) + { + return !(left == right); + } + + public override int GetHashCode() + { + return HashCode.Combine(IsSuccessful, Value, Exception, ErrorMessage); + } + + public static implicit operator Result(TResult value) + { + return new Result(value); + } + + public static implicit operator Result(Exception value) + { + return new Result(value); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Utils/StringExtensions.cs b/src/CrossWikiEditor.Core/Utils/StringExtensions.cs index 3494eb1..35f7120 100644 --- a/src/CrossWikiEditor.Core/Utils/StringExtensions.cs +++ b/src/CrossWikiEditor.Core/Utils/StringExtensions.cs @@ -40,6 +40,7 @@ public static bool Contains( { return isCaseSensitive ? str.Contains(value) : str.Contains(value, StringComparison.OrdinalIgnoreCase); } + Regex r = isCaseSensitive ? new Regex(value) : new Regex(value, RegexOptions.IgnoreCase); return r.IsMatch(str); } diff --git a/src/CrossWikiEditor.Core/Utils/Tools.cs b/src/CrossWikiEditor.Core/Utils/Tools.cs index 88591ff..3582776 100644 --- a/src/CrossWikiEditor.Core/Utils/Tools.cs +++ b/src/CrossWikiEditor.Core/Utils/Tools.cs @@ -3,7 +3,7 @@ public static partial class Tools { /// - /// Removes underscores and wiki syntax from links + /// Removes underscores and wiki syntax from links /// public static string RemoveSyntax(string text) { @@ -34,7 +34,7 @@ public static string RemoveSyntax(string text) } /// - /// Returns index of first character different between strings + /// Returns index of first character different between strings /// /// First string /// Second string @@ -69,7 +69,7 @@ public static string GetPageTitleFromUrl(string url) // If the URL structure is not as expected, attempt to extract from the path string path = UnescapeDataStringRec(uri.AbsolutePath); - var extractedTitle = path[(path.LastIndexOf('/') + 1)..]; + string? extractedTitle = path[(path.LastIndexOf('/') + 1)..]; return extractedTitle.Replace("_", " "); } diff --git a/src/CrossWikiEditor.Core/Utils/Unit.cs b/src/CrossWikiEditor.Core/Utils/Unit.cs index 89dc77c..38c267e 100644 --- a/src/CrossWikiEditor.Core/Utils/Unit.cs +++ b/src/CrossWikiEditor.Core/Utils/Unit.cs @@ -2,15 +2,55 @@ public readonly struct Unit : IEquatable, IComparable { - public static readonly Unit Default = new Unit(); - public override int GetHashCode() => 0; - public bool Equals(Unit other) => true; - public override bool Equals(object? obj) => true; - public static bool operator ==(Unit lhs, Unit rhs) => true; - public static bool operator !=(Unit lhs, Unit rhs) => false; - public static bool operator >(Unit lhs, Unit rhs) => false; - public static bool operator >=(Unit lhs, Unit rhs) => true; - public static bool operator <(Unit lhs, Unit rhs) => false; - public static bool operator <=(Unit lhs, Unit rhs) => true; - public int CompareTo(Unit other) => 0; + public static readonly Unit Default = new(); + + public override int GetHashCode() + { + return 0; + } + + public bool Equals(Unit other) + { + return true; + } + + public override bool Equals(object? obj) + { + return true; + } + + public static bool operator ==(Unit lhs, Unit rhs) + { + return true; + } + + public static bool operator !=(Unit lhs, Unit rhs) + { + return false; + } + + public static bool operator >(Unit lhs, Unit rhs) + { + return false; + } + + public static bool operator >=(Unit lhs, Unit rhs) + { + return true; + } + + public static bool operator <(Unit lhs, Unit rhs) + { + return false; + } + + public static bool operator <=(Unit lhs, Unit rhs) + { + return true; + } + + public int CompareTo(Unit other) + { + return 0; + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Utils/WikiPageExtensions.cs b/src/CrossWikiEditor.Core/Utils/WikiPageExtensions.cs index 27a3681..7fcc629 100644 --- a/src/CrossWikiEditor.Core/Utils/WikiPageExtensions.cs +++ b/src/CrossWikiEditor.Core/Utils/WikiPageExtensions.cs @@ -36,6 +36,7 @@ private static string TitleWithoutNamespace(this WikiPage wikiPage) { throw new Exception("Title is null"); } + return wikiPage.Title.Contains(':') ? wikiPage.Title.Split(':')[1] : wikiPage.Title; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/Utils/WikiPageModelExtensions.cs b/src/CrossWikiEditor.Core/Utils/WikiPageModelExtensions.cs index 0a2c852..6337698 100644 --- a/src/CrossWikiEditor.Core/Utils/WikiPageModelExtensions.cs +++ b/src/CrossWikiEditor.Core/Utils/WikiPageModelExtensions.cs @@ -15,8 +15,10 @@ public static string ToWikiList(this IEnumerable wikiPageModels, { sb.Append($"{seperator} [[{page.Title}]]{Environment.NewLine}"); } + i++; } + return sb.ToString(); } @@ -24,7 +26,8 @@ public static string ToWikiListAlphabetically(this IEnumerable wi { string seperator = isNumericList ? "#" : "*"; var sb = new StringBuilder(); - IEnumerable> pages = wikiPageModels.GroupBy(p => char.ToLower(p.Title[0])).OrderBy(p => p.First().Title).Select(l => l.OrderBy(p => p.Title)); + IEnumerable> pages = wikiPageModels.GroupBy(p => char.ToLower(p.Title[0])).OrderBy(p => p.First().Title) + .Select(l => l.OrderBy(p => p.Title)); foreach (IEnumerable section in pages) { sb.Append($"== {char.ToUpper(section.First().Title[0])} =={Environment.NewLine}"); @@ -33,6 +36,7 @@ public static string ToWikiListAlphabetically(this IEnumerable wi sb.Append($"{seperator} [[{page.Title}]]{Environment.NewLine}"); } } + return sb.ToString(); } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs index 0296d68..d2263d5 100644 --- a/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/AddOrEditProfileViewModel.cs @@ -3,8 +3,8 @@ public sealed partial class AddOrEditProfileViewModel : ViewModelBase { private readonly IFileDialogService _fileDialogService; - private readonly IProfileRepository _profileRepository; private readonly int _id; + private readonly IProfileRepository _profileRepository; public AddOrEditProfileViewModel( IFileDialogService fileDialogService, @@ -60,7 +60,7 @@ private void Save(IDialog dialog) return; } - var profile = new Profile() + var profile = new Profile { Username = Username, DefaultSettingsPath = ShouldSelectDefaultSettings ? DefaultSettingsPath : string.Empty, @@ -83,5 +83,8 @@ private void Save(IDialog dialog) } [RelayCommand] - private void Cancel(IDialog dialog) => dialog.Close(false); + private void Cancel(IDialog dialog) + { + dialog.Close(false); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/FindAndReplaceViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/FindAndReplaceViewModel.cs index df31d42..6e1d4a7 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/FindAndReplaceViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/FindAndReplaceViewModel.cs @@ -9,12 +9,21 @@ public FindAndReplaceViewModel(NormalFindAndReplaceRules normalFindAndReplaceRul { model.PropertyChanged += OnModelPropertyChanged; } + AddNewRow(); IgnoreLinks = normalFindAndReplaceRules.IgnoreLinks; IgnoreMore = normalFindAndReplaceRules.IgnoreMore; AddToSummary = normalFindAndReplaceRules.AddToSummary; } + [ObservableProperty] public partial ObservableCollection NormalFindAndReplaceRules { get; set; } + + [ObservableProperty] public partial bool IgnoreLinks { get; set; } + + [ObservableProperty] public partial bool IgnoreMore { get; set; } + + [ObservableProperty] public partial bool AddToSummary { get; set; } + [RelayCommand] private void Clean() { @@ -40,17 +49,13 @@ private void Save(IDialog dialog) dialog.Close(rules); } - [ObservableProperty] private ObservableCollection _normalFindAndReplaceRules; - [ObservableProperty] private bool _ignoreLinks; - [ObservableProperty] private bool _ignoreMore; - [ObservableProperty] private bool _addToSummary; - private void OnModelPropertyChanged(object? sender, PropertyChangedEventArgs args) { - if (NormalFindAndReplaceRules.LastOrDefault() is not { IsEmpty: false }) + if (NormalFindAndReplaceRules.LastOrDefault() is not {IsEmpty: false}) { return; } + AddNewRow(); } diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs index ec6529d..2e9496d 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/MoreViewModel.cs @@ -2,9 +2,9 @@ public sealed partial class MoreViewModel : ViewModelBase { - private MoreOptions _moreOptions; private readonly IDialogService _dialogService; private readonly ISettingsService _settingsService; + private MoreOptions _moreOptions; public MoreViewModel( ISettingsService settingsService, @@ -49,20 +49,75 @@ public MoreViewModel( [ObservableProperty] public partial bool SkipIfNoCategoryChanged { get; set; } [ObservableProperty] public partial bool RemoveSortkey { get; set; } - partial void OnIsAppendOrPrependEnabledChanged(bool value) => _moreOptions.IsAppendPrependEnabled = value; - partial void OnIsAppendChanged(bool value) => _moreOptions.IsAppend = value; - partial void OnAppendOrPrependContentChanged(string value) => _moreOptions.AppendOrPrependContent = value; - partial void OnAppendOrPrependNewLinesChanged(int value) => _moreOptions.AppendOrPrependNewLines = value; - partial void OnShouldSortMetadataAfterAppendOrPrependChanged(bool value) => _moreOptions.ShouldSortMetaDataAfterAppendOrPrepend = value; - partial void OnFileTypeChanged(FileTaskType value) => _moreOptions.FileActions[0].Type = value; - partial void OnSourceFileChanged(string value) => _moreOptions.FileActions[0].SourceFile = value; - partial void OnReplaceFileOrCommentChanged(string value) => _moreOptions.FileActions[0].ReplaceFileOrComment = value; - partial void OnSkipIfNoFileChangedChanged(bool value) => _moreOptions.FileActions[0].SkipIfNoChanged = value; - partial void OnCategoryTypeChanged(CategoryTaskType value) => _moreOptions.CategoryActions[0].Type = value; - partial void OnSourceCategoryChanged(string value) => _moreOptions.CategoryActions[0].SourceCategory = value; - partial void OnReplaceCategoryChanged(string value) => _moreOptions.CategoryActions[0].ReplaceCategory = value; - partial void OnSkipIfNoCategoryChangedChanged(bool value) => _moreOptions.CategoryActions[0].SkipIfNoChanged = value; - partial void OnRemoveSortkeyChanged(bool value) => _moreOptions.CategoryActions[0].RemoveSortkey = value; + partial void OnIsAppendOrPrependEnabledChanged(bool value) + { + _moreOptions.IsAppendPrependEnabled = value; + } + + partial void OnIsAppendChanged(bool value) + { + _moreOptions.IsAppend = value; + } + + partial void OnAppendOrPrependContentChanged(string value) + { + _moreOptions.AppendOrPrependContent = value; + } + + partial void OnAppendOrPrependNewLinesChanged(int value) + { + _moreOptions.AppendOrPrependNewLines = value; + } + + partial void OnShouldSortMetadataAfterAppendOrPrependChanged(bool value) + { + _moreOptions.ShouldSortMetaDataAfterAppendOrPrepend = value; + } + + partial void OnFileTypeChanged(FileTaskType value) + { + _moreOptions.FileActions[0].Type = value; + } + + partial void OnSourceFileChanged(string value) + { + _moreOptions.FileActions[0].SourceFile = value; + } + + partial void OnReplaceFileOrCommentChanged(string value) + { + _moreOptions.FileActions[0].ReplaceFileOrComment = value; + } + + partial void OnSkipIfNoFileChangedChanged(bool value) + { + _moreOptions.FileActions[0].SkipIfNoChanged = value; + } + + partial void OnCategoryTypeChanged(CategoryTaskType value) + { + _moreOptions.CategoryActions[0].Type = value; + } + + partial void OnSourceCategoryChanged(string value) + { + _moreOptions.CategoryActions[0].SourceCategory = value; + } + + partial void OnReplaceCategoryChanged(string value) + { + _moreOptions.CategoryActions[0].ReplaceCategory = value; + } + + partial void OnSkipIfNoCategoryChangedChanged(bool value) + { + _moreOptions.CategoryActions[0].SkipIfNoChanged = value; + } + + partial void OnRemoveSortkeyChanged(bool value) + { + _moreOptions.CategoryActions[0].RemoveSortkey = value; + } private void PopulateProperties() { diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs index dfdbb1c..4a9121d 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/OptionsViewModel.cs @@ -4,9 +4,9 @@ namespace CrossWikiEditor.Core.ViewModels.ControlViewModels; public sealed partial class OptionsViewModel : ViewModelBase { - private GeneralOptions _generalOptions; private readonly IDialogService _dialogService; private readonly ISettingsService _settingsService; + private GeneralOptions _generalOptions; public OptionsViewModel( ISettingsService settingsService, @@ -26,7 +26,7 @@ public OptionsViewModel( PropertyChanged += OptionsViewModel_PropertyChanged; } - [ObservableProperty] public partial bool AutoTag { get;set; } + [ObservableProperty] public partial bool AutoTag { get; set; } [ObservableProperty] public partial bool ApplyGeneralFixes { get; set; } [ObservableProperty] public partial bool UnicodifyWholePage { get; set; } [ObservableProperty] public partial bool FindAndReplace { get; set; } @@ -53,6 +53,7 @@ private void OptionsViewModel_PropertyChanged(object? sender, PropertyChangedEve { return; } + PropertyInfo property = typeof(OptionsViewModel).GetProperty(e.PropertyName!)!; PropertyInfo targetProperty = typeof(GeneralOptions).GetProperty(e.PropertyName)!; targetProperty.SetValue(_generalOptions, property.GetValue(this)); diff --git a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/StartViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/StartViewModel.cs index 977c1bb..3393dfd 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/StartViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ControlViewModels/StartViewModel.cs @@ -3,8 +3,9 @@ public sealed partial class StartViewModel : ViewModelBase { private readonly IMessengerWrapper _messenger; - private bool _isProcessing = false; - private bool _isSaving = false; + private bool _isProcessing; + private bool _isSaving; + public StartViewModel(IMessengerWrapper messenger) { _messenger = messenger; @@ -40,7 +41,7 @@ private void Save() { if (!IsBusy) { - _messenger.Send(new SaveOrSkipPageMessage(shouldSavePage: true)); + _messenger.Send(new SaveOrSkipPageMessage(true)); } } @@ -49,7 +50,7 @@ private void Skip() { if (!IsBusy) { - _messenger.Send(new SaveOrSkipPageMessage(shouldSavePage: false)); + _messenger.Send(new SaveOrSkipPageMessage(false)); } } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs index a18848d..28d53b0 100644 --- a/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/DatabaseScannerViewModel.cs @@ -4,14 +4,14 @@ namespace CrossWikiEditor.Core.ViewModels; public sealed partial class DatabaseScannerViewModel : ViewModelBase { - private Task? _scannerTask; - private Task? _updateUiTask; - private CancellationTokenSource _scannerCancellationTokenSource = new(); - private readonly ConcurrentQueue _titlesQueue = new(); + private readonly IFileDialogService _fileDialogService; private readonly ISettingsService _settingsService; + private readonly ConcurrentQueue _titlesQueue = new(); private readonly IWikiClientCache _wikiClientCache; - private readonly IFileDialogService _fileDialogService; public EventHandler? _convertedTextChanged; + private CancellationTokenSource _scannerCancellationTokenSource = new(); + private Task? _scannerTask; + private Task? _updateUiTask; public DatabaseScannerViewModel( ISettingsService settingsService, @@ -31,8 +31,8 @@ public DatabaseScannerViewModel( Base = string.Empty; Generator = string.Empty; Case = string.Empty; - MinStartYear = new(new DateTime(2000, 1, 1)); - MinEndYear = new(new DateTime(2000, 1, 1)); + MinStartYear = new DateTimeOffset(new DateTime(2000, 1, 1)); + MinEndYear = new DateTimeOffset(new DateTime(2000, 1, 1)); ConvertedText = string.Empty; NumberOfPagesOnEachSection = 25; } @@ -41,11 +41,11 @@ public DatabaseScannerViewModel( [ObservableProperty] public partial ObservableCollection TalkNamespaces { get; set; } [ObservableProperty] public partial ObservableCollection Pages { get; set; } - [ObservableProperty] public partial bool IsTitleContainsEnabled { get; set;} + [ObservableProperty] public partial bool IsTitleContainsEnabled { get; set; } [ObservableProperty] public partial bool IsTitleNotContainsEnabled { get; set; } - [ObservableProperty] public partial string TitleContains {get;set;} + [ObservableProperty] public partial string TitleContains { get; set; } [ObservableProperty] public partial string TitleNotContains { get; set; } - [ObservableProperty] public partial bool IsTitleContainsRegex {get;set;} + [ObservableProperty] public partial bool IsTitleContainsRegex { get; set; } [ObservableProperty] public partial bool IsTitleContainsCaseSensitive { get; set; } [ObservableProperty] public partial bool IsAllTalkChecked { get; set; } @@ -85,7 +85,7 @@ partial void OnIsAllSubjectCheckedChanged(bool value) public async Task BrowseCommand() { string[]? result = await _fileDialogService.OpenFilePickerAsync("Open Database dump", false); - if (result is not { Length: 1 }) + if (result is not {Length: 1}) { return; } @@ -101,6 +101,7 @@ private void Start() { return; } + _scannerTask = Task.Run(Scan, _scannerCancellationTokenSource.Token); _updateUiTask = Task.Run(async () => @@ -157,16 +158,19 @@ private void Scan() { break; } + if (reader.NodeType != XmlNodeType.Element || reader.Name != "page") { continue; } + DbPage page = ParsePageElement(reader); if (ShouldIncludePage(page)) { _titlesQueue.Enqueue(page.Title!); } } + _scannerTask = null; } @@ -213,15 +217,18 @@ private bool ViolatesTitleContains(DbPage page) { return false; } + if (page.Revision.Count == 0) { return true; } + string? currentText = page.Revision[^1].Text; if (currentText == null) { return true; } + return !currentText.Contains(TitleContains, IsTitleContainsRegex, IsTitleContainsCaseSensitive); } @@ -236,8 +243,10 @@ private bool ViolatesTitleNotContains(DbPage page) return currentText?.Contains(TitleNotContains, IsTitleContainsRegex, IsTitleContainsCaseSensitive) == true; } - private bool ViolatesRevisionDateRange(DbPage page) => - IsSearchDateChecked && page.Revision.All(rev => rev.Timestamp <= SelectedStartDate || rev.Timestamp >= SelectedEndDate); + private bool ViolatesRevisionDateRange(DbPage page) + { + return IsSearchDateChecked && page.Revision.All(rev => rev.Timestamp <= SelectedStartDate || rev.Timestamp >= SelectedEndDate); + } private DbPage ParsePageElement(XmlReader reader) { @@ -266,9 +275,9 @@ private DbPage ParsePageElement(XmlReader reader) } } - if (reader is { NodeType: XmlNodeType.EndElement, Name: "page" }) + if (reader is {NodeType: XmlNodeType.EndElement, Name: "page"}) { - return new DbPage() + return new DbPage { Id = id, Ns = ns, @@ -277,6 +286,7 @@ private DbPage ParsePageElement(XmlReader reader) }; } } + throw new UnreachableException(); } @@ -328,9 +338,10 @@ private DbRevision ParseRevisionElement(XmlReader reader) break; } } - if (reader is { NodeType: XmlNodeType.EndElement, Name: "revision" }) + + if (reader is {NodeType: XmlNodeType.EndElement, Name: "revision"}) { - return new DbRevision() + return new DbRevision { Id = id, Parentid = parentId, @@ -345,6 +356,7 @@ private DbRevision ParseRevisionElement(XmlReader reader) }; } } + throw new UnreachableException(); } @@ -363,15 +375,17 @@ private DbContributor ParseContributorElement(XmlReader reader) username = reader.ReadElementContentAsString(); break; } - if (reader is { NodeType: XmlNodeType.EndElement, Name: "contributor" }) + + if (reader is {NodeType: XmlNodeType.EndElement, Name: "contributor"}) { - return new DbContributor() + return new DbContributor { Id = id, Username = username }; } } + throw new UnreachableException(); } @@ -394,13 +408,13 @@ private void ParseSiteInfo(XmlReader reader) Case = reader.ReadString(); break; case "namespaces": - { - ParseNamespaces(reader); - break; - } + { + ParseNamespaces(reader); + break; + } } - if (reader is { NodeType: XmlNodeType.EndElement, Name: "siteinfo" }) + if (reader is {NodeType: XmlNodeType.EndElement, Name: "siteinfo"}) { break; } @@ -418,6 +432,7 @@ private void ParseNamespaces(XmlReader reader) { continue; } + if (ns.Id.IsEven()) { SubjectNamespaces.Add(ns); @@ -427,7 +442,8 @@ private void ParseNamespaces(XmlReader reader) TalkNamespaces.Add(ns); } } - if (reader is { NodeType: XmlNodeType.EndElement, Name: "namespaces" }) + + if (reader is {NodeType: XmlNodeType.EndElement, Name: "namespaces"}) { break; } @@ -446,13 +462,22 @@ private void SetUpFromDb(string dbPath) } } } - private void MakeAlphabetisedList() => _convertedTextChanged?.Invoke(this, Pages.ToWikiListAlphabetically(IsNumericList)); - private void MakeNumericList() => _convertedTextChanged?.Invoke(this, Pages.ToWikiList(IsNumericList, NumberOfPagesOnEachSection)); + + private void MakeAlphabetisedList() + { + _convertedTextChanged?.Invoke(this, Pages.ToWikiListAlphabetically(IsNumericList)); + } + + private void MakeNumericList() + { + _convertedTextChanged?.Invoke(this, Pages.ToWikiList(IsNumericList, NumberOfPagesOnEachSection)); + } + private void UpdateUi(WikiSite wikiSite) { while (!_titlesQueue.IsEmpty) { - if (_titlesQueue.TryDequeue(out var title)) + if (_titlesQueue.TryDequeue(out string? title)) { Pages.Add(new WikiPageModel(new WikiPage(wikiSite, title))); } diff --git a/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs index a21b152..724a010 100644 --- a/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/FilterViewModel.cs @@ -5,7 +5,7 @@ public partial class FilterViewModel : ViewModelBase private readonly TextFileListProvider _textFileListProvider; public FilterViewModel( - List subjectNamespaces, + List subjectNamespaces, List talkNamespaces, TextFileListProvider textFileListProvider) { @@ -13,12 +13,25 @@ public FilterViewModel( SubjectNamespaces = subjectNamespaces.ToObservableCollection(); TalkNamespaces = talkNamespaces.ToObservableCollection(); Pages = []; - SetOperations = new[] { Models.SetOperations.SymmetricDifference, Models.SetOperations.Intersection }.ToObservableCollection(); + SetOperations = new[] {Models.SetOperations.SymmetricDifference, Models.SetOperations.Intersection}.ToObservableCollection(); RemoveTitlesContaining = string.Empty; KeepTitlesContaining = string.Empty; SelectedSetOperations = Models.SetOperations.SymmetricDifference; } + [ObservableProperty] public partial ObservableCollection SubjectNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection TalkNamespaces { get; set; } + [ObservableProperty] public partial ObservableCollection Pages { get; set; } + [ObservableProperty] public partial ObservableCollection SetOperations { get; set; } + [ObservableProperty] public partial bool IsAllTalkChecked { get; set; } + [ObservableProperty] public partial bool IsAllSubjectChecked { get; set; } + [ObservableProperty] public partial bool UseRegex { get; set; } + [ObservableProperty] public partial bool SortAlphabetically { get; set; } + [ObservableProperty] public partial bool RemoveDuplicates { get; set; } + [ObservableProperty] public partial string RemoveTitlesContaining { get; set; } + [ObservableProperty] public partial string KeepTitlesContaining { get; set; } + [ObservableProperty] public partial SetOperations SelectedSetOperations { get; set; } + [RelayCommand] private void Save(IDialog dialog) { @@ -49,7 +62,7 @@ private async Task OpenFile() if (_textFileListProvider.CanMake) { Result> result = await _textFileListProvider.MakeList(); - if (result is { IsSuccessful: true, Value: not null }) + if (result is {IsSuccessful: true, Value: not null}) { Pages = result.Value.ToObservableCollection(); } @@ -75,17 +88,4 @@ partial void OnIsAllSubjectCheckedChanged(bool value) .Select(x => new WikiNamespace(x.Id, x.Name, value)) .ToObservableCollection(); } - - [ObservableProperty] public partial ObservableCollection SubjectNamespaces { get; set; } - [ObservableProperty] public partial ObservableCollection TalkNamespaces { get; set; } - [ObservableProperty] public partial ObservableCollection Pages { get; set; } - [ObservableProperty] public partial ObservableCollection SetOperations { get; set; } - [ObservableProperty] public partial bool IsAllTalkChecked { get; set; } - [ObservableProperty] public partial bool IsAllSubjectChecked { get; set; } - [ObservableProperty] public partial bool UseRegex { get; set; } - [ObservableProperty] public partial bool SortAlphabetically { get; set; } - [ObservableProperty] public partial bool RemoveDuplicates { get; set; } - [ObservableProperty] public partial string RemoveTitlesContaining { get; set; } - [ObservableProperty] public partial string KeepTitlesContaining { get; set; } - [ObservableProperty] public partial SetOperations SelectedSetOperations { get; set; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/MainWindowViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/MainWindowViewModel.cs index c51accd..241a4c2 100644 --- a/src/CrossWikiEditor.Core/ViewModels/MainWindowViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/MainWindowViewModel.cs @@ -5,8 +5,6 @@ public sealed class MainWindowViewModel : ViewModelBase private PageListProcessor? _listProcessor; private Task? _myBot; - public static MainWindowViewModel? Instance { get; private set; } - public MainWindowViewModel(StatusBarViewModel statusBarViewModel, MakeListViewModel makeListViewModel, OptionsViewModel optionsViewModel, @@ -42,13 +40,16 @@ public MainWindowViewModel(StatusBarViewModel statusBarViewModel, _myBot = Task.Run(async () => { _listProcessor?.Stop(); - _listProcessor = new PageListProcessor(messenger, settingsService, [..MakeListViewModel.Pages], OptionsViewModel.NormalFindAndReplaceRules); + _listProcessor = new PageListProcessor(messenger, settingsService, [..MakeListViewModel.Pages], + OptionsViewModel.NormalFindAndReplaceRules); await _listProcessor.Start(); }); }); messenger.Register(this, (recipient, message) => _listProcessor?.Stop()); } + public static MainWindowViewModel? Instance { get; private set; } + public StatusBarViewModel StatusBarViewModel { get; } public MakeListViewModel MakeListViewModel { get; } public OptionsViewModel OptionsViewModel { get; } diff --git a/src/CrossWikiEditor.Core/ViewModels/MakeListViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/MakeListViewModel.cs index 84e4344..9996e50 100644 --- a/src/CrossWikiEditor.Core/ViewModels/MakeListViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/MakeListViewModel.cs @@ -4,14 +4,14 @@ namespace CrossWikiEditor.Core.ViewModels; public sealed partial class MakeListViewModel : ViewModelBase { - private readonly ILogger _logger; - private readonly IDialogService _dialogService; private readonly IWikiClientCache _clientCache; + private readonly IDialogService _dialogService; + private readonly IFileDialogService _fileDialogService; + private readonly ILogger _logger; private readonly IPageService _pageService; + private readonly ISettingsService _settingsService; private readonly ISystemService _systemService; private readonly IViewModelFactory _viewModelFactory; - private readonly IFileDialogService _fileDialogService; - private readonly ISettingsService _settingsService; public MakeListViewModel( IMessengerWrapper messenger, @@ -41,13 +41,23 @@ public MakeListViewModel( messenger.Register(this, (recipient, message) => Pages.Remove(Pages.First(p => p.Title == message.Page.Title))); } + [ObservableProperty] public partial ObservableCollection ListProviders { get; set; } + + [ObservableProperty] public partial IListProvider SelectedListProvider { get; set; } + + [ObservableProperty] public partial ObservableCollection Pages { get; set; } = []; + + [ObservableProperty] public partial ObservableCollection SelectedPages { get; set; } = []; + + [ObservableProperty] public partial string NewPageTitle { get; set; } = string.Empty; + [RelayCommand] private async Task AddNewPage() { if (!string.IsNullOrWhiteSpace(NewPageTitle)) { Result result = await _clientCache.GetWikiPageModel(_settingsService.CurrentApiUrl, NewPageTitle); - if (result is { IsSuccessful: true, Value: not null }) + if (result is {IsSuccessful: true, Value: not null}) { Pages.Add(result.Value); } @@ -87,7 +97,7 @@ private async Task MakeList(CancellationToken arg) _ => throw new UnreachableException("Wait what? A list is either limited or unlimited.") }; - if (result is { IsSuccessful: true, Value: not null }) + if (result is {IsSuccessful: true, Value: not null}) { Pages.AddRange(result.Value); } @@ -103,7 +113,8 @@ private void OpenInBrowser() { foreach (WikiPageModel selectedPage in SelectedPages) { - _systemService.OpenLinkInBrowser($"{_settingsService.GetCurrentSettings().GetIndexUrl()}title={HttpUtility.UrlEncode(selectedPage.Title)}"); + _systemService.OpenLinkInBrowser( + $"{_settingsService.GetCurrentSettings().GetIndexUrl()}title={HttpUtility.UrlEncode(selectedPage.Title)}"); } } @@ -153,13 +164,14 @@ private async Task Paste() { return; } + string[] titles = clipboardText.Split([Environment.NewLine], StringSplitOptions.None); string urlApi = _settingsService.CurrentApiUrl; foreach (string title in titles) { Result result = await _clientCache.GetWikiPageModel(urlApi, title); - if (result is { IsSuccessful: true, Value: not null }) + if (result is {IsSuccessful: true, Value: not null}) { Pages.Add(result.Value); } @@ -286,13 +298,16 @@ private async Task SaveList() { return; } + string suggestedTitle = SelectedListProvider.Title; if (!string.IsNullOrWhiteSpace(SelectedListProvider.Param)) { suggestedTitle += $"_{SelectedListProvider.Param}"; } + suggestedTitle += $"_{DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture)}.txt"; - (_, Func>? openWriteStream) = await _fileDialogService.SaveFilePickerAsync("Save pages", suggestedFileName: suggestedTitle.ToFilenameSafe()); + (_, Func>? openWriteStream) = + await _fileDialogService.SaveFilePickerAsync("Save pages", suggestedFileName: suggestedTitle.ToFilenameSafe()); if (openWriteStream is not null) { Stream stream = await openWriteStream(); @@ -316,10 +331,4 @@ private void SortReverseAlphabetically() { Pages = Pages.OrderByDescending(x => x.Title).ToObservableCollection(); } - - [ObservableProperty] private ObservableCollection _listProviders; - [ObservableProperty] private IListProvider _selectedListProvider; - [ObservableProperty] private ObservableCollection _pages = []; - [ObservableProperty] private ObservableCollection _selectedPages = []; - [ObservableProperty] private string _newPageTitle = string.Empty; } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/MenuViewModels/FileMenuViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/MenuViewModels/FileMenuViewModel.cs index aac966d..0351c3e 100644 --- a/src/CrossWikiEditor.Core/ViewModels/MenuViewModels/FileMenuViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/MenuViewModels/FileMenuViewModel.cs @@ -7,18 +7,23 @@ public sealed partial class FileMenuViewModel( IDialogService dialogService, IMessengerWrapper messenger) { - [RelayCommand] private void ResetToDefaultSettings() => settingsService.SetCurrentSettings(settingsService.GetDefaultSettings()); + [RelayCommand] + private void ResetToDefaultSettings() + { + settingsService.SetCurrentSettings(settingsService.GetDefaultSettings()); + } [RelayCommand] private async Task OpenSettings() { string[]? result = await fileDialogService.OpenFilePickerAsync("Select settings", false, ["*.json"]); - if (result is { Length: 1 }) + if (result is {Length: 1}) { string newSettingsPath = result[0]; try { - UserSettings? newUserSettings = settingsService.GetSettingsByPath(newSettingsPath) ?? throw new InvalidOperationException("Failed to load the settings"); + UserSettings? newUserSettings = settingsService.GetSettingsByPath(newSettingsPath) ?? + throw new InvalidOperationException("Failed to load the settings"); settingsService.SetCurrentSettings(newUserSettings); } catch (InvalidOperationException) @@ -28,11 +33,45 @@ private async Task OpenSettings() } } - [RelayCommand] private void SaveSettings() => settingsService.SaveCurrentSettings(); - [RelayCommand] private void SaveSettingsAs() => throw new NotImplementedException(); - [RelayCommand] private void SaveSettingsAsDefault() => throw new NotImplementedException(); - [RelayCommand] private async Task LoginProfiles() => await dialogService.ShowDialog(viewModelFactory.GetProfilesViewModel()); - [RelayCommand] private void Logout() => throw new NotImplementedException(); - [RelayCommand] private void RefreshStatusAndTypos() => throw new NotImplementedException(); - [RelayCommand] private void Exit() => messenger.Send(new ExitApplicationMessage()); + [RelayCommand] + private void SaveSettings() + { + settingsService.SaveCurrentSettings(); + } + + [RelayCommand] + private void SaveSettingsAs() + { + throw new NotImplementedException(); + } + + [RelayCommand] + private void SaveSettingsAsDefault() + { + throw new NotImplementedException(); + } + + [RelayCommand] + private async Task LoginProfiles() + { + await dialogService.ShowDialog(viewModelFactory.GetProfilesViewModel()); + } + + [RelayCommand] + private void Logout() + { + throw new NotImplementedException(); + } + + [RelayCommand] + private void RefreshStatusAndTypos() + { + throw new NotImplementedException(); + } + + [RelayCommand] + private void Exit() + { + messenger.Send(new ExitApplicationMessage()); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/PreferencesViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/PreferencesViewModel.cs index 599a437..4ebcecc 100644 --- a/src/CrossWikiEditor.Core/ViewModels/PreferencesViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/PreferencesViewModel.cs @@ -2,8 +2,17 @@ public sealed partial class PreferencesViewModel : ViewModelBase { - private readonly ISettingsService _settingsService; private readonly IMessengerWrapper _messenger; + private readonly ISettingsService _settingsService; + + [ObservableProperty] private ObservableCollection _languages = new( + [ + "en", + "hy", + "hyw", + "es", + "ru" + ]); public PreferencesViewModel(ISettingsService settingsService, IMessengerWrapper messenger) { @@ -22,30 +31,31 @@ public PreferencesViewModel(ISettingsService settingsService, IMessengerWrapper SelectedProject = settingsService.GetCurrentSettings().UserWiki.Project; } - [ObservableProperty] private bool _minimizeToSystray; - [ObservableProperty] private bool _warnOnExit; - [ObservableProperty] private bool _savePageListWithSettings; - [ObservableProperty] private bool _lowThreadPriority; - [ObservableProperty] private bool _previewDiffInBotMode; - [ObservableProperty] private bool _enableLogging; - [ObservableProperty] private ProjectEnum _selectedProject = ProjectEnum.Wikipedia; - [ObservableProperty] private ObservableCollection _projects = new(Enum.GetValues()); - [ObservableProperty] private string _selectedLanguage = "en"; - - [ObservableProperty] - private ObservableCollection _languages = new( - [ - "en", - "hy", - "hyw", - "es", - "ru" - ]); + [ObservableProperty] public partial bool MinimizeToSystray { get; set; } + + [ObservableProperty] public partial bool WarnOnExit { get; set; } + + [ObservableProperty] public partial bool SavePageListWithSettings { get; set; } + + [ObservableProperty] public partial bool LowThreadPriority { get; set; } + + [ObservableProperty] public partial bool PreviewDiffInBotMode { get; set; } + + [ObservableProperty] public partial bool EnableLogging { get; set; } + + [ObservableProperty] public partial ProjectEnum SelectedProject { get; set; } = ProjectEnum.Wikipedia; + + [ObservableProperty] public partial ObservableCollection Projects { get; set; } = new(Enum.GetValues()); + + [ObservableProperty] public partial string SelectedLanguage { get; set; } = "en"; - [ObservableProperty] private bool _suppressUsingAwb; - [ObservableProperty] private bool _ignoreNoBots; - [ObservableProperty] private bool _emptyPageListOnProjectChange; - [ObservableProperty] private Alerts _alerts; + [ObservableProperty] public partial bool SuppressUsingAwb { get; set; } + + [ObservableProperty] public partial bool IgnoreNoBots { get; set; } + + [ObservableProperty] public partial bool EmptyPageListOnProjectChange { get; set; } + + [ObservableProperty] public partial Alerts Alerts { get; set; } [RelayCommand] private void Save(IDialog dialog) @@ -64,26 +74,47 @@ private void Cancel(IDialog dialog) public partial class Alerts : ObservableObject { - [ObservableProperty] private bool _ambiguousCitationDates; - [ObservableProperty] private bool _containsSicTag; - [ObservableProperty] private bool _dabPageWithRef; - [ObservableProperty] private bool _deadLinks; - [ObservableProperty] private bool _duplicateParametersInWpBannerShell; - [ObservableProperty] private bool _hasRefAfterReferences; - [ObservableProperty] private bool _hasFootnotesTemplate; - [ObservableProperty] private bool _headersWithWikilinks; - [ObservableProperty] private bool _invalidCitationParameters; - [ObservableProperty] private bool _linksWithDoublePipes; - [ObservableProperty] private bool _linksWithNoTarget; - [ObservableProperty] private bool _longArticleWithStubTag; - [ObservableProperty] private bool _multipleDefaultSort; - [ObservableProperty] private bool _noCategory; - [ObservableProperty] private bool _seeAlsoOutOfPlace; - [ObservableProperty] private bool _startsWithHeading; - [ObservableProperty] private bool _unbalancedBrackets; - [ObservableProperty] private bool _unclosedTags; - [ObservableProperty] private bool _unformattedReferences; - [ObservableProperty] private bool _unknownParametersInMultipleIssues; - [ObservableProperty] private bool _unknownParametersInWpBannerShell; - [ObservableProperty] private bool _editorsSignatureOrLink; + [ObservableProperty] public partial bool AmbiguousCitationDates { get; set; } + + [ObservableProperty] public partial bool ContainsSicTag { get; set; } + + [ObservableProperty] public partial bool DabPageWithRef { get; set; } + + [ObservableProperty] public partial bool DeadLinks { get; set; } + + [ObservableProperty] public partial bool DuplicateParametersInWpBannerShell { get; set; } + + [ObservableProperty] public partial bool HasRefAfterReferences { get; set; } + + [ObservableProperty] public partial bool HasFootnotesTemplate { get; set; } + + [ObservableProperty] public partial bool HeadersWithWikilinks { get; set; } + + [ObservableProperty] public partial bool InvalidCitationParameters { get; set; } + + [ObservableProperty] public partial bool LinksWithDoublePipes { get; set; } + + [ObservableProperty] public partial bool LinksWithNoTarget { get; set; } + + [ObservableProperty] public partial bool LongArticleWithStubTag { get; set; } + + [ObservableProperty] public partial bool MultipleDefaultSort { get; set; } + + [ObservableProperty] public partial bool NoCategory { get; set; } + + [ObservableProperty] public partial bool SeeAlsoOutOfPlace { get; set; } + + [ObservableProperty] public partial bool StartsWithHeading { get; set; } + + [ObservableProperty] public partial bool UnbalancedBrackets { get; set; } + + [ObservableProperty] public partial bool UnclosedTags { get; set; } + + [ObservableProperty] public partial bool UnformattedReferences { get; set; } + + [ObservableProperty] public partial bool UnknownParametersInMultipleIssues { get; set; } + + [ObservableProperty] public partial bool UnknownParametersInWpBannerShell { get; set; } + + [ObservableProperty] public partial bool EditorsSignatureOrLink { get; set; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/ProfilesViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ProfilesViewModel.cs index d0dff37..2c6031d 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ProfilesViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ProfilesViewModel.cs @@ -1,15 +1,17 @@ namespace CrossWikiEditor.Core.ViewModels; -public sealed partial class ProfilesViewModel(IFileDialogService fileDialogService, - IDialogService dialogService, - IProfileRepository profileRepository, - IUserService userService, - ISettingsService settingsService, - IMessengerWrapper messenger) +public sealed partial class ProfilesViewModel( + IFileDialogService fileDialogService, + IDialogService dialogService, + IProfileRepository profileRepository, + IUserService userService, + ISettingsService settingsService, + IMessengerWrapper messenger) : ViewModelBase { - [ObservableProperty] private Profile? _selectedProfile; - [ObservableProperty] private ObservableCollection _profiles = new(profileRepository.GetAll() ?? []); + [ObservableProperty] public partial Profile? SelectedProfile { get; set; } + + [ObservableProperty] public partial ObservableCollection Profiles { get; set; } = new(profileRepository.GetAll() ?? []); public string Username { get; set; } = ""; public string Password { get; set; } = ""; @@ -78,7 +80,7 @@ private async Task QuickLogin(IDialog dialog) return; } - var profile = new Profile() + var profile = new Profile { Username = Username, Password = Password @@ -92,7 +94,7 @@ private async Task Login(Profile profile, IDialog dialog) currentUserSettings ??= settingsService.GetCurrentSettings(); Result loginResult = await userService.Login(profile, currentUserSettings.GetApiUrl()); - if (loginResult is { IsSuccessful: true }) + if (loginResult is {IsSuccessful: true}) { messenger.Send(new NewAccountLoggedInMessage(profile)); if (!string.IsNullOrEmpty(profile.DefaultSettingsPath)) diff --git a/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs index 4027371..57c69e4 100644 --- a/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/ReportViewModels/EditBoxViewModel.cs @@ -8,5 +8,5 @@ public EditBoxViewModel(IMessengerWrapper messenger) messenger.Register(this, (recipient, message) => Content = message.NewContent); } - [ObservableProperty] public partial string Content { get; set; } + [ObservableProperty] public partial string Content { get; set; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesAndRedirectFilterViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesAndRedirectFilterViewModel.cs index 2af3180..093f83b 100644 --- a/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesAndRedirectFilterViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesAndRedirectFilterViewModel.cs @@ -2,11 +2,15 @@ public sealed partial class SelectNamespacesAndRedirectFilterViewModel(List namespaces) : ViewModelBase { - [ObservableProperty] private ObservableCollection _namespaces = namespaces.ToObservableCollection(); - [ObservableProperty] private bool _isAllNamespacesChecked; - [ObservableProperty] private int _selectedRedirectFilter = 0; - [ObservableProperty] private bool _includeRedirects; - [ObservableProperty] private bool _isIncludeRedirectsVisible; + [ObservableProperty] public partial ObservableCollection Namespaces { get; set; } = namespaces.ToObservableCollection(); + + [ObservableProperty] public partial bool IsAllNamespacesChecked { get; set; } + + [ObservableProperty] public partial int SelectedRedirectFilter { get; set; } = 0; + + [ObservableProperty] public partial bool IncludeRedirects { get; set; } + + [ObservableProperty] public partial bool IsIncludeRedirectsVisible { get; set; } partial void OnIsAllNamespacesCheckedChanged(bool value) { diff --git a/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesViewModel.cs index f068376..36a0b67 100644 --- a/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/SelectNamespacesViewModel.cs @@ -2,6 +2,13 @@ public sealed partial class SelectNamespacesViewModel(List namespaces, bool isMultiselect = true) : ViewModelBase { + [ObservableProperty] + public partial ObservableCollection Namespaces { get; set; } = namespaces.Where(x => x.Id >= 0).ToObservableCollection(); + + [ObservableProperty] public partial bool IsAllSelected { get; set; } + + [ObservableProperty] public partial bool IsMultiselect { get; set; } = isMultiselect; + [RelayCommand] private void Select(IDialog dialog) { @@ -15,8 +22,4 @@ partial void OnIsAllSelectedChanged(bool value) .Select(x => new WikiNamespace(x.Id, x.Name, value)) .ToObservableCollection(); } - - [ObservableProperty] private ObservableCollection _namespaces = namespaces.Where(x => x.Id >= 0).ToObservableCollection(); - [ObservableProperty] private bool _isAllSelected; - [ObservableProperty] private bool _isMultiselect = isMultiselect; } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/ViewModels/SelectProtectionSelectionPageViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/SelectProtectionSelectionPageViewModel.cs index f8ced05..97d23a2 100644 --- a/src/CrossWikiEditor.Core/ViewModels/SelectProtectionSelectionPageViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/SelectProtectionSelectionPageViewModel.cs @@ -2,8 +2,9 @@ public sealed partial class SelectProtectionSelectionPageViewModel : ViewModelBase { - [ObservableProperty] private int _protectionType; - [ObservableProperty] private int _protectionLevel; + [ObservableProperty] public partial int ProtectionType { get; set; } + + [ObservableProperty] public partial int ProtectionLevel { get; set; } [RelayCommand] private void Ok(IDialog dialog) diff --git a/src/CrossWikiEditor.Core/ViewModels/StatusBarViewModel.cs b/src/CrossWikiEditor.Core/ViewModels/StatusBarViewModel.cs index d4f3d44..be5bd76 100644 --- a/src/CrossWikiEditor.Core/ViewModels/StatusBarViewModel.cs +++ b/src/CrossWikiEditor.Core/ViewModels/StatusBarViewModel.cs @@ -2,8 +2,8 @@ namespace CrossWikiEditor.Core.ViewModels; public sealed partial class StatusBarViewModel : ViewModelBase { - private readonly IViewModelFactory _viewModelFactory; private readonly IDialogService _dialogService; + private readonly IViewModelFactory _viewModelFactory; public StatusBarViewModel(IViewModelFactory viewModelFactory, IDialogService dialogService, @@ -24,13 +24,13 @@ public StatusBarViewModel(IViewModelFactory viewModelFactory, [ObservableProperty] [NotifyPropertyChangedFor(nameof(CurrentWiki))] - private string _username = "User: "; + public partial string Username { get; set; } = "User: "; [ObservableProperty] [NotifyPropertyChangedFor(nameof(CurrentWiki))] - private string _languageCode; + public partial string LanguageCode { get; set; } - [ObservableProperty] private string _project; + [ObservableProperty] public partial string Project { get; set; } [RelayCommand] private async Task UsernameClicked() diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllPagesGeneratorEx.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllPagesGeneratorEx.cs index f7361bf..06e91b7 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllPagesGeneratorEx.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllPagesGeneratorEx.cs @@ -19,7 +19,7 @@ public sealed class AllPagesGeneratorEx(WikiSite site) : AllPagesGenerator(site) {"apminsize", MinPageContentLength}, {"apmaxsize", MaxPageContentLength}, {"apprtype", ProtectionType}, - {"apprlevel", ProtectionLevel}, + {"apprlevel", ProtectionLevel} }; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllUsersPageGenerator.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllUsersPageGenerator.cs index dd61fb0..e48f591 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllUsersPageGenerator.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/AllUsersPageGenerator.cs @@ -9,7 +9,7 @@ public sealed class AllUsersPageGenerator(WikiSite site) : WikiList(si public override IEnumerable> EnumListParameters() { - return new Dictionary() + return new Dictionary { {"aulimit", "max"}, {"aufrom", StartFrom} @@ -18,7 +18,7 @@ public sealed class AllUsersPageGenerator(WikiSite site) : WikiList(si protected override WikiPage ItemFromJson(JToken json) { - var name = json["name"]!.Value(); + string? name = json["name"]!.Value(); var wikiPage = new WikiPage(Site, $"User:{name}", 2); wikiPage.RefreshAsync(); return wikiPage; diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/ExternalUrlUsageGenerator.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/ExternalUrlUsageGenerator.cs index 1f60f2a..649f027 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/ExternalUrlUsageGenerator.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/ExternalUrlUsageGenerator.cs @@ -11,7 +11,7 @@ public sealed class ExternalUrlUsageGenerator(WikiSite site) : WikiList> EnumListParameters() { - return new Dictionary() + return new Dictionary { {"euprop", "ids|title|url"}, {"euprotocol", Protocol}, @@ -32,12 +32,13 @@ protected override ExternalUrlUsageItem ItemFromJson(JToken json) { throw new Exception("External url usage generation error"); } - return new ExternalUrlUsageItem() + + return new ExternalUrlUsageItem { PageId = pageId.Value(), NamespaceId = ns.Value(), Title = title.Value() ?? string.Empty, - Url = url.Value() ?? string.Empty, + Url = url.Value() ?? string.Empty }; } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionResultItem.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionResultItem.cs index 50e4159..54373c8 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionResultItem.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionResultItem.cs @@ -6,60 +6,43 @@ public sealed class UserContributionResultItem(WikiPage wikiPage) { public WikiPage WikiPage { get; } = wikiPage; - [JsonProperty("userid")] - public int UserId { get; set; } + [JsonProperty("userid")] public int UserId { get; set; } - [JsonProperty("user")] - public string UserName { get; set; } = string.Empty; + [JsonProperty("user")] public string UserName { get; set; } = string.Empty; - [JsonProperty] - public int Pageid { get; set; } + [JsonProperty] public int Pageid { get; set; } - [JsonProperty("revid")] - public int Revid { get; set; } + [JsonProperty("revid")] public int Revid { get; set; } - [JsonProperty("parentid")] - public int ParentId { get; set; } + [JsonProperty("parentid")] public int ParentId { get; set; } /// - /// Namespace id of the page. + /// Namespace id of the page. /// [JsonProperty("ns")] public string NamespaceId { get; set; } = string.Empty; - [JsonProperty] - public string Title { get; set; } = string.Empty; + [JsonProperty] public string Title { get; set; } = string.Empty; - [JsonProperty] - public string timestamp { get; set; } = string.Empty; + [JsonProperty] public string timestamp { get; set; } = string.Empty; - [JsonProperty("new")] - public bool IsNew { get; set; } + [JsonProperty("new")] public bool IsNew { get; set; } - [JsonProperty("minor")] - public bool IsMinor { get; set; } + [JsonProperty("minor")] public bool IsMinor { get; set; } - [JsonProperty("top")] - public bool IsTop { get; set; } + [JsonProperty("top")] public bool IsTop { get; set; } - [JsonProperty] - public string Comment { get; set; } = string.Empty; + [JsonProperty] public string Comment { get; set; } = string.Empty; - [JsonProperty("parsedcomment")] - public string ParsedComment { get; set; } = string.Empty; + [JsonProperty("parsedcomment")] public string ParsedComment { get; set; } = string.Empty; - [JsonProperty] - public bool Patrolled { get; set; } + [JsonProperty] public bool Patrolled { get; set; } - [JsonProperty("autopatrolled")] - public bool AutoPatrolled { get; set; } + [JsonProperty("autopatrolled")] public bool AutoPatrolled { get; set; } - [JsonProperty("size")] - public int ContentLength { get; set; } + [JsonProperty("size")] public int ContentLength { get; set; } - [JsonProperty("sizediff")] - public int ContentLengthDiff { get; set; } + [JsonProperty("sizediff")] public int ContentLengthDiff { get; set; } - [JsonProperty("tags")] - public string[] Tags { get; set; } = []; -} + [JsonProperty("tags")] public string[] Tags { get; set; } = []; +} \ No newline at end of file diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionsGenerator.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionsGenerator.cs index 7ade70a..4890a14 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionsGenerator.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/Generators/UserContributionsGenerator.cs @@ -5,12 +5,12 @@ namespace CrossWikiEditor.Core.WikiClientLibraryUtils.Generators; public sealed class UserContributionsGenerator : WikiList { - private readonly List? _usernames; private readonly List? _userIds; + private readonly List? _usernames; private readonly string? _userPrefix; /// - /// Create a wikilist of user contributions by usernames. + /// Create a wikilist of user contributions by usernames. /// public UserContributionsGenerator(WikiSite site, List usernames) : base(site) { @@ -20,7 +20,7 @@ public UserContributionsGenerator(WikiSite site, List usernames) : base( } /// - /// Create a wikilist of user contributions by user ids. + /// Create a wikilist of user contributions by user ids. /// public UserContributionsGenerator(WikiSite site, List userIds) : base(site) { @@ -30,7 +30,7 @@ public UserContributionsGenerator(WikiSite site, List userIds) : base(site) } /// - /// Create a wikilist of user contributions by user prefixes. + /// Create a wikilist of user contributions by user prefixes. /// public UserContributionsGenerator(WikiSite site, string userPrefix) : base(site) { @@ -42,102 +42,103 @@ public UserContributionsGenerator(WikiSite site, string userPrefix) : base(site) public override string ListName => "usercontribs"; /// - /// The start timestamp to return from, i.e. revisions before this timestamp. + /// The start timestamp to return from, i.e. revisions before this timestamp. /// public DateTime? StartTime { get; set; } /// - /// The end timestamp to return to, i.e. revisions after this timestamp. + /// The end timestamp to return to, i.e. revisions after this timestamp. /// public DateTime? EndTime { get; set; } /// - /// Adds the page ID and revision ID. + /// Adds the page ID and revision ID. /// public bool IncludeIds { get; set; } /// - /// Adds the title and namespace ID of the page. + /// Adds the title and namespace ID of the page. /// public bool IncludeTitle { get; set; } /// - /// Adds the timestamp of the edit. + /// Adds the timestamp of the edit. /// public bool IncludeTimestamp { get; set; } /// - /// Adds the comment of the edit. If the comment has been revision deleted, a commenthidden property will be returned. + /// Adds the comment of the edit. If the comment has been revision deleted, a commenthidden property will be returned. /// public bool IncludeComment { get; set; } /// - /// Adds the parsed comment of the edit. If the comment has been revision deleted, a commenthidden property will be returned. + /// Adds the parsed comment of the edit. If the comment has been revision deleted, a commenthidden property will be + /// returned. /// public bool IncludeParsedComment { get; set; } /// - /// Adds the new size of the edit. + /// Adds the new size of the edit. /// public bool IncludeSize { get; set; } /// - /// Adds the size delta of the edit against its parent. + /// Adds the size delta of the edit against its parent. /// public bool IncludeSizeDiff { get; set; } /// - /// Adds flags of the edit. + /// Adds flags of the edit. /// public bool IncludeFlags { get; set; } /// - /// Tags patrolled edits. + /// Tags patrolled edits. /// public bool IncludePatrolled { get; set; } /// - /// Lists tags for the edit. + /// Lists tags for the edit. /// public bool IncludeTags { get; set; } /// - /// Show only items that are new. + /// Show only items that are new. /// public PropertyFilterOption NewFilter { get; set; } /// - /// Show only items that are auto patrolled. + /// Show only items that are auto patrolled. /// public PropertyFilterOption AutoPatrolledFilter { get; set; } /// - /// Show only items that are minor. + /// Show only items that are minor. /// public PropertyFilterOption MinorFilter { get; set; } /// - /// Show only items that are patrolled. + /// Show only items that are patrolled. /// public PropertyFilterOption PatrolledFilter { get; set; } /// - /// Show only items that top. + /// Show only items that top. /// public PropertyFilterOption TopFilter { get; set; } /// - /// Only list revisions tagged with this tag. + /// Only list revisions tagged with this tag. /// public string? Tag { get; set; } /// - /// In which direction to enumerate: + /// In which direction to enumerate: /// public bool OrderDescending { get; set; } /// - /// Only list contributions in these namespaces. + /// Only list contributions in these namespaces. /// public int? NamespaceId { get; set; } @@ -172,20 +173,19 @@ public UserContributionsGenerator(WikiSite site, string userPrefix) : base(site) protected override UserContributionResultItem ItemFromJson(JToken json) { - var title = json["title"]; + JToken? title = json["title"]; if (title is null) { throw new Exception("Title field is missing from json"); } + var wikiPage = new WikiPage(Site, title.Value() ?? string.Empty); - MediaWikiHelper.PopulatePageFromJson(wikiPage, (JObject) json, new WikiPageQueryProvider() + MediaWikiHelper.PopulatePageFromJson(wikiPage, (JObject) json, new WikiPageQueryProvider { Properties = [] }); return new UserContributionResultItem(wikiPage); - } - - // ReSharper disable EnforceIfStatementBraces + } // ReSharper disable EnforceIfStatementBraces private string PrepareUcProp() { var props = new List(); diff --git a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/MagicWordInfo.cs b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/MagicWordInfo.cs index 2e5f97d..81f0883 100644 --- a/src/CrossWikiEditor.Core/WikiClientLibraryUtils/MagicWordInfo.cs +++ b/src/CrossWikiEditor.Core/WikiClientLibraryUtils/MagicWordInfo.cs @@ -3,8 +3,8 @@ namespace CrossWikiEditor.Core.WikiClientLibraryUtils; /// -/// This class is mostly copied from WikiClientLibrary itself. Once this class is released and is available via Nuget, -/// We should get rid of this class. +/// This class is mostly copied from WikiClientLibrary itself. Once this class is released and is available via Nuget, +/// We should get rid of this class. /// [JsonObject(MemberSerialization.OptIn)] public sealed class MagicWordInfo diff --git a/src/CrossWikiEditor.Tests/BaseTest.cs b/src/CrossWikiEditor.Tests/BaseTest.cs index 92c5b77..dd6f411 100644 --- a/src/CrossWikiEditor.Tests/BaseTest.cs +++ b/src/CrossWikiEditor.Tests/BaseTest.cs @@ -7,20 +7,20 @@ namespace CrossWikiEditor.Tests; [Parallelizable] public abstract class BaseTest { - protected IFileDialogService _fileDialogService; - protected ISystemService _systemService; + protected ICategoryService _categoryService; + protected IClipboard _clipboard; + protected IDialog _dialog; protected IDialogService _dialogService; + protected IFileDialogService _fileDialogService; + protected ILogger _logger; + protected IMessengerWrapper _messenger; + protected IPageService _pageService; protected IProfileRepository _profileRepository; protected ISettingsService _settingsService; - protected IViewModelFactory _viewModelFactory; - protected IDialog _dialog; - protected IMessengerWrapper _messenger; - protected IClipboard _clipboard; - protected ILogger _logger; + protected ISystemService _systemService; protected IUserService _userService; - protected IPageService _pageService; - protected ICategoryService _categoryService; + protected IViewModelFactory _viewModelFactory; protected IWikiClientCache _wikiClientCache; protected void SetUpServices() diff --git a/src/CrossWikiEditor.Tests/CrossWikiEditor.Tests.csproj b/src/CrossWikiEditor.Tests/CrossWikiEditor.Tests.csproj index 4a2e60d..dd9b0a1 100644 --- a/src/CrossWikiEditor.Tests/CrossWikiEditor.Tests.csproj +++ b/src/CrossWikiEditor.Tests/CrossWikiEditor.Tests.csproj @@ -11,26 +11,26 @@ - + - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - + diff --git a/src/CrossWikiEditor.Tests/Fakers.cs b/src/CrossWikiEditor.Tests/Fakers.cs index 2bef256..5250fa3 100644 --- a/src/CrossWikiEditor.Tests/Fakers.cs +++ b/src/CrossWikiEditor.Tests/Fakers.cs @@ -13,11 +13,13 @@ public static class Fakers .RuleFor(p => p.Notes, f => f.Random.Words()) .RuleFor(p => p.Username, f => f.Internet.UserName()); - public static Faker GetWikiPageModelFaker(string apiRoot, IWikiClientCache wikiClientCache) => - new Faker() + public static readonly Faker WikiNamespaceFaker = new Faker() + .CustomInstantiator(f => new WikiNamespace(f.UniqueIndex, f.Random.Word())); + + public static Faker GetWikiPageModelFaker(string apiRoot, IWikiClientCache wikiClientCache) + { + return new Faker() .CustomInstantiator(f => new WikiPageModel(f.Random.Word() + f.UniqueIndex, apiRoot, wikiClientCache)) .RuleFor(p => p.NamespaceId, f => f.Random.Int(0, 20)); - - public static readonly Faker WikiNamespaceFaker = new Faker() - .CustomInstantiator(f => new WikiNamespace(f.UniqueIndex, f.Random.Word(), false)); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Tests/ListProviders/AllPagesListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/AllPagesListProviderTests.cs index 287d712..08f84c7 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/AllPagesListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/AllPagesListProviderTests.cs @@ -18,16 +18,22 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/AllPagesNoRedirectsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/AllPagesNoRedirectsListProviderTests.cs index bf22d4b..8e207a5 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/AllPagesNoRedirectsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/AllPagesNoRedirectsListProviderTests.cs @@ -18,16 +18,22 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/AllPagesWithPrefixListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/AllPagesWithPrefixListProviderTests.cs index a2ae1a8..bdec65a 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/AllPagesWithPrefixListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/AllPagesWithPrefixListProviderTests.cs @@ -16,16 +16,22 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/AllRedirectsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/AllRedirectsListProviderTests.cs index d57399c..0f90189 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/AllRedirectsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/AllRedirectsListProviderTests.cs @@ -18,16 +18,22 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/AllUsersListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/AllUsersListProviderTests.cs index af4c2c2..e0485b1 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/AllUsersListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/AllUsersListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageListProviderTests.cs index e2bf922..83a8bf5 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageListProviderTests.cs @@ -14,8 +14,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageNoHiddenCategoriesListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageNoHiddenCategoriesListProviderTests.cs index 66b9b55..3e450b8 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageNoHiddenCategoriesListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageNoHiddenCategoriesListProviderTests.cs @@ -14,14 +14,23 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() { // arrange - _categoryService.GetCategoriesOf(_settingsService.CurrentApiUrl, _sut.Param, 73, includeHidden: false) + _categoryService.GetCategoriesOf(_settingsService.CurrentApiUrl, _sut.Param, 73, false) .Returns(_expectedPages); await base.MakeList_ShouldReturnServiceResults(_expectedPages); @@ -31,7 +40,7 @@ public async Task MakeList_ShouldReturnServiceResults() public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenServiceReturnsUnsuccessfulResult() { // arrange - _categoryService.GetCategoriesOf(_settingsService.CurrentApiUrl, _sut.Param, 73, includeHidden: false) + _categoryService.GetCategoriesOf(_settingsService.CurrentApiUrl, _sut.Param, 73, false) .Returns(new Exception("failed to get pages")); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProviderTests.cs index ac8d323..af3c07a 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoriesOnPageOnlyHiddenCategoriesListProviderTests.cs @@ -14,8 +14,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoryListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoryListProviderTests.cs index 56709b4..c0ab2d5 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoryListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoryListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursive1LevelListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursive1LevelListProviderTests.cs index 719107b..9368745 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursive1LevelListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursive1LevelListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursiveListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursiveListProviderTests.cs index 1d7afb9..f8bdb2e 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursiveListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/CategoryRecursiveListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/FilesOnPageListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/FilesOnPageListProviderTests.cs index 2709853..d0b86ba 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/FilesOnPageListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/FilesOnPageListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/HtmlScraperListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/HtmlScraperListProviderTests.cs index 4577749..0d854f7 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/HtmlScraperListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/HtmlScraperListProviderTests.cs @@ -6,28 +6,28 @@ namespace CrossWikiEditor.Tests.ListProviders; public sealed class HtmlScraperListProviderTests : ListProvidersBaseTest { - private IHttpClientFactory _httpClientFactory; - private MockHttpMessageHandler _mockHttpMessageHandler; - private readonly string _htmlWithDuplicateLinks = """ - - - Kotlin programming language - Ռեո դղյակ - Ռեո դղյակ - Ռեո դղյակ - Ռեո դղյակ - Ռեո դղյակ - - - """; + + + Kotlin programming language + Ռեո դղյակ + Ռեո դղյակ + Ռեո դղյակ + Ռեո դղյակ + Ռեո դղյակ + + + """; private readonly string _htmlWithoutLinks = """ - - - - - """; + + + + + """; + + private IHttpClientFactory _httpClientFactory; + private MockHttpMessageHandler _mockHttpMessageHandler; [SetUp] public void SetUp() @@ -40,8 +40,17 @@ public void SetUp() new SimpleHtmlParser(_logger, _settingsService, _wikiClientCache)); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnFailure_WhenRequestIsNotSuccessful() @@ -51,7 +60,7 @@ public async Task MakeList_ShouldReturnFailure_WhenRequestIsNotSuccessful() _httpClientFactory.CreateClient("Scraper").Returns(new HttpClient(_mockHttpMessageHandler)); _mockHttpMessageHandler .When(_sut.Param) - .Respond(HttpStatusCode.Found, new StringContent("error message")); + .Respond(HttpStatusCode.Found, new StringContent("error message")); // act Result> result = await _sut.MakeList(); diff --git a/src/CrossWikiEditor.Tests/ListProviders/ImageFileLinksListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/ImageFileLinksListProviderTests.cs index 1f05ec4..4c379e9 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/ImageFileLinksListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/ImageFileLinksListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/LinkSearchListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/LinkSearchListProviderTests.cs index 5c75dfe..f8d76b6 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/LinkSearchListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/LinkSearchListProviderTests.cs @@ -11,8 +11,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageBlueListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageBlueListProviderTests.cs index 93cdcdf..21566d6 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageBlueListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageBlueListProviderTests.cs @@ -21,8 +21,17 @@ public void SetUp() _expectedPages.Add(new WikiPageModel("8 Յուլիս", _userSettings.GetApiUrl(), _wikiClientCache)); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnBluePageServiceResults() @@ -33,8 +42,8 @@ public async Task MakeList_ShouldReturnBluePageServiceResults() await MakeList_ShouldReturnServiceResults( [ - new("8 Յուլիս", _userSettings.GetApiUrl(), _wikiClientCache), - new("Գրիգոր Ամիրեանի Բնակելի Տուն", _userSettings.GetApiUrl(), _wikiClientCache) + new WikiPageModel("8 Յուլիս", _userSettings.GetApiUrl(), _wikiClientCache), + new WikiPageModel("Գրիգոր Ամիրեանի Բնակելի Տուն", _userSettings.GetApiUrl(), _wikiClientCache) ]); } diff --git a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageListProviderTests.cs index 588b57f..f2bb776 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageRedListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageRedListProviderTests.cs index b687d51..fb45a1e 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageRedListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/LinksOnPageRedListProviderTests.cs @@ -21,8 +21,17 @@ public void SetUp() _expectedPages.Add(new WikiPageModel("8 Յուլիս", _userSettings.GetApiUrl(), _wikiClientCache)); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnBluePageServiceResults() @@ -36,7 +45,7 @@ await MakeList_ShouldReturnServiceResults( _expectedPages[0], _expectedPages[1], _expectedPages[2], - _expectedPages[3], + _expectedPages[3] ]); } diff --git a/src/CrossWikiEditor.Tests/ListProviders/ListProvidersBaseTest.cs b/src/CrossWikiEditor.Tests/ListProviders/ListProvidersBaseTest.cs index dd4ee66..0675971 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/ListProvidersBaseTest.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/ListProvidersBaseTest.cs @@ -2,12 +2,12 @@ namespace CrossWikiEditor.Tests.ListProviders; public abstract class ListProvidersBaseTest : BaseTest where T : ListProviderBase { - protected UserSettings _userSettings; + protected List _expectedPages; + protected SelectNamespacesAndRedirectFilterViewModel _selectNamespacesAndRedirectFilterViewModel; protected SelectNamespacesViewModel _selectNamespacesViewModel; protected SelectProtectionSelectionPageViewModel _selectProtectionSelectionPageViewModel; - protected SelectNamespacesAndRedirectFilterViewModel _selectNamespacesAndRedirectFilterViewModel; - protected List _expectedPages; protected T _sut; + protected UserSettings _userSettings; [Test] public async Task GetLimit_ShouldReturn50_WhenNoValueIsReturned() @@ -17,11 +17,12 @@ public async Task GetLimit_ShouldReturn50_WhenNoValueIsReturned() Assert.Pass(); return; } + // arrange _dialogService.ShowDialog(Arg.Any()).Returns(null as int?); // act - var result = await limitedListProvider.GetLimit(); + int result = await limitedListProvider.GetLimit(); // assert result.Should().Be(50); @@ -35,12 +36,13 @@ public async Task GetLimit_ShouldReturnPromptValue() Assert.Pass(); return; } + // arrange _dialogService.ShowDialog(Arg.Is(vm => vm.IsNumeric && vm.Value == 50 && vm.Title == "How many page" && vm.Text == "Limit: ")).Returns(42); // act - var result = await limitedListProvider.GetLimit(); + int result = await limitedListProvider.GetLimit(); // assert result.Should().Be(42); @@ -50,7 +52,7 @@ protected void SetUpUserSettings(string languageCode, ProjectEnum project) { _userSettings = new UserSettings { - UserWiki = new(languageCode, project) + UserWiki = new UserWiki(languageCode, project) }; _settingsService.GetCurrentSettings().Returns(_userSettings); _settingsService.CurrentApiUrl.Returns(_userSettings.GetApiUrl()); @@ -65,6 +67,7 @@ protected async Task MakeList_ShouldReturnServiceResults(List exp { await needAdditionalParamsListProvider.GetAdditionalParams(); } + Result> result = await (_sut as ILimitedListProvider)!.MakeList(73); // assert @@ -79,7 +82,7 @@ protected void CanMake_ShouldBeFalse_WhenParamIsEmpty() _sut.Param = ""; // act - var result = _sut.CanMake; + bool result = _sut.CanMake; // assert result.Should().BeFalse(); @@ -91,7 +94,7 @@ protected void CanMake_ShouldBeTrue_WhenParamIsEmpty() _sut.Param = "not empty"; // act - var result = _sut.CanMake; + bool result = _sut.CanMake; // assert result.Should().BeTrue(); diff --git a/src/CrossWikiEditor.Tests/ListProviders/NewPagesListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/NewPagesListProviderTests.cs index 75872ac..0aa13f8 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/NewPagesListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/NewPagesListProviderTests.cs @@ -3,6 +3,7 @@ namespace CrossWikiEditor.Tests.ListProviders; public sealed class NewPagesListProviderTests : ListProvidersBaseTest { private readonly int[] _testArray = [7, 2, 3, 9]; + [SetUp] public void SetUp() { @@ -14,21 +15,27 @@ public void SetUp() Param = "start from here" }; _dialogService.ShowDialog(_selectNamespacesViewModel).Returns(_testArray); - _viewModelFactory.GetSelectNamespacesViewModel(true).Returns(_selectNamespacesViewModel); + _viewModelFactory.GetSelectNamespacesViewModel().Returns(_selectNamespacesViewModel); _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/PagesWithPropListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/PagesWithPropListProviderTests.cs index 9057cd8..fc0b1dd 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/PagesWithPropListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/PagesWithPropListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksListProviderTests.cs index f750a80..5138108 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksListProviderTests.cs @@ -18,16 +18,22 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProviderTests.cs index 3192d88..e6c2fc0 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/PagesWithoutLanguageLinksNoRedirectsListProviderTests.cs @@ -18,22 +18,29 @@ public void SetUp() } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() { // arrange - _pageService.GetAllPages(_userSettings.GetApiUrl(), _sut.Param, 7, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty, 73) + _pageService.GetAllPages(_userSettings.GetApiUrl(), _sut.Param, 7, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty, + 73) .Returns(_expectedPages); await MakeList_ShouldReturnServiceResults(_expectedPages); @@ -43,7 +50,8 @@ public async Task MakeList_ShouldReturnPageServiceResults() public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult() { // arrange - _pageService.GetAllPages(_userSettings.GetApiUrl(), _sut.Param, 7, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty, 73) + _pageService.GetAllPages(_userSettings.GetApiUrl(), _sut.Param, 7, PropertyFilterOption.WithoutProperty, PropertyFilterOption.WithoutProperty, + 73) .Returns(new Exception("failed to get pages")); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/RandomListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/RandomListProviderTests.cs index d57f7e5..05138de 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/RandomListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/RandomListProviderTests.cs @@ -9,8 +9,8 @@ public void SetUp() SetUpUserSettings("hyw", ProjectEnum.Wikipedia); _selectNamespacesAndRedirectFilterViewModel = new SelectNamespacesAndRedirectFilterViewModel( [ - new(0, ""), - new(1, "Քննարկում:") + new WikiNamespace(0, ""), + new WikiNamespace(1, "Քննարկում:") ]) { IsIncludeRedirectsVisible = false @@ -73,7 +73,7 @@ public async Task MakeList_ShouldReturnPageServiceResults(RedirectFilter redirec // arrange _dialogService.ShowDialog(_selectNamespacesAndRedirectFilterViewModel) .Returns(new NamespacesAndRedirectFilterOptions([3, 4], allowRedirectLinks, redirectFilter)); - _pageService.GetRandomPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] { 3, 4 })), filterRedirects, 73) + _pageService.GetRandomPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] {3, 4})), filterRedirects, 73) .Returns(_expectedPages); await MakeList_ShouldReturnServiceResults(_expectedPages); @@ -87,12 +87,13 @@ public async Task MakeList_ShouldReturnPageServiceResults(RedirectFilter redirec [TestCase(RedirectFilter.Redirects, true, false)] [TestCase(RedirectFilter.NoRedirects, false, false)] [TestCase((RedirectFilter) 7, null, false)] - public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult(RedirectFilter redirectFilter, bool? filterRedirects, bool allowRedirectLinks) + public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult(RedirectFilter redirectFilter, + bool? filterRedirects, bool allowRedirectLinks) { // arrange _dialogService.ShowDialog(_selectNamespacesAndRedirectFilterViewModel) .Returns(new NamespacesAndRedirectFilterOptions([3, 4], allowRedirectLinks, redirectFilter)); - _pageService.GetRandomPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] { 3, 4 })), filterRedirects, 73) + _pageService.GetRandomPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] {3, 4})), filterRedirects, 73) .Returns(new Exception("failed to get pages")); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/RecentChangesListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/RecentChangesListProviderTests.cs index f2fd3e8..d401c11 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/RecentChangesListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/RecentChangesListProviderTests.cs @@ -13,27 +13,33 @@ public void SetUp() Param = "start from here" }; _dialogService.ShowDialog(_selectNamespacesViewModel).Returns([7, 2, 3, 9]); - _viewModelFactory.GetSelectNamespacesViewModel(true).Returns(_selectNamespacesViewModel); + _viewModelFactory.GetSelectNamespacesViewModel().Returns(_selectNamespacesViewModel); _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } [Test] - public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() => + public new async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsNotCalled(); + } [Test] - public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() => + public async Task CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList() + { await base.CanMake_ShouldBeFalse_WhenGetAdditionalParamsReturnsEmptyList(_selectNamespacesViewModel); + } [Test] - public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() => + public async Task CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList() + { await base.CanMake_ShouldBeTrue_WhenGetAdditionalParamsReturnsNonEmptyList(_selectNamespacesViewModel); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() { // arrange - _pageService.GetRecentlyChangedPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] { 7, 2, 3, 9 })), 73) + _pageService.GetRecentlyChangedPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] {7, 2, 3, 9})), 73) .Returns(_expectedPages); await MakeList_ShouldReturnServiceResults(_expectedPages); @@ -43,7 +49,7 @@ public async Task MakeList_ShouldReturnPageServiceResults() public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult() { // arrange - _pageService.GetRecentlyChangedPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] { 7, 2, 3, 9 })), 73) + _pageService.GetRecentlyChangedPages(_userSettings.GetApiUrl(), Arg.Is(x => x.SequenceEqual(new[] {7, 2, 3, 9})), 73) .Returns(new Exception("failed to get pages")); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/TextFileListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/TextFileListProviderTests.cs index 8fa9912..e109614 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/TextFileListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/TextFileListProviderTests.cs @@ -16,15 +16,15 @@ public async Task MakeList_ShouldReadBulletWikiList() { // arrange const string text = """ - *[[title1]] + *[[title1]] - * [[Category:title (f e )2|few (fewcas)]] + * [[Category:title (f e )2|few (fewcas)]] - * [[title3]] - * [[titl e3|display]] - """; + * [[title3]] + * [[titl e3|display]] + """; SetupForSingleFile(text); // act @@ -45,15 +45,15 @@ public async Task MakeList_ShouldReadNumberedWikiList() { // arrange const string text = """ - #[[title1]] - - - # [[Category:title (f e )2|few (fewcas)]] - - - # [[title3]] - # [[titl e3|display]] - """; + #[[title1]] + + + # [[Category:title (f e )2|few (fewcas)]] + + + # [[title3]] + # [[titl e3|display]] + """; SetupForSingleFile(text); // act @@ -74,12 +74,12 @@ public async Task MakeList_ShouldReadPlainList() { // arrange const string text = """ - title1 - title2 - - - title3 - """; + title1 + title2 + + + title3 + """; SetupForSingleFile(text); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/TransclusionsOnPageListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/TransclusionsOnPageListProviderTests.cs index de5daec..c3a1348 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/TransclusionsOnPageListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/TransclusionsOnPageListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/UserContributionsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/UserContributionsListProviderTests.cs index a9d910a..6b631f9 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/UserContributionsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/UserContributionsListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WhatLinksHereListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WhatLinksHereListProviderTests.cs index b261117..98ebca0 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WhatLinksHereListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WhatLinksHereListProviderTests.cs @@ -9,8 +9,8 @@ public void SetUp() SetUpUserSettings("hyw", ProjectEnum.Wikipedia); _selectNamespacesAndRedirectFilterViewModel = new SelectNamespacesAndRedirectFilterViewModel( [ - new(0, ""), - new(1, "Քննարկում:") + new WikiNamespace(0, ""), + new WikiNamespace(1, "Քննարկում:") ]); _sut = new WhatLinksHereListProvider(_dialogService, _pageService, _settingsService, _viewModelFactory) { @@ -87,7 +87,8 @@ public async Task MakeList_ShouldReturnPageServiceResults(RedirectFilter redirec // arrange _dialogService.ShowDialog(_selectNamespacesAndRedirectFilterViewModel) .Returns(new NamespacesAndRedirectFilterOptions([3, 4], allowRedirectLinks, redirectFilter)); - _pageService.GetPagesLinkedTo(_userSettings.GetApiUrl(), _sut.Param, Arg.Is(x => x.SequenceEqual(new[] { 3, 4 })), allowRedirectLinks, filterRedirects, 73) + _pageService.GetPagesLinkedTo(_userSettings.GetApiUrl(), _sut.Param, Arg.Is(x => x.SequenceEqual(new[] {3, 4})), allowRedirectLinks, + filterRedirects, 73) .Returns(_expectedPages); await MakeList_ShouldReturnServiceResults(_expectedPages); @@ -101,12 +102,14 @@ public async Task MakeList_ShouldReturnPageServiceResults(RedirectFilter redirec [TestCase(RedirectFilter.Redirects, true, false)] [TestCase(RedirectFilter.NoRedirects, false, false)] [TestCase((RedirectFilter) 7, null, false)] - public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult(RedirectFilter redirectFilter, bool? filterRedirects, bool allowRedirectLinks) + public async Task MakeList_ShouldReturnUnsuccessfulResult_WhenPageServiceReturnsUnsuccessfulResult(RedirectFilter redirectFilter, + bool? filterRedirects, bool allowRedirectLinks) { // arrange _dialogService.ShowDialog(_selectNamespacesAndRedirectFilterViewModel) .Returns(new NamespacesAndRedirectFilterOptions([3, 4], allowRedirectLinks, redirectFilter)); - _pageService.GetPagesLinkedTo(_userSettings.GetApiUrl(), _sut.Param, Arg.Is(x => x.SequenceEqual(new[] { 3, 4 })), allowRedirectLinks, filterRedirects, 73) + _pageService.GetPagesLinkedTo(_userSettings.GetApiUrl(), _sut.Param, Arg.Is(x => x.SequenceEqual(new[] {3, 4})), allowRedirectLinks, + filterRedirects, 73) .Returns(new Exception("failed to get pages")); // act diff --git a/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereAllNsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereAllNsListProviderTests.cs index b6f7edd..d01fc5e 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereAllNsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereAllNsListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereListProviderTests.cs index d19800b..78c8d13 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WhatTranscludesHereListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextAllNsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextAllNsListProviderTests.cs index 4fbdc6f..aa470be 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextAllNsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextAllNsListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextListProviderTests.cs index 8d72cda..e4e8354 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTextListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleAllNsListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleAllNsListProviderTests.cs index b9d5d95..deb7bc1 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleAllNsListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleAllNsListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleListProviderTests.cs b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleListProviderTests.cs index ca7b211..60b0035 100644 --- a/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleListProviderTests.cs +++ b/src/CrossWikiEditor.Tests/ListProviders/WikiSearchInTitleListProviderTests.cs @@ -15,8 +15,17 @@ public void SetUp() _expectedPages = Fakers.GetWikiPageModelFaker(_userSettings.GetApiUrl(), _wikiClientCache).Generate(4); } - [Test] public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() => base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); - [Test] public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() => base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + [Test] + public new void CanMake_ShouldBeFalse_WhenParamIsEmpty() + { + base.CanMake_ShouldBeFalse_WhenParamIsEmpty(); + } + + [Test] + public new void CanMake_ShouldBeTrue_WhenParamIsEmpty() + { + base.CanMake_ShouldBeTrue_WhenParamIsEmpty(); + } [Test] public async Task MakeList_ShouldReturnPageServiceResults() diff --git a/src/CrossWikiEditor.Tests/Services/WikiServices/WikiClientCacheTests.cs b/src/CrossWikiEditor.Tests/Services/WikiServices/WikiClientCacheTests.cs index c21597d..fcf945c 100644 --- a/src/CrossWikiEditor.Tests/Services/WikiServices/WikiClientCacheTests.cs +++ b/src/CrossWikiEditor.Tests/Services/WikiServices/WikiClientCacheTests.cs @@ -4,8 +4,8 @@ namespace CrossWikiEditor.Tests.Services.WikiServices; public sealed class WikiClientCacheTests : BaseTest { - private WikiClientCache _sut; private const string ApiRoot = "https://hy.wikipedia.org/w/api.php?"; + private WikiClientCache _sut; [SetUp] public void SetUp() @@ -115,7 +115,8 @@ public async Task GetWikiPageModel_ShouldReturnFailedResult_WhenForInvalidApi() // assert result.IsSuccessful.Should().BeFalse(); - result.ErrorMessage.Should().Be("An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set."); + result.ErrorMessage.Should() + .Be("An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set."); } [Test] diff --git a/src/CrossWikiEditor.Tests/Usings.cs b/src/CrossWikiEditor.Tests/Usings.cs index 3e871e3..95a65b5 100644 --- a/src/CrossWikiEditor.Tests/Usings.cs +++ b/src/CrossWikiEditor.Tests/Usings.cs @@ -10,7 +10,6 @@ global using NSubstitute; global using NSubstitute.ReturnsExtensions; global using NUnit.Framework; - global using CrossWikiEditor.Core.ListProviders; global using CrossWikiEditor.Core.ListProviders.BaseListProviders; global using CrossWikiEditor.Core.Messages; diff --git a/src/CrossWikiEditor.Tests/Utils/CollectionExtensionsTests.cs b/src/CrossWikiEditor.Tests/Utils/CollectionExtensionsTests.cs index 8c6abf9..9ea9dd7 100644 --- a/src/CrossWikiEditor.Tests/Utils/CollectionExtensionsTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/CollectionExtensionsTests.cs @@ -19,7 +19,7 @@ public void ToObservableCollection_ShouldReturnEmptyCollection_WhenEnumerableIsE public void ToObservableCollection_ShouldReturnFullCollection_WhenEnumerableIsValid() { // arrange - var nums = new List { 1, 2, 3, 4, 5 }; + var nums = new List {1, 2, 3, 4, 5}; // act var result = nums.ToObservableCollection(); @@ -44,7 +44,7 @@ public void RandomSubset_ShouldThrowArgumentNullException_WhenCollectionIsNull() public void RandomSubset_ShouldReturnOutOfBoundException_WhenSubsetSizeIsLargerThanCollectionSize() { // arrange - var list = new List { 3, 4, 2 }; + var list = new List {3, 4, 2}; // act @@ -57,7 +57,7 @@ public void RandomSubset_ShouldReturnOutOfBoundException_WhenSubsetSizeIsLargerT public void RandomSubset_ShouldReturnSubsetOfGivenSize() { // arrange - var list = new List { 2, 12, 42, 7, -5 }; + var list = new List {2, 12, 42, 7, -5}; // act List result = list.RandomSubset(3); diff --git a/src/CrossWikiEditor.Tests/Utils/LanguageSpecificRegexesTests.cs b/src/CrossWikiEditor.Tests/Utils/LanguageSpecificRegexesTests.cs index 44ae8c5..09dc89b 100644 --- a/src/CrossWikiEditor.Tests/Utils/LanguageSpecificRegexesTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/LanguageSpecificRegexesTests.cs @@ -12,9 +12,9 @@ public async Task SetUp() SetUpServices(); const string apiRoot = "https://en.wikipedia.org/w/api.php?"; _settingsService.CurrentApiUrl.Returns(apiRoot); - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("en", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("en", ProjectEnum.Wikipedia) }); var enWiki = new WikiSite(new WikiClient(), apiRoot); await enWiki.Initialization; diff --git a/src/CrossWikiEditor.Tests/Utils/MessengerWrapperTests.cs b/src/CrossWikiEditor.Tests/Utils/MessengerWrapperTests.cs index f8ceb2b..a0baff3 100644 --- a/src/CrossWikiEditor.Tests/Utils/MessengerWrapperTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/MessengerWrapperTests.cs @@ -27,7 +27,7 @@ public void Register_ShouldInvokeMessengerRegisterMethod() // Arrange IMessenger? mockMessenger = Substitute.For(); var wrapper = new MessengerWrapper(mockMessenger); - var recipient = new object(); + object? recipient = new(); MessageHandler handler = (sender, args) => { }; // Act diff --git a/src/CrossWikiEditor.Tests/Utils/NumberExtensionsTests.cs b/src/CrossWikiEditor.Tests/Utils/NumberExtensionsTests.cs index fbd9a99..33d6e61 100644 --- a/src/CrossWikiEditor.Tests/Utils/NumberExtensionsTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/NumberExtensionsTests.cs @@ -12,7 +12,10 @@ public sealed class NumberExtensionsTests [TestCase(3, ExpectedResult = false)] [TestCase(-11, ExpectedResult = false)] [TestCase(11, ExpectedResult = false)] - public bool IsEven(int value) => value.IsEven(); + public bool IsEven(int value) + { + return value.IsEven(); + } [TestCase(0, ExpectedResult = false)] [TestCase(-2, ExpectedResult = false)] @@ -24,5 +27,8 @@ public sealed class NumberExtensionsTests [TestCase(3, ExpectedResult = true)] [TestCase(-11, ExpectedResult = true)] [TestCase(11, ExpectedResult = true)] - public bool IsOdd(int value) => value.IsOdd(); + public bool IsOdd(int value) + { + return value.IsOdd(); + } } \ No newline at end of file diff --git a/src/CrossWikiEditor.Tests/Utils/StringExtensionsTests.cs b/src/CrossWikiEditor.Tests/Utils/StringExtensionsTests.cs index d5a5ca8..2a42c10 100644 --- a/src/CrossWikiEditor.Tests/Utils/StringExtensionsTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/StringExtensionsTests.cs @@ -54,7 +54,7 @@ public void Contains_SubstringFound_ReturnsTrue() const string substring = "test"; // Act - bool result = input.Contains(substring, isRegex: false); + bool result = input.Contains(substring, false); // Assert result.Should().BeTrue(); @@ -68,7 +68,7 @@ public void Contains_SubstringNotFound_ReturnsFalse() const string substring = "missing"; // Act - bool result = input.Contains(substring, isRegex: false); + bool result = input.Contains(substring, false); // Assert result.Should().BeFalse(); @@ -82,7 +82,7 @@ public void Contains_RegexMatch_ReturnsTrue() const string regexPattern = @"\d{3}-\d{3}-\d{4}"; // Act - bool result = input.Contains(regexPattern, isRegex: true); + bool result = input.Contains(regexPattern, true); // Assert result.Should().BeTrue(); @@ -96,7 +96,7 @@ public void Contains_RegexNoMatch_ReturnsFalse() const string regexPattern = @"\d{3}-\d{3}-\d{4}"; // Act - bool result = input.Contains(regexPattern, isRegex: true); + bool result = input.Contains(regexPattern, true); // Assert result.Should().BeFalse(); @@ -110,7 +110,7 @@ public bool Contains_Substring_CaseSensitive(string text, string substring) // arrange // act - bool result = text.Contains(substring, isRegex: false, isCaseSensitive: true); + bool result = text.Contains(substring, false, true); // assert return result; @@ -124,7 +124,7 @@ public bool Contains_Substring_CaseSensitivity(string text, string substring) // arrange // act - bool result = text.Contains(substring, isRegex: false, isCaseSensitive: false); + bool result = text.Contains(substring, false, false); // assert return result; diff --git a/src/CrossWikiEditor.Tests/Utils/ToolsTests.cs b/src/CrossWikiEditor.Tests/Utils/ToolsTests.cs index e879472..a111bcc 100644 --- a/src/CrossWikiEditor.Tests/Utils/ToolsTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/ToolsTests.cs @@ -6,7 +6,8 @@ public sealed class ToolsTests [TestCase("https://en.wikipedia.org/wiki/Mathematics?", ExpectedResult = "Mathematics")] [TestCase("https://en.wikipedia.org/wiki/Artificial_intelligence?foo=bar", ExpectedResult = "Artificial intelligence")] [TestCase("https://hy.wikipedia.org/wiki/%D5%80%D5%A1%D5%B5%D5%A1%D5%BD%D5%BF%D5%A1%D5%B6", ExpectedResult = "Հայաստան")] - [TestCase("https://hy.wikipedia.org/wiki/%25D5%2580%25D5%25A1%25D5%25B5%25D5%25A1%25D5%25BD%25D5%25BF%25D5%25A1%25D5%25B6", ExpectedResult = "Հայաստան")] + [TestCase("https://hy.wikipedia.org/wiki/%25D5%2580%25D5%25A1%25D5%25B5%25D5%25A1%25D5%25BD%25D5%25BF%25D5%25A1%25D5%25B6", + ExpectedResult = "Հայաստան")] [TestCase("https://fringe.fandom.com/wiki/White_Tulip", ExpectedResult = "White Tulip")] public string GetPageTitleFromUrl_ShouldParseDirectLinks(string url) { @@ -17,7 +18,8 @@ public string GetPageTitleFromUrl_ShouldParseDirectLinks(string url) [TestCase("https://en.wikipedia.org/w/index.php?title=Mathematics&action=edit", ExpectedResult = "Mathematics")] [TestCase("https://en.wikipedia.org/w/index.php?title=Mathematics", ExpectedResult = "Mathematics")] [TestCase("https://en.wikipedia.org/w/index.php?title=Artificial_intelligence&veaction=edit", ExpectedResult = "Artificial intelligence")] - [TestCase("https://hy.wikipedia.org/w/index.php?title=%D5%80%D5%A1%D5%B5%D5%A1%D5%BD%D5%BF%D5%A1%D5%B6&action=history", ExpectedResult = "Հայաստան")] + [TestCase("https://hy.wikipedia.org/w/index.php?title=%D5%80%D5%A1%D5%B5%D5%A1%D5%BD%D5%BF%D5%A1%D5%B6&action=history", + ExpectedResult = "Հայաստան")] [TestCase("https://hy.wikipedia.org/w/index.php?title=%D5%80%D5%A1%D5%B5%D5%A1%D5%BD%D5%BF%D5%A1%D5%B6&action=edit", ExpectedResult = "Հայաստան")] [TestCase("https://fringe.fandom.com/wiki/White_Tulip?action=history", ExpectedResult = "White Tulip")] public string GetPageTitleFromUrl_ShouldParseSecondaryLinks(string url) diff --git a/src/CrossWikiEditor.Tests/Utils/WikiPageModelExtensionsTests.cs b/src/CrossWikiEditor.Tests/Utils/WikiPageModelExtensionsTests.cs index 0fcc765..2bc5a2c 100644 --- a/src/CrossWikiEditor.Tests/Utils/WikiPageModelExtensionsTests.cs +++ b/src/CrossWikiEditor.Tests/Utils/WikiPageModelExtensionsTests.cs @@ -35,7 +35,7 @@ public void ToWikiList_ShouldMakeNumericList_SectionIsLargerThanPages() # [[{pages[2].Title}]] # [[{pages[3].Title}]] # [[{pages[4].Title}]] - + """; // act @@ -84,7 +84,7 @@ public void ToWikiList_ShouldMakeNumericList_SectionIsExactMultipleOfPages() == 3 == # [[{pages[4].Title}]] # [[{pages[5].Title}]] - + """; // act @@ -106,7 +106,7 @@ public void ToWikiList_ShouldMakeBulletList_SectionIsLargerThanPages() * [[{pages[2].Title}]] * [[{pages[3].Title}]] * [[{pages[4].Title}]] - + """; // act @@ -155,7 +155,7 @@ public void ToWikiList_ShouldMakeBulletList_SectionIsExactMultipleOfPages() == 3 == * [[{pages[4].Title}]] * [[{pages[5].Title}]] - + """; // act @@ -195,27 +195,27 @@ public void ToWikiListAlphabetically_ShouldMakeNumericList() new("Bafwea", ApiRoot, _wikiClientCache), new("Aafew", ApiRoot, _wikiClientCache), new("Aa", ApiRoot, _wikiClientCache), - new("Wfwaa", ApiRoot, _wikiClientCache), + new("Wfwaa", ApiRoot, _wikiClientCache) }; const string expectedList = """ - == 1 == - # [[1aafew]] - == A == - # [[aa]] - # [[Aa]] - # [[Aafew]] - == B == - # [[baa]] - # [[Baa]] - # [[bafwea]] - # [[Bafwea]] - == W == - # [[wfwaa]] - # [[Wfwaa]] - # [[wfwfweaa]] - # [[Wfwfweaa]] - - """; + == 1 == + # [[1aafew]] + == A == + # [[aa]] + # [[Aa]] + # [[Aafew]] + == B == + # [[baa]] + # [[Baa]] + # [[bafwea]] + # [[Bafwea]] + == W == + # [[wfwaa]] + # [[Wfwaa]] + # [[wfwfweaa]] + # [[Wfwfweaa]] + + """; // act string list = pages.ToWikiListAlphabetically(true); @@ -241,27 +241,27 @@ public void ToWikiListAlphabetically_ShouldMakeBulletList() new("Bafwea", ApiRoot, _wikiClientCache), new("Aafew", ApiRoot, _wikiClientCache), new("Aa", ApiRoot, _wikiClientCache), - new("Wfwaa", ApiRoot, _wikiClientCache), + new("Wfwaa", ApiRoot, _wikiClientCache) }; - const string expectedList = $""" - == 1 == - * [[1aafew]] - == A == - * [[aa]] - * [[Aa]] - * [[Aafew]] - == B == - * [[baa]] - * [[Baa]] - * [[bafwea]] - * [[Bafwea]] - == W == - * [[wfwaa]] - * [[Wfwaa]] - * [[wfwfweaa]] - * [[Wfwfweaa]] - - """; + const string expectedList = """ + == 1 == + * [[1aafew]] + == A == + * [[aa]] + * [[Aa]] + * [[Aafew]] + == B == + * [[baa]] + * [[Baa]] + * [[bafwea]] + * [[Bafwea]] + == W == + * [[wfwaa]] + * [[Wfwaa]] + * [[wfwfweaa]] + * [[Wfwfweaa]] + + """; // act string list = pages.ToWikiListAlphabetically(false); diff --git a/src/CrossWikiEditor.Tests/ViewModels/FilterViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/FilterViewModelTests.cs index dd1c259..13b42af 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/FilterViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/FilterViewModelTests.cs @@ -11,26 +11,26 @@ public void SetUp() { SetUpServices(); _sut = new FilterViewModel( - [ - new(0, ""), - new(2, "Մասնակից"), - new(4, "Վիքիպեդիա"), - new(6, "Պատկեր"), - new(8, "MediaWiki"), - new(10, "Կաղապար"), - new(12, "Օգնություն"), - new(14, "Կատեգորիա"), - ], - [ - new(1, "Քննարկում"), - new(3, "Մասնակցի քննարկում"), - new(5, "Վիքիպեդիայի քննարկում"), - new(7, "Պատկերի քննարկում"), - new(9, "MediaWiki քննարկում"), - new(11, "Կաղապարի քննարկում"), - new(13, "Օգնության քննարկում"), - new(15, "Կատեգորիայի քննարկում"), - ], new TextFileListProvider(_fileDialogService, _systemService, _settingsService, _wikiClientCache)); + [ + new WikiNamespace(0, ""), + new WikiNamespace(2, "Մասնակից"), + new WikiNamespace(4, "Վիքիպեդիա"), + new WikiNamespace(6, "Պատկեր"), + new WikiNamespace(8, "MediaWiki"), + new WikiNamespace(10, "Կաղապար"), + new WikiNamespace(12, "Օգնություն"), + new WikiNamespace(14, "Կատեգորիա") + ], + [ + new WikiNamespace(1, "Քննարկում"), + new WikiNamespace(3, "Մասնակցի քննարկում"), + new WikiNamespace(5, "Վիքիպեդիայի քննարկում"), + new WikiNamespace(7, "Պատկերի քննարկում"), + new WikiNamespace(9, "MediaWiki քննարկում"), + new WikiNamespace(11, "Կաղապարի քննարկում"), + new WikiNamespace(13, "Օգնության քննարկում"), + new WikiNamespace(15, "Կատեգորիայի քննարկում") + ], new TextFileListProvider(_fileDialogService, _systemService, _settingsService, _wikiClientCache)); _settingsService.CurrentApiUrl.Returns("https://hy.wikipedia.org/w/api.php?"); } @@ -104,15 +104,15 @@ public void OpenFileCommand_ShouldSetPages_WhenListProviderMakesSuccessful() { // arrange const string text = """ - #[[title1]] + #[[title1]] - # [[Category:title (f e )2|few (fewcas)]] + # [[Category:title (f e )2|few (fewcas)]] - # [[title3]] - # [[titl e3|display]] - """; + # [[title3]] + # [[titl e3|display]] + """; _fileDialogService .OpenFilePickerAsync("Select text files to extract pages", true) .Returns(["some/path/text.txt"]); @@ -147,7 +147,7 @@ public void SaveCommand_ShouldCloseWithViewModelValues() _sut.UseRegex = true; _sut.SelectedSetOperations = SetOperations.Intersection; _sut.Pages = Fakers.GetWikiPageModelFaker(_settingsService.CurrentApiUrl, _wikiClientCache) - .Generate(10).ToObservableCollection(); + .Generate(10).ToObservableCollection(); IDialog dialog = Substitute.For(); var namespacesToKeep = _sut.SubjectNamespaces.Where(n => n.IsChecked).Select(n => n.Id).ToList(); namespacesToKeep.AddRange(_sut.TalkNamespaces.Where(n => n.IsChecked).Select(n => n.Id)); diff --git a/src/CrossWikiEditor.Tests/ViewModels/MakeListViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/MakeListViewModelTests.cs index 340f508..47b8d27 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/MakeListViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/MakeListViewModelTests.cs @@ -1,16 +1,15 @@ using System.Collections.ObjectModel; using System.Text; using System.Web; - using CommunityToolkit.Mvvm.Messaging; namespace CrossWikiEditor.Tests.ViewModels; public sealed class MakeListViewModelTests : BaseTest { - private MakeListViewModel _sut; private const string ApiRoot = "https://hy.wikipedia.org/w/api.php?"; private readonly WikiClient _wikiClient = new(); + private MakeListViewModel _sut; [SetUp] public void SetUp() @@ -23,15 +22,16 @@ public void SetUp() ]; _sut = new MakeListViewModel(_messenger, _logger, _dialogService, _wikiClientCache, _pageService, _systemService, _viewModelFactory, _fileDialogService, _settingsService, listProviders); - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _settingsService.CurrentApiUrl.Returns(ApiRoot); _wikiClientCache.GetWikiSite(Arg.Any()).Returns(new WikiSite(_wikiClient, ApiRoot)); } #region Messenger + [Test] public void Messenger_ShouldRemovePage_WhenPageUpdatedMessageReceived() { @@ -41,7 +41,7 @@ public void Messenger_ShouldRemovePage_WhenPageUpdatedMessageReceived() new("Page1", ApiRoot, _wikiClientCache), new("Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), - new("Page4", ApiRoot, _wikiClientCache), + new("Page4", ApiRoot, _wikiClientCache) }; List listProviders = [ @@ -63,15 +63,252 @@ public void Messenger_ShouldRemovePage_WhenPageUpdatedMessageReceived() _sut.Pages[1].Title.Should().Be("Page3"); _sut.Pages[2].Title.Should().Be("Page4"); } + + #endregion + + #region SelectAllCommand + + [Test] + public void SelectAllCommand_ShouldSelectAllPages() + { + // arrange + _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); + _sut.SelectedPages = []; + + // act + _sut.SelectAllCommand.Execute(null); + + // assert + _sut.Pages.Should().HaveCount(5); + _sut.Pages.Should().BeEquivalentTo(_sut.SelectedPages); + } + + #endregion + + #region SelectNoneCommand + + [Test] + public void SelectNoneCommand_ShouldUnSelectAllPages() + { + // arrange + _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); + _sut.SelectedPages = []; + + // act + _sut.SelectNoneCommand.Execute(null); + + // assert + _sut.Pages.Should().HaveCount(5); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region PastCommand + + [Test] + public void PastCommand_ShouldSplitClipboardAndAddPages() + { + // arrange + _sut.Pages = + new List {new("page1", ApiRoot, _wikiClientCache), new("page2", ApiRoot, _wikiClientCache)}.ToObservableCollection(); + _systemService.GetClipboardTextAsync() + .Returns($"page3{Environment.NewLine}fewfew{Environment.NewLine}ofiewf203{Environment.NewLine} foiwej "); + _wikiClientCache.GetWikiPageModel(ApiRoot, Arg.Any()) + .Returns(args => new WikiPageModel(((string) args[1]).Trim(), ApiRoot, _wikiClientCache)); + + // act + _sut.PasteCommand.Execute(null); + + // assert + _sut.Pages.Should().BeEquivalentTo(new List + { + new("page1", ApiRoot, _wikiClientCache), new("page2", ApiRoot, _wikiClientCache), new("page3", ApiRoot, _wikiClientCache), + new("fewfew", ApiRoot, _wikiClientCache), new("ofiewf203", ApiRoot, _wikiClientCache), new("foiwej", ApiRoot, _wikiClientCache) + }.ToObservableCollection()); + } + + #endregion + + #region RemoveAllCommand + + [Test] + public void RemoveAllCommand_ShouldRemoveAllPages() + { + // arrange + List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); + List? selectedPages = pages.RandomSubset(4); + _sut.Pages = pages.ToObservableCollection(); + _sut.SelectedPages = selectedPages.ToObservableCollection(); + + // act + _sut.RemoveAllCommand.Execute(null); + + // assert + _sut.Pages.Should().BeEmpty(); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region RemoveDuplicate + + [Test] + public void RemoveDuplicate_ShouldRemoveDuplicatePages() + { + // arrange + List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); + pages = [.. pages, .. pages.RandomSubset(4)]; + _sut.Pages = pages.ToObservableCollection(); + _sut.SelectedPages = pages.RandomSubset(2).ToObservableCollection(); + + // act + _sut.RemoveDuplicateCommand.Execute(null); + + // assert + _sut.Pages.Should().BeEquivalentTo(pages.Distinct()); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region RemoveNonMainSpaceCommand + + [Test] + public void RemoveNonMainSpaceCommand_ShouldRemoveNonMainSpacePages() + { + // arrange + _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); + _sut.SelectedPages = _sut.Pages.ToList().RandomSubset(3).ToObservableCollection(); + _sut.Pages[0].NamespaceId = 0; + _sut.Pages[1].NamespaceId = 2; + _sut.Pages[2].NamespaceId = 0; + _sut.Pages[3].NamespaceId = 12; + _sut.Pages[4].NamespaceId = 13; + var nonSelected = new List {_sut.Pages[0], _sut.Pages[2]}; + + // act + _sut.RemoveNonMainSpaceCommand.Execute(null); + + // assert + _sut.Pages.Should().BeEquivalentTo(nonSelected); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region MoveToTopCommand + + [Test] + public void MoveToTopCommand_ShouldMoveSelectedPagesToTheTop() + { + // arrange + _sut.Pages = new List + { + new("template:page1", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), + new("user:Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache) + }.ToObservableCollection(); + _sut.SelectedPages = new List {new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache)} + .ToObservableCollection(); + + // act + _sut.MoveToTopCommand.Execute(null); + + // assert + _sut.Pages.Should() + .BeEquivalentTo( + new List + { + new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), + new("template:page1", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), + new("Page5", ApiRoot, _wikiClientCache) + }, + options => options.WithStrictOrdering()); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region MoveToBottomCommand + + [Test] + public void MoveToBottomCommand_ShouldMoveSelectedPagesToTheBottom() + { + // arrange + _sut.Pages = new List + { + new("template:page1", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), + new("user:Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache) + }.ToObservableCollection(); + _sut.SelectedPages = new List {new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache)} + .ToObservableCollection(); + + // act + _sut.MoveToBottomCommand.Execute(null); + + // assert + _sut.Pages.Should() + .BeEquivalentTo( + new List + { + new("template:page1", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), + new("Page5", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache) + }, + options => options.WithStrictOrdering()); + _sut.SelectedPages.Should().BeEmpty(); + } + + #endregion + + #region SortAlphabeticallyCommand + + [Test] + public void SortAlphabeticallyCommand_ShouldSortAlphabetically() + { + // arrange + _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10).ToObservableCollection(); + + // act + _sut.SortAlphabeticallyCommand.Execute(null); + + // assert + _sut.Pages.Should() + .BeEquivalentTo( + _sut.Pages.OrderBy(x => x.Title), + options => options.WithStrictOrdering()); + } + + #endregion + + #region SortReverseAlphabeticallyCommand + + [Test] + public void SortReverseAlphabeticallyCommand_ShouldSortReverseAlphabetically() + { + // arrange + _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10).ToObservableCollection(); + + // act + _sut.SortReverseAlphabeticallyCommand.Execute(null); + + // assert + _sut.Pages.Should() + .BeEquivalentTo( + _sut.Pages.OrderByDescending(x => x.Title), + options => options.WithStrictOrdering()); + } + #endregion #region AddNewPageCommand + [Test] public void AddNewPageCommand_ShouldDoNothing_WhenNewPageTitleIsEmpty([Values("", " ")] string newPageTitle) { // arrange _sut.NewPageTitle = newPageTitle; - var originalPages = new List { new("Page1", ApiRoot, _wikiClientCache), new("Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache) }; + var originalPages = new List + {new("Page1", ApiRoot, _wikiClientCache), new("Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache)}; _sut.Pages = originalPages.ToObservableCollection(); // act @@ -123,11 +360,13 @@ public void AddNewPageCommand_ShouldTrimPage_WhenNewPageTitleContainsWhitespaces _sut.AddNewPageCommand.Execute(null); // assert - _sut.Pages.Should().BeEquivalentTo(new List { new("new page title", ApiRoot, _wikiClientCache) }); + _sut.Pages.Should().BeEquivalentTo(new List {new("new page title", ApiRoot, _wikiClientCache)}); } + #endregion #region RemoveCommand + [Test] public void RemoveCommand_ShouldDoNothing_WhenThereIsNoSelectedPage() { @@ -149,7 +388,7 @@ public void RemoveCommand_ShouldRemoveSelectedPages_WhenSelectedPageIsInPages() // arrange List? randomPages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); _sut.Pages = randomPages.ToObservableCollection(); - _sut.SelectedPages = new[] { _sut.Pages[3], _sut.Pages[6], _sut.Pages[1] }.ToObservableCollection(); + _sut.SelectedPages = new[] {_sut.Pages[3], _sut.Pages[6], _sut.Pages[1]}.ToObservableCollection(); randomPages.RemoveAt(1); randomPages.RemoveAt(2); randomPages.RemoveAt(4); @@ -189,9 +428,11 @@ public void RemoveCommand_ShouldClearSelectedPage() // assert _sut.SelectedPages.Should().BeEmpty(); } + #endregion #region MakeListCommand + [Test] public void MakeListCommand_ShouldGetLimit_WhenListProviderIsLimited() { @@ -282,9 +523,11 @@ public void MakeListCommand_ShouldRequestAdditionalParams_WhenNeedsAdditionalPar // assert listProvider.Received(1).GetAdditionalParams(); } + #endregion #region OpenInBrowserCommand + [Test] public void OpenInBrowserCommand_ShouldDoNothing_WhenThereIsNoSelectedPage() { @@ -305,7 +548,7 @@ public void OpenInBrowserCommand_ShouldOpenAllSelectedPages_WhenThereAreSelected _sut.SelectedPages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(4).ToObservableCollection(); _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _systemService.OpenLinkInBrowser(Arg.Any()).Returns(Unit.Default); @@ -321,9 +564,11 @@ public void OpenInBrowserCommand_ShouldOpenAllSelectedPages_WhenThereAreSelected _systemService.OpenLinkInBrowser($"https://hy.wikipedia.org/w/index.php?title={HttpUtility.UrlEncode(_sut.SelectedPages[3].Title)}"); }); } + #endregion #region OpenHistoryInBrowserCommand + [Test] public void OpenHistoryInBrowserCommand_ShouldDoNothing_WhenThereIsNoSelectedPage() { @@ -344,7 +589,7 @@ public void OpenHistoryInBrowserCommand_ShouldOpenAllSelectedPages_WhenThereAreS _sut.SelectedPages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(4).ToObservableCollection(); _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _systemService.OpenLinkInBrowser(Arg.Any()).Returns(Unit.Default); @@ -360,9 +605,11 @@ public void OpenHistoryInBrowserCommand_ShouldOpenAllSelectedPages_WhenThereAreS _systemService.OpenLinkInBrowser($"https://hy.wikipedia.org/w/index.php?title={_sut.SelectedPages[3].Title}&action=history"); }); } + #endregion #region CutCommand + [Test] public void CutCommand_ShouldDoNothing_WhenSelectedPagesIsEmpty() { @@ -382,7 +629,7 @@ public void CutCommand_ShouldCutSelectedPageTitlesAndRemoveThem() // arrange List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5); _sut.Pages = pages.ToObservableCollection(); - _sut.SelectedPages = new List { _sut.Pages[2], _sut.Pages[4], _sut.Pages[1] }.ToObservableCollection(); + _sut.SelectedPages = new List {_sut.Pages[2], _sut.Pages[4], _sut.Pages[1]}.ToObservableCollection(); // act _sut.CutCommand.Execute(null); @@ -391,11 +638,13 @@ public void CutCommand_ShouldCutSelectedPageTitlesAndRemoveThem() _systemService.Received(1) .SetClipboardTextAsync($"{pages[2].Title}{Environment.NewLine}{pages[4].Title}{Environment.NewLine}{pages[1].Title}"); _sut.SelectedPages.Should().BeEmpty(); - _sut.Pages.Should().BeEquivalentTo(new List { pages[0], pages[3] }.ToObservableCollection()); + _sut.Pages.Should().BeEquivalentTo(new List {pages[0], pages[3]}.ToObservableCollection()); } + #endregion #region CopyCommand + [Test] public void CopyCommand_ShouldDoNothing_WhenSelectedPagesIsEmpty() { @@ -428,43 +677,11 @@ public void CopyCommand_ShouldCopySelectedPageTitles() _sut.SelectedPages.Should().BeEquivalentTo(selectedPages); _sut.Pages.Should().BeEquivalentTo(pages); } - #endregion - - #region SelectAllCommand - [Test] - public void SelectAllCommand_ShouldSelectAllPages() - { - // arrange - _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); - _sut.SelectedPages = []; - - // act - _sut.SelectAllCommand.Execute(null); - - // assert - _sut.Pages.Should().HaveCount(5); - _sut.Pages.Should().BeEquivalentTo(_sut.SelectedPages); - } - #endregion - #region SelectNoneCommand - [Test] - public void SelectNoneCommand_ShouldUnSelectAllPages() - { - // arrange - _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); - _sut.SelectedPages = []; - - // act - _sut.SelectNoneCommand.Execute(null); - - // assert - _sut.Pages.Should().HaveCount(5); - _sut.SelectedPages.Should().BeEmpty(); - } #endregion #region SelectInverseCommand + [Test] public void SelectInverseCommand_ShouldSelectAll_WhenNonIsSelected() { @@ -512,32 +729,11 @@ public void SelectInverseCommand_ShouldInverseSelection() _sut.Pages.Should().HaveCount(5); _sut.SelectedPages.Should().BeEquivalentTo(pages.Where(p => !selectedPages.Contains(p))); } - #endregion - #region PastCommand - [Test] - public void PastCommand_ShouldSplitClipboardAndAddPages() - { - // arrange - _sut.Pages = new List { new("page1", ApiRoot, _wikiClientCache), new("page2", ApiRoot, _wikiClientCache) }.ToObservableCollection(); - _systemService.GetClipboardTextAsync() - .Returns($"page3{Environment.NewLine}fewfew{Environment.NewLine}ofiewf203{Environment.NewLine} foiwej "); - _wikiClientCache.GetWikiPageModel(ApiRoot, Arg.Any()) - .Returns(args => new WikiPageModel(((string) args[1]).Trim(), ApiRoot, _wikiClientCache)); - - // act - _sut.PasteCommand.Execute(null); - - // assert - _sut.Pages.Should().BeEquivalentTo(new List - { - new("page1", ApiRoot, _wikiClientCache), new("page2", ApiRoot, _wikiClientCache), new("page3", ApiRoot, _wikiClientCache), - new("fewfew", ApiRoot, _wikiClientCache), new("ofiewf203", ApiRoot, _wikiClientCache), new("foiwej", ApiRoot, _wikiClientCache) - }.ToObservableCollection()); - } #endregion #region RemoveSelectedCommand + [Test] public void RemoveSelectedCommand_ShouldDoNothing_WhenSelectedPagesIsEmpty() { @@ -571,112 +767,11 @@ public void RemoveSelectedCommand_ShouldRemoveSelectedPages() _sut.Pages.Should().BeEquivalentTo(notSelectedPages); _sut.SelectedPages.Should().BeEmpty(); } - #endregion - - #region RemoveAllCommand - [Test] - public void RemoveAllCommand_ShouldRemoveAllPages() - { - // arrange - List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); - List? selectedPages = pages.RandomSubset(4); - _sut.Pages = pages.ToObservableCollection(); - _sut.SelectedPages = selectedPages.ToObservableCollection(); - - // act - _sut.RemoveAllCommand.Execute(null); - - // assert - _sut.Pages.Should().BeEmpty(); - _sut.SelectedPages.Should().BeEmpty(); - } - #endregion - - #region RemoveDuplicate - [Test] - public void RemoveDuplicate_ShouldRemoveDuplicatePages() - { - // arrange - List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); - pages = [.. pages, .. pages.RandomSubset(4)]; - _sut.Pages = pages.ToObservableCollection(); - _sut.SelectedPages = pages.RandomSubset(2).ToObservableCollection(); - - // act - _sut.RemoveDuplicateCommand.Execute(null); - - // assert - _sut.Pages.Should().BeEquivalentTo(pages.Distinct()); - _sut.SelectedPages.Should().BeEmpty(); - } - #endregion - - #region RemoveNonMainSpaceCommand - [Test] - public void RemoveNonMainSpaceCommand_ShouldRemoveNonMainSpacePages() - { - // arrange - _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(5).ToObservableCollection(); - _sut.SelectedPages = _sut.Pages.ToList().RandomSubset(3).ToObservableCollection(); - _sut.Pages[0].NamespaceId = 0; - _sut.Pages[1].NamespaceId = 2; - _sut.Pages[2].NamespaceId = 0; - _sut.Pages[3].NamespaceId = 12; - _sut.Pages[4].NamespaceId = 13; - var nonSelected = new List { _sut.Pages[0], _sut.Pages[2] }; - - // act - _sut.RemoveNonMainSpaceCommand.Execute(null); - - // assert - _sut.Pages.Should().BeEquivalentTo(nonSelected); - _sut.SelectedPages.Should().BeEmpty(); - } - #endregion - #region MoveToTopCommand - [Test] - public void MoveToTopCommand_ShouldMoveSelectedPagesToTheTop() - { - // arrange - _sut.Pages = new List - {new("template:page1", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache)}.ToObservableCollection(); - _sut.SelectedPages = new List { new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache) }.ToObservableCollection(); - - // act - _sut.MoveToTopCommand.Execute(null); - - // assert - _sut.Pages.Should() - .BeEquivalentTo( - new List { new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), new("template:page1", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache) }, - options => options.WithStrictOrdering()); - _sut.SelectedPages.Should().BeEmpty(); - } - #endregion - - #region MoveToBottomCommand - [Test] - public void MoveToBottomCommand_ShouldMoveSelectedPagesToTheBottom() - { - // arrange - _sut.Pages = new List - {new("template:page1", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache)}.ToObservableCollection(); - _sut.SelectedPages = new List { new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache) }.ToObservableCollection(); - - // act - _sut.MoveToBottomCommand.Execute(null); - - // assert - _sut.Pages.Should() - .BeEquivalentTo( - new List { new("template:page1", ApiRoot, _wikiClientCache), new("user:Page2", ApiRoot, _wikiClientCache), new("Page5", ApiRoot, _wikiClientCache), new("category:page2", ApiRoot, _wikiClientCache), new("Page3", ApiRoot, _wikiClientCache) }, - options => options.WithStrictOrdering()); - _sut.SelectedPages.Should().BeEmpty(); - } #endregion #region ConvertToTalkPagesCommand + [Test] public void ConvertToTalkPagesCommand_ShouldConvertPagesToTalkPages_WhenPageServiceReturnsSuccess() { @@ -685,7 +780,7 @@ public void ConvertToTalkPagesCommand_ShouldConvertPagesToTalkPages_WhenPageServ List? talkPages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10); _sut.Pages = pages.ToObservableCollection(); _pageService.ConvertToTalk(Arg.Is>(argPages => argPages.SequenceEqual(pages))) - .Returns(talkPages); + .Returns(talkPages); // act _sut.ConvertToTalkPagesCommand.Execute(null); @@ -709,9 +804,11 @@ public void ConvertToTalkPagesCommand_ShouldDoNothing_WhenPageServiceReturnsFail // assert _sut.Pages.Should().BeEquivalentTo(pages); } + #endregion #region ConvertFromTalkPagesCommand + [Test] public void ConvertFromTalkPagesCommand_ShouldConvertPagesFromTalkPages_WhenPageServiceReturnsSuccess() { @@ -744,9 +841,11 @@ public void ConvertFromTalkPagesCommand_ShouldDoNothing_WhenPageServiceReturnsFa // assert _sut.Pages.Should().BeEquivalentTo(pages); } + #endregion #region FilterCommand + [Test] public void FilterCommand_ShouldRemoveDuplicates_WhenRemoveDuplicatesIsTrue() { @@ -776,7 +875,7 @@ public void FilterCommand_ShouldRemoveTitlesContaining_WhenRemoveTitlesContainin new("babb", ApiRoot, _wikiClientCache), new("bewgrbb", ApiRoot, _wikiClientCache), new("abbb", ApiRoot, _wikiClientCache), - new("aaa", ApiRoot, _wikiClientCache), + new("aaa", ApiRoot, _wikiClientCache) }); // act @@ -800,7 +899,7 @@ public void FilterCommand_ShouldOnlyKeepTitlesContaining_WhenKeepTitlesContainin new("babb", ApiRoot, _wikiClientCache), new("bewgrbb", ApiRoot, _wikiClientCache), new("abbb", ApiRoot, _wikiClientCache), - new("aaa", ApiRoot, _wikiClientCache), + new("aaa", ApiRoot, _wikiClientCache) }); // act @@ -825,7 +924,7 @@ public void FilterCommand_ShouldRemoveTitlesContainingRegex_WhenRemoveTitlesCont new("babb", ApiRoot, _wikiClientCache), new("be4wgrbb", ApiRoot, _wikiClientCache), new("abbb", ApiRoot, _wikiClientCache), - new("aa2a", ApiRoot, _wikiClientCache), + new("aa2a", ApiRoot, _wikiClientCache) }); // act @@ -849,7 +948,7 @@ public void FilterCommand_ShouldOnlyKeepTitlesContainingRegex_WhenKeepTitlesCont new("babb", ApiRoot, _wikiClientCache), new("be4wgrbb", ApiRoot, _wikiClientCache), new("abbb", ApiRoot, _wikiClientCache), - new("aa2a", ApiRoot, _wikiClientCache), + new("aa2a", ApiRoot, _wikiClientCache) }); // act @@ -874,7 +973,7 @@ public async Task FilterCommand_ShouldKeepOnlyPagesInGivenNamespaces_WhenNamespa new("Մասնակից:babb", ApiRoot, _wikiClientCache), new("Քննարկում:be4wgrbb", ApiRoot, _wikiClientCache), new("Օգնություն:abbb", ApiRoot, _wikiClientCache), - new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache), + new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache) }); await Task.WhenAll(_sut.Pages.Select(p => p.InitAsync)); @@ -897,7 +996,7 @@ public void FilterCommand_ShouldKeepIntersection_WhenSetOperationIsIntersectionA new("Մասնակից:babb", ApiRoot, _wikiClientCache), new("Քննարկում:be4wgrbb", ApiRoot, _wikiClientCache), new("Օգնություն:abbb", ApiRoot, _wikiClientCache), - new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache), + new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache) }; _dialogService.ShowDialog(Arg.Any()) .Returns(new FilterOptions([], "", "", true, false, true, SetOperations.Intersection, [pages[1], pages[3]])); @@ -922,7 +1021,7 @@ public void FilterCommand_ShouldKeepSymmetricDifference_WhenSetOperationIsSymmet new("Մասնակից:babb", ApiRoot, _wikiClientCache), new("Քննարկում:be4wgrbb", ApiRoot, _wikiClientCache), new("Օգնություն:abbb", ApiRoot, _wikiClientCache), - new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache), + new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache) }; var filterPages = new List { @@ -954,7 +1053,7 @@ public void FilterCommand_ShouldSort_WhenSortAlphabeticallyIsTrue() new("Մասնակից:babb", ApiRoot, _wikiClientCache), new("Քննարկում:be4wgrbb", ApiRoot, _wikiClientCache), new("Օգնություն:abbb", ApiRoot, _wikiClientCache), - new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache), + new("Վիքիպեդիա:aa2a", ApiRoot, _wikiClientCache) }; _dialogService.ShowDialog(Arg.Any()) .Returns(new FilterOptions([], "", "", true, true, true, SetOperations.SymmetricDifference, [])); @@ -984,7 +1083,7 @@ public void FilterCommand_ShouldRemoveTitleContainingAndKeepTitlesContaining_Whe new("babb", ApiRoot, _wikiClientCache), new("bewgrbb", ApiRoot, _wikiClientCache), new("abbb", ApiRoot, _wikiClientCache), - new("aaa", ApiRoot, _wikiClientCache), + new("aaa", ApiRoot, _wikiClientCache) }); // act @@ -1008,7 +1107,7 @@ public void FilterCommand_ShouldRemoveTitleContainingAndKeepTitlesContainingUseR new("babb", ApiRoot, _wikiClientCache), new("bewg2rbb", ApiRoot, _wikiClientCache), new("abgbgb", ApiRoot, _wikiClientCache), - new("a4aa", ApiRoot, _wikiClientCache), + new("a4aa", ApiRoot, _wikiClientCache) }); // act @@ -1023,6 +1122,7 @@ public void FilterCommand_ShouldRemoveTitleContainingAndKeepTitlesContainingUseR #endregion #region SaveListCommand + [Test] public void SaveListCommand_ShouldSaveFile_WhenUserPickedALocationAndPagesExist() { @@ -1033,8 +1133,8 @@ public void SaveListCommand_ShouldSaveFile_WhenUserPickedALocationAndPagesExist( _sut.SelectedListProvider = listProvider; listProvider.Title.Returns("listProviderTitle"); listProvider.Param.Returns("ListProviderParam"); - _fileDialogService.SaveFilePickerAsync("Save pages", defaultExtension: Arg.Any(), Arg.Any()) - .Returns((Substitute.For>>(), openWriteStream)); + _fileDialogService.SaveFilePickerAsync("Save pages", Arg.Any(), Arg.Any()) + .Returns((Substitute.For>>(), openWriteStream)); openWriteStream().Returns(stream); List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(3); _sut.Pages = pages.ToObservableCollection(); @@ -1047,9 +1147,12 @@ public void SaveListCommand_ShouldSaveFile_WhenUserPickedALocationAndPagesExist( stream.Received(3).WriteAsync(Arg.Any>(), Arg.Any()); Received.InOrder(() => { - stream.WriteAsync(Arg.Is>(b => Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[0].Title}]]{Environment.NewLine}")); - stream.WriteAsync(Arg.Is>(b => Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[1].Title}]]{Environment.NewLine}")); - stream.WriteAsync(Arg.Is>(b => Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[2].Title}]]{Environment.NewLine}")); + stream.WriteAsync(Arg.Is>(b => + Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[0].Title}]]{Environment.NewLine}")); + stream.WriteAsync(Arg.Is>(b => + Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[1].Title}]]{Environment.NewLine}")); + stream.WriteAsync(Arg.Is>(b => + Encoding.UTF8.GetString(b.ToArray()) == $"# [[:{pages[2].Title}]]{Environment.NewLine}")); }); stream.Received(1).Close(); } @@ -1062,7 +1165,7 @@ public void SaveListCommand_ShouldDoNothing_WhenUserDidNotPickALocationAndPagesE _sut.SelectedListProvider = listProvider; listProvider.Title.Returns("listProviderTitle"); listProvider.Param.Returns("ListProviderParam"); - _fileDialogService.SaveFilePickerAsync("Save pages", defaultExtension: Arg.Any(), Arg.Any()) + _fileDialogService.SaveFilePickerAsync("Save pages", Arg.Any(), Arg.Any()) .Returns((null, null)); List? pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(3); _sut.Pages = pages.ToObservableCollection(); @@ -1072,7 +1175,7 @@ public void SaveListCommand_ShouldDoNothing_WhenUserDidNotPickALocationAndPagesE // assert - _fileDialogService.Received(1).SaveFilePickerAsync("Save pages", defaultExtension: Arg.Any(), Arg.Any()); + _fileDialogService.Received(1).SaveFilePickerAsync("Save pages", Arg.Any(), Arg.Any()); } [Test] @@ -1083,7 +1186,7 @@ public void SaveListCommand_ShouldDoNothing_WhenUserPagesDoNotExist() _sut.SelectedListProvider = listProvider; listProvider.Title.Returns("listProviderTitle"); listProvider.Param.Returns("ListProviderParam"); - _fileDialogService.SaveFilePickerAsync("Save pages", defaultExtension: Arg.Any(), Arg.Any()) + _fileDialogService.SaveFilePickerAsync("Save pages", Arg.Any(), Arg.Any()) .Returns((null, null)); // act @@ -1091,43 +1194,8 @@ public void SaveListCommand_ShouldDoNothing_WhenUserPagesDoNotExist() // assert - _fileDialogService.DidNotReceive().SaveFilePickerAsync("Save pages", defaultExtension: Arg.Any(), Arg.Any()); + _fileDialogService.DidNotReceive().SaveFilePickerAsync("Save pages", Arg.Any(), Arg.Any()); } - #endregion - #region SortAlphabeticallyCommand - [Test] - public void SortAlphabeticallyCommand_ShouldSortAlphabetically() - { - // arrange - _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10).ToObservableCollection(); - - // act - _sut.SortAlphabeticallyCommand.Execute(null); - - // assert - _sut.Pages.Should() - .BeEquivalentTo( - _sut.Pages.OrderBy(x => x.Title), - options => options.WithStrictOrdering()); - } - #endregion - - #region SortReverseAlphabeticallyCommand - [Test] - public void SortReverseAlphabeticallyCommand_ShouldSortReverseAlphabetically() - { - // arrange - _sut.Pages = Fakers.GetWikiPageModelFaker(ApiRoot, _wikiClientCache).Generate(10).ToObservableCollection(); - - // act - _sut.SortReverseAlphabeticallyCommand.Execute(null); - - // assert - _sut.Pages.Should() - .BeEquivalentTo( - _sut.Pages.OrderByDescending(x => x.Title), - options => options.WithStrictOrdering()); - } #endregion } \ No newline at end of file diff --git a/src/CrossWikiEditor.Tests/ViewModels/PreferencesViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/PreferencesViewModelTests.cs index bdb55fb..bf09a56 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/PreferencesViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/PreferencesViewModelTests.cs @@ -29,8 +29,7 @@ public void SaveCommand_ShouldSendProjectChangedMessage( [Test] public void SaveCommand_ShouldSendLanguageCodeChangedMessage( - [Values("hy", "hyw", "en")] - string language) + [Values("hy", "hyw", "en")] string language) { // arrange _sut.SelectedLanguage = language; diff --git a/src/CrossWikiEditor.Tests/ViewModels/ProfilesViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/ProfilesViewModelTests.cs index 4227b28..4db970b 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/ProfilesViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/ProfilesViewModelTests.cs @@ -1,5 +1,3 @@ -using CrossWikiEditor.Core.Utils; - namespace CrossWikiEditor.Tests.ViewModels; public sealed class ProfilesViewModelTests : BaseTest @@ -33,15 +31,15 @@ public void LoginCommand_ShouldReturn_WhenSelectedAccountIsNull() public void LoginCommand_ShouldLogin_WhenSelectedUserIsValid() { // arrange - var profile = new Profile() + var profile = new Profile { Username = "username", Password = "password" }; _sut.SelectedProfile = profile; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(Unit.Default); @@ -59,16 +57,16 @@ public void LoginCommand_ShouldLogin_WhenSelectedUserIsValid() public void LoginCommand_ShouldSetCurrentUserPref_WhenProfileHasDefaultPref() { // arrange - var profile = new Profile() + var profile = new Profile { Username = "username", Password = "password", DefaultSettingsPath = "some/settings/path/file.xml" }; _sut.SelectedProfile = profile; - var userSettings = new UserSettings() + var userSettings = new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }; _settingsService.GetSettingsByPath(profile.DefaultSettingsPath).Returns(userSettings); _userService.Login(Arg.Any(), Arg.Any()).Returns(Unit.Default); @@ -89,15 +87,15 @@ public void LoginCommand_ShouldSetCurrentUserPref_WhenProfileHasDefaultPref() public void LoginCommand_ShouldAlertDefaultMessage_WhenLoginIsUnSuccessfulAndThereIsNoMessage() { // arrange - var profile = new Profile() + var profile = new Profile { Username = "username", Password = "password" }; _sut.SelectedProfile = profile; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(new Exception(string.Empty)); @@ -115,15 +113,15 @@ public void LoginCommand_ShouldAlertDefaultMessage_WhenLoginIsUnSuccessfulAndThe public void LoginCommand_ShouldAlertErrorMessage_WhenLoginIsUnSuccessful() { // arrange - var profile = new Profile() + var profile = new Profile { Username = "username", Password = "password" }; _sut.SelectedProfile = profile; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(new Exception("this is an error message")); @@ -153,7 +151,7 @@ public void AddCommand_ShouldOpenAddOrEditProfileViewModel() public void AddCommand_ShouldUpdateProfiles_WhenAddOrEditProfileViewModelReturnsTrue() { // arrange - var newProfiles = new List() + var newProfiles = new List { new() { @@ -283,9 +281,9 @@ public void QuickLoginCommand_ShouldLogin_WhenPasswordAndUsernameArePresent() // arrange _sut.Username = "username"; _sut.Password = "Qwer1234"; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hyw", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hyw", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(Unit.Default); @@ -326,9 +324,9 @@ public void QuickLoginCommand_ShouldSendAccountLoggedInMessage_WhenLoggedInSucce // arrange _sut.Username = "username"; _sut.Password = "Qwer1234"; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hyw", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hyw", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(Unit.Default); @@ -346,9 +344,9 @@ public void QuickLoginCommand_ShouldAlertUser_WhenLoggedInUnsuccessfully() // arrange _sut.Username = "username"; _sut.Password = "Qwer1234"; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hyw", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hyw", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(new Exception("Password is wrong")); @@ -366,9 +364,9 @@ public void QuickLoginCommand_ShouldAlertDefaultMessage_WhenLoginIsUnsuccessfulA // arrange _sut.Username = "username"; _sut.Password = "Qwer1234"; - _settingsService.GetCurrentSettings().Returns(new UserSettings() + _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hy", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hy", ProjectEnum.Wikipedia) }); _userService.Login(Arg.Any(), Arg.Any()).Returns(new Exception(errorMessage)); diff --git a/src/CrossWikiEditor.Tests/ViewModels/PromptViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/PromptViewModelTests.cs index 6f6e745..3f70e2c 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/PromptViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/PromptViewModelTests.cs @@ -3,6 +3,7 @@ public sealed class PromptViewModelTests : BaseTest { private PromptViewModel _sut; + [SetUp] public void SetUp() { diff --git a/src/CrossWikiEditor.Tests/ViewModels/SelectNamespacesViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/SelectNamespacesViewModelTests.cs index b3300df..dce9725 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/SelectNamespacesViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/SelectNamespacesViewModelTests.cs @@ -9,14 +9,14 @@ public void SetUp() { _sut = new SelectNamespacesViewModel( [ - new(0, "namespace name with id 0"), - new(1, "namespace name with id 1"), - new(2, "namespace name with id 2"), - new(3, "namespace name with id 3"), - new(4, "namespace name with id 4"), - new(5, "namespace name with id 5"), - new(6, "namespace name with id 6"), - new(7, "namespace name with id 7"), + new WikiNamespace(0, "namespace name with id 0"), + new WikiNamespace(1, "namespace name with id 1"), + new WikiNamespace(2, "namespace name with id 2"), + new WikiNamespace(3, "namespace name with id 3"), + new WikiNamespace(4, "namespace name with id 4"), + new WikiNamespace(5, "namespace name with id 5"), + new WikiNamespace(6, "namespace name with id 6"), + new WikiNamespace(7, "namespace name with id 7") ]); } diff --git a/src/CrossWikiEditor.Tests/ViewModels/StatusBarViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/StatusBarViewModelTests.cs index 9144ae2..3878374 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/StatusBarViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/StatusBarViewModelTests.cs @@ -24,7 +24,7 @@ public void Messanger_ShouldUpdateUsername_WhenNewAccountLoggedInMessageReceived _sut = new StatusBarViewModel(_viewModelFactory, _dialogService, _settingsService, messenger); // act - messenger.Send(new NewAccountLoggedInMessage(new Profile() + messenger.Send(new NewAccountLoggedInMessage(new Profile { Username = "this is a new username" })); @@ -67,14 +67,14 @@ public void CurrentWiki_ShouldComeFromCurrentPref() // arrange _settingsService.GetCurrentSettings().Returns(new UserSettings { - UserWiki = new("hyw", ProjectEnum.Wikipedia) + UserWiki = new UserWiki("hyw", ProjectEnum.Wikipedia) }); // act _sut = new StatusBarViewModel(_viewModelFactory, _dialogService, _settingsService, _messenger); // assert - _sut.CurrentWiki.Should().Be($"hyw:Wikipedia"); + _sut.CurrentWiki.Should().Be("hyw:Wikipedia"); } [Test] diff --git a/src/CrossWikiEditor.Tests/ViewModels/WhatLinksHereOptionsViewModelTests.cs b/src/CrossWikiEditor.Tests/ViewModels/WhatLinksHereOptionsViewModelTests.cs index f4cb211..4ebbf56 100644 --- a/src/CrossWikiEditor.Tests/ViewModels/WhatLinksHereOptionsViewModelTests.cs +++ b/src/CrossWikiEditor.Tests/ViewModels/WhatLinksHereOptionsViewModelTests.cs @@ -47,6 +47,7 @@ public void OkCommand_ShouldCloseWithCorrectValues() _dialog.Received(1).Close(Arg.Is(options => options.IncludeRedirects == sut.IncludeRedirects && (int) options.RedirectFilter == sut.SelectedRedirectFilter - && options.Namespaces.OrderBy(e => e).SequenceEqual(sut.Namespaces.Where(x => x.IsChecked).Select(n => n.Id).OrderBy(e => e)))); + && Enumerable.OrderBy(options.Namespaces, e => e) + .SequenceEqual(sut.Namespaces.Where(x => x.IsChecked).Select(n => n.Id).OrderBy(e => e)))); } } \ No newline at end of file diff --git a/src/CrossWikiEditor/App.axaml b/src/CrossWikiEditor/App.axaml index 0be6688..60f54ea 100644 --- a/src/CrossWikiEditor/App.axaml +++ b/src/CrossWikiEditor/App.axaml @@ -12,12 +12,22 @@ - - + - + - diff --git a/src/CrossWikiEditor/App.axaml.cs b/src/CrossWikiEditor/App.axaml.cs index a93737f..56873be 100644 --- a/src/CrossWikiEditor/App.axaml.cs +++ b/src/CrossWikiEditor/App.axaml.cs @@ -1,14 +1,12 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; - using CrossWikiEditor.Core; using CrossWikiEditor.Core.Repositories; using CrossWikiEditor.Core.Utils; using CrossWikiEditor.Core.ViewModels; using CrossWikiEditor.DependencyModules; using CrossWikiEditor.Views; - using Microsoft.Extensions.DependencyInjection; namespace CrossWikiEditor; diff --git a/src/CrossWikiEditor/Assets/MwDiff.css b/src/CrossWikiEditor/Assets/MwDiff.css index 95d3c0a..b3e19b2 100644 --- a/src/CrossWikiEditor/Assets/MwDiff.css +++ b/src/CrossWikiEditor/Assets/MwDiff.css @@ -60,7 +60,7 @@ white-space: break-spaces } -@media only screen and (max-width:720px) { +@media only screen and (max-width: 720px) { .client-js .mw-diff-inline-added ins, .client-js .mw-diff-inline-changed ins, .client-js .mw-diff-inline-moved ins, .client-js .mw-diff-inline-deleted ins, .client-js .mw-diff-inline-added del, .client-js .mw-diff-inline-changed del, .client-js .mw-diff-inline-moved del, .client-js .mw-diff-inline-deleted del { cursor: pointer } @@ -81,26 +81,26 @@ margin: 1em 0 } - .mw-diff-table-prefix .mw-diff-inline-legend { - margin-right: auto - } +.mw-diff-table-prefix .mw-diff-inline-legend { + margin-right: auto +} - .mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-ins, .mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-del { - display: inline-block; - padding: 4px 6px - } +.mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-ins, .mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-del { + display: inline-block; + padding: 4px 6px +} - .mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-ins { - background: #a3d3ff - } +.mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-ins { + background: #a3d3ff +} - .mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-del { - background: #ffe49c - } +.mw-diff-table-prefix .mw-diff-inline-legend .mw-diff-inline-legend-del { + background: #ffe49c +} - .mw-diff-table-prefix .mw-diffPage-inlineToggle-container { - margin-left: 1em - } +.mw-diff-table-prefix .mw-diffPage-inlineToggle-container { + margin-left: 1em +} .diff-addedline, .diff-deletedline, .diff-context { vertical-align: top; @@ -119,7 +119,7 @@ } .diff-editfont-monospace .diff-addedline, .diff-editfont-monospace .diff-deletedline, .diff-editfont-monospace .diff-context, .diff-editfont-monospace .mw-diff-inline-added, .diff-editfont-monospace .mw-diff-inline-deleted, .diff-editfont-monospace .mw-diff-inline-moved, .diff-editfont-monospace .mw-diff-inline-changed, .diff-editfont-monospace .mw-diff-inline-context { - font-family: monospace,monospace + font-family: monospace, monospace } .diff-editfont-sans-serif .diff-addedline, .diff-editfont-sans-serif .diff-deletedline, .diff-editfont-sans-serif .diff-context, .diff-editfont-sans-serif .mw-diff-inline-added, .diff-editfont-sans-serif .mw-diff-inline-deleted, .diff-editfont-sans-serif .mw-diff-inline-moved, .diff-editfont-sans-serif .mw-diff-inline-changed, .diff-editfont-sans-serif .mw-diff-inline-context { @@ -237,7 +237,7 @@ } .mw-diff-inline-added.mw-diff-empty-line::after, .mw-diff-inline-deleted.mw-diff-empty-line::after, .mw-inline-diff-newline::after { - font-family: 'Courier New',monospace; + font-family: 'Courier New', monospace; font-size: 87.5%; padding: 0 3px; display: inline-block; @@ -267,7 +267,7 @@ display: none } -@media only screen and (max-width:720px) { +@media only screen and (max-width: 720px) { .mw-diff-inline-legend { display: none } diff --git a/src/CrossWikiEditor/Controls/Hyperlink.cs b/src/CrossWikiEditor/Controls/Hyperlink.cs index 989a6b8..64c3b30 100644 --- a/src/CrossWikiEditor/Controls/Hyperlink.cs +++ b/src/CrossWikiEditor/Controls/Hyperlink.cs @@ -10,33 +10,11 @@ namespace CrossWikiEditor.Controls; public sealed class Hyperlink : InlineUIContainer { - private readonly Underline _underline; - private readonly TextBlock _textBlock; - private readonly Button _button; public static readonly StyledProperty TextProperty = AvaloniaProperty.Register("Text"); public static readonly StyledProperty HrefProperty = AvaloniaProperty.Register("Href"); - - public Span Content => _underline; - - public string Text - { - get => GetValue(TextProperty); - set - { - _textBlock.Text = value; - SetValue(TextProperty, value); - } - } - - public string Href - { - get => GetValue(HrefProperty); - set - { - ToolTip.SetTip(_button, value); - SetValue(HrefProperty, value); - } - } + private readonly Button _button; + private readonly TextBlock _textBlock; + private readonly Underline _underline; public Hyperlink() { @@ -60,6 +38,28 @@ public Hyperlink() Child = _button; } + public Span Content => _underline; + + public string Text + { + get => GetValue(TextProperty); + set + { + _textBlock.Text = value; + SetValue(TextProperty, value); + } + } + + public string Href + { + get => GetValue(HrefProperty); + set + { + ToolTip.SetTip(_button, value); + SetValue(HrefProperty, value); + } + } + private static void OpenUrl(string url) { var psi = new ProcessStartInfo diff --git a/src/CrossWikiEditor/Converters/Converters.cs b/src/CrossWikiEditor/Converters/Converters.cs index e1aed29..7475fc5 100644 --- a/src/CrossWikiEditor/Converters/Converters.cs +++ b/src/CrossWikiEditor/Converters/Converters.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using Avalonia.Data.Converters; +using Avalonia.Data.Converters; using CrossWikiEditor.Core.Models; namespace CrossWikiEditor.Converters; @@ -19,6 +18,7 @@ public static class Converters SetOperations.SymmetricDifference => "Symmetric difference", _ => x.ToString() }); + public static readonly IMultiValueConverter FirstEqualsToAnyConverter = new FuncMultiValueConverter(items => { @@ -27,11 +27,13 @@ public static class Converters { return true; } - var first = itemsList[0]; + + object? first = itemsList[0]; if (first == null) { return false; } + for (int i = 1; i < itemsList.Count; i++) { if (first.Equals(itemsList[i])) @@ -39,6 +41,7 @@ public static class Converters return true; } } + return false; }); } \ No newline at end of file diff --git a/src/CrossWikiEditor/CrossWikiEditor.csproj b/src/CrossWikiEditor/CrossWikiEditor.csproj index f125ac0..a8017e9 100644 --- a/src/CrossWikiEditor/CrossWikiEditor.csproj +++ b/src/CrossWikiEditor/CrossWikiEditor.csproj @@ -13,28 +13,28 @@ - + - - + + - - - - + + + + - - - - - + + + + + - + diff --git a/src/CrossWikiEditor/DependencyModules/ServicesModule.cs b/src/CrossWikiEditor/DependencyModules/ServicesModule.cs index 814ac64..31c5cc3 100644 --- a/src/CrossWikiEditor/DependencyModules/ServicesModule.cs +++ b/src/CrossWikiEditor/DependencyModules/ServicesModule.cs @@ -1,6 +1,4 @@ using Avalonia.Controls; -using Avalonia.Input.Platform; -using Avalonia.Platform.Storage; using CommunityToolkit.Mvvm.Messaging; using CrossWikiEditor.Core.Services; using CrossWikiEditor.Core.Services.HtmlParsers; diff --git a/src/CrossWikiEditor/DependencyModules/ViewModelsModule.cs b/src/CrossWikiEditor/DependencyModules/ViewModelsModule.cs index 593c9cc..b2541b3 100644 --- a/src/CrossWikiEditor/DependencyModules/ViewModelsModule.cs +++ b/src/CrossWikiEditor/DependencyModules/ViewModelsModule.cs @@ -1,4 +1,3 @@ -using CrossWikiEditor.Core.Services; using CrossWikiEditor.Core.ViewModels; using CrossWikiEditor.Core.ViewModels.ControlViewModels; using CrossWikiEditor.Core.ViewModels.MenuViewModels; diff --git a/src/CrossWikiEditor/DialogExtensions.cs b/src/CrossWikiEditor/DialogExtensions.cs index 4e127d5..b8e7a14 100644 --- a/src/CrossWikiEditor/DialogExtensions.cs +++ b/src/CrossWikiEditor/DialogExtensions.cs @@ -1,5 +1,4 @@ using Avalonia.Controls; - using CrossWikiEditor.Core; namespace CrossWikiEditor; diff --git a/src/CrossWikiEditor/Services/DialogService.cs b/src/CrossWikiEditor/Services/DialogService.cs index c0a4045..08821af 100644 --- a/src/CrossWikiEditor/Services/DialogService.cs +++ b/src/CrossWikiEditor/Services/DialogService.cs @@ -1,7 +1,6 @@ using CrossWikiEditor.Core; using CrossWikiEditor.Core.Services; using CrossWikiEditor.Core.ViewModels; - using Microsoft.Extensions.DependencyInjection; namespace CrossWikiEditor.Services; diff --git a/src/CrossWikiEditor/Services/FileDialogService.cs b/src/CrossWikiEditor/Services/FileDialogService.cs index 72e792d..72e485c 100644 --- a/src/CrossWikiEditor/Services/FileDialogService.cs +++ b/src/CrossWikiEditor/Services/FileDialogService.cs @@ -1,6 +1,5 @@ using System.Web; using Avalonia.Platform.Storage; - using CrossWikiEditor.Core.Services; namespace CrossWikiEditor.Services; @@ -12,22 +11,24 @@ public sealed class FileDialogService(IStorageProvider storageProvider) : IFileD bool allowMultiple, List? patterns = null) { - var options = new FilePickerOpenOptions() + var options = new FilePickerOpenOptions { Title = title, - AllowMultiple = allowMultiple, + AllowMultiple = allowMultiple }; if (patterns is not null) { - options.FileTypeFilter = [new FilePickerFileType("Select file...") { Patterns = patterns }]; + options.FileTypeFilter = [new FilePickerFileType("Select file...") {Patterns = patterns}]; } + IReadOnlyList result = await storageProvider.OpenFilePickerAsync(options); return result.Select(f => HttpUtility.UrlDecode(f.Path.AbsolutePath)).ToArray(); } - public async Task<(Func>? openReadStream, Func>? openWriteStream)> SaveFilePickerAsync(string title, string? defaultExtension = null, string? suggestedFileName = null) + public async Task<(Func>? openReadStream, Func>? openWriteStream)> SaveFilePickerAsync(string title, + string? defaultExtension = null, string? suggestedFileName = null) { - IStorageFile? storageFile = await storageProvider.SaveFilePickerAsync(new FilePickerSaveOptions() + IStorageFile? storageFile = await storageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { Title = title, ShowOverwritePrompt = true, diff --git a/src/CrossWikiEditor/Services/SystemService.cs b/src/CrossWikiEditor/Services/SystemService.cs index a89f85b..fc99c96 100644 --- a/src/CrossWikiEditor/Services/SystemService.cs +++ b/src/CrossWikiEditor/Services/SystemService.cs @@ -1,11 +1,8 @@ using System.Diagnostics; using System.Text; - using Avalonia.Input.Platform; - using CrossWikiEditor.Core.Services; using CrossWikiEditor.Core.Utils; - using Serilog; namespace CrossWikiEditor.Services; diff --git a/src/CrossWikiEditor/Styles/ButtonStyles.axaml b/src/CrossWikiEditor/Styles/ButtonStyles.axaml index 853b9f8..60cdf7b 100644 --- a/src/CrossWikiEditor/Styles/ButtonStyles.axaml +++ b/src/CrossWikiEditor/Styles/ButtonStyles.axaml @@ -7,6 +7,7 @@ \ No newline at end of file diff --git a/src/CrossWikiEditor/Styles/DialogStyles.axaml b/src/CrossWikiEditor/Styles/DialogStyles.axaml index 7580f5f..9b4b960 100644 --- a/src/CrossWikiEditor/Styles/DialogStyles.axaml +++ b/src/CrossWikiEditor/Styles/DialogStyles.axaml @@ -1,7 +1,9 @@  \ No newline at end of file diff --git a/src/CrossWikiEditor/Views/AddNewProfileView.axaml b/src/CrossWikiEditor/Views/AddNewProfileView.axaml index d956ed0..404413f 100644 --- a/src/CrossWikiEditor/Views/AddNewProfileView.axaml +++ b/src/CrossWikiEditor/Views/AddNewProfileView.axaml @@ -6,35 +6,83 @@ SizeToContent="WidthAndHeight" CanResize="False" Classes="DialogWindow" - mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="200" + mc:Ignorable="d" + d:DesignWidth="400" + d:DesignHeight="200" x:Class="CrossWikiEditor.Views.AddNewProfileView" x:DataType="viewModels:AddOrEditProfileViewModel" x:Name="This" Title="Add New Profile"> - - - + + + - Save Password? + + Save Password? + - - + - Select default settings? + + Select default settings? + - - - - + + - + - - Skip page when no disambiguations made - - - - + + + Skip page when no disambiguations made + + + + + diff --git a/src/CrossWikiEditor/Views/ControlViews/FindAndReplaceView.axaml b/src/CrossWikiEditor/Views/ControlViews/FindAndReplaceView.axaml index ddbb7f5..c02dacf 100644 --- a/src/CrossWikiEditor/Views/ControlViews/FindAndReplaceView.axaml +++ b/src/CrossWikiEditor/Views/ControlViews/FindAndReplaceView.axaml @@ -6,45 +6,99 @@ xmlns:controlViewModels="clr-namespace:CrossWikiEditor.Core.ViewModels.ControlViewModels;assembly=CrossWikiEditor.Core" Classes="DialogWindow" SizeToContent="Width" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="800" + d:DesignHeight="450" x:Class="CrossWikiEditor.Views.ControlViews.FindAndReplaceView" x:DataType="controlViewModels:FindAndReplaceViewModel" x:Name="This" Title="Find and Replace"> - - - - - + + + + + See - + / in - + - - - - + + + + - - - - + + + + Find and replace + + + + + @@ -40,7 +85,10 @@ - + Regex typo fixing Skip if no typo fixed diff --git a/src/CrossWikiEditor/Views/ControlViews/SkipView.axaml b/src/CrossWikiEditor/Views/ControlViews/SkipView.axaml index d91d9a3..294ee91 100644 --- a/src/CrossWikiEditor/Views/ControlViews/SkipView.axaml +++ b/src/CrossWikiEditor/Views/ControlViews/SkipView.axaml @@ -2,51 +2,118 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="800" + d:DesignHeight="450" x:Class="CrossWikiEditor.Views.ControlViews.SkipView"> - - - - Contains: + + + + + Contains: + - + Regex Case sensitive Check after - - Doesn't contain: + + + Doesn't contain: + - + Regex Case sensitive Check after - - - Page is in use - Edit blocked by spam filter - Page contains no links - No changes are made - Only whitespaces - Only casing - Only genfixes - Only minor genfixes - Only cosmetic changes - Page is redirect - No alert + + + + Page is in use + + + Edit blocked by spam filter + + + Page contains no links + + + No changes are made + + + Only whitespaces + + + Only casing + + + Only genfixes + + + Only minor genfixes + + + Only cosmetic changes + + + Page is redirect + + + No alert + - - - - - + + + + + diff --git a/src/CrossWikiEditor/Views/ControlViews/StartView.axaml b/src/CrossWikiEditor/Views/ControlViews/StartView.axaml index fa28d0b..b573372 100644 --- a/src/CrossWikiEditor/Views/ControlViews/StartView.axaml +++ b/src/CrossWikiEditor/Views/ControlViews/StartView.axaml @@ -3,20 +3,33 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controlViewModels="clr-namespace:CrossWikiEditor.Core.ViewModels.ControlViewModels;assembly=CrossWikiEditor.Core" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="800" + d:DesignHeight="450" x:DataType="controlViewModels:StartViewModel" x:Class="CrossWikiEditor.Views.ControlViews.StartView"> - - + + - - + + Lock Minor edit - + @@ -44,40 +57,93 @@ - - + + - + - - + + - - + + - - + + - - + + - - - + Skip + + + Regex - + Case sensitive diff --git a/src/CrossWikiEditor/Views/DatabaseScannerView.axaml b/src/CrossWikiEditor/Views/DatabaseScannerView.axaml index cd24b5c..353b2be 100644 --- a/src/CrossWikiEditor/Views/DatabaseScannerView.axaml +++ b/src/CrossWikiEditor/Views/DatabaseScannerView.axaml @@ -6,103 +6,198 @@ xmlns:controls="clr-namespace:CrossWikiEditor.Controls" xmlns:models="clr-namespace:CrossWikiEditor.Core.Models;assembly=CrossWikiEditor.Core" xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="800" + d:DesignHeight="450" x:DataType="viewModels:DatabaseScannerViewModel" x:Class="CrossWikiEditor.Views.DatabaseScannerView" x:Name="This" Title="DatabaseScannerView"> - + - - - - - - - - - - - + + + + - - - - - - + + + + - + - + - - - + + + - - - - + + + + - - - - - + + + + + - + @@ -90,22 +151,29 @@ - - + Command="{Binding ConvertToTalkPagesCommand}" + Header="Convert to talk pages" /> + Command="{Binding ConvertFromTalkPagesCommand}" + Header="Convert from talk pages" /> - - + Command="{Binding SortAlphabeticallyCommand}" + Header="Sort alphabetically" /> @@ -125,13 +193,20 @@ - - - diff --git a/src/CrossWikiEditor/Views/MenuView.axaml b/src/CrossWikiEditor/Views/MenuView.axaml index b121689..7a9c7aa 100644 --- a/src/CrossWikiEditor/Views/MenuView.axaml +++ b/src/CrossWikiEditor/Views/MenuView.axaml @@ -4,24 +4,33 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:menuViewModels="clr-namespace:CrossWikiEditor.Core.ViewModels.MenuViewModels;assembly=CrossWikiEditor.Core" x:DataType="menuViewModels:MenuViewModel" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="800" + d:DesignHeight="450" x:Class="CrossWikiEditor.Views.MenuView"> - + - - + + - - - + + + - + diff --git a/src/CrossWikiEditor/Views/PreferencesView.axaml b/src/CrossWikiEditor/Views/PreferencesView.axaml index 0d80de9..80b75d6 100644 --- a/src/CrossWikiEditor/Views/PreferencesView.axaml +++ b/src/CrossWikiEditor/Views/PreferencesView.axaml @@ -8,17 +8,23 @@ MaxHeight="400" MaxWidth="600" x:DataType="viewModels:PreferencesViewModel" - mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="400" + mc:Ignorable="d" + d:DesignWidth="600" + d:DesignHeight="400" x:Class="CrossWikiEditor.Views.PreferencesView" x:Name="This" Title="Preferences"> - + - - - + + + @@ -28,33 +34,49 @@ - - + + - + - - - + + - - + - - + - + @@ -62,9 +84,11 @@ -