From 94b231723cdac03447c1fafc6469ede70c8b7786 Mon Sep 17 00:00:00 2001 From: Coen van den Munckhof Date: Thu, 17 Aug 2023 18:30:00 +0200 Subject: [PATCH] Cache files (#69) * Remove more json stuff + cache RepositoryAction files and env files for speeding up process. * Update a shitload of packages * Replace Moq with FakeItEasy in last test project * added tests + update log statements --- .../ProcessExecution/GitCommandException.cs | 3 +- .../IRepositoryActionDeserializer.cs | 8 ++ ...JsonDynamicRepositoryActionDeserializer.cs | 11 +-- ...YamlDynamicRepositoryActionDeserializer.cs | 16 ++-- .../RepositoryActionsFileStore.cs | 94 +++++++++++++++++++ .../RepositorySpecificConfiguration.cs | 74 +++++++-------- src/RepoM.Api/RepoM.Api.csproj | 11 ++- src/RepoM.App/App.xaml.cs | 24 ++++- src/RepoM.App/Bootstrapper.cs | 5 +- src/RepoM.App/RepoM.App.csproj | 9 +- .../RepoM.Core.Plugin.csproj | 8 +- ...onAzureDevOpsCreatePullRequestsV1Mapper.cs | 2 +- .../RepoM.Plugin.AzureDevOps.csproj | 6 +- .../RepoM.Plugin.Clipboard.csproj | 6 +- .../RepoM.Plugin.EverythingFileSearch.csproj | 6 +- .../Internal/HeidiConfigurationService.cs | 4 +- .../RepoM.Plugin.Heidi.csproj | 6 +- .../RepoM.Plugin.LuceneQueryParser.csproj | 6 +- .../RepoM.Plugin.SonarCloud.csproj | 6 +- .../RepoM.Plugin.Statistics.csproj | 6 +- ...RepoM.Plugin.WindowsExplorerGitInfo.csproj | 6 +- ...amicRepositoryActionDeserializerFactory.cs | 52 +++++----- .../DocumentationTests.cs | 2 +- ...DynamicRepositoryActionDeserializerTest.cs | 2 +- .../RepositoryConfigurationReaderTests.cs | 38 ++++++++ .../RepositorySpecificConfigurationTest.cs | 7 +- tests/RepoM.Api.Tests/RepoM.Api.Tests.csproj | 18 ++-- tests/RepoM.App.Tests/RepoM.App.Tests.csproj | 18 ++-- .../AzureDevOpsGetPullRequestsV1Test.cs | 36 +++---- ...llRequestsV1Test.Deserialize.testfile.json | 21 ----- .../DocumentationTests.cs | 2 +- .../RepoM.Plugin.AzureDevOps.Tests.csproj | 18 ++-- ...amicRepositoryActionDeserializerFactory.cs | 8 +- .../ActionClipboardCopyV1DeserializerTest.cs | 37 +++----- ...DeserializerTest.Deserialize.testfile.json | 12 --- .../DocumentationTests.cs | 2 +- .../RepoM.Plugin.Clipboard.Tests.csproj | 18 ++-- ...amicRepositoryActionDeserializerFactory.cs | 8 +- ...M.Plugin.EverythingFileSearch.Tests.csproj | 15 +-- .../ActionHeidiDatabasesV1DeserializerTest.cs | 38 +++----- ...DeserializerTest.Deserialize.testfile.json | 17 ---- .../DocumentationTests.cs | 2 +- .../RepoM.Plugin.Heidi.Tests.csproj | 18 ++-- ...llRequestsV1Test.Deserialize.testfile.json | 21 ----- ...amicRepositoryActionDeserializerFactory.cs | 8 +- ...epoM.Plugin.LuceneQueryParser.Tests.csproj | 16 ++-- .../RepoM.Plugin.Misc.Tests.csproj | 18 ++-- .../DocumentationTests.cs | 2 +- .../RepoM.Plugin.SonarCloud.Tests.csproj | 18 ++-- .../SonarCloudSetFavoriteV1Test.cs | 37 +++----- ...etFavoriteV1Test.Deserialize.testfile.json | 12 --- ...amicRepositoryActionDeserializerFactory.cs | 8 +- .../RepoM.Plugin.Statistics.Tests.csproj | 18 ++-- ...Plugin.WindowsExplorerGitInfo.Tests.csproj | 18 ++-- .../DefaultRepositoryMonitorTests.cs | 14 +-- tests/SystemTests/SystemTests.csproj | 17 ++-- 56 files changed, 487 insertions(+), 426 deletions(-) create mode 100644 src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.cs create mode 100644 src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.cs create mode 100644 tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositoryConfigurationReaderTests.cs delete mode 100644 tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/TestFiles/AzureDevOpsGetPullRequestsV1Test.Deserialize.testfile.json delete mode 100644 tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/TestFiles/ActionClipboardCopyV1DeserializerTest.Deserialize.testfile.json delete mode 100644 tests/RepoM.Plugin.Heidi.Tests/ActionProvider/TestFiles/ActionHeidiDatabasesV1DeserializerTest.Deserialize.testfile.json delete mode 100644 tests/RepoM.Plugin.Heidi.Tests/TestFiles/AzureDevOpsPullRequestsV1Test.Deserialize.testfile.json delete mode 100644 tests/RepoM.Plugin.SonarCloud.Tests/TestFiles/SonarCloudSetFavoriteV1Test.Deserialize.testfile.json diff --git a/src/RepoM.Api/Git/ProcessExecution/GitCommandException.cs b/src/RepoM.Api/Git/ProcessExecution/GitCommandException.cs index e2ae4718..def7b062 100644 --- a/src/RepoM.Api/Git/ProcessExecution/GitCommandException.cs +++ b/src/RepoM.Api/Git/ProcessExecution/GitCommandException.cs @@ -2,9 +2,10 @@ namespace RepoM.Api.Git.ProcessExecution; using System; +[Serializable] public class GitCommandException : Exception { - public GitCommandException() : base() { } + public GitCommandException() { } public GitCommandException(string message) : base(message) { } diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.cs new file mode 100644 index 00000000..f1b41dda --- /dev/null +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.cs @@ -0,0 +1,8 @@ +namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; + +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; + +public interface IRepositoryActionDeserializer +{ + RepositoryActionConfiguration Deserialize(string content); +} \ No newline at end of file diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/JsonDynamicRepositoryActionDeserializer.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/JsonDynamicRepositoryActionDeserializer.cs index bb805c06..93d55eaf 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/JsonDynamicRepositoryActionDeserializer.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/JsonDynamicRepositoryActionDeserializer.cs @@ -10,7 +10,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; -public class JsonDynamicRepositoryActionDeserializer +internal class JsonDynamicRepositoryActionDeserializer { private readonly ActionDeserializerComposition _deserializers; private static readonly JsonSerializer _jsonSerializer = new() @@ -29,7 +29,6 @@ public class JsonDynamicRepositoryActionDeserializer CommentHandling = CommentHandling.Ignore, }; - public JsonDynamicRepositoryActionDeserializer(ActionDeserializerComposition deserializers) { _deserializers = deserializers ?? throw new ArgumentNullException(nameof(deserializers)); @@ -99,7 +98,7 @@ private void DeserializeRepositoryActions(JToken? repositoryActionsToken, Reposi continue; } - RepositoryAction? customAction = _deserializers.DeserializeSingleAction(typeValue!, variable, _jsonSerializer); + RepositoryAction? customAction = _deserializers.DeserializeSingleAction(typeValue, variable, _jsonSerializer); if (customAction == null) { continue; @@ -230,11 +229,9 @@ private static int DeserializeVersion(JToken? versionToken) return DEFAULT_VERSION; } - var version = DEFAULT_VERSION; - if (versionToken.Type == JTokenType.Integer) { - version = versionToken.Value(); + var version = versionToken.Value(); return version < 1 ? DEFAULT_VERSION : version; } @@ -246,7 +243,7 @@ private static int DeserializeVersion(JToken? versionToken) return DEFAULT_VERSION; } - if (int.TryParse(versionString, out version)) + if (int.TryParse(versionString, out var version)) { return version < 1 ? DEFAULT_VERSION : version; } diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.cs index 4a5a2ee0..65d08274 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.cs @@ -1,29 +1,29 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; -using System; +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using YamlDotNet.Serialization; -public class YamlDynamicRepositoryActionDeserializer +public class YamlDynamicRepositoryActionDeserializer : IRepositoryActionDeserializer { private readonly JsonDynamicRepositoryActionDeserializer _jsonDynamicRepositoryActionDeserializer; private readonly IDeserializer _deserializer; private readonly ISerializer _serializer; - public YamlDynamicRepositoryActionDeserializer(JsonDynamicRepositoryActionDeserializer jsonDynamicRepositoryActionDeserializer) + public YamlDynamicRepositoryActionDeserializer(ActionDeserializerComposition deserializers) { - _jsonDynamicRepositoryActionDeserializer = jsonDynamicRepositoryActionDeserializer ?? throw new ArgumentNullException(nameof(jsonDynamicRepositoryActionDeserializer)); + _jsonDynamicRepositoryActionDeserializer = new JsonDynamicRepositoryActionDeserializer(deserializers); _deserializer = new DeserializerBuilder().Build(); _serializer = new SerializerBuilder().JsonCompatible().Build(); } - public RepositoryActionConfiguration Deserialize(string rawContent) + public RepositoryActionConfiguration Deserialize(string content) { - var yamlObject = _deserializer.Deserialize(rawContent, typeof(object)); + var yamlObject = _deserializer.Deserialize(content, typeof(object)); if (yamlObject == null) { - // todo, log, throw?, .. - return _jsonDynamicRepositoryActionDeserializer.Deserialize(rawContent); + // maybe it is json, just give it a try + return _jsonDynamicRepositoryActionDeserializer.Deserialize(content); } var json = _serializer.Serialize(yamlObject); diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.cs new file mode 100644 index 00000000..ccc76250 --- /dev/null +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.cs @@ -0,0 +1,94 @@ +namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider; + +using System; +using System.Collections.Generic; +using System.IO.Abstractions; +using System.Runtime.Caching; +using DotNetEnv; +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; + +internal abstract class FileStore where T : class +{ + private readonly ObjectCache _cache; + + protected FileStore(ObjectCache cache) + { + _cache = cache ?? throw new ArgumentNullException(nameof(cache)); + } + + internal T? Get(string filename) + { + if (_cache[filename] is T fileContents) + { + return fileContents; + } + + return null; + } + + internal T AddOrGetExisting(string filename, T value) + { + var policy = new CacheItemPolicy(); + var filePaths = new List(1) { filename, }; + policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); + var cacheResult = _cache.AddOrGetExisting(filename, value, policy) as T; + return cacheResult ?? value; + } +} + +internal class RepositoryActionsFileStore : FileStore +{ + private readonly IFileSystem _fileSystem; + private readonly IRepositoryActionDeserializer _repositoryActionsDeserializer; + + + public RepositoryActionsFileStore(IFileSystem fileSystem, IRepositoryActionDeserializer repositoryActionsDeserializer, ObjectCache cache) : base(cache) + { + _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); + _repositoryActionsDeserializer = repositoryActionsDeserializer ?? throw new ArgumentNullException(nameof(repositoryActionsDeserializer)); + } + + public RepositoryActionConfiguration? TryGet(string filename) + { + RepositoryActionConfiguration? result = Get(filename); + + if (result != null) + { + return result; + } + + var payload = _fileSystem.File.ReadAllText(filename); + RepositoryActionConfiguration? fileContents = _repositoryActionsDeserializer.Deserialize(payload); + + if (fileContents == null) + { + return null; + } + + return AddOrGetExisting(filename, fileContents); + } +} + +internal class EnvFileStore : FileStore> +{ + public EnvFileStore(ObjectCache cache) : base(cache) + { + } + + public IDictionary TryGet(string filename) + { + Dictionary? result = Get(filename); + + if (result != null) + { + return result; + } + + IEnumerable>? envResult = Env.Load(filename, new LoadOptions(setEnvVars: false)); + + Dictionary? fileContents = envResult == null ? new Dictionary(0) : envResult.ToDictionary(); + + return AddOrGetExisting(filename, fileContents); + } +} \ No newline at end of file diff --git a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs index c377bc89..d972ae8c 100644 --- a/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs +++ b/src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfiguration.cs @@ -5,7 +5,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using System.IO; using System.IO.Abstractions; using System.Linq; -using System.Text; +using System.Runtime.Caching; using DotNetEnv; using Microsoft.Extensions.Logging; using RepoM.Api.Common; @@ -27,23 +27,26 @@ public class RepositoryConfigurationReader public const string FILENAME = "RepositoryActions.yaml"; private readonly IAppDataPathProvider _appDataPathProvider; private readonly IFileSystem _fileSystem; - private readonly YamlDynamicRepositoryActionDeserializer _yamlAppSettingsDeserializer; private readonly IRepositoryExpressionEvaluator _repoExpressionEvaluator; private readonly ILogger _logger; - + private readonly RepositoryActionsFileStore _repositoryActionsFileStore; + private readonly EnvFileStore _envFileStore; public RepositoryConfigurationReader( IAppDataPathProvider appDataPathProvider, IFileSystem fileSystem, - YamlDynamicRepositoryActionDeserializer yamlAppSettingsDeserializer, + IRepositoryActionDeserializer repositoryActionsDeserializer, IRepositoryExpressionEvaluator repoExpressionEvaluator, - ILogger logger) + ILogger logger, + ObjectCache cache) { _appDataPathProvider = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider)); _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); - _yamlAppSettingsDeserializer = yamlAppSettingsDeserializer ?? throw new ArgumentNullException(nameof(yamlAppSettingsDeserializer)); _repoExpressionEvaluator = repoExpressionEvaluator ?? throw new ArgumentNullException(nameof(repoExpressionEvaluator)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + + _repositoryActionsFileStore = new RepositoryActionsFileStore(_fileSystem, repositoryActionsDeserializer, cache); + _envFileStore = new EnvFileStore(cache); } private string GetRepositoryActionsFilename(string basePath) @@ -107,32 +110,37 @@ private string GetRepositoryActionsFilename(string basePath) try { - var content = _fileSystem.File.ReadAllText(filename, Encoding.UTF8); - rootFile = Deserialize(_fileSystem.Path.GetExtension(filename), content); + rootFile = _repositoryActionsFileStore.TryGet(filename); } catch (Exception e) { throw new InvalidConfigurationException(filename, e.Message, e); } - + + if (rootFile == null) + { + throw new InvalidConfigurationException(filename, "Could not read and deserialize file"); + } + Redirect? redirect = rootFile.Redirect; - if (!string.IsNullOrWhiteSpace(redirect?.Filename)) + if (!string.IsNullOrWhiteSpace(redirect?.Filename) && IsEnabled(redirect.Enabled, true, null)) { - if (IsEnabled(redirect.Enabled, true, null)) + filename = EvaluateString(redirect.Filename, null); + if (_fileSystem.File.Exists(filename)) { - filename = EvaluateString(redirect.Filename, null); - if (_fileSystem.File.Exists(filename)) + try { - try - { - var content = _fileSystem.File.ReadAllText(filename, Encoding.UTF8); - rootFile = Deserialize(_fileSystem.Path.GetExtension(filename), content); - } - catch (Exception e) - { - _logger.LogWarning(e, "Could not read and deserialize file '{file}'", filename); - throw new InvalidConfigurationException(filename, e.Message, e); - } + rootFile = _repositoryActionsFileStore.TryGet(filename); + } + catch (Exception e) + { + _logger.LogWarning(e, "Could not read and deserialize file '{file}'", filename); + throw new InvalidConfigurationException(filename, e.Message, e); + } + + if (rootFile == null) + { + throw new InvalidConfigurationException(filename, "Could not read and deserialize file"); } } } @@ -177,7 +185,7 @@ List EvaluateVariables(IEnumerable? vars) try { - IEnumerable>? currentEnvVars = Env.Load(f, new LoadOptions(setEnvVars: false)); + IDictionary currentEnvVars = _envFileStore.TryGet(f); if (envVars == null || !envVars.Any()) { envVars = currentEnvVars.ToDictionary(); @@ -231,8 +239,7 @@ List EvaluateVariables(IEnumerable? vars) try { - var content = _fileSystem.File.ReadAllText(f, Encoding.UTF8); - repoSpecificConfig = Deserialize(_fileSystem.Path.GetExtension(f), content); + repoSpecificConfig = _repositoryActionsFileStore.TryGet(filename); } catch (Exception) { @@ -284,21 +291,6 @@ private bool IsEnabled(string? booleanExpression, bool defaultWhenNullOrEmpty, I ? defaultWhenNullOrEmpty : _repoExpressionEvaluator.EvaluateBooleanExpression(booleanExpression!, repository); } - - private RepositoryActionConfiguration Deserialize(string extension, string rawContent) - { - if (extension.StartsWith('.')) - { - extension = extension[1..]; - } - - if ("yaml".Equals(extension, StringComparison.CurrentCultureIgnoreCase) || "yml".Equals(extension, StringComparison.CurrentCultureIgnoreCase)) - { - return _yamlAppSettingsDeserializer.Deserialize(rawContent); - } - - throw new NotImplementedException("Unknown extension"); - } } public class RepositoryTagsConfigurationFactory : IRepositoryTagsFactory diff --git a/src/RepoM.Api/RepoM.Api.csproj b/src/RepoM.Api/RepoM.Api.csproj index a3b750af..31df4267 100644 --- a/src/RepoM.Api/RepoM.Api.csproj +++ b/src/RepoM.Api/RepoM.Api.csproj @@ -7,17 +7,22 @@ - + - + - + + + + + + diff --git a/src/RepoM.App/App.xaml.cs b/src/RepoM.App/App.xaml.cs index 327aff7c..fb54b6f1 100644 --- a/src/RepoM.App/App.xaml.cs +++ b/src/RepoM.App/App.xaml.cs @@ -12,7 +12,6 @@ namespace RepoM.App; using RepoM.Api.Git; using RepoM.Api.IO; using RepoM.App.i18n; -using SimpleInjector; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using RepoM.Api.Plugins; @@ -23,6 +22,7 @@ namespace RepoM.App; using RepoM.App.Services; using Container = SimpleInjector.Container; using RepoM.App.Services.HotKey; +using Serilog.Enrichers; /// /// Interaction logic for App.xaml @@ -39,6 +39,7 @@ public partial class App : Application [STAThread] public static void Main() { + Thread.CurrentThread.Name ??= "UI"; var app = new App(); app.InitializeComponent(); app.Run(); @@ -73,7 +74,7 @@ protected override void OnStartup(StartupEventArgs e) Bootstrapper.RegisterPlugins(pluginFinder, fileSystem, loggerFactory).GetAwaiter().GetResult(); #if DEBUG - Bootstrapper.Container.Verify(VerificationOption.VerifyAndDiagnose); + Bootstrapper.Container.Verify(SimpleInjector.VerificationOption.VerifyAndDiagnose); #endif UseRepositoryMonitor(Bootstrapper.Container); @@ -110,6 +111,22 @@ private static IConfiguration SetupConfiguration(IFileSystem fileSystem) { const string FILENAME = "appsettings.serilog.json"; var fullFilename = Path.Combine(DefaultAppDataPathProvider.Instance.AppDataPath, FILENAME); + if (!fileSystem.File.Exists(fullFilename)) + { + try + { + var fullFilenameTemplate = Path.Combine(DefaultAppDataPathProvider.Instance.AppResourcesPath, FILENAME); + if (fileSystem.File.Exists(fullFilenameTemplate)) + { + fileSystem.File.Copy(fullFilenameTemplate, fullFilename); + } + } + catch (Exception) + { + // swallow + } + } + if (!fileSystem.File.Exists(fullFilename)) { fullFilename = FILENAME; @@ -127,6 +144,9 @@ private static ILoggerFactory CreateLoggerFactory(IConfiguration config) ILoggerFactory loggerFactory = new LoggerFactory(); LoggerConfiguration loggerConfiguration = new LoggerConfiguration() + .Enrich.WithThreadId() + .Enrich.WithThreadName() + .Enrich.WithProperty(ThreadNameEnricher.ThreadNamePropertyName, "BG") .ReadFrom.Configuration(config); Logger logger = loggerConfiguration.CreateLogger(); diff --git a/src/RepoM.App/Bootstrapper.cs b/src/RepoM.App/Bootstrapper.cs index c69e1cfe..4d864834 100644 --- a/src/RepoM.App/Bootstrapper.cs +++ b/src/RepoM.App/Bootstrapper.cs @@ -48,6 +48,7 @@ namespace RepoM.App; using System.Linq; using Microsoft.VisualStudio.Services.Common; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; +using System.Runtime.Caching; internal static class Bootstrapper { @@ -55,6 +56,7 @@ internal static class Bootstrapper public static void RegisterServices(IFileSystem fileSystem) { + Container.RegisterInstance(MemoryCache.Default); Container.Register(Lifestyle.Singleton); Container.RegisterInstance(StatusCharacterMap.Instance); Container.Register(Lifestyle.Singleton); @@ -162,8 +164,7 @@ static IEnumerable GetExportedTypesFrom(Assembly assembly) new[] { typeof(IActionToRepositoryActionMapper).Assembly, }, Lifestyle.Singleton); - Container.Register(Lifestyle.Singleton); - Container.Register(Lifestyle.Singleton); + Container.Register(Lifestyle.Singleton); Container.Register(Lifestyle.Singleton); diff --git a/src/RepoM.App/RepoM.App.csproj b/src/RepoM.App/RepoM.App.csproj index 30a10283..f7ab42fc 100644 --- a/src/RepoM.App/RepoM.App.csproj +++ b/src/RepoM.App/RepoM.App.csproj @@ -39,15 +39,15 @@ - + - + - + @@ -70,4 +70,7 @@ Settings.Designer.cs + + + \ No newline at end of file diff --git a/src/RepoM.Core.Plugin/RepoM.Core.Plugin.csproj b/src/RepoM.Core.Plugin/RepoM.Core.Plugin.csproj index d42797f6..430c4679 100644 --- a/src/RepoM.Core.Plugin/RepoM.Core.Plugin.csproj +++ b/src/RepoM.Core.Plugin/RepoM.Core.Plugin.csproj @@ -5,8 +5,12 @@ - + - + + + + + diff --git a/src/RepoM.Plugin.AzureDevOps/ActionProvider/ActionAzureDevOpsCreatePullRequestsV1Mapper.cs b/src/RepoM.Plugin.AzureDevOps/ActionProvider/ActionAzureDevOpsCreatePullRequestsV1Mapper.cs index 6aee41ef..2da5cf47 100644 --- a/src/RepoM.Plugin.AzureDevOps/ActionProvider/ActionAzureDevOpsCreatePullRequestsV1Mapper.cs +++ b/src/RepoM.Plugin.AzureDevOps/ActionProvider/ActionAzureDevOpsCreatePullRequestsV1Mapper.cs @@ -77,7 +77,7 @@ public IEnumerable Map(RepositoryAction action, IEnumerabl // check if branch exists! if (!repository.Branches.Contains(action.ToBranch)) { - _logger.LogInformation("Branch '{branch}' does not exist", action.ToBranch); + _logger.LogInformation("Branch {branch} does not exist", action.ToBranch); return Array.Empty(); } } diff --git a/src/RepoM.Plugin.AzureDevOps/RepoM.Plugin.AzureDevOps.csproj b/src/RepoM.Plugin.AzureDevOps/RepoM.Plugin.AzureDevOps.csproj index b7ec5aac..c5685a27 100644 --- a/src/RepoM.Plugin.AzureDevOps/RepoM.Plugin.AzureDevOps.csproj +++ b/src/RepoM.Plugin.AzureDevOps/RepoM.Plugin.AzureDevOps.csproj @@ -5,7 +5,7 @@ - + @@ -16,4 +16,8 @@ + + + + diff --git a/src/RepoM.Plugin.Clipboard/RepoM.Plugin.Clipboard.csproj b/src/RepoM.Plugin.Clipboard/RepoM.Plugin.Clipboard.csproj index ca3deaef..31bbfba9 100644 --- a/src/RepoM.Plugin.Clipboard/RepoM.Plugin.Clipboard.csproj +++ b/src/RepoM.Plugin.Clipboard/RepoM.Plugin.Clipboard.csproj @@ -5,7 +5,7 @@ - + @@ -13,4 +13,8 @@ + + + + diff --git a/src/RepoM.Plugin.EverythingFileSearch/RepoM.Plugin.EverythingFileSearch.csproj b/src/RepoM.Plugin.EverythingFileSearch/RepoM.Plugin.EverythingFileSearch.csproj index 3400e2ba..d7c3e13d 100644 --- a/src/RepoM.Plugin.EverythingFileSearch/RepoM.Plugin.EverythingFileSearch.csproj +++ b/src/RepoM.Plugin.EverythingFileSearch/RepoM.Plugin.EverythingFileSearch.csproj @@ -5,7 +5,7 @@ - + @@ -17,4 +17,8 @@ + + + + diff --git a/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs b/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs index 34198909..f47ac9ab 100644 --- a/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs +++ b/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs @@ -24,7 +24,7 @@ internal sealed class HeidiConfigurationService : IHeidiConfigurationService, ID private IFileSystemWatcher? _fileWatcher; private IDisposable? _eventSubscription; private Dictionary> _repositoryHeidiConfigs = new(); - private ImmutableArray _rawDatabases = new(); + private ImmutableArray _rawDatabases; private string? _heidiConfigFile; public event EventHandler? ConfigurationUpdated; @@ -110,7 +110,7 @@ private async void OnFileUpdate(FileSystemEventArgs e) { try { - _logger.LogDebug("Filename changed '{name}' '{type}' '{fullPath}'", e.Name, e.ChangeType, e.FullPath); + _logger.LogDebug("Filename {name} {type} ({fullPath})", e.Name, e.ChangeType, e.FullPath); // for now, check exact path and file if (!e.FullPath.Equals(_heidiConfigFile, StringComparison.CurrentCultureIgnoreCase)) diff --git a/src/RepoM.Plugin.Heidi/RepoM.Plugin.Heidi.csproj b/src/RepoM.Plugin.Heidi/RepoM.Plugin.Heidi.csproj index f0cd40f7..80914bbb 100644 --- a/src/RepoM.Plugin.Heidi/RepoM.Plugin.Heidi.csproj +++ b/src/RepoM.Plugin.Heidi/RepoM.Plugin.Heidi.csproj @@ -5,7 +5,7 @@ - + @@ -14,4 +14,8 @@ + + + + diff --git a/src/RepoM.Plugin.LuceneQueryParser/RepoM.Plugin.LuceneQueryParser.csproj b/src/RepoM.Plugin.LuceneQueryParser/RepoM.Plugin.LuceneQueryParser.csproj index 5bcfb7cd..cf0fc85e 100644 --- a/src/RepoM.Plugin.LuceneQueryParser/RepoM.Plugin.LuceneQueryParser.csproj +++ b/src/RepoM.Plugin.LuceneQueryParser/RepoM.Plugin.LuceneQueryParser.csproj @@ -6,11 +6,15 @@ - + + + + + diff --git a/src/RepoM.Plugin.SonarCloud/RepoM.Plugin.SonarCloud.csproj b/src/RepoM.Plugin.SonarCloud/RepoM.Plugin.SonarCloud.csproj index 88bb8159..98b14c1b 100644 --- a/src/RepoM.Plugin.SonarCloud/RepoM.Plugin.SonarCloud.csproj +++ b/src/RepoM.Plugin.SonarCloud/RepoM.Plugin.SonarCloud.csproj @@ -5,7 +5,7 @@ - + @@ -13,4 +13,8 @@ + + + + diff --git a/src/RepoM.Plugin.Statistics/RepoM.Plugin.Statistics.csproj b/src/RepoM.Plugin.Statistics/RepoM.Plugin.Statistics.csproj index 85efa631..ac481766 100644 --- a/src/RepoM.Plugin.Statistics/RepoM.Plugin.Statistics.csproj +++ b/src/RepoM.Plugin.Statistics/RepoM.Plugin.Statistics.csproj @@ -5,7 +5,7 @@ - + @@ -14,4 +14,8 @@ + + + + diff --git a/src/RepoM.Plugin.WindowsExplorerGitInfo/RepoM.Plugin.WindowsExplorerGitInfo.csproj b/src/RepoM.Plugin.WindowsExplorerGitInfo/RepoM.Plugin.WindowsExplorerGitInfo.csproj index e9499fdb..3d5667da 100644 --- a/src/RepoM.Plugin.WindowsExplorerGitInfo/RepoM.Plugin.WindowsExplorerGitInfo.csproj +++ b/src/RepoM.Plugin.WindowsExplorerGitInfo/RepoM.Plugin.WindowsExplorerGitInfo.csproj @@ -5,7 +5,7 @@ - + @@ -14,4 +14,8 @@ + + + + diff --git a/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs index e346cc73..403e4e69 100644 --- a/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Api.Tests/DynamicRepositoryActionDeserializerFactory.cs @@ -10,34 +10,38 @@ namespace RepoM.Api.Tests; internal static class DynamicRepositoryActionDeserializerFactory { - public static JsonDynamicRepositoryActionDeserializer Create() + public static YamlDynamicRepositoryActionDeserializer Create() { - return new JsonDynamicRepositoryActionDeserializer( - new ActionDeserializerComposition( - new IActionDeserializer[] - { - new ActionExecutableV1Deserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new ActionFolderV1Deserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new DefaultActionDeserializer(), - new ActionForEachV1Deserializer(), - new DefaultActionDeserializer(), - }, - Array.Empty>())); + return new YamlDynamicRepositoryActionDeserializer(CreateActionDeserializerComposition()); } public static YamlDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) { - var jsonDynamicRepositoryActionDeserializer = new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); - return new YamlDynamicRepositoryActionDeserializer(jsonDynamicRepositoryActionDeserializer); + var actionDeserializerComposition = new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>()); + return new YamlDynamicRepositoryActionDeserializer(actionDeserializerComposition); + } + + private static ActionDeserializerComposition CreateActionDeserializerComposition() + { + return new ActionDeserializerComposition( + new IActionDeserializer[] + { + new ActionExecutableV1Deserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new ActionFolderV1Deserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new DefaultActionDeserializer(), + new ActionForEachV1Deserializer(), + new DefaultActionDeserializer(), + }, + Array.Empty>()); } } \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DocumentationTests.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DocumentationTests.cs index 027017a0..3f53509e 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DocumentationTests.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DocumentationTests.cs @@ -19,7 +19,7 @@ public class DocumentationTests public DocumentationTests() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("DocumentationFiles"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs index 7d74f379..23d5c185 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/DynamicRepositoryActionDeserializerTest.cs @@ -22,7 +22,7 @@ public class DynamicRepositoryActionDeserializerTest public DynamicRepositoryActionDeserializerTest() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositoryConfigurationReaderTests.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositoryConfigurationReaderTests.cs new file mode 100644 index 00000000..84368c9a --- /dev/null +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositoryConfigurationReaderTests.cs @@ -0,0 +1,38 @@ +namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; + +using System; +using System.IO.Abstractions; +using System.Runtime.Caching; +using FakeItEasy; +using FluentAssertions; +using Microsoft.Extensions.Logging; +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; +using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; +using RepoM.Core.Plugin.Common; +using RepoM.Core.Plugin.Expressions; +using Xunit; + +public class RepositoryConfigurationReaderTests +{ + [Fact] + public void Ctor_ShouldThrow_WhenArgumentNull() + { + // arrange + + // act + Func act1 = () => new RepositoryConfigurationReader(A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy(), null!); + Func act2 = () => new RepositoryConfigurationReader(A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy(), null!, A.Dummy()); + Func act3 = () => new RepositoryConfigurationReader(A.Dummy(), A.Dummy(), A.Dummy(), null!, A.Dummy(), A.Dummy()); + Func act4 = () => new RepositoryConfigurationReader(A.Dummy(), A.Dummy(), null!, A.Dummy(), A.Dummy(), A.Dummy()); + Func act5 = () => new RepositoryConfigurationReader(A.Dummy(), null!, A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy()); + Func act6 = () => new RepositoryConfigurationReader(null!, A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy(), A.Dummy()); + + // assert + act1.Should().Throw(); + act2.Should().Throw(); + act3.Should().Throw(); + act4.Should().Throw(); + act5.Should().Throw(); + act6.Should().Throw(); + } +} \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs index a6f6085c..3935f11f 100644 --- a/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs +++ b/tests/RepoM.Api.Tests/IO/ModuleBasedRepositoryActionProvider/RepositorySpecificConfigurationTest.cs @@ -4,6 +4,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using System.Collections.Generic; using System.IO; using System.IO.Abstractions.TestingHelpers; +using System.Runtime.Caching; using System.Text; using System.Threading.Tasks; using EasyTestFile; @@ -62,8 +63,7 @@ public RepositorySpecificConfigurationTest() _appDataPathProvider = A.Fake(); A.CallTo(() => _appDataPathProvider.AppDataPath).Returns(_tempPath); - JsonDynamicRepositoryActionDeserializer jsonAppSettingsDeserializer = DynamicRepositoryActionDeserializerFactory.Create(); - _yamlAppSettingsDeserializer = new YamlDynamicRepositoryActionDeserializer(jsonAppSettingsDeserializer); + _yamlAppSettingsDeserializer = DynamicRepositoryActionDeserializerFactory.Create(); var dateTimeTimeVariableProviderOptions = new DateTimeVariableProviderOptions() { @@ -211,6 +211,7 @@ private RepositorySpecificConfiguration CreateSut() _fileSystem, _yamlAppSettingsDeserializer, _repositoryExpressionEvaluator, - NullLogger.Instance)); + NullLogger.Instance, + new MemoryCache(Guid.NewGuid().ToString()))); } } \ No newline at end of file diff --git a/tests/RepoM.Api.Tests/RepoM.Api.Tests.csproj b/tests/RepoM.Api.Tests/RepoM.Api.Tests.csproj index 51750d6d..fb7ffc32 100644 --- a/tests/RepoM.Api.Tests/RepoM.Api.Tests.csproj +++ b/tests/RepoM.Api.Tests/RepoM.Api.Tests.csproj @@ -15,20 +15,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.App.Tests/RepoM.App.Tests.csproj b/tests/RepoM.App.Tests/RepoM.App.Tests.csproj index 20bf7d59..d04e35fa 100644 --- a/tests/RepoM.App.Tests/RepoM.App.Tests.csproj +++ b/tests/RepoM.App.Tests/RepoM.App.Tests.csproj @@ -15,20 +15,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/AzureDevOpsGetPullRequestsV1Test.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/AzureDevOpsGetPullRequestsV1Test.cs index 8f29383e..abca7bd4 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/AzureDevOpsGetPullRequestsV1Test.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/AzureDevOpsGetPullRequestsV1Test.cs @@ -9,48 +9,43 @@ namespace RepoM.Plugin.AzureDevOps.Tests.ActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; -using RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Plugin.AzureDevOps.ActionProvider.Options; using VerifyTests; using VerifyXunit; using Xunit; -using XunitEnumMemberData; [UsesEasyTestFile] [UsesVerify] public class AzureDevOpsGetPullRequestsV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sutJson; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; - private readonly YamlDynamicRepositoryActionDeserializer _sutYaml; + private readonly YamlDynamicRepositoryActionDeserializer _sut; public AzureDevOpsGetPullRequestsV1Test() { - _sutJson = CreateWithDeserializer(new DefaultActionDeserializer()); - _sutYaml = new YamlDynamicRepositoryActionDeserializer(_sutJson); + _sut = new YamlDynamicRepositoryActionDeserializer(CreateWithDeserializer(new DefaultActionDeserializer())); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize(SerializationType type) + [Fact] + public async Task Deserialize() { // arrange - var content = await EasyTestFile.LoadAsText(_testFileSettings.SetExtension(type)); + var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, type); + RepositoryActionConfiguration result = SutDeserialize(content); // assert - await Verifier.Verify(result, _verifySettings).IgnoreParametersForVerified(type); + await Verifier.Verify(result, _verifySettings); } [Fact] @@ -61,24 +56,19 @@ public async Task Deserialize_ShouldBeOfExpectedType() var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, SerializationType.Json); + RepositoryActionConfiguration result = SutDeserialize(content); // assert _ = result.ActionsCollection.Actions.Should().AllBeOfType(); } - private RepositoryActionConfiguration SutDeserialize(string rawContent, SerializationType type) + private RepositoryActionConfiguration SutDeserialize(string rawContent) { - return type switch - { - SerializationType.Json => _sutJson.Deserialize(rawContent), - SerializationType.Yaml => _sutYaml.Deserialize(rawContent), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), - }; + return _sut.Deserialize(rawContent); } - private static JsonDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) + private static ActionDeserializerComposition CreateWithDeserializer(IActionDeserializer actionDeserializer) { - return new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new IActionDeserializer[] { actionDeserializer, }, Array.Empty>())); + return new ActionDeserializerComposition(new IActionDeserializer[] { actionDeserializer, }, Array.Empty>()); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/TestFiles/AzureDevOpsGetPullRequestsV1Test.Deserialize.testfile.json b/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/TestFiles/AzureDevOpsGetPullRequestsV1Test.Deserialize.testfile.json deleted file mode 100644 index 6decd93d..00000000 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionProvider/TestFiles/AzureDevOpsGetPullRequestsV1Test.Deserialize.testfile.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "azure-devops-get-prs@1", - "show-when-empty": true, - "repository-id": "repo_id_guid", - "project-id": "{var.AzureDevOpsProjectId}" - }, - { - "type": "azure-devops-get-prs@1", - "show-when-empty": "false", - "project-id": "abc" - }, - { - "type": "azure-devops-get-prs@1", - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/DocumentationTests.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/DocumentationTests.cs index 7e4d983f..1830ef7d 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/DocumentationTests.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/DocumentationTests.cs @@ -20,7 +20,7 @@ public class DocumentationTests public DocumentationTests() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("DocumentationFiles"); diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/RepoM.Plugin.AzureDevOps.Tests.csproj b/tests/RepoM.Plugin.AzureDevOps.Tests/RepoM.Plugin.AzureDevOps.Tests.csproj index 64a505dd..6a43daa3 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/RepoM.Plugin.AzureDevOps.Tests.csproj +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/RepoM.Plugin.AzureDevOps.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs index 2600f060..47ce64b9 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs @@ -10,9 +10,9 @@ namespace RepoM.Plugin.AzureDevOps.Tests.TestFramework; internal static class DynamicRepositoryActionDeserializerFactory { - public static JsonDynamicRepositoryActionDeserializer Create() + public static YamlDynamicRepositoryActionDeserializer Create() { - return new JsonDynamicRepositoryActionDeserializer( + return new YamlDynamicRepositoryActionDeserializer( new ActionDeserializerComposition( new IActionDeserializer[] { @@ -22,8 +22,8 @@ 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>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/ActionClipboardCopyV1DeserializerTest.cs b/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/ActionClipboardCopyV1DeserializerTest.cs index 9a90984d..eee6f60b 100644 --- a/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/ActionClipboardCopyV1DeserializerTest.cs +++ b/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/ActionClipboardCopyV1DeserializerTest.cs @@ -9,48 +9,43 @@ namespace RepoM.Plugin.Clipboard.Tests.ActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; -using RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Plugin.Clipboard.ActionProvider; using VerifyTests; using VerifyXunit; using Xunit; -using XunitEnumMemberData; [UsesEasyTestFile] [UsesVerify] public class ActionClipboardCopyV1DeserializerTest { - private readonly JsonDynamicRepositoryActionDeserializer _sutJson; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; - private readonly YamlDynamicRepositoryActionDeserializer _sutYaml; + private readonly YamlDynamicRepositoryActionDeserializer _sut; public ActionClipboardCopyV1DeserializerTest() { - _sutJson = CreateWithDeserializer(new DefaultActionDeserializer()); - _sutYaml = new YamlDynamicRepositoryActionDeserializer(_sutJson); + _sut = CreateWithDeserializer(new DefaultActionDeserializer()); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize(SerializationType type) + [Fact] + public async Task Deserialize() { // arrange - 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] @@ -61,24 +56,14 @@ public async Task Deserialize_ShouldBeOfExpectedType() var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, SerializationType.Json); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert _ = result.ActionsCollection.Actions.Should().AllBeOfType(); } - private RepositoryActionConfiguration SutDeserialize(string rawContent, SerializationType type) - { - return type switch - { - SerializationType.Json => _sutJson.Deserialize(rawContent), - SerializationType.Yaml => _sutYaml.Deserialize(rawContent), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), - }; - } - - private static JsonDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) + private static YamlDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) { - return new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/TestFiles/ActionClipboardCopyV1DeserializerTest.Deserialize.testfile.json b/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/TestFiles/ActionClipboardCopyV1DeserializerTest.Deserialize.testfile.json deleted file mode 100644 index 0131bccc..00000000 --- a/tests/RepoM.Plugin.Clipboard.Tests/ActionProvider/TestFiles/ActionClipboardCopyV1DeserializerTest.Deserialize.testfile.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "clipboard-copy@1", - "name": "Copy to clipboard", - "text": "x {var.data} z", - "active": true - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Clipboard.Tests/DocumentationTests.cs b/tests/RepoM.Plugin.Clipboard.Tests/DocumentationTests.cs index 92186af2..67965f24 100644 --- a/tests/RepoM.Plugin.Clipboard.Tests/DocumentationTests.cs +++ b/tests/RepoM.Plugin.Clipboard.Tests/DocumentationTests.cs @@ -20,7 +20,7 @@ public class DocumentationTests public DocumentationTests() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("DocumentationFiles"); diff --git a/tests/RepoM.Plugin.Clipboard.Tests/RepoM.Plugin.Clipboard.Tests.csproj b/tests/RepoM.Plugin.Clipboard.Tests/RepoM.Plugin.Clipboard.Tests.csproj index 97d81a7f..01a99239 100644 --- a/tests/RepoM.Plugin.Clipboard.Tests/RepoM.Plugin.Clipboard.Tests.csproj +++ b/tests/RepoM.Plugin.Clipboard.Tests/RepoM.Plugin.Clipboard.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.Clipboard.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Plugin.Clipboard.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs index 4f0b48c3..32d8049c 100644 --- a/tests/RepoM.Plugin.Clipboard.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Plugin.Clipboard.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs @@ -10,9 +10,9 @@ namespace RepoM.Plugin.Clipboard.Tests.TestFramework; internal static class DynamicRepositoryActionDeserializerFactory { - public static JsonDynamicRepositoryActionDeserializer Create() + public static YamlDynamicRepositoryActionDeserializer Create() { - return new JsonDynamicRepositoryActionDeserializer( + return new YamlDynamicRepositoryActionDeserializer( new ActionDeserializerComposition( new IActionDeserializer[] { @@ -21,8 +21,8 @@ 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>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.EverythingFileSearch.Tests/RepoM.Plugin.EverythingFileSearch.Tests.csproj b/tests/RepoM.Plugin.EverythingFileSearch.Tests/RepoM.Plugin.EverythingFileSearch.Tests.csproj index e8c172b4..eb49c5f9 100644 --- a/tests/RepoM.Plugin.EverythingFileSearch.Tests/RepoM.Plugin.EverythingFileSearch.Tests.csproj +++ b/tests/RepoM.Plugin.EverythingFileSearch.Tests/RepoM.Plugin.EverythingFileSearch.Tests.csproj @@ -15,17 +15,18 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/ActionHeidiDatabasesV1DeserializerTest.cs b/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/ActionHeidiDatabasesV1DeserializerTest.cs index 3e88c90a..7f0e42ce 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/ActionHeidiDatabasesV1DeserializerTest.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/ActionHeidiDatabasesV1DeserializerTest.cs @@ -9,48 +9,42 @@ namespace RepoM.Plugin.Heidi.Tests.ActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; -using RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Plugin.Heidi.ActionProvider; using VerifyTests; using VerifyXunit; using Xunit; -using XunitEnumMemberData; [UsesEasyTestFile] [UsesVerify] public class ActionHeidiDatabasesV1DeserializerTest { - private readonly JsonDynamicRepositoryActionDeserializer _sutJson; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; - private readonly YamlDynamicRepositoryActionDeserializer _sutYaml; + private readonly YamlDynamicRepositoryActionDeserializer _sut; public ActionHeidiDatabasesV1DeserializerTest() { - _sutJson = CreateWithDeserializer(new DefaultActionDeserializer()); - _sutYaml = new YamlDynamicRepositoryActionDeserializer(_sutJson); - + _sut = CreateWithDeserializer(new DefaultActionDeserializer()); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize(SerializationType type) + [Fact] + public async Task Deserialize() { // arrange - 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] @@ -61,24 +55,14 @@ public async Task Deserialize_ShouldBeOfExpectedType() var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, SerializationType.Json); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert _ = result.ActionsCollection.Actions.Should().AllBeOfType(); } - private RepositoryActionConfiguration SutDeserialize(string rawContent, SerializationType type) - { - return type switch - { - SerializationType.Json => _sutJson.Deserialize(rawContent), - SerializationType.Yaml => _sutYaml.Deserialize(rawContent), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), - }; - } - - private static JsonDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) + private static YamlDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) { - return new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/TestFiles/ActionHeidiDatabasesV1DeserializerTest.Deserialize.testfile.json b/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/TestFiles/ActionHeidiDatabasesV1DeserializerTest.Deserialize.testfile.json deleted file mode 100644 index 65cb52be..00000000 --- a/tests/RepoM.Plugin.Heidi.Tests/ActionProvider/TestFiles/ActionHeidiDatabasesV1DeserializerTest.Deserialize.testfile.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "heidi-databases@1", - "name": "My Databases", - "executable": "{var.HeidiExe}", - "active": true - }, - { - "type": "heidi-databases@1", - "name": "My Databases with default heidi", - "active": true - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Heidi.Tests/DocumentationTests.cs b/tests/RepoM.Plugin.Heidi.Tests/DocumentationTests.cs index 885b36ca..3dba7591 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/DocumentationTests.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/DocumentationTests.cs @@ -20,7 +20,7 @@ public class DocumentationTests public DocumentationTests() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("DocumentationFiles"); diff --git a/tests/RepoM.Plugin.Heidi.Tests/RepoM.Plugin.Heidi.Tests.csproj b/tests/RepoM.Plugin.Heidi.Tests/RepoM.Plugin.Heidi.Tests.csproj index 7b2fcc2b..74076db4 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/RepoM.Plugin.Heidi.Tests.csproj +++ b/tests/RepoM.Plugin.Heidi.Tests/RepoM.Plugin.Heidi.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.Heidi.Tests/TestFiles/AzureDevOpsPullRequestsV1Test.Deserialize.testfile.json b/tests/RepoM.Plugin.Heidi.Tests/TestFiles/AzureDevOpsPullRequestsV1Test.Deserialize.testfile.json deleted file mode 100644 index 6decd93d..00000000 --- a/tests/RepoM.Plugin.Heidi.Tests/TestFiles/AzureDevOpsPullRequestsV1Test.Deserialize.testfile.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "azure-devops-get-prs@1", - "show-when-empty": true, - "repository-id": "repo_id_guid", - "project-id": "{var.AzureDevOpsProjectId}" - }, - { - "type": "azure-devops-get-prs@1", - "show-when-empty": "false", - "project-id": "abc" - }, - { - "type": "azure-devops-get-prs@1", - "active": false - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.Heidi.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Plugin.Heidi.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs index 2762c84c..6e8bad15 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs @@ -10,9 +10,9 @@ namespace RepoM.Plugin.Heidi.Tests.TestFramework; internal static class DynamicRepositoryActionDeserializerFactory { - public static JsonDynamicRepositoryActionDeserializer Create() + public static YamlDynamicRepositoryActionDeserializer Create() { - return new JsonDynamicRepositoryActionDeserializer( + return new YamlDynamicRepositoryActionDeserializer( new ActionDeserializerComposition( new IActionDeserializer[] { @@ -21,8 +21,8 @@ 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>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.LuceneQueryParser.Tests/RepoM.Plugin.LuceneQueryParser.Tests.csproj b/tests/RepoM.Plugin.LuceneQueryParser.Tests/RepoM.Plugin.LuceneQueryParser.Tests.csproj index a7198a7d..cdd5ee96 100644 --- a/tests/RepoM.Plugin.LuceneQueryParser.Tests/RepoM.Plugin.LuceneQueryParser.Tests.csproj +++ b/tests/RepoM.Plugin.LuceneQueryParser.Tests/RepoM.Plugin.LuceneQueryParser.Tests.csproj @@ -15,19 +15,19 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all 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 7a239cf2..8e636b44 100644 --- a/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj +++ b/tests/RepoM.Plugin.Misc.Tests/RepoM.Plugin.Misc.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/DocumentationTests.cs b/tests/RepoM.Plugin.SonarCloud.Tests/DocumentationTests.cs index d035150a..0e3e3160 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/DocumentationTests.cs +++ b/tests/RepoM.Plugin.SonarCloud.Tests/DocumentationTests.cs @@ -20,7 +20,7 @@ public class DocumentationTests public DocumentationTests() { - _sut = new YamlDynamicRepositoryActionDeserializer(DynamicRepositoryActionDeserializerFactory.Create()); + _sut = DynamicRepositoryActionDeserializerFactory.Create(); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("DocumentationFiles"); diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/RepoM.Plugin.SonarCloud.Tests.csproj b/tests/RepoM.Plugin.SonarCloud.Tests/RepoM.Plugin.SonarCloud.Tests.csproj index e2d4b02e..306c09b2 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/RepoM.Plugin.SonarCloud.Tests.csproj +++ b/tests/RepoM.Plugin.SonarCloud.Tests/RepoM.Plugin.SonarCloud.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudSetFavoriteV1Test.cs b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudSetFavoriteV1Test.cs index 28ed587d..85487004 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudSetFavoriteV1Test.cs +++ b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudSetFavoriteV1Test.cs @@ -9,48 +9,43 @@ namespace RepoM.Plugin.SonarCloud.Tests; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionDeserializers; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; -using RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider; using RepoM.Core.Plugin.RepositoryOrdering.Configuration; using RepoM.Plugin.SonarCloud; using VerifyTests; using VerifyXunit; using Xunit; -using XunitEnumMemberData; [UsesEasyTestFile] [UsesVerify] public class SonarCloudSetFavoriteV1Test { - private readonly JsonDynamicRepositoryActionDeserializer _sutJson; private readonly EasyTestFileSettings _testFileSettings; private readonly VerifySettings _verifySettings; - private readonly YamlDynamicRepositoryActionDeserializer _sutYaml; + private readonly YamlDynamicRepositoryActionDeserializer _sut; public SonarCloudSetFavoriteV1Test() { - _sutJson = CreateWithDeserializer(new DefaultActionDeserializer()); - _sutYaml = new YamlDynamicRepositoryActionDeserializer(_sutJson); + _sut = CreateWithDeserializer(new DefaultActionDeserializer()); _testFileSettings = new EasyTestFileSettings(); _testFileSettings.UseDirectory("TestFiles"); - _testFileSettings.UseExtension("json"); + _testFileSettings.UseExtension("yaml"); _verifySettings = new VerifySettings(); _verifySettings.UseDirectory("Verified"); } - [Theory] - [EnumMemberData(typeof(SerializationType))] - public async Task Deserialize(SerializationType type) + [Fact] + public async Task Deserialize() { // arrange - 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] @@ -61,24 +56,14 @@ public async Task Deserialize_ShouldBeOfExpectedType() var content = await EasyTestFile.LoadAsText(_testFileSettings); // act - RepositoryActionConfiguration result = SutDeserialize(content, SerializationType.Json); + RepositoryActionConfiguration result = _sut.Deserialize(content); // assert _ = result.ActionsCollection.Actions.Should().AllBeOfType(); } - private RepositoryActionConfiguration SutDeserialize(string rawContent, SerializationType type) - { - return type switch - { - SerializationType.Json => _sutJson.Deserialize(rawContent), - SerializationType.Yaml => _sutYaml.Deserialize(rawContent), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), - }; - } - - private static JsonDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) + private static YamlDynamicRepositoryActionDeserializer CreateWithDeserializer(IActionDeserializer actionDeserializer) { - return new JsonDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new IActionDeserializer[] { actionDeserializer, }, Array.Empty>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new IActionDeserializer[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/TestFiles/SonarCloudSetFavoriteV1Test.Deserialize.testfile.json b/tests/RepoM.Plugin.SonarCloud.Tests/TestFiles/SonarCloudSetFavoriteV1Test.Deserialize.testfile.json deleted file mode 100644 index 249e6850..00000000 --- a/tests/RepoM.Plugin.SonarCloud.Tests/TestFiles/SonarCloudSetFavoriteV1Test.Deserialize.testfile.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "repository-actions": { - "actions": [ - { - "type": "sonarcloud-set-favorite@1", - "name": "Star project", - "project": "project-a", - "active": true - } - ] - } -} \ No newline at end of file diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs b/tests/RepoM.Plugin.SonarCloud.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs index a8e73c37..14a88c3b 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs +++ b/tests/RepoM.Plugin.SonarCloud.Tests/TestFramework/DynamicRepositoryActionDeserializerFactory.cs @@ -9,9 +9,9 @@ namespace RepoM.Plugin.SonarCloud.Tests.TestFramework; internal static class DynamicRepositoryActionDeserializerFactory { - public static JsonDynamicRepositoryActionDeserializer Create() + public static YamlDynamicRepositoryActionDeserializer Create() { - return new JsonDynamicRepositoryActionDeserializer( + return new YamlDynamicRepositoryActionDeserializer( new ActionDeserializerComposition( new IActionDeserializer[] { @@ -20,8 +20,8 @@ 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>())); + return new YamlDynamicRepositoryActionDeserializer(new ActionDeserializerComposition(new[] { actionDeserializer, }, Array.Empty>())); } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Statistics.Tests/RepoM.Plugin.Statistics.Tests.csproj b/tests/RepoM.Plugin.Statistics.Tests/RepoM.Plugin.Statistics.Tests.csproj index 7af43d52..ecb213b4 100644 --- a/tests/RepoM.Plugin.Statistics.Tests/RepoM.Plugin.Statistics.Tests.csproj +++ b/tests/RepoM.Plugin.Statistics.Tests/RepoM.Plugin.Statistics.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests.csproj b/tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests.csproj index e652275b..aca46131 100644 --- a/tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests.csproj +++ b/tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests/RepoM.Plugin.WindowsExplorerGitInfo.Tests.csproj @@ -16,20 +16,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SystemTests/DefaultRepositoryMonitorTests.cs b/tests/SystemTests/DefaultRepositoryMonitorTests.cs index 01e68ebf..57020dc1 100644 --- a/tests/SystemTests/DefaultRepositoryMonitorTests.cs +++ b/tests/SystemTests/DefaultRepositoryMonitorTests.cs @@ -7,9 +7,9 @@ namespace SystemTests; using System.IO.Abstractions; using System.Linq; using System.Threading; +using FakeItEasy; using FluentAssertions; using Microsoft.Extensions.Logging.Abstractions; -using Moq; using NUnit.Framework; using RepoM.Api.Common; using RepoM.Api.Git; @@ -41,21 +41,21 @@ public void OneTimeSetUp() var repoPath = Path.Combine(_rootPath, Guid.NewGuid().ToString()); _fileSystem.Directory.CreateDirectory(repoPath); - var appSettingsService = new Mock(); - appSettingsService.Setup(x => x.EnabledSearchProviders).Returns(new List(0)); + IAppSettingsService appSettingsService = A.Fake(); + A.CallTo(() => appSettingsService.EnabledSearchProviders).Returns(new List(0)); - var defaultRepositoryReader = new DefaultRepositoryReader(new Mock().Object, NullLogger.Instance); + var defaultRepositoryReader = new DefaultRepositoryReader(A.Dummy(), NullLogger.Instance); _monitor = new DefaultRepositoryMonitor( new GivenPathProvider(new [] { repoPath, }), defaultRepositoryReader, new DefaultRepositoryDetectorFactory(defaultRepositoryReader), new DefaultRepositoryObserverFactory(), - new GitRepositoryFinderFactory(appSettingsService.Object, new List() { new GravellGitRepositoryFinderFactory(new NeverSkippingPathSkipper(), _fileSystem), }), + new GitRepositoryFinderFactory(appSettingsService, new List() { new GravellGitRepositoryFinderFactory(new NeverSkippingPathSkipper(), _fileSystem), }), new UselessRepositoryStore(), new DefaultRepositoryInformationAggregator( new DirectThreadDispatcher()), - new Mock().Object, - new Mock().Object, + A.Dummy(), + A.Dummy(), _fileSystem) { DelayGitRepositoryStatusAfterCreationMilliseconds = 100, diff --git a/tests/SystemTests/SystemTests.csproj b/tests/SystemTests/SystemTests.csproj index b742cc87..68ae4869 100644 --- a/tests/SystemTests/SystemTests.csproj +++ b/tests/SystemTests/SystemTests.csproj @@ -18,20 +18,19 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + - - + + - - + +