diff --git a/README.md b/README.md index 6b142cfb..479ecf89 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,9 @@ The `RepositoryActions.yaml` file also contains a section to define tags per rep ## Ordering and Filtering -[Filtering](docs/Filtering.md) [Ordering](docs/Ordering.md) +The order of the repositories shown in RepoM is customizable. The default is alphabetical on the repository name. Read more about ordering [here](docs/Ordering.md). + +The repositories shown in RepoM are filtered using the search box in RepoM. But the default set can also be configured using different presets. [This page](docs/Filtering.md) describes how to create custom filter presets. ## Global configuration diff --git a/README.source.md b/README.source.md index 6b142cfb..479ecf89 100644 --- a/README.source.md +++ b/README.source.md @@ -54,7 +54,9 @@ The `RepositoryActions.yaml` file also contains a section to define tags per rep ## Ordering and Filtering -[Filtering](docs/Filtering.md) [Ordering](docs/Ordering.md) +The order of the repositories shown in RepoM is customizable. The default is alphabetical on the repository name. Read more about ordering [here](docs/Ordering.md). + +The repositories shown in RepoM are filtered using the search box in RepoM. But the default set can also be configured using different presets. [This page](docs/Filtering.md) describes how to create custom filter presets. ## Global configuration diff --git a/_ref/RepoM.Sorting.yaml b/_ref/RepoM.Sorting.yaml index 573c6c6f..8985b78e 100644 --- a/_ref/RepoM.Sorting.yaml +++ b/_ref/RepoM.Sorting.yaml @@ -1,5 +1,5 @@ Work: - type: composition@1 + type: composition-comparer@1 comparers: - type: score-comparer@1 score-provider: @@ -19,7 +19,7 @@ Work: property: Name weight: 1 Work Dynamic: - type: composition@1 + type: composition-comparer@1 comparers: - type: score-comparer@1 score-provider: @@ -58,7 +58,7 @@ Work Dynamic: property: Name weight: 1 Prive: - type: composition@1 + type: composition-comparer@1 comparers: - type: score-comparer@1 score-provider: diff --git a/docs/Ordering.md b/docs/Ordering.md index f88e523e..3e852a7f 100644 --- a/docs/Ordering.md +++ b/docs/Ordering.md @@ -1,3 +1,98 @@ # Ordering -todo. +The order of the repositories shown in RepoM is customizable. The default is alphabetical on the repository name. + +Orderings are defined in yaml using repository-`comparers` and repository-`scorers`. You can switch at any given time between orderings using the hamburgermenu in RepoM. + +## Definitions + +A [`comparer`](#comparers) compares two repositories resulting in an order between the two. The comparison is defined by the type of comparer. It is possible to compare by repository name (assending order) or to compare repositories by the timestamp of the last action performed by RepoM. + +[`Scorers`](#scorers) however calculate a score over exactly one repository. It does not compare repositories. Comparing repositories by score, use the `score-comparer@1`. + +## Comparers + +- [`az-comparer@1`](#az-comparer1) +- [`composition-comparer@1`](#composition-comparer1) +- [`score-comparer@1`](#score-comparer1) +- [`sum-comparer@1`](#sum-comparer1) + +These comparers are available by using the corresponding plugin. +- [`last-opened-comparer@1`](#last-opened-comparer1) + +### `az-comparer@1` + +Compares two repositories by a given property alphabetically in ascending order. + +Properties: + +- `property`: Repository property. Currently, only `Name`, and `Location` are supported. Otherwise, comparison will always result in `0`. (optional) +- `weight`: The weight of this comparer. The higher the weight, the higher the impact. + +### `composition-comparer@1` + +Compares two repositories by a composition of comparers. + +Properties: + +- `comparers`: List of comparers. The first comparer not resulting in `0` will be used as final result. + +### `score-comparer@1` + +Compares two repositories by a repository score. The calculation of the repository score is defined in the score provider. + +Properties: + +- `score-provider`: The score provider to calculate a score for a repository. (optional) + +### `sum-comparer@1` + +Compares two repositories by the sum of the results of the comparers. + +Properties: + +- `comparers`: A list of comparers. The sum of the results of the comparers will be used as final result. + +### `last-opened-comparer@1` + +Compares two repositories by the timestamp of the last action RepoM performed on the repository. + +Properties: + +- `weight`: The weight of this comparer. The higher the weight, the higher the impact. + + +## Scorers + +- [`is-pinned-scorer@1`](#is-pinned-scorer1) +- [`tag-scorer@1`](#tag-scorer1) + +These scorers are available by using the corresponding plugin. +- [`usage-scorer@1`](#usage-scorer1) + +### `is-pinned-scorer@1` + +Repository scorer based on the pinned state of a repository. + +Properties: + +- `weight`: The weight of this scorer. The higher the weight, the higher the impact. + +### `tag-scorer@1` + +Repository scorer based on the tags of a repository. + +Properties: + +- `weight`: The weight of this scorer. The higher the weight, the higher the impact. +- `tag`: The tag to match on. If the repository has this tag, the score will return the weight, otherwise, `0`. (optional) + +### `usage-scorer@1` + +Repository scorer based on it's usage by RepoM. The more it's used, the higher the score. + +Properties: + +- `windows`: Specific 'windows' to calculate the score for. +- `max-score`: The maximum score a repository can get. + diff --git a/docs/RepoM.Plugin.Heidi.md b/docs/RepoM.Plugin.Heidi.md index 5f9ae21f..fc212f7d 100644 --- a/docs/RepoM.Plugin.Heidi.md +++ b/docs/RepoM.Plugin.Heidi.md @@ -1,6 +1,6 @@ # Heidi -This module integrates with a portable [HeidiSQL](https://www.heidisql.com/) installation. The portable Heidi DB saves it's database configuration in a portable configuration file. +This module integrates with a portable [HeidiSQL](https://www.heidisql.com/) installation. The portable Heidi DB saves its database configuration in a portable configuration file. This module monitors this file and provides an action menu and a variable provider to access this information. To use this module, make sure it is enabled in RepoM by opening the menu and navigate to 'Plugins'. When enabling or disabling a plugin, you should restart RepoM. diff --git a/docs/Settings.md b/docs/Settings.md index 8aeba947..291937d5 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -21,8 +21,6 @@ This is the default configuration. }, "ReposRootDirectories": [], "EnabledSearchProviders": [], - "SonarCloudPersonalAccessToken": null, - "AzureDevOps": null, "Plugins": [] } ``` @@ -38,6 +36,4 @@ Properties: diff --git a/docs/mdsource/Ordering.source.md b/docs/mdsource/Ordering.source.md index f88e523e..8add4959 100644 --- a/docs/mdsource/Ordering.source.md +++ b/docs/mdsource/Ordering.source.md @@ -1,3 +1,19 @@ # Ordering -todo. +The order of the repositories shown in RepoM is customizable. The default is alphabetical on the repository name. + +Orderings are defined in yaml using repository-`comparers` and repository-`scorers`. You can switch at any given time between orderings using the hamburgermenu in RepoM. + +## Definitions + +A [`comparer`](#comparers) compares two repositories resulting in an order between the two. The comparison is defined by the type of comparer. It is possible to compare by repository name (assending order) or to compare repositories by the timestamp of the last action performed by RepoM. + +[`Scorers`](#scorers) however calculate a score over exactly one repository. It does not compare repositories. Comparing repositories by score, use the `score-comparer@1`. + +## Comparers + +include: RepositoriesComparerConfigurationTests.CoreComparersMarkdown.verified.md + +## Scorers + +include: RepositoriesScorerConfigurationTests.CoreScorersMarkdown.verified.md diff --git a/docs/mdsource/RepoM.Plugin.Heidi.source.md b/docs/mdsource/RepoM.Plugin.Heidi.source.md index 640c8838..547cb94e 100644 --- a/docs/mdsource/RepoM.Plugin.Heidi.source.md +++ b/docs/mdsource/RepoM.Plugin.Heidi.source.md @@ -1,6 +1,6 @@ # Heidi -This module integrates with a portable [HeidiSQL](https://www.heidisql.com/) installation. The portable Heidi DB saves it's database configuration in a portable configuration file. +This module integrates with a portable [HeidiSQL](https://www.heidisql.com/) installation. The portable Heidi DB saves its database configuration in a portable configuration file. This module monitors this file and provides an action menu and a variable provider to access this information. include: _plugin_enable diff --git a/src/RepoM.Api/Bootstrapper.cs b/src/RepoM.Api/Bootstrapper.cs index 2188ce0d..37a9339b 100644 --- a/src/RepoM.Api/Bootstrapper.cs +++ b/src/RepoM.Api/Bootstrapper.cs @@ -12,7 +12,9 @@ namespace RepoM.Api; using System.Threading.Tasks; using System; using RepoM.Api.Plugins.SimpleInjector; +using RepoM.Core.Plugin; using RepoM.Core.Plugin.Common; +using RepoM.Core.Plugin.RepositoryOrdering.Configuration; public class CoreBootstrapper { @@ -21,6 +23,8 @@ public class CoreBootstrapper private readonly IAppDataPathProvider _appDataProvider; private readonly ILoggerFactory _loggerFactory; + private static readonly Assembly _thisAssembly = typeof(CoreBootstrapper).Assembly; + public CoreBootstrapper(IPluginFinder pluginFinder, IFileSystem fileSystem, IAppDataPathProvider appDataProvider, ILoggerFactory loggerFactory) { _pluginFinder = pluginFinder ?? throw new ArgumentNullException(nameof(pluginFinder)); @@ -29,6 +33,22 @@ public CoreBootstrapper(IPluginFinder pluginFinder, IFileSystem fileSystem, IApp _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); } + public static void RegisterRepositoryScorerConfigurationsTypes(Container container) + { + foreach (Type type in GetNonAbstractNonGenericInheritedExportedTypesFrom(_thisAssembly)) + { + container.RegisterScorerConfigurationForType(type); + } + } + + public static void RegisterRepositoryComparerConfigurationsTypes(Container container) + { + foreach (Type type in GetNonAbstractNonGenericInheritedExportedTypesFrom(_thisAssembly)) + { + container.RegisterComparerConfigurationForType(type); + } + } + public async Task LoadAndRegisterPluginsAsync(Container container, string baseDirectory) { _ = container ?? throw new ArgumentNullException(nameof(container)); @@ -79,4 +99,26 @@ private static PluginSettings ConvertToPluginSettings(PluginInfo pluginInfo, str { return new PluginSettings(pluginInfo.Name, pluginInfo.AssemblyPath.Replace(baseDir, string.Empty), enabled); } + + static IEnumerable GetExportedTypesFrom(Assembly assembly) + { + try + { + return assembly.DefinedTypes.Select(info => info.AsType()); + } + catch (NotSupportedException) + { + // A type load exception would typically happen on an Anonymously Hosted DynamicMethods + // Assembly and it would be safe to skip this exception. + return Enumerable.Empty(); + } + } + + static IEnumerable GetNonAbstractNonGenericInheritedExportedTypesFrom(Assembly assembly) + { + return GetExportedTypesFrom(assembly) + .Where(t => typeof(T).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo())) + .Where(t => t.GetTypeInfo() is { IsAbstract: false, IsGenericTypeDefinition: false, }); + + } } \ No newline at end of file diff --git a/src/RepoM.Api/Common/AppSettings.cs b/src/RepoM.Api/Common/AppSettings.cs index da02207e..176e6a65 100644 --- a/src/RepoM.Api/Common/AppSettings.cs +++ b/src/RepoM.Api/Common/AppSettings.cs @@ -57,18 +57,6 @@ public sealed class AppSettings [UiConfigured] public List EnabledSearchProviders { get; set; } = new(); - /// - /// SonarCloud PAT. - /// - [Obsolete("This is done using plugin.")] - public string? SonarCloudPersonalAccessToken { get; set; } = string.Empty; - - /// - /// Azure DevOps config. - /// - [Obsolete("This is done using plugin.")] - public AzureDevOpsOptions? AzureDevOps { get; set; } = AzureDevOpsOptions.Default; - /// /// List of plugins. /// @@ -82,8 +70,6 @@ public sealed class AppSettings MenuSize = Size.Default, ReposRootDirectories = new(), EnabledSearchProviders = new List(1), - SonarCloudPersonalAccessToken = null, - AzureDevOps = AzureDevOpsOptions.Default, Plugins = new List(), }; } @@ -94,15 +80,6 @@ public sealed class UiConfiguredAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public sealed class ManualConfiguredAttribute : Attribute { } -public class AzureDevOpsOptions -{ - public string? PersonalAccessToken { get; set; } = string.Empty; - - public string? BaseUrl { get; set; } = string.Empty; - - public static AzureDevOpsOptions? Default => null; -} - public class Size { public double Height { get; set; } @@ -118,16 +95,9 @@ public class Size public class PluginOptions { - public PluginOptions() - { - Name = string.Empty; - DllName = string.Empty; - Enabled = false; - } - - public string Name { get; init; } + public string Name { get; init; } = string.Empty; - public string DllName { get; init; } + public string DllName { get; init; } = string.Empty; - public bool Enabled { get; init; } + public bool Enabled { get; init; } = false; } \ No newline at end of file diff --git a/src/RepoM.Api/Common/FileAppSettingsService.cs b/src/RepoM.Api/Common/FileAppSettingsService.cs index a64c1d6e..149bda62 100644 --- a/src/RepoM.Api/Common/FileAppSettingsService.cs +++ b/src/RepoM.Api/Common/FileAppSettingsService.cs @@ -235,126 +235,6 @@ public List EnabledSearchProviders } } - [Obsolete("Will be removed in next big version")] - public string SonarCloudPersonalAccessToken - { - get => Settings.SonarCloudPersonalAccessToken ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.SonarCloudPersonalAccessToken == null) - { - return; - } - - Settings.SonarCloudPersonalAccessToken = null; - } - else - { - if (value.Equals(Settings.SonarCloudPersonalAccessToken, StringComparison.InvariantCulture)) - { - return; - } - - Settings.SonarCloudPersonalAccessToken = value; - } - - NotifyChange(); - Save(); - } - } - - [Obsolete("Will be removed in next big version")] - public string AzureDevOpsPersonalAccessToken - { - get => Settings.AzureDevOps?.PersonalAccessToken ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.AzureDevOps == null) - { - return; - } - - if (string.IsNullOrWhiteSpace(Settings.AzureDevOps.PersonalAccessToken)) - { - return; - } - - Settings.AzureDevOps.PersonalAccessToken = null; - - if (Settings.AzureDevOps.BaseUrl == null) - { - Settings.AzureDevOps = null; - } - } - else - { - if (Settings.AzureDevOps == null) - { - Settings.AzureDevOps = new AzureDevOpsOptions { PersonalAccessToken = value, }; - } - else - { - if (value.Equals(Settings.AzureDevOps.PersonalAccessToken, StringComparison.InvariantCulture)) - { - return; - } - } - } - - NotifyChange(); - Save(); - } - } - - [Obsolete("Will be removed in next big version")] - public string AzureDevOpsBaseUrl - { - get => Settings.AzureDevOps?.BaseUrl ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.AzureDevOps == null) - { - return; - } - - if (string.IsNullOrWhiteSpace(Settings.AzureDevOps.BaseUrl)) - { - return; - } - - Settings.AzureDevOps.BaseUrl = null; - - if (Settings.AzureDevOps.PersonalAccessToken == null) - { - Settings.AzureDevOps = null; - } - } - else - { - if (Settings.AzureDevOps == null) - { - Settings.AzureDevOps = new AzureDevOpsOptions { BaseUrl = value, }; - } - else - { - if (value.Equals(Settings.AzureDevOps.BaseUrl, StringComparison.InvariantCulture)) - { - return; - } - } - } - - NotifyChange(); - Save(); - } - } - public List Plugins { get => _plugins ??= Convert(Settings.Plugins); diff --git a/src/RepoM.Api/Common/FilesCompareSettingsService.cs b/src/RepoM.Api/Common/FilesCompareSettingsService.cs index f79356b8..67231d35 100644 --- a/src/RepoM.Api/Common/FilesCompareSettingsService.cs +++ b/src/RepoM.Api/Common/FilesCompareSettingsService.cs @@ -5,7 +5,6 @@ namespace RepoM.Api.Common; using System.IO; using System.IO.Abstractions; using System.Linq; -using System.Reflection; using Microsoft.Extensions.Logging; using RepoM.Core.Plugin.Common; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; @@ -14,30 +13,45 @@ namespace RepoM.Api.Common; public class FilesCompareSettingsService : ICompareSettingsService { + private const string FILENAME = "RepoM.Ordering.yaml"; private readonly IFileSystem _fileSystem; private readonly ILogger _logger; - private readonly IEnumerable _registrations; private readonly IAppDataPathProvider _appDataPathProvider; private Dictionary? _configuration; - + private readonly IDeserializer _deserializer; + public FilesCompareSettingsService( IAppDataPathProvider appDataPathProvider, IFileSystem fileSystem, - IEnumerable registrations, + IEnumerable> comparerRegistrations, + IEnumerable> scorerRegistrations, ILogger logger) { _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _registrations = registrations.ToList(); + _appDataPathProvider = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider)); - } - public Dictionary Configuration => _configuration ??= Load(); + var comparerTypesDictionary = comparerRegistrations.ToDictionary(registration => registration.Tag, registration => registration.ConfigurationType); + var scorerTypesDictionary = scorerRegistrations.ToDictionary(registration => registration.Tag, registration => registration.ConfigurationType); + _deserializer = new DeserializerBuilder() + .WithNamingConvention(HyphenatedNamingConvention.Instance) + .WithTypeDiscriminatingNodeDeserializer(options => + { + options.AddKeyValueTypeDiscriminator(nameof(IRepositoryScorerConfiguration.Type).ToLower(), scorerTypesDictionary); + options.AddKeyValueTypeDiscriminator(nameof(IRepositoriesComparerConfiguration.Type).ToLower(), comparerTypesDictionary); + }, + maxDepth: -1, + maxLength: -1) + .Build(); + } + public Dictionary Configuration => _configuration ??= Load(); + private string GetFileName() { - return _fileSystem.Path.Combine(_appDataPathProvider.AppDataPath, "RepoM.Ordering.yaml"); + return _fileSystem.Path.Combine(_appDataPathProvider.AppDataPath, FILENAME); } private Dictionary Load() @@ -59,34 +73,29 @@ private Dictionary LoadInner() if (!_fileSystem.File.Exists(file)) { - throw new FileNotFoundException("Comparer configuration file not found", file); + var templateFilename = _fileSystem.Path.Combine(_appDataPathProvider.AppResourcesPath, FILENAME); + if (_fileSystem.File.Exists(templateFilename)) + { + try + { + _fileSystem.File.Copy(templateFilename, file); + } + catch (Exception e) + { + _logger.LogError(e, "Could not copy template file '{templateFilename}' to '{file}'", templateFilename, file); + } + } + + if (!_fileSystem.File.Exists(file)) + { + throw new FileNotFoundException("Comparer configuration file not found", file); + } } try { var yml = _fileSystem.File.ReadAllText(file); - - IDeserializer deserializer = new DeserializerBuilder() - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .WithTypeDiscriminatingNodeDeserializer(options => - { - options.AddKeyValueTypeDiscriminator( - "type", - _registrations - .Where(reg => typeof(IRepositoryScorerConfiguration).GetTypeInfo().IsAssignableFrom(reg.ConfigurationType.GetTypeInfo())) - .ToDictionary(registration => registration.Tag, x => x.ConfigurationType)); - - options.AddKeyValueTypeDiscriminator( - "type", - _registrations - .Where(reg => typeof(IRepositoriesComparerConfiguration).GetTypeInfo().IsAssignableFrom(reg.ConfigurationType.GetTypeInfo())) - .ToDictionary(registration => registration.Tag, x => x.ConfigurationType)); - }, - maxDepth: -1, - maxLength: -1) - .Build(); - - return deserializer.Deserialize>(yml); + return _deserializer.Deserialize>(yml); } catch (Exception ex) { diff --git a/src/RepoM.Api/Common/FilesFilterSettingsService.cs b/src/RepoM.Api/Common/FilesFilterSettingsService.cs index 0e9ff64a..5bb56403 100644 --- a/src/RepoM.Api/Common/FilesFilterSettingsService.cs +++ b/src/RepoM.Api/Common/FilesFilterSettingsService.cs @@ -12,6 +12,7 @@ namespace RepoM.Api.Common; public class FilesFilterSettingsService : IFilterSettingsService { + private const string FILENAME = "RepoM.Filtering.yaml"; private readonly IFileSystem _fileSystem; private readonly ILogger _logger; private readonly IAppDataPathProvider _appDataPathProvider; @@ -31,7 +32,7 @@ public FilesFilterSettingsService( private string GetFileName() { - return _fileSystem.Path.Combine(_appDataPathProvider.AppDataPath, "RepoM.Filtering.yaml"); + return _fileSystem.Path.Combine(_appDataPathProvider.AppDataPath, FILENAME); } private Dictionary Load() @@ -40,7 +41,23 @@ private Dictionary Load() if (!_fileSystem.File.Exists(file)) { - throw new FileNotFoundException("Comparer configuration file not found", file); + var templateFilename = _fileSystem.Path.Combine(_appDataPathProvider.AppResourcesPath, FILENAME); + if (_fileSystem.File.Exists(templateFilename)) + { + try + { + _fileSystem.File.Copy(templateFilename, file); + } + catch (Exception e) + { + _logger.LogError(e, "Could not copy template file '{templateFilename}' to '{file}'", templateFilename, file); + } + } + + if (!_fileSystem.File.Exists(file)) + { + throw new FileNotFoundException("Filtering configuration file not found", file); + } } try diff --git a/src/RepoM.Api/Common/IAppSettingsService.cs b/src/RepoM.Api/Common/IAppSettingsService.cs index 82b31647..6b6fd51c 100644 --- a/src/RepoM.Api/Common/IAppSettingsService.cs +++ b/src/RepoM.Api/Common/IAppSettingsService.cs @@ -30,15 +30,6 @@ public interface IAppSettingsService List EnabledSearchProviders { get; set; } - [Obsolete("Will be removed in next big version")] - string SonarCloudPersonalAccessToken { get; set; } - - [Obsolete("Will be removed in next big version")] - string AzureDevOpsPersonalAccessToken { get; set; } - - [Obsolete("Will be removed in next big version")] - string AzureDevOpsBaseUrl { get; set; } - string SortKey { get; set; } string QueryParserKey { get; set; } diff --git a/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs b/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs index 03b1f34d..9468bab1 100644 --- a/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs +++ b/src/RepoM.Api/IO/DefaultAppDataPathProvider.cs @@ -7,6 +7,7 @@ namespace RepoM.Api.IO; public class DefaultAppDataPathProvider : IAppDataPathProvider { private static readonly string _applicationDataRepoM = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RepoM"); + private static readonly string _appResourcesPath = GetAppResourcePath(); private DefaultAppDataPathProvider() { @@ -16,8 +17,10 @@ private DefaultAppDataPathProvider() public string AppDataPath => _applicationDataRepoM; - [Obsolete("Not used.")] - public string GetAppResourcesPath() + + public string AppResourcesPath => _appResourcesPath; + + private static string GetAppResourcePath() { var entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); if (entryAssembly == null) diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/ActionDeserializers/ActionDeserializerComposition.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/ActionDeserializers/ActionDeserializerComposition.cs index bb40f2a9..3a6fb83c 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/ActionDeserializers/ActionDeserializerComposition.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/ActionDeserializers/ActionDeserializerComposition.cs @@ -48,7 +48,7 @@ public ActionDeserializerComposition(IEnumerable deserializ private RepositoryAction? DeserializeWithDefaultDeserializers(string type, JToken jToken, JsonSerializer jsonSerializer) { - IKeyTypeRegistration? registration = _typeRegistrations.FirstOrDefault(x => x.Tag.Equals(type, StringComparison.CurrentCultureIgnoreCase)); + IKeyTypeRegistration? registration = Array.Find(_typeRegistrations, x => x.Tag.Equals(type, StringComparison.CurrentCultureIgnoreCase)); if (registration != null) { diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Data/RepositoryAction.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Data/RepositoryAction.cs index 0e0338a5..941a4613 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Data/RepositoryAction.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Data/RepositoryAction.cs @@ -135,26 +135,20 @@ public static class ContainerExtensions { public static void RegisterDefaultRepositoryActionDeserializerForType(this Container container) where T : RepositoryAction { - container.Collection.AppendInstance>(new RepositoryActionKeyTypeRegistration()); + RegisterDefaultRepositoryActionDeserializerForType(container, typeof(T)); } public static void RegisterDefaultRepositoryActionDeserializerForType(this Container container, Type type) { - container.Collection.AppendInstance>(new RepositoryActionKeyTypeRegistration(type)); + container.Collection.AppendInstance>(new FixedTypeRegistration(type, TypeRepositoryActionAttributeReader.GetValue(type))); } } public sealed class DefaultActionDeserializer : IActionDeserializer where T : RepositoryAction { - public DefaultActionDeserializer() - { - ConfigurationType = typeof(T); - Tag = typeof(T).GetCustomAttribute()?.Type ?? throw new InvalidOperationException($"RepositoryActionAttribute not found on {typeof(T).FullName}"); - } + private Type ConfigurationType { get; } = typeof(T); - private Type ConfigurationType { get; } - - private string Tag { get; } + private string Tag { get; } = TypeRepositoryActionAttributeReader.GetValue(typeof(T)); public bool CanDeserialize(string type) @@ -168,28 +162,13 @@ public bool CanDeserialize(string type) } } -file sealed class RepositoryActionKeyTypeRegistration : IKeyTypeRegistration where T : RepositoryAction -{ - public RepositoryActionKeyTypeRegistration() - { - ConfigurationType = typeof(T); - Tag = typeof(T).GetCustomAttribute()?.Type ?? throw new InvalidOperationException($"RepositoryActionAttribute not found on {typeof(T).FullName}"); - } - - public Type ConfigurationType { get; } - - public string Tag { get; } -} - -file sealed class RepositoryActionKeyTypeRegistration : IKeyTypeRegistration +/// +/// This class 'assumes' that the type has a custom attribute of type with a property 'Type' that is the type value. +/// +file static class TypeRepositoryActionAttributeReader { - public RepositoryActionKeyTypeRegistration(Type t) + public static string GetValue(Type type) { - ConfigurationType = t; - Tag = t.GetCustomAttribute()?.Type ?? throw new InvalidOperationException($"RepositoryActionAttribute not found on {t.FullName}"); + return type.GetCustomAttribute()?.Type ?? throw new InvalidOperationException($"RepositoryActionAttribute not found on {type.FullName}"); } - - public Type ConfigurationType { get; } - - public string Tag { get; } } diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs index a8601e4f..c377bc89 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs @@ -24,27 +24,23 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider; public class RepositoryConfigurationReader { + public const string FILENAME = "RepositoryActions.yaml"; private readonly IAppDataPathProvider _appDataPathProvider; private readonly IFileSystem _fileSystem; - private readonly JsonDynamicRepositoryActionDeserializer _jsonAppSettingsDeserializer; private readonly YamlDynamicRepositoryActionDeserializer _yamlAppSettingsDeserializer; private readonly IRepositoryExpressionEvaluator _repoExpressionEvaluator; private readonly ILogger _logger; - private const string FILENAME = "RepositoryActions."; - public const string FILENAME_JSON = FILENAME + "json"; public RepositoryConfigurationReader( IAppDataPathProvider appDataPathProvider, IFileSystem fileSystem, - JsonDynamicRepositoryActionDeserializer jsonAppSettingsDeserializer, YamlDynamicRepositoryActionDeserializer yamlAppSettingsDeserializer, IRepositoryExpressionEvaluator repoExpressionEvaluator, ILogger logger) { _appDataPathProvider = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); - _jsonAppSettingsDeserializer = jsonAppSettingsDeserializer ?? throw new ArgumentNullException(nameof(jsonAppSettingsDeserializer)); _yamlAppSettingsDeserializer = yamlAppSettingsDeserializer ?? throw new ArgumentNullException(nameof(yamlAppSettingsDeserializer)); _repoExpressionEvaluator = repoExpressionEvaluator ?? throw new ArgumentNullException(nameof(repoExpressionEvaluator)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -52,20 +48,31 @@ public RepositoryConfigurationReader( private string GetRepositoryActionsFilename(string basePath) { - var extensions = new [] { "yml", "yaml", "json", }; + var filename = Path.Combine(basePath, FILENAME); + if (_fileSystem.File.Exists(filename)) + { + return filename; + } - var path = Path.Combine(basePath, FILENAME); - foreach (var ext in extensions) + var filenameTemplate = Path.Combine(_appDataPathProvider.AppResourcesPath, FILENAME); + if (_fileSystem.File.Exists(filenameTemplate)) { - var filename = path + ext; + try + { + _fileSystem.File.Copy(filenameTemplate, filename); + } + catch (Exception e) + { + _logger.LogError(e, "Could not copy default {FILENAME} to {AppDataPath}", FILENAME, _appDataPathProvider.AppDataPath); + } + if (_fileSystem.File.Exists(filename)) { return filename; } } - var failingFilename = path + "{" + string.Join(",",extensions) + "}"; - throw new ConfigurationFileNotFoundException(failingFilename); + throw new ConfigurationFileNotFoundException(filename); } public (Dictionary? envVars, List? Variables, List? actions, List? tags) Get(params IRepository[] repositories) @@ -101,7 +108,7 @@ private string GetRepositoryActionsFilename(string basePath) try { var content = _fileSystem.File.ReadAllText(filename, Encoding.UTF8); - rootFile = Deserialize(Path.GetExtension(filename), content); + rootFile = Deserialize(_fileSystem.Path.GetExtension(filename), content); } catch (Exception e) { @@ -119,7 +126,7 @@ private string GetRepositoryActionsFilename(string basePath) try { var content = _fileSystem.File.ReadAllText(filename, Encoding.UTF8); - rootFile = Deserialize(Path.GetExtension(filename), content); + rootFile = Deserialize(_fileSystem.Path.GetExtension(filename), content); } catch (Exception e) { @@ -225,7 +232,7 @@ List EvaluateVariables(IEnumerable? vars) try { var content = _fileSystem.File.ReadAllText(f, Encoding.UTF8); - repoSpecificConfig = Deserialize(Path.GetExtension(f), content); + repoSpecificConfig = Deserialize(_fileSystem.Path.GetExtension(f), content); } catch (Exception) { @@ -267,7 +274,7 @@ List EvaluateVariables(IEnumerable? vars) private string EvaluateString(string? input, IRepository? repository) { - object? v = Evaluate(input, repository); + var v = Evaluate(input, repository); return v?.ToString() ?? string.Empty; } @@ -285,11 +292,6 @@ private RepositoryActionConfiguration Deserialize(string extension, string rawCo extension = extension[1..]; } - if ("json".Equals(extension, StringComparison.CurrentCultureIgnoreCase)) - { - return _jsonAppSettingsDeserializer.Deserialize(rawContent); - } - if ("yaml".Equals(extension, StringComparison.CurrentCultureIgnoreCase) || "yml".Equals(extension, StringComparison.CurrentCultureIgnoreCase)) { return _yamlAppSettingsDeserializer.Deserialize(rawContent); @@ -490,7 +492,7 @@ public IEnumerable CreateActions(params Repository[] repos } } - private List EvaluateVariables(IEnumerable? vars, Repository? repository) + private List EvaluateVariables(IEnumerable? vars, IRepository? repository) { if (vars == null || repository == null) { @@ -549,6 +551,6 @@ private bool IsEnabled(string? booleanExpression, bool defaultWhenNullOrEmpty, I { return string.IsNullOrWhiteSpace(booleanExpression) ? defaultWhenNullOrEmpty - : _repoExpressionEvaluator.EvaluateBooleanExpression(booleanExpression!, repository); + : _repoExpressionEvaluator.EvaluateBooleanExpression(booleanExpression, repository); } } \ No newline at end of file diff --git a/src/RepoM.Api/IO/VariableProviders/CustomEnvironmentVariableVariableProvider.cs b/src/RepoM.Api/IO/VariableProviders/CustomEnvironmentVariableVariableProvider.cs index 7801be6b..20a73eac 100644 --- a/src/RepoM.Api/IO/VariableProviders/CustomEnvironmentVariableVariableProvider.cs +++ b/src/RepoM.Api/IO/VariableProviders/CustomEnvironmentVariableVariableProvider.cs @@ -9,7 +9,7 @@ namespace RepoM.Api.IO.VariableProviders; using RepoM.Core.Plugin.Repository; [UsedImplicitly] -public class CustomEnvironmentVariableVariableProvider : IVariableProvider +public class CustomEnvironmentVariableVariableProvider : RepoM.Core.Plugin.VariableProviders.IVariableProvider { private const string PREFIX = "Env."; diff --git a/src/RepoM.Api/IO/VariableProviders/RepoMVariableProvider.cs b/src/RepoM.Api/IO/VariableProviders/RepoMVariableProvider.cs index aee8bfe6..066edad1 100644 --- a/src/RepoM.Api/IO/VariableProviders/RepoMVariableProvider.cs +++ b/src/RepoM.Api/IO/VariableProviders/RepoMVariableProvider.cs @@ -92,7 +92,7 @@ class PropertyHandler : IItemHandler } } -public class RepoMVariableProvider : IVariableProvider +public class RepoMVariableProvider : RepoM.Core.Plugin.VariableProviders.IVariableProvider { private static readonly char[] _separatorChars = { '.', '[', }; private const string PREFIX = "var."; diff --git a/src/RepoM.Api/IO/VariableProviders/RepositoryVariableProvider.cs b/src/RepoM.Api/IO/VariableProviders/RepositoryVariableProvider.cs index 18b2dd4a..8c01b6ca 100644 --- a/src/RepoM.Api/IO/VariableProviders/RepositoryVariableProvider.cs +++ b/src/RepoM.Api/IO/VariableProviders/RepositoryVariableProvider.cs @@ -2,10 +2,9 @@ namespace RepoM.Api.IO.VariableProviders; using System; using System.Linq; -using ExpressionStringEvaluator.VariableProviders; using RepoM.Core.Plugin.Repository; -public class RepositoryVariableProvider : IVariableProvider +public class RepositoryVariableProvider : RepoM.Core.Plugin.VariableProviders.IVariableProvider { public bool CanProvide(string key) { diff --git a/src/RepoM.Api/IO/WindowsPathSkipper.cs b/src/RepoM.Api/IO/WindowsPathSkipper.cs index 3eeff8ce..23e6fc7d 100644 --- a/src/RepoM.Api/IO/WindowsPathSkipper.cs +++ b/src/RepoM.Api/IO/WindowsPathSkipper.cs @@ -2,7 +2,6 @@ namespace RepoM.Api.IO; using System; using System.Collections.Generic; -using System.Linq; using RepoM.Core.Plugin.RepositoryFinder; public class WindowsPathSkipper : IPathSkipper diff --git a/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1.cs b/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1.cs index b332a62b..bf8df1ed 100644 --- a/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1.cs @@ -2,6 +2,9 @@ namespace RepoM.Api.Ordering.Az; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; +/// +/// Compares two repositories by a given property alphabetically in ascending order. +/// public class AlphabetComparerConfigurationV1 : IRepositoriesComparerConfiguration { public const string TYPE_VALUE = "az-comparer@1"; @@ -12,7 +15,13 @@ public string Type set => _ = value; } + /// + /// Repository property. Currently, only `Name`, and `Location` are supported. Otherwise, comparison will always result in `0`. + /// public string? Property { get; set; } - + + /// + /// The weight of this comparer. The higher the weight, the higher the impact. + /// public int Weight { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1Registration.cs deleted file mode 100644 index 244bfc8a..00000000 --- a/src/RepoM.Api/Ordering/Az/AlphabetComparerConfigurationV1Registration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RepoM.Api.Ordering.Az; - -using System; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -public class AlphabetComparerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(AlphabetComparerConfigurationV1); - - public string Tag => AlphabetComparerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1.cs b/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1.cs index 6664467e..d3daec26 100644 --- a/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1.cs @@ -3,9 +3,12 @@ namespace RepoM.Api.Ordering.Composition; using System.Collections.Generic; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; -public class CompositionComparerConfigurationV1 : IRepositoriesComparerConfiguration +/// +/// Compares two repositories by a composition of comparers. +/// +public sealed class CompositionComparerConfigurationV1 : IRepositoriesComparerConfiguration { - public const string TYPE_VALUE = "composition@1"; + public const string TYPE_VALUE = "composition-comparer@1"; public string Type { @@ -13,5 +16,8 @@ public string Type set => _ = value; } + /// + /// List of comparers. The first comparer not resulting in `0` will be used as final result. + /// public List Comparers { get; set; } = new(); } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1Registration.cs deleted file mode 100644 index 798abc1f..00000000 --- a/src/RepoM.Api/Ordering/Composition/CompositionComparerConfigurationV1Registration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RepoM.Api.Ordering.Composition; - -using System; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -public class CompositionComparerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(CompositionComparerConfigurationV1); - - public string Tag => CompositionComparerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1.cs b/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1.cs index c909b067..b9e187ba 100644 --- a/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1.cs @@ -2,7 +2,10 @@ namespace RepoM.Api.Ordering.IsPinned; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; -public class IsPinnedScorerConfigurationV1 : IRepositoryScorerConfiguration +/// +/// Repository scorer based on the pinned state of a repository. +/// +public sealed class IsPinnedScorerConfigurationV1 : IRepositoryScorerConfiguration { public const string TYPE_VALUE = "is-pinned-scorer@1"; @@ -12,5 +15,8 @@ public string Type set => _ = value; } + /// + /// The weight of this scorer. The higher the weight, the higher the impact. + /// public int Weight { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1Registration.cs deleted file mode 100644 index d03cd543..00000000 --- a/src/RepoM.Api/Ordering/IsPinned/IsPinnedScorerConfigurationV1Registration.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace RepoM.Api.Ordering.IsPinned; - -using System; -using JetBrains.Annotations; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -[UsedImplicitly] -public class IsPinnedScorerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(IsPinnedScorerConfigurationV1); - - public string Tag => IsPinnedScorerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1.cs b/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1.cs index 2229cc20..cbd1b3d3 100644 --- a/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1.cs @@ -2,7 +2,10 @@ namespace RepoM.Api.Ordering.Label; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; -public class TagScorerConfigurationV1 : IRepositoryScorerConfiguration +/// +/// Repository scorer based on the tags of a repository. +/// +public sealed class TagScorerConfigurationV1 : IRepositoryScorerConfiguration { public const string TYPE_VALUE = "tag-scorer@1"; @@ -12,7 +15,13 @@ public string Type set => _ = value; } + /// + /// The weight of this scorer. The higher the weight, the higher the impact. + /// public int Weight { get; set; } + /// + /// The tag to match on. If the repository has this tag, the score will return the weight, otherwise, `0`. + /// public string? Tag { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1Registration.cs deleted file mode 100644 index 342d5c6a..00000000 --- a/src/RepoM.Api/Ordering/Label/TagScorerConfigurationV1Registration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RepoM.Api.Ordering.Label; - -using System; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -public class TagScorerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(TagScorerConfigurationV1); - - public string Tag => TagScorerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1.cs b/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1.cs index 1e048589..bfb97440 100644 --- a/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1.cs @@ -2,6 +2,9 @@ namespace RepoM.Api.Ordering.Score; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; +/// +/// Compares two repositories by a repository score. The calculation of the repository score is defined in the score provider. +/// public class ScoreComparerConfigurationV1 : IRepositoriesComparerConfiguration { public const string TYPE_VALUE = "score-comparer@1"; @@ -12,5 +15,8 @@ public string Type set => _ = value; } + /// + /// The score provider to calculate a score for a repository. + /// public IRepositoryScorerConfiguration? ScoreProvider { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1Registration.cs deleted file mode 100644 index 8b192db1..00000000 --- a/src/RepoM.Api/Ordering/Score/ScoreComparerConfigurationV1Registration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RepoM.Api.Ordering.Score; - -using System; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -public class ScoreComparerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(ScoreComparerConfigurationV1); - - public string Tag => ScoreComparerConfigurationV1.TYPE_VALUE; -} diff --git a/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1.cs b/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1.cs index 43c254a2..0609521b 100644 --- a/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1.cs +++ b/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1.cs @@ -3,7 +3,10 @@ namespace RepoM.Api.Ordering.Sum; using System.Collections.Generic; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; -public class SumComparerConfigurationV1 : IRepositoriesComparerConfiguration +/// +/// Compares two repositories by the sum of the results of the comparers. +/// +public sealed class SumComparerConfigurationV1 : IRepositoriesComparerConfiguration { public const string TYPE_VALUE = "sum-comparer@1"; @@ -13,5 +16,8 @@ public string Type set => _ = value; } + /// + /// A list of comparers. The sum of the results of the comparers will be used as final result. + /// public List Comparers { get; set; } = new(); } \ No newline at end of file diff --git a/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1Registration.cs b/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1Registration.cs deleted file mode 100644 index 6b527bbc..00000000 --- a/src/RepoM.Api/Ordering/Sum/SumComparerConfigurationV1Registration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RepoM.Api.Ordering.Sum; - -using System; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -public class SumComparerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(SumComparerConfigurationV1); - - public string Tag => SumComparerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.App/Bootstrapper.cs b/src/RepoM.App/Bootstrapper.cs index a0606dec..c69e1cfe 100644 --- a/src/RepoM.App/Bootstrapper.cs +++ b/src/RepoM.App/Bootstrapper.cs @@ -33,7 +33,6 @@ namespace RepoM.App; using RepoM.Core.Plugin.RepositoryActions; using RepoM.Core.Plugin.RepositoryFiltering; using RepoM.Core.Plugin.RepositoryFinder; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Core.Plugin.RepositoryOrdering; using System.IO.Abstractions; using System.Reflection; @@ -94,8 +93,7 @@ public static void RegisterServices(IFileSystem fileSystem) Container.Collection.Append(() => new FreeTextMatcher(ignoreCase: true, ignoreCaseTag: true), Lifestyle.Singleton); Container.Register(Lifestyle.Singleton); - - + Container.Collection.Append(Lifestyle.Singleton); Container.RegisterInstance(fileSystem); @@ -108,15 +106,11 @@ public static void RegisterServices(IFileSystem fileSystem) typeof(IRepositoryExpressionEvaluator).Assembly, }; - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); - Container.Collection.Append(Lifestyle.Singleton); + RegisterExpressionStringVariableProviders(); + + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); Container.Collection.Append(Lifestyle.Singleton); Container.Collection.Register(typeof(IMethod), repoExpressionEvaluators, Lifestyle.Singleton); @@ -176,11 +170,9 @@ static IEnumerable GetExportedTypesFrom(Assembly assembly) Container.RegisterSingleton(); Container.RegisterSingleton(); - Container.Collection.Register( - typeof(IConfigurationRegistration), - new[] { typeof(IConfigurationRegistration).Assembly, typeof(IsPinnedScorerConfigurationV1Registration).Assembly, }, - Lifestyle.Singleton); - + CoreBootstrapper.RegisterRepositoryComparerConfigurationsTypes(Container); + CoreBootstrapper.RegisterRepositoryScorerConfigurationsTypes(Container); + Container.Register, IsPinnedScorerFactory>(Lifestyle.Singleton); Container.Register, TagScorerFactory>(Lifestyle.Singleton); Container.Register, AzRepositoryComparerFactory>(Lifestyle.Singleton); @@ -199,6 +191,16 @@ static IEnumerable GetExportedTypesFrom(Assembly assembly) Container.RegisterSingleton(); } + private static void RegisterExpressionStringVariableProviders() + { + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + Container.Collection.Append(Lifestyle.Singleton); + } + public static async Task RegisterPlugins( IPluginFinder pluginFinder, IFileSystem fileSystem, diff --git a/src/RepoM.App/RepositoryFiltering/DefaultINamedQueryParser.cs b/src/RepoM.App/RepositoryFiltering/DefaultINamedQueryParser.cs index 14edcea1..2321a568 100644 --- a/src/RepoM.App/RepositoryFiltering/DefaultINamedQueryParser.cs +++ b/src/RepoM.App/RepositoryFiltering/DefaultINamedQueryParser.cs @@ -1,7 +1,5 @@ namespace RepoM.App.RepositoryFiltering; -using System.Collections.Generic; -using System.Linq; using JetBrains.Annotations; using RepoM.Core.Plugin.RepositoryFiltering; using RepoM.Core.Plugin.RepositoryFiltering.Clause; diff --git a/src/RepoM.App/RepositoryFiltering/QueryMatchers/FreeTextMatcher.cs b/src/RepoM.App/RepositoryFiltering/QueryMatchers/FreeTextMatcher.cs index e09731bb..497f8481 100644 --- a/src/RepoM.App/RepositoryFiltering/QueryMatchers/FreeTextMatcher.cs +++ b/src/RepoM.App/RepositoryFiltering/QueryMatchers/FreeTextMatcher.cs @@ -1,7 +1,6 @@ namespace RepoM.App.RepositoryFiltering.QueryMatchers; using System; -using System.Linq; using JetBrains.Annotations; using RepoM.Core.Plugin.Repository; using RepoM.Core.Plugin.RepositoryFiltering; diff --git a/src/RepoM.Core.Plugin/Common/IAppDataPathProvider.cs b/src/RepoM.Core.Plugin/Common/IAppDataPathProvider.cs index d3d676e6..137b61d7 100644 --- a/src/RepoM.Core.Plugin/Common/IAppDataPathProvider.cs +++ b/src/RepoM.Core.Plugin/Common/IAppDataPathProvider.cs @@ -1,14 +1,8 @@ namespace RepoM.Core.Plugin.Common; -using System; - -/// -/// Provides RepoM common directories. -/// public interface IAppDataPathProvider { string AppDataPath { get; } - [Obsolete("Not used.")] // todo - string GetAppResourcesPath(); + string AppResourcesPath { get; } } \ No newline at end of file diff --git a/src/RepoM.Core.Plugin/ContainerExtensions.cs b/src/RepoM.Core.Plugin/ContainerExtensions.cs new file mode 100644 index 00000000..80e0dbe2 --- /dev/null +++ b/src/RepoM.Core.Plugin/ContainerExtensions.cs @@ -0,0 +1,41 @@ +namespace RepoM.Core.Plugin; + +using System; +using System.Reflection; +using RepoM.Core.Plugin.RepositoryOrdering.Configuration; +using SimpleInjector; + +public static class ContainerExtensions +{ + public static void RegisterComparerConfigurationForType(this Container container) where T : IRepositoriesComparerConfiguration + { + RegisterComparerConfigurationForType(container, typeof(T)); + } + + public static void RegisterComparerConfigurationForType(this Container container, Type type) + { + container.Collection.AppendInstance>(new FixedTypeRegistration(type, TypeValueFieldReader.GetTypeValue(type))); + } + + public static void RegisterScorerConfigurationForType(this Container container) where T : IRepositoryScorerConfiguration + { + RegisterScorerConfigurationForType(container, typeof(T)); + } + + public static void RegisterScorerConfigurationForType(this Container container, Type type) + { + container.Collection.AppendInstance>(new FixedTypeRegistration(type, TypeValueFieldReader.GetTypeValue(type))); + } +} + +/// +/// This class 'assumes' that the type has a public field named 'TYPE_VALUE' that contains the value to be used as the type value. +/// +file static class TypeValueFieldReader +{ + public static string GetTypeValue(Type type) + { + FieldInfo fieldInfo = type.GetField("TYPE_VALUE") ?? throw new Exception("Could not locate field 'TYPE_VALUE'"); + return fieldInfo.GetValue(null)?.ToString() ?? throw new Exception("Could not get value of property 'TYPE_VALUE'"); + } +} \ No newline at end of file diff --git a/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/FixedTypeRegistration.cs b/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/FixedTypeRegistration.cs new file mode 100644 index 00000000..7f5eeb67 --- /dev/null +++ b/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/FixedTypeRegistration.cs @@ -0,0 +1,24 @@ +namespace RepoM.Core.Plugin.RepositoryOrdering.Configuration; + +using System; +using System.Diagnostics; + +[DebuggerDisplay($"{{{nameof(Tag)}}}")] +public sealed class FixedTypeRegistration : IKeyTypeRegistration +{ + public FixedTypeRegistration(Type configurationType, string tag) + { + ConfigurationType = configurationType; + + if (string.IsNullOrEmpty(tag)) + { + throw new ArgumentNullException(nameof(tag)); + } + + Tag = tag; + } + + public Type ConfigurationType { get; } + + public string Tag { get; } +} \ No newline at end of file diff --git a/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IConfigurationRegistration.cs b/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IKeyTypeRegistration{T}.cs similarity index 59% rename from src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IConfigurationRegistration.cs rename to src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IKeyTypeRegistration{T}.cs index 0db34ca1..6561a008 100644 --- a/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IConfigurationRegistration.cs +++ b/src/RepoM.Core.Plugin/RepositoryOrdering/Configuration/IKeyTypeRegistration{T}.cs @@ -1,17 +1,12 @@ namespace RepoM.Core.Plugin.RepositoryOrdering.Configuration; using System; +using System.Diagnostics.CodeAnalysis; /// /// Configuration registration per name /// -public interface IConfigurationRegistration : IKeyTypeRegistration -{ -} - -/// -/// Configuration registration per name -/// +[SuppressMessage("Major Code Smell", "S2326:Unused type parameters should be removed", Justification = "Used for registrations in DI container.")] public interface IKeyTypeRegistration { public Type ConfigurationType { get; } diff --git a/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs b/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs index 725d54e7..ff7fb48d 100644 --- a/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs +++ b/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs @@ -2,7 +2,6 @@ namespace RepoM.Plugin.AzureDevOps; using System.Threading.Tasks; using JetBrains.Annotations; -using RepoM.Api.Common; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Core.Plugin; @@ -25,50 +24,19 @@ public async Task RegisterServicesAsync(Container container, IPackageConfigurati RegisterServices(container); } - private async Task ExtractAndRegisterConfiguration(Container container, IPackageConfiguration packageConfiguration) + private static async Task ExtractAndRegisterConfiguration(Container container, IPackageConfiguration packageConfiguration) { var version = await packageConfiguration.GetConfigurationVersionAsync().ConfigureAwait(false); - AzureDevopsConfigV1 config; + AzureDevopsConfigV1? config = null; if (version == CurrentConfigVersion.VERSION) { - AzureDevopsConfigV1? result = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); - config = result ?? new AzureDevopsConfigV1(); - } - else - { - config = await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); + config = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); } - // this is temporarly to support the old way of storing the configuration - if (string.IsNullOrWhiteSpace(config.BaseUrl) && string.IsNullOrWhiteSpace(config.PersonalAccessToken)) - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); + config ??= await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); - var c = new AzureDevopsConfigV1 - { - PersonalAccessToken = appSettingsService.AzureDevOpsPersonalAccessToken, - BaseUrl = appSettingsService.AzureDevOpsBaseUrl, - }; - _ = packageConfiguration.PersistConfigurationAsync(c, CurrentConfigVersion.VERSION); // do not await - - return new AzureDevopsConfiguration(c.BaseUrl, c.PersonalAccessToken); - }); - } - else - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - - appSettingsService.AzureDevOpsBaseUrl = "This value has been copied to the new configuration file for this module."; - appSettingsService.AzureDevOpsPersonalAccessToken = "This value has been copied to the new configuration file for this module."; - - return new AzureDevopsConfiguration(config.BaseUrl, config.PersonalAccessToken); - }); - } + container.RegisterInstance(new AzureDevopsConfiguration(config.BaseUrl, config.PersonalAccessToken)); } private static void RegisterServices(Container container) diff --git a/src/RepoM.Plugin.Heidi/HeidiPackage.cs b/src/RepoM.Plugin.Heidi/HeidiPackage.cs index ffc2757c..3cd2e438 100644 --- a/src/RepoM.Plugin.Heidi/HeidiPackage.cs +++ b/src/RepoM.Plugin.Heidi/HeidiPackage.cs @@ -23,43 +23,19 @@ public async Task RegisterServicesAsync(Container container, IPackageConfigurati RegisterServices(container); } - private async Task ExtractAndRegisterConfiguration(Container container, IPackageConfiguration packageConfiguration) + private static async Task ExtractAndRegisterConfiguration(Container container, IPackageConfiguration packageConfiguration) { var version = await packageConfiguration.GetConfigurationVersionAsync().ConfigureAwait(false); - HeidiConfigV1 config; + HeidiConfigV1? config = null; if (version == CurrentConfigVersion.VERSION) { - HeidiConfigV1? result = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); - config = result ?? new HeidiConfigV1(); - } - else - { - config = await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); + config = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); } - // this is temporarly to support the old way of storing the configuration - if (string.IsNullOrWhiteSpace(config.ConfigPath) && string.IsNullOrWhiteSpace(config.ConfigFilename) && string.IsNullOrWhiteSpace(config.ExecutableFilename)) - { - container.RegisterSingleton(() => - { - var oldSettingsProvider = new EnvironmentVariablesHeidiSettings(); - - var c = new HeidiConfigV1 - { - ConfigPath = oldSettingsProvider.ConfigPath, - ConfigFilename = oldSettingsProvider.ConfigFilename, - ExecutableFilename = oldSettingsProvider.DefaultExe, - }; - _ = packageConfiguration.PersistConfigurationAsync(c, CurrentConfigVersion.VERSION); // do not await + config ??= await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); - return new HeidiModuleConfiguration(c.ConfigPath, c.ConfigFilename, c.ExecutableFilename); - }); - } - else - { - container.RegisterInstance(new HeidiModuleConfiguration(config.ConfigPath, config.ConfigFilename, config.ExecutableFilename)); - } + container.RegisterInstance(new HeidiModuleConfiguration(config.ConfigPath, config.ConfigFilename, config.ExecutableFilename)); } private static void RegisterServices(Container container) diff --git a/src/RepoM.Plugin.Heidi/Internal/EnvironmentVariablesHeidiSettings.cs b/src/RepoM.Plugin.Heidi/Internal/EnvironmentVariablesHeidiSettings.cs deleted file mode 100644 index 2116d276..00000000 --- a/src/RepoM.Plugin.Heidi/Internal/EnvironmentVariablesHeidiSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace RepoM.Plugin.Heidi.Internal; - -using System; - -[Obsolete("Will be removed in next major version.")] -internal class EnvironmentVariablesHeidiSettings : IHeidiSettings -{ - private const string ENV_VAR_PREFIX = "REPOM_HEIDI_"; - - public string ConfigPath { get; } = DetermineValueUsingEnvironment("CONFIG_PATH", "C:\\StandAloneProgramFiles\\HeidiSQL_12.3_64_Portable\\"); - - public string ConfigFilename { get; } = DetermineValueUsingEnvironment("CONFIG_FILENAME", "portable_settings.txt"); - - public string DefaultExe { get; } = DetermineValueUsingEnvironment("EXE", "heidi.exe"); - - private static string DetermineValueUsingEnvironment(string envVarName, string defaultValue) - { - try - { - var result = Environment.GetEnvironmentVariable(ENV_VAR_PREFIX + envVarName) ?? Environment.GetEnvironmentVariable(ENV_VAR_PREFIX + envVarName, EnvironmentVariableTarget.User); - return string.IsNullOrWhiteSpace(result) ? defaultValue : result; - } - catch (Exception) - { - return defaultValue; - } - } -} \ No newline at end of file diff --git a/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs b/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs index 794bdbcc..321ef595 100644 --- a/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs +++ b/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs @@ -3,7 +3,6 @@ namespace RepoM.Plugin.SonarCloud; using System.Threading.Tasks; using ExpressionStringEvaluator.Methods; using JetBrains.Annotations; -using RepoM.Api.Common; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Core.Plugin; @@ -25,43 +24,15 @@ private static async Task ExtractAndRegisterConfiguration(Container container, I { var version = await packageConfiguration.GetConfigurationVersionAsync().ConfigureAwait(false); - SonarCloudConfigV1 config; + SonarCloudConfigV1? config = null; if (version == CurrentConfigVersion.VERSION) { - SonarCloudConfigV1? result = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); - config = result ?? new SonarCloudConfigV1(); + config = await packageConfiguration.LoadConfigurationAsync().ConfigureAwait(false); } - else - { - config = await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); - } - - // this is temporarly to support the old way of storing the configuration - if (string.IsNullOrWhiteSpace(config.PersonalAccessToken)) - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - var c = new SonarCloudConfigV1 - { - PersonalAccessToken = appSettingsService.SonarCloudPersonalAccessToken, - BaseUrl = config.BaseUrl, - }; - _ = packageConfiguration.PersistConfigurationAsync(c, CurrentConfigVersion.VERSION); // fire and forget ;-) + config ??= await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); - return new SonarCloudConfiguration(c.BaseUrl, c.PersonalAccessToken); - }); - } - else - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - appSettingsService.SonarCloudPersonalAccessToken = "This value has been copied to the new configuration file for this module."; - return new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken); - }); - } + container.RegisterInstance(new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken)); } private static void RegisterServices(Container container) diff --git a/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1.cs b/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1.cs index 41b5350b..f57d91e1 100644 --- a/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1.cs +++ b/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1.cs @@ -2,6 +2,9 @@ namespace RepoM.Plugin.Statistics.Ordering; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; +/// +/// Compares two repositories by the timestamp of the last action RepoM performed on the repository. +/// public sealed class LastOpenedConfigurationV1 : IRepositoriesComparerConfiguration { public const string TYPE_VALUE = "last-opened-comparer@1"; @@ -12,5 +15,8 @@ public string Type set => _ = value; } + /// + /// The weight of this comparer. The higher the weight, the higher the impact. + /// public int Weight { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1Registration.cs b/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1Registration.cs deleted file mode 100644 index 618c80a4..00000000 --- a/src/RepoM.Plugin.Statistics/Ordering/LastOpenedConfigurationV1Registration.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace RepoM.Plugin.Statistics.Ordering; - -using System; -using JetBrains.Annotations; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -[UsedImplicitly] -public class LastOpenedConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(LastOpenedConfigurationV1); - - public string Tag => LastOpenedConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1.cs b/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1.cs index 7ee5f1e8..b9b6e3ba 100644 --- a/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1.cs +++ b/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1.cs @@ -4,6 +4,9 @@ namespace RepoM.Plugin.Statistics.Ordering; using System.Collections.Generic; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; +/// +/// Repository scorer based on it's usage by RepoM. The more it's used, the higher the score. +/// public sealed class UsageScorerConfigurationV1 : IRepositoryScorerConfiguration { public const string TYPE_VALUE = "usage-scorer@1"; @@ -14,16 +17,34 @@ public string Type set => _ = value; } - public List Windows { get; set; } = new List(); + /// + /// Specific 'windows' to calculate the score for. + /// + public List Windows { get; set; } = new List(); + /// + /// The maximum score a repository can get. + /// public int? MaxScore { get; set; } = null; } -public sealed class Windows +/// +/// Window specifies the range for a given weight. +/// +public sealed class Window { + /// + /// Timespan for the given window. + /// public TimeSpan Until { get; set; } + /// + /// The weight used for this window. + /// public int Weight { get; set; } + /// + /// Maximum number of actions performed to be taken into account for this window. The rest will be used in the next window. + /// public int MaxItems { get; set; } } \ No newline at end of file diff --git a/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1Registration.cs b/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1Registration.cs deleted file mode 100644 index 352140fc..00000000 --- a/src/RepoM.Plugin.Statistics/Ordering/UsageScorerConfigurationV1Registration.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace RepoM.Plugin.Statistics.Ordering; - -using System; -using JetBrains.Annotations; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; - -[UsedImplicitly] -public class UsageScorerConfigurationV1Registration : IConfigurationRegistration -{ - public Type ConfigurationType { get; } = typeof(UsageScorerConfigurationV1); - - public string Tag => UsageScorerConfigurationV1.TYPE_VALUE; -} \ No newline at end of file diff --git a/src/RepoM.Plugin.Statistics/StatisticsPackage.cs b/src/RepoM.Plugin.Statistics/StatisticsPackage.cs index f94ba742..55fde394 100644 --- a/src/RepoM.Plugin.Statistics/StatisticsPackage.cs +++ b/src/RepoM.Plugin.Statistics/StatisticsPackage.cs @@ -6,7 +6,6 @@ namespace RepoM.Plugin.Statistics; using RepoM.Core.Plugin; using RepoM.Core.Plugin.RepositoryActions; using RepoM.Core.Plugin.RepositoryOrdering; -using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Core.Plugin.VariableProviders; using RepoM.Plugin.Statistics.Ordering; using RepoM.Plugin.Statistics.PersistentConfiguration; @@ -66,10 +65,10 @@ private static async Task ExtractAndRegisterConfiguration(Container container, I private static void RegisterPluginHooks(Container container) { // ordering - container.Collection.Append(Lifestyle.Singleton); + container.RegisterScorerConfigurationForType(); container.Register, UsageScorerFactory>(Lifestyle.Singleton); - container.Collection.Append(Lifestyle.Singleton); + container.RegisterComparerConfigurationForType(); container.Register, LastOpenedComparerFactory>(Lifestyle.Singleton); // action executor diff --git a/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs index dc2cb9c9..e346cc73 100644 --- a/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs @@ -1,7 +1,6 @@ namespace RepoM.Api.Tests; using System; -using System.Collections.Generic; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; @@ -36,8 +35,9 @@ public static JsonDynamicRepositoryActionDeserializer Create() Array.Empty>())); } - public static JsonDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) + public static YamlDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) { - return new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); + var jsonDynamicRepositoryActionDeserializer = new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); + return new YamlDynamicRepositoryActionDeserializer(jsonDynamicRepositoryActionDeserializer); } } \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/AssociateFileV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/AssociateFileV1Test.cs index b726d0ce..9926b36a 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/AssociateFileV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/AssociateFileV1Test.cs @@ -4,7 +4,6 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; using EasyTestFile; using EasyTestFileXunit; using FluentAssertions; -using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; @@ -16,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class AssociateFileV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -26,7 +25,7 @@ public AssociateFileV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowseRepositoryV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowseRepositoryV1Test.cs index 1189a1e2..06d41d68 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowseRepositoryV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowseRepositoryV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class BrowseRepositoryV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public BrowseRepositoryV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowserV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowserV1Test.cs index 5f69ff23..4134af7c 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowserV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/BrowserV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class BrowserV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public BrowserV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/CommandV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/CommandV1Test.cs index 766b7d1f..44cdc699 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/CommandV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/CommandV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class CommandV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public CommandV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ExecutableV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ExecutableV1Test.cs index c8d386e2..d9baaf33 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ExecutableV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ExecutableV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class ExecutableV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public ExecutableV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/FolderV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/FolderV1Test.cs index b4616d7e..2d34889a 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/FolderV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/FolderV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class FolderV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public FolderV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ForEachV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ForEachV1Test.cs index 30cef194..51af797e 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ForEachV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/ForEachV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class ForEachV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public ForEachV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitCheckoutV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitCheckoutV1Test.cs index dbc98e22..212f8a30 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitCheckoutV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitCheckoutV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class GitCheckoutV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public GitCheckoutV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitFetchV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitFetchV1Test.cs index 9bae94f0..6afc7a01 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitFetchV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitFetchV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class GitFetchV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public GitFetchV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPullV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPullV1Test.cs index ded3ed6b..4fbdd15e 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPullV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPullV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class GitPullV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public GitPullV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPushV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPushV1Test.cs index 7553e152..aa0bb9bf 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPushV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/GitPushV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class GitPushV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public GitPushV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/IgnoreRepositoryV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/IgnoreRepositoryV1Test.cs index 5123568c..cdb7bae9 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/IgnoreRepositoryV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/IgnoreRepositoryV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class IgnoreRepositoryV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public IgnoreRepositoryV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/JustTextV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/JustTextV1Test.cs index 754b2d11..0311dc37 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/JustTextV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/JustTextV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class JustTextV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public JustTextV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/PinRepositoryV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/PinRepositoryV1Test.cs index acea7cf9..191a0731 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/PinRepositoryV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/PinRepositoryV1Test.cs @@ -4,7 +4,6 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; using EasyTestFile; using EasyTestFileXunit; using FluentAssertions; -using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; @@ -16,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class PinRepositoryV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -26,7 +25,7 @@ public PinRepositoryV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/SeparatorV1Test.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/SeparatorV1Test.cs index 214ad7e7..48f37932 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/SeparatorV1Test.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/SeparatorV1Test.cs @@ -15,7 +15,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.Action; [UsesVerify] public class SeparatorV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sut; + private readonly YamlDynamicRepositoryActionDeserializer _sut; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -25,7 +25,7 @@ public SeparatorV1Test() _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.json deleted file mode 100644 index 1881aecf..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "associate-file@1", - "name": "Goto google.com", - "active": false, - "extension": "*.sln" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.yaml new file mode 100644 index 00000000..ee6adb4c --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/AssociateFileV1Test.Deserialize_AssociateFile1.testfile.yaml @@ -0,0 +1,6 @@ +repository-actions: + actions: + - type: associate-file@1 + name: Goto google.com + active: false + extension: '*.sln' diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.json deleted file mode 100644 index 88bac422..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "browse-repository@1", - "name": "fo true", - "first-only": true - }, - { - "type": "browse-repository@1", - "name": "fo false", - "first-only": false - }, - { - "type": "browse-repository@1", - "name": "fo empty" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.yaml new file mode 100644 index 00000000..70add465 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowseRepositoryV1Test.Deserialize_ActionBrowseRepositoryRepositoryV1.testfile.yaml @@ -0,0 +1,10 @@ +repository-actions: + actions: + - type: browse-repository@1 + name: fo true + first-only: true + - type: browse-repository@1 + name: fo false + first-only: false + - type: browse-repository@1 + name: fo empty diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.json deleted file mode 100644 index 1eb4dc9a..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "browser@1", - "name": "Goto google.com", - "active": false, - "url": "https://google.com" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.yaml new file mode 100644 index 00000000..ce8baa2f --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/BrowserV1Test.Deserialize_ActionBrowserV1.testfile.yaml @@ -0,0 +1,6 @@ +repository-actions: + actions: + - type: browser@1 + name: Goto google.com + active: false + url: https://google.com diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.json deleted file mode 100644 index 9dd7c698..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "command@1", - "name": "{OpenIn} Windows Terminal", - "command": "wt", - "arguments": "-d \"{Repository.SafePath}\"" - }, - { - "type": "command@1", - "name": "{OpenIn} Windows Command Shell", - "command": "cmd", - // single quotes - "arguments": "/K \"cd /d {Repository.SafePath}\"", - "active": "false" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.yaml new file mode 100644 index 00000000..96996882 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/CommandV1Test.Deserialize_CommandV1.testfile.yaml @@ -0,0 +1,11 @@ +repository-actions: + actions: + - type: command@1 + name: '{OpenIn} Windows Terminal' + command: wt + arguments: -d "{Repository.SafePath}" + - type: command@1 + name: '{OpenIn} Windows Command Shell' + command: cmd + arguments: /K "cd /d {Repository.SafePath}" + active: false diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.json deleted file mode 100644 index 3044c2fa..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "executable@1", - "name": "{OpenIn} Sourcetree", - "executables": [ - "%LocalAppData%/SourceTree/SourceTree.exe", - "%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe" - ], - "arguments": "-f \"{Repository.Location}{backslash}{Repository.Name}\"", - "active": "true" - }, - { - "type": "executable@1", - "name": "{OpenIn} Sourcetree 1", - "executable": "%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe" - }, - - { - "type": "executable@1", - "name": "{OpenIn} Sourcetree 1.1", - "executables": [ - ], - "executable": "%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe" - }, - { - "type": "executable@1", - "name": "{OpenIn} Sourcetree 2", - "executables": [ - "%LocalAppData%/SourceTree/SourceTree.exe", - "%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe" - ], - // this property should be ignored because executables is filled - "executable": "%PROGRAMFILES(X86)%/ignored.exe " - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.yaml new file mode 100644 index 00000000..7a7efb81 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ExecutableV1Test.Deserialize_ExecutableV1.testfile.yaml @@ -0,0 +1,23 @@ +repository-actions: + actions: + - type: executable@1 + name: '{OpenIn} Sourcetree' + executables: + - '%LocalAppData%/SourceTree/SourceTree.exe' + - '%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe' + arguments: -f "{Repository.Location}{backslash}{Repository.Name}" + active: true + - type: executable@1 + name: '{OpenIn} Sourcetree 1' + executable: '%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe' + - type: executable@1 + name: '{OpenIn} Sourcetree 1.1' + executables: [] + executable: '%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe' + - type: executable@1 + name: '{OpenIn} Sourcetree 2' + executables: + - '%LocalAppData%/SourceTree/SourceTree.exe' + - '%PROGRAMFILES(X86)%/Atlassian/SourceTree/SourceTree.exe' + # this property should be ignored because executables is filled + executable: '%PROGRAMFILES(X86)%/ignored.exe ' diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.json deleted file mode 100644 index 70f1ac4b..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "folder@1", - "name": "Folder 1", - "items": - [ - { - "type": "folder@1", - "name": "Folder 2", - "active": true, - "is-deferred": "False", - "items": [ - { - "type": "folder@1", - "name": "Folder 3", - "active": "false", - "is-deferred": true - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.yaml new file mode 100644 index 00000000..3604b0c8 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/FolderV1Test.Deserialize_FolderV1.testfile.yaml @@ -0,0 +1,14 @@ +repository-actions: + actions: + - type: folder@1 + name: Folder 1 + items: + - type: folder@1 + name: Folder 2 + active: true + is-deferred: False + items: + - type: folder@1 + name: Folder 3 + active: false + is-deferred: true diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.json deleted file mode 100644 index 047b416f..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "foreach@1", - "enumerable": "{var.DTAP}", - "variable": "environment", - "actions": [ - { - "type": "browser@1", - "name": "{var.environment}", - "url": "{var.url}" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.yaml new file mode 100644 index 00000000..7d9c1c76 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/ForEachV1Test.Deserialize_ForEachV1.testfile.yaml @@ -0,0 +1,9 @@ +repository-actions: + actions: + - type: foreach@1 + enumerable: '{var.DTAP}' + variable: environment + actions: + - type: browser@1 + name: '{var.environment}' + url: '{var.url}' diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.json deleted file mode 100644 index 0bf4247d..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "repository-actions": - { - "actions": - [ - { - "type": "git-checkout@1" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.yaml new file mode 100644 index 00000000..8688454f --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitCheckoutV1Test.Deserialize_GitCheckoutV1.testfile.yaml @@ -0,0 +1,3 @@ +repository-actions: + actions: + - type: git-checkout@1 diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.json deleted file mode 100644 index 8e428b0d..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "git-fetch@1" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.yaml new file mode 100644 index 00000000..e3cd7bca --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitFetchV1Test.Deserialize_GitFetchV1.testfile.yaml @@ -0,0 +1,3 @@ +repository-actions: + actions: + - type: git-fetch@1 diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.json deleted file mode 100644 index e4342597..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "git-pull@1" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.yaml new file mode 100644 index 00000000..8166d4d2 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPullV1Test.Deserialize_GitPullV1.testfile.yaml @@ -0,0 +1,3 @@ +repository-actions: + actions: + - type: git-pull@1 diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.json deleted file mode 100644 index 0522a09b..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "git-push@1" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.yaml new file mode 100644 index 00000000..e5460d6b --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/GitPushV1Test.Deserialize_GitPushV1.testfile.yaml @@ -0,0 +1,3 @@ +repository-actions: + actions: + - type: git-push@1 diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.json deleted file mode 100644 index 570a5e80..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "ignore-repository@1" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.yaml new file mode 100644 index 00000000..e6b54863 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/IgnoreRepositoryV1Test.Deserialize_IgnoreRepositoryV1.testfile.yaml @@ -0,0 +1,3 @@ +repository-actions: + actions: + - type: ignore-repository@1 diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.json deleted file mode 100644 index 8788cf19..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "just-text@1", - "name": "This is a message" - }, - { - "type": "just-text@1", - "name": "This is a message 2", - "enabled": true - }, - { - "type": "just-text@1", - "name": "This is a message 3", - "enabled": false - }, - { - "type": "just-text@1", - "name": "This is a message 4", - "enabled": "false" - }, - { - "type": "just-text@1", - "name": "This is a message 5", - "enabled": "dummy" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.yaml new file mode 100644 index 00000000..b756d21d --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/JustTextV1Test.Deserialize_JustText1.testfile.yaml @@ -0,0 +1,16 @@ +repository-actions: + actions: + - type: just-text@1 + name: This is a message + - type: just-text@1 + name: This is a message 2 + enabled: true + - type: just-text@1 + name: This is a message 3 + enabled: false + - type: just-text@1 + name: This is a message 4 + enabled: "false" + - type: just-text@1 + name: This is a message 5 + enabled: dummy diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.json deleted file mode 100644 index 04dae04f..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "pin-repository@1" - }, - { - "type": "pin-repository@1", - "mode": "toggle" - }, - { - "type": "pin-repository@1", - "mode": "pin" - }, - { - "type": "pin-repository@1", - "mode": "unpin" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.yaml new file mode 100644 index 00000000..b9ec510e --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/PinRepositoryV1Test.Deserialize_PinV1.testfile.yaml @@ -0,0 +1,9 @@ +repository-actions: + actions: + - type: pin-repository@1 + - type: pin-repository@1 + mode: toggle + - type: pin-repository@1 + mode: pin + - type: pin-repository@1 + mode: unpin diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.json deleted file mode 100644 index 3bfde5a5..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "separator@1", - "name": "doesn't matter'" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.yaml new file mode 100644 index 00000000..647d7ef5 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/TestFiles/SeparatorV1Test.Deserialize_SeparatorV1.testfile.yaml @@ -0,0 +1,4 @@ +repository-actions: + actions: + - type: separator@1 + name: doesn't matter diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/Verified/SeparatorV1Test.Deserialize_SeparatorV1.verified.txt b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/Verified/SeparatorV1Test.Deserialize_SeparatorV1.verified.txt index b6461fa9..6353e831 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/Verified/SeparatorV1Test.Deserialize_SeparatorV1.verified.txt +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/Action/Verified/SeparatorV1Test.Deserialize_SeparatorV1.verified.txt @@ -5,7 +5,7 @@ { $type: RepositoryActionSeparatorV1, Type: separator@1, - Name: doesn't matter' + Name: doesn't matter } ] } diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMapperCompositionFactory.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMapperCompositionFactory.cs index 6fbad79c..761f8338 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMapperCompositionFactory.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMapperCompositionFactory.cs @@ -1,6 +1,5 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; -using System.Collections.Generic; using System.IO.Abstractions; using RepoM.Api.Common; using RepoM.Api.Git; @@ -40,9 +39,9 @@ public static ActionMapperComposition Create( public static ActionMapperComposition CreateSmall(IRepositoryExpressionEvaluator expressionEvaluator, IActionToRepositoryActionMapper actionToRepositoryActionMapper) { - var list = new IActionToRepositoryActionMapper[1] + var list = new[] { - actionToRepositoryActionMapper + actionToRepositoryActionMapper, }; return new ActionMapperComposition(list, expressionEvaluator); } diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMappers/ActionAssociateFileV1MapperTests.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMappers/ActionAssociateFileV1MapperTests.cs index 3060b795..cd0689e1 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMappers/ActionAssociateFileV1MapperTests.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/ActionMappers/ActionAssociateFileV1MapperTests.cs @@ -1,11 +1,9 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider.ActionMappers; using System; -using System.Collections.Generic; using System.Linq; using FakeItEasy; using FluentAssertions; -using LibGit2Sharp; using RepoM.Api.Common; using RepoM.Api.Git; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs index 66b8a187..7d74f379 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs @@ -1,468 +1,402 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using System; -using System.Dynamic; using System.Threading.Tasks; using EasyTestFile; using EasyTestFileXunit; using FluentAssertions; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; using VerifyTests; using VerifyXunit; using Xunit; -using Xunit.Abstractions; -using XunitEnumMemberData; [UsesEasyTestFile] [UsesVerify] public class DynamicRepositoryActionDeserializerTest { - private readonly ITestOutputHelper _outputHelper; - private readonly JsonDynamicRepositoryActionDeserializer _sutJson; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; - private readonly YamlDynamicRepositoryActionDeserializer _sutYaml; + private readonly YamlDynamicRepositoryActionDeserializer _sut; - public DynamicRepositoryActionDeserializerTest(ITestOutputHelper outputHelper) + public DynamicRepositoryActionDeserializerTest() { - _outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); - _sutJson = DynamicRepositoryActionDeserializerFactory.Create(); - _sutYaml = new YamlDynamicRepositoryActionDeserializer(_sutJson); + _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); } - private RepositoryActionConfiguration SutDeserialize(string rawContent, SerializationType type) - { - if (type == SerializationType.Json) - { - var expConverter = new ExpandoObjectConverter(); - dynamic deserializedObject = JsonConvert.DeserializeObject(rawContent, expConverter)!; - - var serializer = new YamlDotNet.Serialization.Serializer(); - string yaml = serializer.Serialize(deserializedObject); - - _outputHelper.WriteLine(string.Empty); - _outputHelper.WriteLine("----------------------------------------"); - _outputHelper.WriteLine(rawContent); - _outputHelper.WriteLine("----------------------------------------"); - _outputHelper.WriteLine(string.Empty); - _outputHelper.WriteLine("----------------------------------------"); - _outputHelper.WriteLine(yaml); - _outputHelper.WriteLine("----------------------------------------"); - _outputHelper.WriteLine(string.Empty); - } - - return type switch - { - SerializationType.Json => _sutJson.Deserialize(rawContent), - SerializationType.Yaml => _sutYaml.Deserialize(rawContent), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), - }; - } - - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnData_WhenContentIsEmptyVersion1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnData_WhenContentIsEmptyVersion1() { // arrange _testFileSettings.UseFileName("Version1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_RepositorySpecificEnvFiles_1(SerializationType type) + + [Fact] + public async Task Deserialize_RepositorySpecificEnvFiles_1() { // arrange _testFileSettings.UseFileName("RepositorySpecificEnvFilesExplanation1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_RepositoryTagsFiles_1(SerializationType type) + [Fact] + public async Task Deserialize_RepositoryTagsFiles_1() { // arrange _testFileSettings.UseFileName("RepositoryTagsExplanation1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnEmptyObject_WhenContentIsEmpty(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnEmptyObject_WhenContentIsEmpty() { // arrange _testFileSettings.UseFileName("Empty"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnEmptyObject_WhenVersionIsUnknown(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnEmptyObject_WhenVersionIsUnknown() { // arrange _testFileSettings.UseFileName("Version100"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithVariables_WhenContentIsVariablesOnly(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithVariables_WhenContentIsVariablesOnly() { // arrange _testFileSettings.UseFileName("VariablesOnly1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags1() { // arrange _testFileSettings.UseFileName("RepositoryTags1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithLatestTags_WhenContentHasDoubleTags(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithLatestTags_WhenContentHasDoubleTags() { // arrange _testFileSettings.UseFileName("RepositoryTagsDouble"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags2(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags2() { // arrange _testFileSettings.UseFileName("RepositoryTags2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert await Verifier.Verify(result, _verifySettings) - .UseMethodName(nameof(Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags1)) - .IgnoreParametersForVerified(type); + .UseMethodName(nameof(Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags1)); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags3(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryTags_WhenContentIsRepositoryTags3() { // arrange _testFileSettings.UseFileName("RepositoryTags3"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions1() { // arrange _testFileSettings.UseFileName("RepositoryActions1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions2(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions2() { // arrange _testFileSettings.UseFileName("RepositoryActions2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert await Verifier.Verify(result, _verifySettings) - .IgnoreParametersForVerified(type) .UseMethodName(nameof(Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions1)); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions3(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRepositoryActions_WhenContentIsRepositoryActions3() { // arrange _testFileSettings.UseFileName("RepositoryActions3"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect1() { // arrange _testFileSettings.UseFileName("Redirect1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect2(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect2() { // arrange _testFileSettings.UseFileName("Redirect2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert await Verifier.Verify(result, _verifySettings) - .IgnoreParametersForVerified(type) .UseMethodName(nameof(Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect1)); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect3(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObjectWithRedirect_WhenContentIsRedirect3() { // arrange _testFileSettings.UseFileName("Redirect3"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObject_WhenContentIsRepositorySpecificEnvFile1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObject_WhenContentIsRepositorySpecificEnvFile1() { // arrange _testFileSettings.UseFileName("RepositorySpecificEnvFile1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ShouldReturnObject_WhenContentIsRepositorySpecificConfigFile1(SerializationType type) + [Fact] + public async Task Deserialize_ShouldReturnObject_WhenContentIsRepositorySpecificConfigFile1() { // arrange _testFileSettings.UseFileName("RepositorySpecificConfigFile1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_Sample1(SerializationType type) + [Fact] + public async Task Deserialize_Sample1() { // arrange _testFileSettings.UseFileName("Sample1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_Sample2(SerializationType type) + [Fact] + public async Task Deserialize_Sample2() { // arrange _testFileSettings.UseFileName("Sample2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_Sample3(SerializationType type) + [Fact] + public async Task Deserialize_Sample3() { // arrange _testFileSettings.UseFileName("Sample3"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_VariableObject1(SerializationType type) + [Fact] + public async Task Deserialize_VariableObject1() { // arrange _testFileSettings.UseFileName("VariableObject1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_VariableObject2(SerializationType type) + [Fact] + public async Task Deserialize_VariableObject2() { // arrange _testFileSettings.UseFileName("VariableObject2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ForEach1(SerializationType type) + [Fact] + public async Task Deserialize_ForEach1() { // arrange _testFileSettings.UseFileName("ForEach1"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ForEach2(SerializationType type) + [Fact] + public async Task Deserialize_ForEach2() { // arrange _testFileSettings.UseFileName("ForEach2"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize_ForEach3(SerializationType type) + [Fact] + public async Task Deserialize_ForEach3() { // arrange _testFileSettings.UseFileName("ForEach3"); - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } [Fact] @@ -471,7 +405,7 @@ public void EmptyFile_ShouldThrow() // arrange // act - Func act = () => _ = _sutJson.Deserialize(string.Empty); + Func act = () => _ = _sut.Deserialize(string.Empty); // assert _ = act.Should().Throw().WithMessage("Error reading JObject from JsonReader. Path '', line 0, position 0."); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs index ea777afa..a6f6085c 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs @@ -38,7 +38,6 @@ public class RepositorySpecificConfigurationTest { private readonly IAppDataPathProvider _appDataPathProvider; private readonly MockFileSystem _fileSystem; - private readonly JsonDynamicRepositoryActionDeserializer _jsonAppSettingsDeserializer; private readonly YamlDynamicRepositoryActionDeserializer _yamlAppSettingsDeserializer; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; @@ -51,7 +50,7 @@ public RepositorySpecificConfigurationTest() { _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); @@ -63,8 +62,8 @@ public RepositorySpecificConfigurationTest() _appDataPathProvider = A.Fake(); A.CallTo(() => _appDataPathProvider.AppDataPath).Returns(_tempPath); - _jsonAppSettingsDeserializer = DynamicRepositoryActionDeserializerFactory.Create(); - _yamlAppSettingsDeserializer = new YamlDynamicRepositoryActionDeserializer(_jsonAppSettingsDeserializer); + JsonDynamicRepositoryActionDeserializer jsonAppSettingsDeserializer = DynamicRepositoryActionDeserializerFactory.Create(); + _yamlAppSettingsDeserializer = new YamlDynamicRepositoryActionDeserializer(jsonAppSettingsDeserializer); var dateTimeTimeVariableProviderOptions = new DateTimeVariableProviderOptions() { @@ -87,9 +86,12 @@ public RepositorySpecificConfigurationTest() new DateTimeTimeVariableProvider(dateTimeTimeVariableProviderOptions), new DateTimeDateVariableProvider(dateTimeDateVariableProviderOptions), new EmptyVariableProvider(), - new CustomEnvironmentVariableVariableProvider(), - new RepoMVariableProvider(), - new RepositoryVariableProvider(), + new VariableProviderAdapter(new Core.Plugin.VariableProviders.IVariableProvider[] + { + new CustomEnvironmentVariableVariableProvider(), + new RepoMVariableProvider(), + new RepositoryVariableProvider(), + }), new SlashVariableProvider(), new BackslashVariableProvider(), }; @@ -139,19 +141,8 @@ public async Task Create_ShouldRespectMultiSelectRepos() // arrange _testFileSettings.UseFileName("RepositoryActionsMultiSelect"); var content = await EasyTestFile.LoadAsText(_testFileSettings); - _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME_JSON), new MockFileData(content, Encoding.UTF8)); - var sut = new RepositorySpecificConfiguration( - _fileSystem, - _repositoryExpressionEvaluator, - _actionMapperComposition, - _translationService, - new RepositoryConfigurationReader( - _appDataPathProvider, - _fileSystem, - _jsonAppSettingsDeserializer, - _yamlAppSettingsDeserializer, - _repositoryExpressionEvaluator, - NullLogger.Instance)); + _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME), new MockFileData(content, Encoding.UTF8)); + RepositorySpecificConfiguration sut = CreateSut(); // act IEnumerable result = sut.CreateActions(new Repository("path1"), new Repository("path2")); @@ -166,19 +157,8 @@ public async Task Create_ShouldNotCareAboutMultiSelectRepos_WhenSingleRepo() // arrange _testFileSettings.UseFileName("RepositoryActionsMultiSelect"); var content = await EasyTestFile.LoadAsText(_testFileSettings); - _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME_JSON), new MockFileData(content, Encoding.UTF8)); - var sut = new RepositorySpecificConfiguration( - _fileSystem, - _repositoryExpressionEvaluator, - _actionMapperComposition, - _translationService, - new RepositoryConfigurationReader( - _appDataPathProvider, - _fileSystem, - _jsonAppSettingsDeserializer, - _yamlAppSettingsDeserializer, - _repositoryExpressionEvaluator, - NullLogger.Instance)); + _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME), new MockFileData(content, Encoding.UTF8)); + RepositorySpecificConfiguration sut = CreateSut(); // act IEnumerable result = sut.CreateActions(new Repository("path1")); @@ -193,19 +173,8 @@ public async Task Create_ShouldOnlyProcessActiveItems() // arrange _testFileSettings.UseFileName("RepositoryActions1"); var content = await EasyTestFile.LoadAsText(_testFileSettings); - _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME_JSON), new MockFileData(content, Encoding.UTF8)); - var sut = new RepositorySpecificConfiguration( - _fileSystem, - _repositoryExpressionEvaluator, - _actionMapperComposition, - _translationService, - new RepositoryConfigurationReader( - _appDataPathProvider, - _fileSystem, - _jsonAppSettingsDeserializer, - _yamlAppSettingsDeserializer, - _repositoryExpressionEvaluator, - NullLogger.Instance)); + _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME), new MockFileData(content, Encoding.UTF8)); + RepositorySpecificConfiguration sut = CreateSut(); // act IEnumerable result = sut.CreateActions(new Repository("path1")); @@ -220,8 +189,19 @@ public async Task Create_ShouldProcessSeparator1() // arrange _testFileSettings.UseFileName("RepositoryActionsWithSeparator1"); var content = await EasyTestFile.LoadAsText(_testFileSettings); - _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME_JSON), new MockFileData(content, Encoding.UTF8)); - var sut = new RepositorySpecificConfiguration( + _fileSystem.AddFile(Path.Combine(_tempPath, RepositoryConfigurationReader.FILENAME), new MockFileData(content, Encoding.UTF8)); + RepositorySpecificConfiguration sut = CreateSut(); + + // act + IEnumerable result = sut.CreateActions(new Repository("path1")); + + // assert + await Verifier.Verify(result, _verifySettings); + } + + private RepositorySpecificConfiguration CreateSut() + { + return new RepositorySpecificConfiguration( _fileSystem, _repositoryExpressionEvaluator, _actionMapperComposition, @@ -229,15 +209,8 @@ public async Task Create_ShouldProcessSeparator1() new RepositoryConfigurationReader( _appDataPathProvider, _fileSystem, - _jsonAppSettingsDeserializer, _yamlAppSettingsDeserializer, _repositoryExpressionEvaluator, NullLogger.Instance)); - - // act - IEnumerable result = sut.CreateActions(new Repository("path1")); - - // assert - await Verifier.Verify(result, _verifySettings); } } \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Empty.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Empty.testfile.json deleted file mode 100644 index 7a73a41b..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Empty.testfile.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach1.testfile.json deleted file mode 100644 index 40ee3161..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach1.testfile.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "variables": [ - { - "name": "DTAP", - "value": [ - { - "key": "D", - "url": "https://develop.local" - }, - { - "key": "T", - "url": "https://test.local" - }, - { - "key": "A", - "url": "https://acceptance.local" - }, - { - "key": "p", - "url": "https://production.local" - } - ] - } - ], - - "repository-actions": { - "actions": [ - { - "type": "foreach@1", - "enumerable": "{var.DTAP}", - "variable": "environment", - "actions": [ - { - "type": "browser@1", - "name": "{var.environment.key}", - "url": "{var.environment.url}" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach2.testfile.json deleted file mode 100644 index 7fb17e15..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach2.testfile.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "repository-actions": { - "variables": [ - { - "name": "DTAP", - "value": [ - { - "key": "D", - "url": "https://develop.local" - }, - { - "key": "T", - "url": "https://test.local" - }, - { - "key": "A", - "url": "https://acceptance.local" - }, - { - "key": "p", - "url": "https://production.local" - } - ] - } - ], - "actions": [ - { - "type": "foreach@1", - "enumerable": "{var.DTAP}", - "variable": "environment", - "actions": [ - { - "type": "browser@1", - "name": "{var.environment.key}", - "url": "{var.environment.url}" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach3.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach3.testfile.json deleted file mode 100644 index c2da5a00..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/ForEach3.testfile.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "repository-actions": { - "variables": [ - { - "name": "DTAP", - "value": [ - { - "key": "D", - "url": "https://develop.local" - }, - { - "key": "T", - "url": "https://test.local" - }, - { - "key": "A", - "url": "https://acceptance.local" - }, - { - "key": "p", - "url": "https://production.local" - } - ] - } - ], - "actions": [ - { - "type": "foreach@1", - "enumerable": "{var.DTAP}", - "variable": "environment", - "skip": "{IsNull({var.environment.x})}", - "actions": [ - { - "type": "browser@1", - "name": "{var.environment.key}", - "url": "{var.environment.url}" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect1.testfile.json deleted file mode 100644 index 04cbe189..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect1.testfile.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "redirect": "filename.txt" -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect2.testfile.json deleted file mode 100644 index 983f1c5b..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect2.testfile.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "redirect": { - "filename": "filename.txt" - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect3.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect3.testfile.json deleted file mode 100644 index 58d6fb88..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Redirect3.testfile.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "redirect": { - "filename": "filename.txt", - "enabled": "true" - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions1.testfile.json deleted file mode 100644 index a0f5dae8..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions1.testfile.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "repository-actions": - [ - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // optional, default true - "active": "false", - - // optional, default to false - "multi-select-enabled": "true", - - // optional - "variables": [ - { - "name": "name", - "value": "{StringContains({Repository.SafePath}, \"abc\")}" - } - ] - }, - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // false as boolean instead of string - "active": false - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions2.testfile.json deleted file mode 100644 index b5b49347..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions2.testfile.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "repository-actions": - { - "actions": - [ - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // optional, default true - "active": "false", - - // optional, default to false - "multi-select-enabled": "true", - - // optional - "variables": [ - { - "name": "name", - "value": "{StringContains({Repository.SafePath}, \"abc\")}" - } - ] - }, - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // false as boolean instead of string - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions3.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions3.testfile.json deleted file mode 100644 index 7b7bdfbe..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActions3.testfile.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "repository-actions": - { - "variables": - [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment are stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ], - "actions": [ - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // optional, default true - "active": "false", - - // optional, default to false - "multi-select-enabled": "true", - - // optional - "variables": [ - { - "name": "name", - "value": "{StringContains({Repository.SafePath}, \"abc\")}" - } - ], - "url" : "https://google.com" - }, - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // false as boolean instead of string - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.json deleted file mode 100644 index 2aae136e..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "repository-actions": [ - { - "type": "browser@1", - "name": "Google 1", - "url": "https://google.com", - "multi-select-enabled": "true" - }, - { - "type": "browser@1", - "name": "Google 2", - "url": "https://google.com", - "multi-select-enabled": "false" - }, - { - "type": "browser@1", - "name": "Google 3", - "url": "https://google.com", - "multi-select-enabled": "true", - "active": false - }, - { - "type": "browser@1", - "name": "Google 4", - "url": "https://google.com", - "multi-select-enabled": "false" - }, - { - "type": "browser@1", - "name": "Google 5", - "url": "https://google.com", - "multi-select-enabled": "true" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.yaml new file mode 100644 index 00000000..8a7a8ae1 --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsMultiSelect.testfile.yaml @@ -0,0 +1,22 @@ +repository-actions: +- type: browser@1 + name: Google 1 + url: https://google.com + multi-select-enabled: 'true' +- type: browser@1 + name: Google 2 + url: https://google.com + multi-select-enabled: 'false' +- type: browser@1 + name: Google 3 + url: https://google.com + multi-select-enabled: 'true' + active: false +- type: browser@1 + name: Google 4 + url: https://google.com + multi-select-enabled: 'false' +- type: browser@1 + name: Google 5 + url: https://google.com + multi-select-enabled: 'true' \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.json deleted file mode 100644 index d9958345..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "repository-actions": [ - { - "type": "browser@1", - "name": "Google 1", - "url": "https://google.com" - }, - { - "type": "separator@1" - }, - { - "type": "browser@1", - "name": "Google 2", - "url": "https://google.com" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.yaml new file mode 100644 index 00000000..72865cbb --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryActionsWithSeparator1.testfile.yaml @@ -0,0 +1,8 @@ +repository-actions: +- type: browser@1 + name: Google 1 + url: https://google.com +- type: separator@1 +- type: browser@1 + name: Google 2 + url: https://google.com \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificConfigFile1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificConfigFile1.testfile.json deleted file mode 100644 index 1e64c481..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificConfigFile1.testfile.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "repository-specific-config-files": [ - { - "filename": "ab1.env", - "when": "false" - }, - { - "filename": "ab.env" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFile1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFile1.testfile.json deleted file mode 100644 index 978676bc..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFile1.testfile.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "repository-specific-env-files": - [ - { - "filename": "ab1.env", - "when": "false" - }, - { - "filename": "ab.env" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFilesExplanation1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFilesExplanation1.testfile.json deleted file mode 100644 index 129694b5..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositorySpecificEnvFilesExplanation1.testfile.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "repository-specific-env-files": [ - { - "filename": "", - "when": "" - }, - { - "filename": "", - "when": "" - }, - { - "filename": "", - "when": "" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags1.testfile.json deleted file mode 100644 index 1f474293..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags1.testfile.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "repository-tags": - [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": '{StringContains({Repository.SafePath}, "Private")}' - }, - { - "tag": "always-tag" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags2.testfile.json deleted file mode 100644 index c96f46aa..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags2.testfile.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "repository-tags": - { - "tags": - [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags3.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags3.testfile.json deleted file mode 100644 index eafa5c7a..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTags3.testfile.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "repository-tags": { - "tags": [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "variables": - [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsDouble.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsDouble.testfile.json deleted file mode 100644 index 30f8b0b5..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsDouble.testfile.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "repository-tags": [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "repository-tags": [ - { - "tag": "work1", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private1", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag1" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsExplanation1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsExplanation1.testfile.json deleted file mode 100644 index 9dd40008..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/RepositoryTagsExplanation1.testfile.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "repository-tags": [ - { - "tag": "", - "when": "" - }, - { - "tag": "", - "when": "" - }, - { - "tag": "", - "when": "" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample1.testfile.json deleted file mode 100644 index 7f782965..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample1.testfile.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "version": 1, - "repository-tags": { - "tags": [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ] - }, - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - }, - { - "name": "work_repo_2", - // single quote works - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": "false" - }, - { - "name": "is_private_repo", - "value": "false" - }, - { - "name": "x", - "value": "y", - // this value is ignored - "dummy": "value" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample2.testfile.json deleted file mode 100644 index 329ae6dd..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample2.testfile.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "repository-tags": { - "tags": [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ] - }, - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - }, - { - "name": "work_repo_2", - // single quote works - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": "false" - }, - { - "name": "is_private_repo", - "value": "false" - }, - { - "name": "x", - "value": "y", - // this value is ignored - "dummy": "value" - } - ], - "repository-actions": { - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ], - "actions": [ - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // optional, default true - "active": "false", - - // optional, default to false - "multi-select-enabled": "true", - - // optional - "variables": [ - { - "name": "name", - "value": "{StringContains({Repository.SafePath}, \"abc\")}" - } - ] - }, - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // false as boolean instead of string - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample3.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample3.testfile.json deleted file mode 100644 index 35f4707c..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Sample3.testfile.json +++ /dev/null @@ -1,124 +0,0 @@ -{ - "repository-specific-config-files": [ - { - "filename": "{Repostitory.Path}\\RepositoryActions.json", - "when": "false" - }, - { - "filename": "{Repostitory.Path}\\.git\\RepositoryActions.json" - } - ], - "repository-specific-env-files": [ - { - "filename": "ab1.env", - "when": "false" - }, - { - "filename": "ab.env" - } - ], - "repository-tags": { - "tags": [ - { - "tag": "work", - - // optional, default true - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ] - }, - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - }, - { - "name": "work_repo_2", - // single quote works - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": "false" - }, - { - "name": "is_private_repo", - "value": "false" - }, - { - "name": "x", - "value": "y", - // this value is ignored - "dummy": "value" - } - ], - "repository-actions": { - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ], - "actions": [ - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // optional, default true - "active": "false", - - // optional, default to false - "multi-select-enabled": "true", - - // optional - "variables": [ - { - "name": "name", - "value": "{StringContains({Repository.SafePath}, \"abc\")}" - } - ] - }, - { - // type, string, optional, defaults to .. - "type": "browser@1", - "name": "{OpenIn} Windows File Explorer", - // false as boolean instead of string - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject1.testfile.json deleted file mode 100644 index 5c99261a..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject1.testfile.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "version": 1, - "variables": [ - { - "name": "varObject", - "value": { - "name": "abc", - "age": 12, - "isSupeMan": true, - "brothers": [ - "BatMan", - "SupeMan" - ], - "subs": [ - { - "index": 1, - "name": "Uno" - }, - { - "index": 2, - "name": "Twice" - } - ] - }, - "enabled": true - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject2.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject2.testfile.json deleted file mode 100644 index 79c2ebeb..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariableObject2.testfile.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": 1, - "variables": [ - { - "name": "devopsEnvironments", - "value": [ - { - "name": "D", - "url": "https://www.google.com" - }, - { - "name": "T", - "url": "https://github.com" - } - ], - "enabled": true - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariablesOnly1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariablesOnly1.testfile.json deleted file mode 100644 index 5aed374c..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/VariablesOnly1.testfile.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - }, - { - "name": "work_repo_2", - // single quote works - "value": "{StringContains({Repository.SafePath}, \"work\")}", // comment - "enabled": "false" - }, - { - "name": "is_private_repo", - "value": "false" - }, - { - "name": "x", - "value": "y", - // this value is ignored - "dummy": "value" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version1.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version1.testfile.json deleted file mode 100644 index 48d39357..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version1.testfile.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - // file content version. - "version": 1, - - // 'repository-specific-env-files' is an array and specifies loading specific environment files - // loaded environment variables can be used in actions. - "repository-specific-env-files": [], - - // 'variables' is an array. - // variables can be refrerenced in actions. - "variables": [], - - // 'repository-tags' is an array to specify tags for repositories. - // a tag is assigned to a repository when the 'when' predicate is true. - "repository-tags": { - "variables": [], - "tags": [] - }, - - // Repository actions which correspondent with the context menu of RepoM. - "repository-actions": { - "variables": [], - "actions": [] - } -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.json b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.json deleted file mode 100644 index 239445c0..00000000 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - // unknown version: - "version": 100, - "repository-tags": { - "tags": [ - { - "tag": "work", - "when": "{StringContains({Repository.SafePath}, \"work\")}" - }, - { - "tag": "private", - "when": "{StringContains({Repository.SafePath}, \"Private\")}" - }, - { - "tag": "always-tag" - } - ], - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - } - ] - }, - "variables": [ - { - "name": "work_repo", - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": true - }, - // comment ar stripped - { - "name": "work_repo_1", - "value": "true", - // boolean to string works - "enabled": false - }, - { - "name": "work_repo_2", - // single quote works - "value": "{StringContains({Repository.SafePath}, \"work\")}", - "enabled": "false" - }, - { - "name": "is_private_repo", - "value": "false" - }, - { - "name": "x", - "value": "y", - // this value is ignored - "dummy": "value" - } - ] -} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.yaml b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.yaml index b589d016..c5b892c6 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.yaml +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/TestFiles/Version100.testfile.yaml @@ -1,3 +1,4 @@ +# unknown version version: 100 repository-tags: tags: diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig.verified.txt b/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig.verified.txt deleted file mode 100644 index b35d4656..00000000 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig.verified.txt +++ /dev/null @@ -1,4 +0,0 @@ -{ - PersonalAccessToken: MY_TEST_PAT, - BaseUrl: https://dev.azure.com/MyOrg123ABC -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs index baf336f8..84e17e10 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs @@ -34,9 +34,6 @@ public AzureDevOpsPackageTests() A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?)); A.CallTo(() => _packageConfiguration.LoadConfigurationAsync()).ReturnsLazily(() => azureDevopsConfigV1); A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).Returns(Task.CompletedTask); - - A.CallTo(() => _appSettingsService.AzureDevOpsBaseUrl).Returns("https://dev.azure.com/MyOrg123ABC"); - A.CallTo(() => _appSettingsService.AzureDevOpsPersonalAccessToken).Returns("MY_TEST_PAT"); } [Fact] @@ -75,43 +72,35 @@ public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrec _container.Verify(VerificationOption.VerifyAndDiagnose); } - [Theory] - [InlineData(null)] - [InlineData(2)] - [InlineData(10)] - public async Task RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig(int? version) + [Fact] + public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered() { // arrange - AzureDevopsConfigV1? persistedConfig = null; - A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); - RegisterExternals(_container); var sut = new AzureDevOpsPackage(); - await sut.RegisterServicesAsync(_container, _packageConfiguration); - - Fake.ClearRecordedCalls(_packageConfiguration); - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)) - .Invokes(call => persistedConfig = call.Arguments[0] as AzureDevopsConfigV1); // act - // make sure everyting is resolved. This will trigger the copy of the config. - _container.Verify(VerificationOption.VerifyAndDiagnose); - + await sut.RegisterServicesAsync(_container, _packageConfiguration); + // assert - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); - await Verifier.Verify(persistedConfig).IgnoreParametersForVerified(nameof(version)); + Assert.Throws(() => _container.Verify(VerificationOption.VerifyAndDiagnose)); } - [Fact] - public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered() + [Theory] + [InlineData(null)] + [InlineData(2)] + [InlineData(10)] + public async Task RegisterServices_ShouldPersistConfigWhenNotCorrectVersion(int? version) { // arrange + A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); + RegisterExternals(_container); var sut = new AzureDevOpsPackage(); - + // act await sut.RegisterServicesAsync(_container, _packageConfiguration); // assert - Assert.Throws(() => _container.Verify(VerificationOption.VerifyAndDiagnose)); + A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); } private void RegisterExternals(Container container) diff --git a/tests/RepoM.Plugin.Heidi.Tests/EnvironmentVariableManager.cs b/tests/RepoM.Plugin.Heidi.Tests/EnvironmentVariableManager.cs index 4fa6cc0e..38622fb1 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/EnvironmentVariableManager.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/EnvironmentVariableManager.cs @@ -4,7 +4,6 @@ namespace RepoM.Plugin.Heidi.Tests; using System.Collections.Concurrent; using System.Threading; - internal static class EnvironmentVariableManager { private static readonly ConcurrentDictionary _envVarLocks = new(); diff --git a/tests/RepoM.Plugin.Heidi.Tests/HeidiPackageTest.cs b/tests/RepoM.Plugin.Heidi.Tests/HeidiPackageTest.cs index 9348e09b..8fd2eba9 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/HeidiPackageTest.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/HeidiPackageTest.cs @@ -76,27 +76,13 @@ public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrec [InlineData(10)] public async Task RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig(int? version) { - // This test is not complete but has some issues running in AzureDevops. Propbably due to the environment variables. - // Because this functionality will be stripped in a few months (ie, october 2023) this test is not a priority. - // arrange - // using IDisposable d1 = EnvironmentVariableManager.SetEnvironmentVariable("REPOM_HEIDI_CONFIG_PATH", "heidi-configpath-envvar"); - // using IDisposable d2 = EnvironmentVariableManager.SetEnvironmentVariable("REPOM_HEIDI_CONFIG_FILENAME", "heidi-filename-envvar"); - // using IDisposable d3 = EnvironmentVariableManager.SetEnvironmentVariable("REPOM_HEIDI_EXE", "heidi-exe-envvar"); - - HeidiConfigV1? persistedConfig = null; A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); RegisterExternals(_container); var sut = new HeidiPackage(); - await sut.RegisterServicesAsync(_container, _packageConfiguration); - - Fake.ClearRecordedCalls(_packageConfiguration); - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)) - .Invokes(call => persistedConfig = call.Arguments[0] as HeidiConfigV1); // act - // make sure everyting is resolved. This will trigger the copy of the config. - _container.Verify(VerificationOption.VerifyAndDiagnose); + await sut.RegisterServicesAsync(_container, _packageConfiguration); // assert A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); diff --git a/tests/RepoM.Plugin.Heidi.Tests/Internal/EnvironmentVariablesHeidiSettingsTests.cs b/tests/RepoM.Plugin.Heidi.Tests/Internal/EnvironmentVariablesHeidiSettingsTests.cs deleted file mode 100644 index 6b0c68d0..00000000 --- a/tests/RepoM.Plugin.Heidi.Tests/Internal/EnvironmentVariablesHeidiSettingsTests.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace RepoM.Plugin.Heidi.Tests.Internal; - -using System; -using FluentAssertions; -using RepoM.Plugin.Heidi.Internal; -using Xunit; - -public class EnvironmentVariablesHeidiSettingsTests -{ - [Fact] - public void ConfigFilename_ShouldReturnDefault_WhenEnvironmentVariableIsUnset() - { - // arrange - using IDisposable _ = EnvironmentVariableManager.SetEnvironmentVariable("REPOM_HEIDI_CONFIG_FILENAME", string.Empty); - var sut = new EnvironmentVariablesHeidiSettings(); - - // act - var result = sut.ConfigFilename; - - // assert - result.Should().Be("portable_settings.txt"); - } - - [Fact] - public void ConfigFilename_ShouldReturnEnvironmentVariable_WhenEnvironmentVariableIsSet() - { - // arrange - using IDisposable _ = EnvironmentVariableManager.SetEnvironmentVariable("REPOM_HEIDI_CONFIG_FILENAME", "Dummy@#"); - var sut = new EnvironmentVariablesHeidiSettings(); - - // act - var result = sut.ConfigFilename; - - // assert - result.Should().Be("Dummy@#"); - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.cs b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.cs index 65019b6d..ec7b7295 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.cs +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.cs @@ -7,13 +7,11 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; using System.Reflection; using System.Text; using System.Threading.Tasks; -using FakeItEasy; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using NuDoq; using RepoM.Api.Plugins; using RepoM.Core.Plugin; -using RepoM.Core.Plugin.Common; +using RepoM.Plugin.Misc.Tests.TestFramework; using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; using VerifyTests; using VerifyXunit; @@ -22,21 +20,17 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; [UsesVerify] public class DocsModuleSettingsTests { - private readonly IAppDataPathProvider _appDataPathProvider; - private FileBasedPackageConfiguration _fileBasedPackageConfiguration; - private MockFileSystem _fileSystem; - private ILogger _logger; + private const string VERIFY_DIRECTORY = "ModuleSettingsDocs"; + private readonly VerifySettings _verifySettings = new(); + private readonly FileBasedPackageConfiguration _fileBasedPackageConfiguration; + private readonly MockFileSystem _fileSystem; public DocsModuleSettingsTests() { - _appDataPathProvider = A.Fake(); - A.CallTo(() => _appDataPathProvider.AppDataPath).Returns("C:\\tmp\\"); - _fileSystem = new MockFileSystem(new J2N.Collections.Generic.Dictionary() - { - { "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists. - }); - _logger = NullLogger.Instance; - _fileBasedPackageConfiguration = new FileBasedPackageConfiguration(_appDataPathProvider, _fileSystem, _logger, "dummy"); + _fileSystem = MockFileSystemFactory.CreateDefaultFileSystem(); + _fileBasedPackageConfiguration = new FileBasedPackageConfiguration(MockFileSystemFactory.CreateDefaultAppDataProvider(), _fileSystem, NullLogger.Instance, "dummy"); + + _verifySettings.UseDirectory(VERIFY_DIRECTORY); } public static IEnumerable PackagesTestData => PluginStore.Packages.Select(package => new object[] { package, }).ToArray(); @@ -55,8 +49,7 @@ public async Task VerifyChanges() } // assert - var settings = new VerifySettings(); - await Verifier.Verify(results, settings); + await Verifier.Verify(results, _verifySettings); } [Theory] @@ -70,14 +63,11 @@ public async Task DocsModuleSettings(IPackage package) (object? config, string? persistedConfig) = await PersistDefaultConfigAsync(package); // assert - var settings = new VerifySettings(); - // settings.AutoVerify(); - settings.UseDirectory("VerifiedDocs"); - settings.UseTextForParameters(package.GetType().Name); + _verifySettings.UseTextForParameters(package.GetType().Name); if (config == null && persistedConfig == null) { - settings.AppendContentAsFile(CreateConfigWithoutSnippetDocumentationMarkdown(), "md", "desc"); - await Verifier.Verify($"No config in {packageName}", settings: settings); + _verifySettings.AppendContentAsFile(CreateConfigWithoutSnippetDocumentationMarkdown(), "md", "desc"); + await Verifier.Verify($"No config in {packageName}", settings: _verifySettings); } else { @@ -122,10 +112,10 @@ public async Task DocsModuleSettings(IPackage package) configWithSnippetDocumentationMarkdown += Environment.NewLine + sb; } - settings.AppendContentAsFile(configWithSnippetDocumentationMarkdown, "md", "desc"); + _verifySettings.AppendContentAsFile(configWithSnippetDocumentationMarkdown, "md", "desc"); #if DEBUG - await Verifier.Verify(persistedConfig, settings: settings, extension: "json"); + await Verifier.Verify(persistedConfig, settings: _verifySettings, extension: "json"); #else Assert.True(true); // this test should only be run in Debug mode. #endif diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.VerifyChanges.verified.txt deleted file mode 100644 index 1d1fdd54..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.VerifyChanges.verified.txt +++ /dev/null @@ -1,15 +0,0 @@ -{ - RepoM.Plugin.AzureDevOps: [ - RepositoryActionAzureDevOpsCreatePullRequestsV1, - RepositoryActionAzureDevOpsGetPullRequestsV1 - ], - RepoM.Plugin.Clipboard: [ - RepositoryActionClipboardCopyV1 - ], - RepoM.Plugin.Heidi: [ - RepositoryActionHeidiDatabasesV1 - ], - RepoM.Plugin.SonarCloud: [ - RepositoryActionSonarCloudSetFavoriteV1 - ] -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.cs b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.cs index 24bbc3bc..18c6b938 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.cs +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsRepositoryActionsTests.cs @@ -2,18 +2,13 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; using System; using System.Collections.Generic; -using System.IO.Abstractions.TestingHelpers; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; -using FakeItEasy; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; using NuDoq; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; -using RepoM.Api.Plugins; -using RepoM.Core.Plugin.Common; +using RepoM.Plugin.Misc.Tests.TestFramework; using RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; using VerifyTests; @@ -23,21 +18,12 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; [UsesVerify] public class DocsRepositoryActionsTests { - private readonly IAppDataPathProvider _appDataPathProvider; - private FileBasedPackageConfiguration _fileBasedPackageConfiguration; - private MockFileSystem _fileSystem; - private ILogger _logger; + private const string VERIFY_DIRECTORY = "RepositoryActionsDocs"; + private readonly VerifySettings _verifySettings = new(); public DocsRepositoryActionsTests() { - _appDataPathProvider = A.Fake(); - A.CallTo(() => _appDataPathProvider.AppDataPath).Returns("C:\\tmp\\"); - _fileSystem = new MockFileSystem(new J2N.Collections.Generic.Dictionary() - { - { "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists. - }); - _logger = NullLogger.Instance; - _fileBasedPackageConfiguration = new FileBasedPackageConfiguration(_appDataPathProvider, _fileSystem, _logger, "dummy"); + _verifySettings.UseDirectory(VERIFY_DIRECTORY); } public static IEnumerable AssemblyTestData => PluginStore.Assemblies.Select(assembly => new object[] { assembly, }).ToArray(); @@ -48,22 +34,10 @@ public static IEnumerable RepositoryActionsTestData { List results = new(); - foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + foreach (Assembly assembly in RepoMAssemblyStore.GetAssemblies()) { try { - var assemblyName = assembly.GetName().Name; - if (string.IsNullOrEmpty(assemblyName) || !assemblyName.Contains("RepoM")) - { - continue; - } - - // Workaround for Github Actions - if (assemblyName.Contains("Test")) - { - continue; - } - foreach (Type repositoryActionType in assembly.GetRepositoryActionsFromAssembly()) { results.Add(new object[] { new RepositoryTestData(assembly, repositoryActionType), }); @@ -83,46 +57,24 @@ public static IEnumerable RepositoryActionsTestData public async Task VerifyChanges() { // arrange - var results = new Dictionary(); + var assemblies = RepoMAssemblyStore.GetAssemblies() + .Concat(PluginStore.Assemblies) + .Distinct() + .OrderBy(a => a.FullName); // act - foreach (Assembly assembly in PluginStore.Assemblies) - { - results.Add( - assembly.GetName().Name ?? assembly.ToString(), - assembly.GetRepositoryActionsFromAssembly()); - } + var results = assemblies.ToDictionary( + assembly => assembly.GetName().Name ?? assembly.ToString(), + assembly => assembly.GetRepositoryActionsFromAssembly()); // assert - var settings = new VerifySettings(); - await Verifier.Verify(results, settings); - } - - public class RepositoryTestData - { - public RepositoryTestData(Assembly assembly, Type type) - { - Assembly = assembly; - Type = type; - } - - public Assembly Assembly { get; } - - public Type Type { get; } - - public override string ToString() - { - return Assembly.GetName().Name + "-" + Type.Name; - } + await Verifier.Verify(results, _verifySettings); } [Fact] public async Task RepositoryActionBaseDocumentationGeneration() { - var settings = new VerifySettings(); - // settings.AutoVerify(); - settings.UseDirectory("VerifiedDocs1"); - settings.UseTextForParameters(nameof(RepositoryAction)); + _verifySettings.UseTextForParameters(nameof(RepositoryAction)); #if DEBUG var options = new NuDoq.ReaderOptions @@ -150,7 +102,7 @@ public async Task RepositoryActionBaseDocumentationGeneration() } #if DEBUG - await Verifier.Verify(sb.ToString(), settings: settings, extension: "md"); + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); #else await Task.Yield(); Assert.True(true); // this test should only be run in Debug mode. @@ -161,10 +113,7 @@ public async Task RepositoryActionBaseDocumentationGeneration() [MemberData(nameof(RepositoryActionsTestData))] public async Task DocsRepositoryActionsSettings(RepositoryTestData repositoryActionTestData) { - var settings = new VerifySettings(); - // settings.AutoVerify(); - settings.UseDirectory("VerifiedDocs1"); - settings.UseTextForParameters(repositoryActionTestData.Type.Name); + _verifySettings.UseTextForParameters(repositoryActionTestData.Type.Name); var builtinClassNames = new Dictionary { @@ -207,7 +156,7 @@ public async Task DocsRepositoryActionsSettings(RepositoryTestData repositoryAct } #if DEBUG - await Verifier.Verify(sb.ToString(), settings: settings, extension: "md"); + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); #else await Task.Yield(); Assert.True(true); // this test should only be run in Debug mode. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage.verified.json b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage.verified.json similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage.verified.json rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_AzureDevOpsPackage.verified.json diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_ClipboardPackage.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_EverythingPackage.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage.verified.json b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage.verified.json similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage.verified.json rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_HeidiPackage.verified.json diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_LuceneQueryParserPackage.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage.verified.json b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage.verified.json similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage.verified.json rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_SonarCloudPackage.verified.json diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage.verified.json b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage.verified.json similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage.verified.json rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_StatisticsPackage.verified.json diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage#desc.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage#desc.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.DocsModuleSettings_WindowsExplorerGitInfoPackage.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.VerifyChanges.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/DocsModuleSettingsTests.VerifyChanges.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsModuleSettingsTests.VerifyChanges.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsRepositoryActionsTests.DocsModuleSettings_RuntimeAssembly#desc.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsRepositoryActionsTests.VerifyChanges.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsRepositoryActionsTests.DocsModuleSettings_RuntimeAssembly#desc.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/ModuleSettingsDocs/DocsRepositoryActionsTests.VerifyChanges.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.CoreComparersMarkdown.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.CoreComparersMarkdown.verified.md new file mode 100644 index 00000000..a21f24f9 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.CoreComparersMarkdown.verified.md @@ -0,0 +1,28 @@ +- [`az-comparer@1`](#az-comparer1) +- [`composition-comparer@1`](#composition-comparer1) +- [`score-comparer@1`](#score-comparer1) +- [`sum-comparer@1`](#sum-comparer1) + +These comparers are available by using the corresponding plugin. +- [`last-opened-comparer@1`](#last-opened-comparer1) + +### `az-comparer@1` + +include: RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_AlphabetComparerConfigurationV1.verified.md + +### `composition-comparer@1` + +include: RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_CompositionComparerConfigurationV1.verified.md + +### `score-comparer@1` + +include: RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_ScoreComparerConfigurationV1.verified.md + +### `sum-comparer@1` + +include: RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_SumComparerConfigurationV1.verified.md + +### `last-opened-comparer@1` + +include: RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_LastOpenedConfigurationV1.verified.md + diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_AlphabetComparerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_AlphabetComparerConfigurationV1.verified.md new file mode 100644 index 00000000..05ae3fb0 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_AlphabetComparerConfigurationV1.verified.md @@ -0,0 +1,6 @@ +Compares two repositories by a given property alphabetically in ascending order. + +Properties: + +- `property`: Repository property. Currently, only `Name`, and `Location` are supported. Otherwise, comparison will always result in `0`. (optional) +- `weight`: The weight of this comparer. The higher the weight, the higher the impact. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_CompositionComparerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_CompositionComparerConfigurationV1.verified.md new file mode 100644 index 00000000..997265a1 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_CompositionComparerConfigurationV1.verified.md @@ -0,0 +1,5 @@ +Compares two repositories by a composition of comparers. + +Properties: + +- `comparers`: List of comparers. The first comparer not resulting in `0` will be used as final result. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_LastOpenedConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_LastOpenedConfigurationV1.verified.md new file mode 100644 index 00000000..09f295e3 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_LastOpenedConfigurationV1.verified.md @@ -0,0 +1,5 @@ +Compares two repositories by the timestamp of the last action RepoM performed on the repository. + +Properties: + +- `weight`: The weight of this comparer. The higher the weight, the higher the impact. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_ScoreComparerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_ScoreComparerConfigurationV1.verified.md new file mode 100644 index 00000000..ad9e4f82 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_ScoreComparerConfigurationV1.verified.md @@ -0,0 +1,5 @@ +Compares two repositories by a repository score. The calculation of the repository score is defined in the score provider. + +Properties: + +- `score-provider`: The score provider to calculate a score for a repository. (optional) diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_SumComparerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_SumComparerConfigurationV1.verified.md new file mode 100644 index 00000000..d83ee522 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.DocsRepositoriesComparerConfiguration_SumComparerConfigurationV1.verified.md @@ -0,0 +1,5 @@ +Compares two repositories by the sum of the results of the comparers. + +Properties: + +- `comparers`: A list of comparers. The sum of the results of the comparers will be used as final result. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.VerifyChanges.verified.txt new file mode 100644 index 00000000..2ae22d62 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationDocs/RepositoriesComparerConfigurationTests.VerifyChanges.verified.txt @@ -0,0 +1,11 @@ +{ + RepoM.Api: [ + SumComparerConfigurationV1, + ScoreComparerConfigurationV1, + CompositionComparerConfigurationV1, + AlphabetComparerConfigurationV1 + ], + RepoM.Plugin.Statistics: [ + LastOpenedConfigurationV1 + ] +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationTests.cs b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationTests.cs new file mode 100644 index 00000000..67044f52 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesComparerConfigurationTests.cs @@ -0,0 +1,199 @@ +namespace RepoM.Plugin.Misc.Tests.Configuration; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using NuDoq; +using RepoM.Plugin.Misc.Tests.TestFramework; +using RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; +using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; +using VerifyTests; +using VerifyXunit; +using Xunit; + +[UsesVerify] +public class RepositoriesComparerConfigurationTests +{ + private const string VERIFY_DIRECTORY = "RepositoriesComparerConfigurationDocs"; + private readonly VerifySettings _verifySettings = new(); + + public RepositoriesComparerConfigurationTests() + { + _verifySettings.UseDirectory(VERIFY_DIRECTORY); + } + + public static IEnumerable PackagesTestData => PluginStore.Packages.Select(package => new object[] { package, }).ToArray(); + + public static IEnumerable RepositoryComparersData + { + get + { + List results = new(); + + foreach (Assembly assembly in RepoMAssemblyStore.GetAssemblies()) + { + try + { + foreach (Type repositoryActionType in assembly.GetRepositoriesComparerConfigurationFromAssembly()) + { + results.Add(new RepositoryTestData(assembly, repositoryActionType)); + } + } + catch (System.Exception) + { + // skip + } + } + + return results; + } + } + + public static IEnumerable RepositoryComparersDataXunit + { + get + { + return RepositoryComparersData.Select(x => new object[] { x, }).ToArray(); + } + } + + [Fact] + public async Task VerifyChanges() + { + // arrange + var assemblies = RepoMAssemblyStore.GetAssemblies() + .Concat(PluginStore.Assemblies) + .Distinct() + .OrderBy(a => a.FullName); + + // act + var results = assemblies.ToDictionary( + assembly => assembly.GetName().Name ?? assembly.ToString(), + assembly => assembly.GetRepositoriesComparerConfigurationFromAssembly()); + + // assert + await Verifier.Verify(results, _verifySettings); + } + + [Fact] + public async Task CoreComparersMarkdown() + { + // arrange + var sb = new StringBuilder(); + var coreComparerTypes = RepositoryComparersData + .Where(x => !x.Assembly.IsRepoMPluginAssembly()) + .OrderBy(x => x.Assembly.GetName().Name) + .ThenBy(x => x.Type.GetTypeValue()) + .ToArray(); + var pluginComparerTypes = RepositoryComparersData + .Where(x => x.Assembly.IsRepoMPluginAssembly()) + .OrderBy(x => x.Assembly.GetName().Name) + .ThenBy(x => x.Type.GetTypeValue()) + .ToArray(); + + const string PREFIX = $"{nameof(RepositoriesComparerConfigurationTests)}.{nameof(DocsRepositoriesComparerConfiguration)}_"; + const string SUFFIX = ".verified.md"; + + static string CreateTableOfContentItem(Type type) + { + return $"- [`{type.GetTypeValue()}`](#{MarkdownHelpers.CreateGithubMarkdownAnchor(type.GetTypeValue())})"; + } + + static void AppendToStringBuilder(StringBuilder sb, Type t) + { + sb.AppendLine($"### `{t.GetTypeValue()}`"); + sb.AppendLine(string.Empty); + sb.AppendLine($"include: {PREFIX}{t.Name}{SUFFIX}"); // mdsnippet + sb.AppendLine(string.Empty); + } + + // act + + foreach (RepositoryTestData item in coreComparerTypes) + { + sb.AppendLine(CreateTableOfContentItem(item.Type)); + } + + if (pluginComparerTypes.Length > 0) + { + sb.AppendLine(string.Empty); + sb.AppendLine("These comparers are available by using the corresponding plugin."); + foreach (RepositoryTestData item in pluginComparerTypes) + { + sb.AppendLine(CreateTableOfContentItem(item.Type)); + } + } + + sb.AppendLine(string.Empty); + + foreach (RepositoryTestData item in coreComparerTypes) + { + AppendToStringBuilder(sb, item.Type); + } + + foreach (RepositoryTestData item in pluginComparerTypes) + { + AppendToStringBuilder(sb, item.Type); + } + + // assert + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); + } + + [Theory] + [MemberData(nameof(RepositoryComparersDataXunit))] + public async Task DocsRepositoriesComparerConfiguration(RepositoryTestData repositoryActionTestData) + { + _verifySettings.UseTextForParameters(repositoryActionTestData.Type.Name); + + var builtinClassNames = new Dictionary + { + [repositoryActionTestData.Type.Name] = "config", + }; + +#if DEBUG + var options = new NuDoq.ReaderOptions + { + KeepNewLinesInText = true, + }; + AssemblyMembers members = DocReader.Read(repositoryActionTestData.Assembly, options); +#else + var members = new DocumentMembers(System.Xml.Linq.XDocument.Parse(""), Array.Empty()); +#endif + + var visitor = new RepositoryComparerSettingMarkdownVisitor(builtinClassNames); + members.Accept(visitor); + + var sb = new StringBuilder(); + foreach (ClassWriter classWriter in visitor.ClassWriters.OrderBy(c => c.Key).Select(c => c.Value)) + { + var head = classWriter.Head.ToString(); + var properties = classWriter.Properties.ToString(); + + head = head.Trim(); + sb.AppendLine(head); + sb.AppendLine(string.Empty); + + if (string.IsNullOrWhiteSpace(properties)) + { + sb.AppendLine("This comparer does not have properties."); + } + else + { + sb.AppendLine("Properties:"); + sb.AppendLine(string.Empty); + sb.Append(classWriter.Properties); + } + } + +#if DEBUG + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); +#else + await Task.Yield(); + Assert.True(true); // this test should only be run in Debug mode. +#endif + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.CoreScorersMarkdown.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.CoreScorersMarkdown.verified.md new file mode 100644 index 00000000..26d3f78e --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.CoreScorersMarkdown.verified.md @@ -0,0 +1,18 @@ +- [`is-pinned-scorer@1`](#is-pinned-scorer1) +- [`tag-scorer@1`](#tag-scorer1) + +These scorers are available by using the corresponding plugin. +- [`usage-scorer@1`](#usage-scorer1) + +### `is-pinned-scorer@1` + +include: RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_IsPinnedScorerConfigurationV1.verified.md + +### `tag-scorer@1` + +include: RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_TagScorerConfigurationV1.verified.md + +### `usage-scorer@1` + +include: RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_UsageScorerConfigurationV1.verified.md + diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_IsPinnedScorerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_IsPinnedScorerConfigurationV1.verified.md new file mode 100644 index 00000000..f3067898 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_IsPinnedScorerConfigurationV1.verified.md @@ -0,0 +1,5 @@ +Repository scorer based on the pinned state of a repository. + +Properties: + +- `weight`: The weight of this scorer. The higher the weight, the higher the impact. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_TagScorerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_TagScorerConfigurationV1.verified.md new file mode 100644 index 00000000..42b49b5a --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_TagScorerConfigurationV1.verified.md @@ -0,0 +1,6 @@ +Repository scorer based on the tags of a repository. + +Properties: + +- `weight`: The weight of this scorer. The higher the weight, the higher the impact. +- `tag`: The tag to match on. If the repository has this tag, the score will return the weight, otherwise, `0`. (optional) diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_UsageScorerConfigurationV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_UsageScorerConfigurationV1.verified.md new file mode 100644 index 00000000..faced40f --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.DocsRepositoriesScorerConfiguration_UsageScorerConfigurationV1.verified.md @@ -0,0 +1,6 @@ +Repository scorer based on it's usage by RepoM. The more it's used, the higher the score. + +Properties: + +- `windows`: Specific 'windows' to calculate the score for. +- `max-score`: The maximum score a repository can get. diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.VerifyChanges.verified.txt new file mode 100644 index 00000000..325b6110 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationDocs/RepositoriesScorerConfigurationTests.VerifyChanges.verified.txt @@ -0,0 +1,9 @@ +{ + RepoM.Api: [ + TagScorerConfigurationV1, + IsPinnedScorerConfigurationV1 + ], + RepoM.Plugin.Statistics: [ + UsageScorerConfigurationV1 + ] +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationTests.cs b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationTests.cs new file mode 100644 index 00000000..211d506a --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoriesScorerConfigurationTests.cs @@ -0,0 +1,198 @@ +namespace RepoM.Plugin.Misc.Tests.Configuration; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using NuDoq; +using RepoM.Plugin.Misc.Tests.TestFramework; +using RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; +using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; +using VerifyTests; +using VerifyXunit; +using Xunit; + +[UsesVerify] +public class RepositoriesScorerConfigurationTests +{ + private const string VERIFY_DIRECTORY = "RepositoriesScorerConfigurationDocs"; + private readonly VerifySettings _verifySettings = new(); + + public RepositoriesScorerConfigurationTests() + { + _verifySettings.UseDirectory(VERIFY_DIRECTORY); + } + + public static IEnumerable PackagesTestData => PluginStore.Packages.Select(package => new object[] { package, }).ToArray(); + + public static IEnumerable RepositoryScorersData + { + get + { + List results = new(); + + foreach (Assembly assembly in RepoMAssemblyStore.GetAssemblies()) + { + try + { + foreach (Type repositoryActionType in assembly.GetRepositoriesScorerConfigurationFromAssembly()) + { + results.Add(new RepositoryTestData(assembly, repositoryActionType)); + } + } + catch (System.Exception) + { + // skip + } + } + + return results; + } + } + + public static IEnumerable RepositoryComparersDataXunit + { + get + { + return RepositoryScorersData.Select(x => new object[] { x, }).ToArray(); + } + } + + [Fact] + public async Task VerifyChanges() + { + // arrange + var assemblies = RepoMAssemblyStore.GetAssemblies() + .Concat(PluginStore.Assemblies) + .Distinct() + .OrderBy(a => a.FullName); + + // act + var results = assemblies.ToDictionary( + assembly => assembly.GetName().Name ?? assembly.ToString(), + assembly => assembly.GetRepositoriesScorerConfigurationFromAssembly()); + + // assert + await Verifier.Verify(results, _verifySettings); + } + + [Fact] + public async Task CoreScorersMarkdown() + { + // arrange + var sb = new StringBuilder(); + var coreScorerTypes = RepositoryScorersData + .Where(x => !x.Assembly.IsRepoMPluginAssembly()) + .OrderBy(x => x.Assembly.GetName().Name) + .ThenBy(x => x.Type.GetTypeValue()) + .ToArray(); + var pluginScorerTypes = RepositoryScorersData + .Where(x => x.Assembly.IsRepoMPluginAssembly()) + .OrderBy(x => x.Assembly.GetName().Name) + .ThenBy(x => x.Type.GetTypeValue()) + .ToArray(); + + const string PREFIX = $"{nameof(RepositoriesScorerConfigurationTests)}.{nameof(DocsRepositoriesScorerConfiguration)}_"; + const string SUFFIX = ".verified.md"; + + static string CreateTableOfContentItem(Type type) + { + return $"- [`{type.GetTypeValue()}`](#{MarkdownHelpers.CreateGithubMarkdownAnchor(type.GetTypeValue())})"; + } + + static void AppendToStringBuilder(StringBuilder sb, Type t) + { + sb.AppendLine($"### `{t.GetTypeValue()}`"); + sb.AppendLine(string.Empty); + sb.AppendLine($"include: {PREFIX}{t.Name}{SUFFIX}"); // mdsnippet + sb.AppendLine(string.Empty); + } + + // act + foreach (RepositoryTestData item in coreScorerTypes) + { + sb.AppendLine(CreateTableOfContentItem(item.Type)); + } + + if (pluginScorerTypes.Length > 0) + { + sb.AppendLine(string.Empty); + sb.AppendLine("These scorers are available by using the corresponding plugin."); + foreach (RepositoryTestData item in pluginScorerTypes) + { + sb.AppendLine(CreateTableOfContentItem(item.Type)); + } + } + + sb.AppendLine(string.Empty); + + foreach (RepositoryTestData item in coreScorerTypes) + { + AppendToStringBuilder(sb, item.Type); + } + + foreach (RepositoryTestData item in pluginScorerTypes) + { + AppendToStringBuilder(sb, item.Type); + } + + // assert + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); + } + + [Theory] + [MemberData(nameof(RepositoryComparersDataXunit))] + public async Task DocsRepositoriesScorerConfiguration(RepositoryTestData repositoryActionTestData) + { + _verifySettings.UseTextForParameters(repositoryActionTestData.Type.Name); + + var builtinClassNames = new Dictionary + { + [repositoryActionTestData.Type.Name] = "config", + }; + +#if DEBUG + var options = new NuDoq.ReaderOptions + { + KeepNewLinesInText = true, + }; + AssemblyMembers members = DocReader.Read(repositoryActionTestData.Assembly, options); +#else + var members = new DocumentMembers(System.Xml.Linq.XDocument.Parse(""), Array.Empty()); +#endif + + var visitor = new RepositoryComparerSettingMarkdownVisitor(builtinClassNames); + members.Accept(visitor); + + var sb = new StringBuilder(); + foreach (ClassWriter classWriter in visitor.ClassWriters.OrderBy(c => c.Key).Select(c => c.Value)) + { + var head = classWriter.Head.ToString(); + var properties = classWriter.Properties.ToString(); + + head = head.Trim(); + sb.AppendLine(head); + sb.AppendLine(string.Empty); + + if (string.IsNullOrWhiteSpace(properties)) + { + sb.AppendLine("This scorer does not have properties."); + } + else + { + sb.AppendLine("Properties:"); + sb.AppendLine(string.Empty); + sb.Append(classWriter.Properties); + } + } + +#if DEBUG + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); +#else + await Task.Yield(); + Assert.True(true); // this test should only be run in Debug mode. +#endif + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryAction.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryAction.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryAction.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryAction.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAssociateFileV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAssociateFileV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAssociateFileV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAssociateFileV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowseRepositoryV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowseRepositoryV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowseRepositoryV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowseRepositoryV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowserV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowserV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowserV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionBrowserV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionClipboardCopyV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionClipboardCopyV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionClipboardCopyV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionClipboardCopyV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionCommandV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionCommandV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionCommandV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionCommandV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionExecutableV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionExecutableV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionExecutableV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionExecutableV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionFolderV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionFolderV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionFolderV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionFolderV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionForEachV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionForEachV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionForEachV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionForEachV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitCheckoutV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitCheckoutV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitCheckoutV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitCheckoutV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitFetchV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitFetchV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitFetchV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitFetchV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPullV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPullV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPullV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPullV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPushV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPushV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPushV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionGitPushV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionHeidiDatabasesV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionHeidiDatabasesV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionHeidiDatabasesV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionHeidiDatabasesV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionIgnoreRepositoryV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionIgnoreRepositoryV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionIgnoreRepositoryV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionIgnoreRepositoryV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionJustTextV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionJustTextV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionJustTextV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionJustTextV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionPinRepositoryV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionPinRepositoryV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionPinRepositoryV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionPinRepositoryV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSeparatorV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSeparatorV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSeparatorV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSeparatorV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.DocsRepositoryActionsSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.RepositoryActionBaseDocumentationGeneration_RepositoryAction.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.RepositoryActionBaseDocumentationGeneration_RepositoryAction.verified.md similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.RepositoryActionBaseDocumentationGeneration_RepositoryAction.verified.md rename to tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.RepositoryActionBaseDocumentationGeneration_RepositoryAction.verified.md diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.VerifyChanges.verified.txt new file mode 100644 index 00000000..5daa5e1f --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/RepositoryActionsDocs/DocsRepositoryActionsTests.VerifyChanges.verified.txt @@ -0,0 +1,33 @@ +{ + RepoM.Api: [ + RepositoryAction, + RepositoryActionAssociateFileV1, + RepositoryActionBrowseRepositoryV1, + RepositoryActionBrowserV1, + RepositoryActionCommandV1, + RepositoryActionExecutableV1, + RepositoryActionFolderV1, + RepositoryActionForEachV1, + RepositoryActionGitCheckoutV1, + RepositoryActionGitFetchV1, + RepositoryActionGitPullV1, + RepositoryActionGitPushV1, + RepositoryActionIgnoreRepositoryV1, + RepositoryActionJustTextV1, + RepositoryActionPinRepositoryV1, + RepositoryActionSeparatorV1 + ], + RepoM.Plugin.AzureDevOps: [ + RepositoryActionAzureDevOpsCreatePullRequestsV1, + RepositoryActionAzureDevOpsGetPullRequestsV1 + ], + RepoM.Plugin.Clipboard: [ + RepositoryActionClipboardCopyV1 + ], + RepoM.Plugin.Heidi: [ + RepositoryActionHeidiDatabasesV1 + ], + RepoM.Plugin.SonarCloud: [ + RepositoryActionSonarCloudSetFavoriteV1 + ] +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsRepositoryActionsTests.DocsModuleSettings_RuntimeAssembly.verified.json b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsRepositoryActionsTests.DocsModuleSettings_RuntimeAssembly.verified.json deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs/DocsRepositoryActionsTests.DocsModuleSettings_RuntimeAssembly.verified.json +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsCreatePullRequestsV1.verified.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsGetPullRequestsV1.verified.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsPullRequestsV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsPullRequestsV1.verified.md deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionAzureDevOpsPullRequestsV1.verified.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionClipboardCopyV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionClipboardCopyV1.verified.md deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionClipboardCopyV1.verified.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md deleted file mode 100644 index 5f282702..00000000 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/VerifiedDocs1/DocsRepositoryActionsTests.DocsModuleSettings_RepositoryActionSonarCloudSetFavoriteV1.verified.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md similarity index 83% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md rename to tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md index a46ee51b..c847436d 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md +++ b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md @@ -8,6 +8,4 @@ - `MenuSize`: The menu size of RepoM. This is set when the window is resized. (optional, UI configured) - `ReposRootDirectories`: List of root directories where RepoM will search for git repositories. If null or empty, all fixed drives will be searched from the root. (optional, Manual configured) - `EnabledSearchProviders`: List of search providers. Search providers can be added by plugins. (optional, UI configured) -- `SonarCloudPersonalAccessToken`: SonarCloud PAT. (Obsolete, moved to plugin config) -- `AzureDevOps`: Azure DevOps config. (Obsolete, moved to plugin config) - `Plugins`: List of plugins. (optional, UI configured) diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md similarity index 83% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md rename to tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md index 3b39b05a..d49b23d4 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md +++ b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md @@ -15,8 +15,6 @@ This is the default configuration. }, "ReposRootDirectories": [], "EnabledSearchProviders": [], - "SonarCloudPersonalAccessToken": null, - "AzureDevOps": null, "Plugins": [] } ``` diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.VerifyChanges.verified.txt b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.VerifyChanges.verified.txt similarity index 100% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.VerifyChanges.verified.txt rename to tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.VerifyChanges.verified.txt diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.cs similarity index 68% rename from tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs rename to tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.cs index 1a15dedc..d9b2d154 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs +++ b/tests/RepoM.Plugin.Misc.Tests/DefaultAppSettingsTests/DocsAppSettingsTests.cs @@ -1,49 +1,31 @@ -namespace RepoM.Plugin.Misc.Tests.Configuration; +namespace RepoM.Plugin.Misc.Tests.DefaultAppSettingsTests; using System; -using System.Collections.Generic; using System.IO.Abstractions.TestingHelpers; -using System.Reflection; using System.Text; using System.Threading.Tasks; -using FakeItEasy; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using NuDoq; using RepoM.Api.Common; -using RepoM.Api.Plugins; -using RepoM.Core.Plugin; -using RepoM.Core.Plugin.Common; -using RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; +using RepoM.Plugin.Misc.Tests.TestFramework; using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; using VerifyTests; using VerifyXunit; using Xunit; -using YamlDotNet.Serialization; [UsesVerify] public class DocsAppSettingsTests { - private readonly IAppDataPathProvider _appDataPathProvider; - private FileAppSettingsService _fileBasedPackageConfiguration; - private MockFileSystem _fileSystem; - private ILogger _logger; + private readonly VerifySettings _verifySettings = new(); + private readonly FileAppSettingsService _fileBasedPackageConfiguration; + private readonly MockFileSystem _fileSystem; public DocsAppSettingsTests() { - _appDataPathProvider = A.Fake(); - A.CallTo(() => _appDataPathProvider.AppDataPath).Returns("C:\\tmp\\"); - _fileSystem = new MockFileSystem(new J2N.Collections.Generic.Dictionary() - { - { "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists. - }); - _logger = NullLogger.Instance; - _fileBasedPackageConfiguration = new FileAppSettingsService(_appDataPathProvider, _fileSystem, _logger); + _fileSystem = MockFileSystemFactory.CreateDefaultFileSystem(); + _fileBasedPackageConfiguration = new FileAppSettingsService(MockFileSystemFactory.CreateDefaultAppDataProvider(), _fileSystem, NullLogger.Instance); } - // FileAppSettingsService - - [Fact] public async Task AppSettingsJsonFileGeneration() { @@ -65,10 +47,10 @@ public async Task AppSettingsJsonFileGeneration() [Fact] public async Task AppSettingsDocumentationGeneration() { - var settings = new VerifySettings(); - settings.UseTextForParameters(nameof(AppSettings)); + _verifySettings.UseTextForParameters(nameof(AppSettings)); #if DEBUG + // ReSharper disable once RedundantNameQualifier var options = new NuDoq.ReaderOptions { KeepNewLinesInText = true, @@ -94,7 +76,7 @@ public async Task AppSettingsDocumentationGeneration() } #if DEBUG - await Verifier.Verify(sb.ToString(), settings: settings, extension: "md"); + await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md"); #else await Task.Yield(); Assert.True(true); // this test should only be run in Debug mode. diff --git a/tests/RepoM.Plugin.Misc.Tests/PackageTests.cs b/tests/RepoM.Plugin.Misc.Tests/PackageTests.cs index f706f69c..d4777116 100644 --- a/tests/RepoM.Plugin.Misc.Tests/PackageTests.cs +++ b/tests/RepoM.Plugin.Misc.Tests/PackageTests.cs @@ -1,11 +1,7 @@ namespace RepoM.Plugin.Misc.Tests; -using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using FakeItEasy; using FluentAssertions; using RepoM.Core.Plugin; using Xunit; diff --git a/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj b/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj index bd0a44af..7a239cf2 100644 --- a/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj +++ b/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj @@ -51,7 +51,4 @@ - - - diff --git a/tests/RepoM.Plugin.Misc.Tests/RepoMAssemblyStore.cs b/tests/RepoM.Plugin.Misc.Tests/RepoMAssemblyStore.cs new file mode 100644 index 00000000..40d60a8d --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/RepoMAssemblyStore.cs @@ -0,0 +1,39 @@ +namespace RepoM.Plugin.Misc.Tests; + +using System; +using System.Collections.Generic; +using System.Reflection; + +internal static class RepoMAssemblyStore +{ + public static IEnumerable GetAssemblies() + { + List results = new(); + + foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + try + { + var assemblyName = assembly.GetName().Name; + if (string.IsNullOrEmpty(assemblyName) || !assemblyName.Contains("RepoM")) + { + continue; + } + + // Workaround for Github Actions + if (assemblyName.Contains("Test")) + { + continue; + } + + results.Add(assembly); + } + catch (Exception) + { + // skip + } + } + + return results; + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/AssemblyHelpers.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/AssemblyHelpers.cs index 2d35ceb3..dbe47faa 100644 --- a/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/AssemblyHelpers.cs +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/AssemblyHelpers.cs @@ -4,17 +4,45 @@ namespace RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; using System.Collections.Generic; using System.Linq; using System.Reflection; +using RepoM.Core.Plugin.RepositoryOrdering.Configuration; internal static class AssemblyHelpers { public static Type[] GetRepositoryActionsFromAssembly(this Assembly assembly) + { + return assembly.GetTypFromAssembly(); + } + + public static Type[] GetRepositoriesComparerConfigurationFromAssembly(this Assembly assembly) + { + return assembly.GetTypFromAssembly(); + } + + public static Type[] GetRepositoriesScorerConfigurationFromAssembly(this Assembly assembly) + { + return assembly.GetTypFromAssembly(); + } + + private static Type[] GetTypFromAssembly(this Assembly assembly) { return assembly.GetExportedTypesFrom() - .Where(t => typeof(Api.IO.ModuleBasedRepositoryActionProvider.Data.RepositoryAction).IsAssignableFrom(t)) + .Where(t => typeof(T).IsAssignableFrom(t)) .Where(t => t is { IsAbstract: false, IsGenericTypeDefinition: false, }) .ToArray(); } + public static bool IsRepoMPluginAssembly(this Assembly assembly) + { + string? name = assembly.GetName().Name; + if (string.IsNullOrWhiteSpace(name)) + { + throw new Exception("Unexpected assembly without name."); + } + + return name.Contains("Plugin") && name.Contains("RepoM"); + } + + public static IEnumerable GetExportedTypesFrom(this Assembly assembly) { try diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/TypeExtensions.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/TypeExtensions.cs new file mode 100644 index 00000000..4a6ce30f --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/AssemblyAndTypeHelpers/TypeExtensions.cs @@ -0,0 +1,13 @@ +namespace RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; + +using System; +using System.Reflection; + +internal static class TypeExtension +{ + public static string GetTypeValue(this Type type) + { + FieldInfo fieldInfo = type.GetField("TYPE_VALUE") ?? throw new Exception("Could not locate field 'TYPE_VALUE'"); + return fieldInfo.GetValue(null)?.ToString() ?? throw new Exception("Could not get value of property 'TYPE_VALUE'"); + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/MarkdownHelpers.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/MarkdownHelpers.cs new file mode 100644 index 00000000..163dd3f7 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/MarkdownHelpers.cs @@ -0,0 +1,12 @@ +namespace RepoM.Plugin.Misc.Tests.TestFramework; + +internal static class MarkdownHelpers +{ + public static string CreateGithubMarkdownAnchor(string input) + { + return input + .Replace("@", string.Empty) + .Replace(" ", "-") + .ToLower(); + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/MockFileSystemFactory.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/MockFileSystemFactory.cs new file mode 100644 index 00000000..9e6329e4 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/MockFileSystemFactory.cs @@ -0,0 +1,24 @@ +namespace RepoM.Plugin.Misc.Tests.TestFramework; + +using System.Collections.Generic; +using System.IO.Abstractions.TestingHelpers; +using FakeItEasy; +using RepoM.Core.Plugin.Common; + +internal static class MockFileSystemFactory +{ + public static MockFileSystem CreateDefaultFileSystem() + { + return new MockFileSystem(new Dictionary() + { + { "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists. + }); + } + + public static IAppDataPathProvider CreateDefaultAppDataProvider() + { + IAppDataPathProvider appDataPathProvider = A.Fake(); + A.CallTo(() => appDataPathProvider.AppDataPath).Returns("C:\\tmp\\"); + return appDataPathProvider; + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/AppSettingsMarkdownVisitor.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/AppSettingsMarkdownVisitor.cs index cd13f948..40f19a57 100644 --- a/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/AppSettingsMarkdownVisitor.cs +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/AppSettingsMarkdownVisitor.cs @@ -5,7 +5,6 @@ namespace RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; using System.Reflection; using NuDoq; using RepoM.Api.Common; -using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; internal class AppSettingsMarkdownVisitor : Visitor { diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/ClassWriter.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/ClassWriter.cs index cadf6384..4d1a9aca 100644 --- a/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/ClassWriter.cs +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/ClassWriter.cs @@ -4,13 +4,7 @@ namespace RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; internal class ClassWriter { - public ClassWriter() - { - Head = new StringWriter(); - Properties = new StringWriter(); - } + public readonly StringWriter Head = new(); - public readonly StringWriter Head; - - public readonly StringWriter Properties; + public readonly StringWriter Properties = new(); } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/RepositoryComparerSettingMarkdownVisitor.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/RepositoryComparerSettingMarkdownVisitor.cs new file mode 100644 index 00000000..f33dfb91 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/RepositoryComparerSettingMarkdownVisitor.cs @@ -0,0 +1,93 @@ +namespace RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; + +using NuDoq; +using System.IO; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +internal class RepositoryComparerSettingMarkdownVisitor : Visitor +{ + private readonly Dictionary _builtinClassNames; + private StringWriter _writer; + private StringWriter _writerSummary; + + public RepositoryComparerSettingMarkdownVisitor(Dictionary builtinClassNames) + { + _builtinClassNames = builtinClassNames; + + ClassWriters = new Dictionary(); + _writerSummary = new StringWriter(); + _writer = new StringWriter(); + } + + public Dictionary ClassWriters { get; } + + private bool IsBuiltinType(Type? type, [NotNullWhen(true)] out string? shortName) + { + shortName = null; + if (type == null) + { + return false; + } + + if (string.IsNullOrWhiteSpace(type.Namespace)) + { + return false; + } + + return type.Namespace.StartsWith("RepoM") && _builtinClassNames.TryGetValue(type.Name, out shortName); + } + + public override void VisitMember(Member member) + { + if (member.Info is Type type && IsBuiltinType(type, out var shortName)) + { + var classWriter = new ClassWriter(); + ClassWriters[shortName] = classWriter; + + _writer = classWriter.Head; + + base.VisitMember(member); + + _writer = classWriter.Head; + + _writer.WriteLine(_writerSummary); + _writer.WriteLine(); + } + else if (member.Info is PropertyInfo propertyInfo && IsBuiltinType(propertyInfo.DeclaringType, out shortName)) + { + var propertyName = propertyInfo.SanitizePropertyName(); + + ClassWriter classWriter = ClassWriters[shortName]; + + _writer = classWriter.Properties; + + base.VisitMember(member); + + _writer = classWriter.Properties; + + var propertyAttributes = propertyInfo.PropertyAttributesToString(); + + var summary = _writerSummary.ToString(); + + _writer.WriteLine(string.IsNullOrWhiteSpace(summary) + ? $"- `{propertyName}` (no description known){propertyAttributes}" + : $"- `{propertyName}`: {summary}{propertyAttributes}"); + } + + _writerSummary = new StringWriter(); + } + + public override void VisitSummary(Summary summary) + { + _writer = _writerSummary; + base.VisitSummary(summary); + } + + public override void VisitText(Text text) + { + _writer.Write(text.Content); + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Misc.Tests/TestFramework/RepositoryTestData.cs b/tests/RepoM.Plugin.Misc.Tests/TestFramework/RepositoryTestData.cs new file mode 100644 index 00000000..bd0e9710 --- /dev/null +++ b/tests/RepoM.Plugin.Misc.Tests/TestFramework/RepositoryTestData.cs @@ -0,0 +1,25 @@ +namespace RepoM.Plugin.Misc.Tests.TestFramework; + +using System; +using System.Reflection; + +/// +/// Helper class used for naming arguments in xunits test name generation. +/// +public class RepositoryTestData +{ + public RepositoryTestData(Assembly assembly, Type type) + { + Assembly = assembly; + Type = type; + } + + public Assembly Assembly { get; } + + public Type Type { get; } + + public override string ToString() + { + return Assembly.GetName().Name + "-" + Type.Name; + } +} \ No newline at end of file diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs index fa8da3af..958dd28f 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs +++ b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs @@ -32,10 +32,8 @@ public SonarCloudPackageTest() A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?)); A.CallTo(() => _packageConfiguration.LoadConfigurationAsync()).ReturnsLazily(() => sonarCloudConfigV1); A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).Returns(Task.CompletedTask); - - A.CallTo(() => _appSettingsService.SonarCloudPersonalAccessToken).Returns("MY_TEST_PAT_SONAR"); } - + [Fact] public async Task RegisterServices_ShouldBeSuccessful_WhenExternalDependenciesAreRegistered() { @@ -72,32 +70,6 @@ public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrec _container.Verify(VerificationOption.VerifyAndDiagnose); } - [Theory] - [InlineData(null)] - [InlineData(2)] - [InlineData(10)] - public async Task RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig(int? version) - { - // arrange - SonarCloudConfigV1? persistedConfig = null; - A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); - RegisterExternals(_container); - var sut = new SonarCloudPackage(); - await sut.RegisterServicesAsync(_container, _packageConfiguration); - - Fake.ClearRecordedCalls(_packageConfiguration); - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)) - .Invokes(call => persistedConfig = call.Arguments[0] as SonarCloudConfigV1); - - // act - // make sure everyting is resolved. This will trigger the copy of the config. - _container.Verify(VerificationOption.VerifyAndDiagnose); - - // assert - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); - await Verifier.Verify(persistedConfig).IgnoreParametersForVerified(nameof(version)); - } - [Fact] public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered() { diff --git a/tests/RepoM.Plugin.Statistics.Tests/Ordering/LastOpenedComparerTests.cs b/tests/RepoM.Plugin.Statistics.Tests/Ordering/LastOpenedComparerTests.cs index b2bc20ef..c8a28f80 100644 --- a/tests/RepoM.Plugin.Statistics.Tests/Ordering/LastOpenedComparerTests.cs +++ b/tests/RepoM.Plugin.Statistics.Tests/Ordering/LastOpenedComparerTests.cs @@ -1,7 +1,6 @@ namespace RepoM.Plugin.Statistics.Tests.Ordering; using System; -using System.Collections.Generic; using FakeItEasy; using FluentAssertions; using RepoM.Core.Plugin.Repository; diff --git a/tests/SystemTests/DefaultRepositoryMonitorTests.cs b/tests/SystemTests/DefaultRepositoryMonitorTests.cs index 31aeb8de..01e68ebf 100644 --- a/tests/SystemTests/DefaultRepositoryMonitorTests.cs +++ b/tests/SystemTests/DefaultRepositoryMonitorTests.cs @@ -7,14 +7,6 @@ namespace SystemTests; using System.IO.Abstractions; using System.Linq; using System.Threading; -using ExpressionStringEvaluator.Methods; -using ExpressionStringEvaluator.Methods.BooleanToBoolean; -using ExpressionStringEvaluator.Methods.Flow; -using ExpressionStringEvaluator.Methods.StringToBoolean; -using ExpressionStringEvaluator.Methods.StringToInt; -using ExpressionStringEvaluator.Methods.StringToString; -using ExpressionStringEvaluator.VariableProviders; -using ExpressionStringEvaluator.VariableProviders.DateTime; using FluentAssertions; using Microsoft.Extensions.Logging.Abstractions; using Moq; @@ -24,7 +16,6 @@ namespace SystemTests; using RepoM.Api.Git.AutoFetch; using RepoM.Api.IO; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; -using RepoM.Api.IO.VariableProviders; using RepoM.Core.Plugin.RepositoryFinder; using SystemTests.IO; using SystemTests.Mocks; @@ -53,61 +44,9 @@ public void OneTimeSetUp() var appSettingsService = new Mock(); appSettingsService.Setup(x => x.EnabledSearchProviders).Returns(new List(0)); - var dateTimeTimeVariableProviderOptions = new DateTimeVariableProviderOptions() - { - DateTimeProvider = () => DateTime.Now, - }; - - var dateTimeNowVariableProviderOptions = new DateTimeNowVariableProviderOptions() - { - DateTimeProvider = () => DateTime.Now, - }; - - var dateTimeDateVariableProviderOptions = new DateTimeDateVariableProviderOptions() - { - DateTimeProvider = () => DateTime.Now, - }; - - var providers = new List - { - new DateTimeNowVariableProvider(dateTimeNowVariableProviderOptions), - new DateTimeTimeVariableProvider(dateTimeTimeVariableProviderOptions), - new DateTimeDateVariableProvider(dateTimeDateVariableProviderOptions), - new EmptyVariableProvider(), - new CustomEnvironmentVariableVariableProvider(), - new RepoMVariableProvider(), - new RepositoryVariableProvider(), - new SlashVariableProvider(), - new BackslashVariableProvider(), - }; - - var methods = new List - { - new StringTrimEndStringMethod(), - new StringTrimStartStringMethod(), - new StringTrimStringMethod(), - new StringContainsStringMethod(), - new StringLowerStringMethod(), - new StringUpperStringMethod(), - new UrlEncodeStringMethod(), - new UrlDecodeStringMethod(), - new StringEqualsStringMethod(), - new AndBooleanMethod(), - new OrBooleanMethod(), - new StringIsNullOrEmptyBooleanMethod(), - new FileExistsBooleanMethod(), - new NotBooleanMethod(), - new StringLengthMethod(), - new IfThenElseMethod(), - new IfThenMethod(), - new InMethod(), - new StringReplaceMethod(), - new SubstringMethod(), - }; - var defaultRepositoryReader = new DefaultRepositoryReader(new Mock().Object, NullLogger.Instance); _monitor = new DefaultRepositoryMonitor( - new GivenPathProvider(new string[] { repoPath, }), + new GivenPathProvider(new [] { repoPath, }), defaultRepositoryReader, new DefaultRepositoryDetectorFactory(defaultRepositoryReader), new DefaultRepositoryObserverFactory(),