diff --git a/src/RepoM.Api/Common/AppSettings.cs b/src/RepoM.Api/Common/AppSettings.cs index 304128b5..8d1a8384 100644 --- a/src/RepoM.Api/Common/AppSettings.cs +++ b/src/RepoM.Api/Common/AppSettings.cs @@ -37,7 +37,7 @@ public sealed class AppSettings /// This option determines if RepoM should prune branches when fetching from git. /// [UiConfigured] - public bool PruneOnFetch { get; set; } = false; + public bool PruneOnFetch { get; set; } /// /// Preferred menu sizes of the RepoM. Will be set when window is resized. diff --git a/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs b/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs index 0d4ce78e..927e5e98 100644 --- a/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs +++ b/src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs @@ -26,6 +26,7 @@ internal sealed class HeidiConfigurationService : IHeidiConfigurationService, ID private Dictionary> _repositoryHeidiConfigs = new(); private ImmutableArray _rawDatabases; private string? _heidiConfigFile; + internal readonly TimeSpan FileEventsThrottleTimeout = TimeSpan.FromSeconds(1); public event EventHandler? ConfigurationUpdated; @@ -55,7 +56,7 @@ public Task InitializeAsync() .FromEventPattern(_fileWatcher, nameof(_fileWatcher.Changed)) .ObserveOn(Scheduler.Default) .Select(e => e.EventArgs) - .Throttle(TimeSpan.FromSeconds(1)) + .Throttle(FileEventsThrottleTimeout) .Subscribe(OnFileUpdate); Task.Run(() => OnFileUpdate(new FileSystemEventArgs(WatcherChangeTypes.Changed, _settings.ConfigPath, _settings.ConfigFilename))); @@ -137,7 +138,7 @@ private async void OnFileUpdate(FileSystemEventArgs e) repository, heidiDatabases.Single(x => x.Key.Equals(repository.HeidiKey)), e.FullPath); - newResult.TryAdd(repository.Repository, new List()); + newResult.TryAdd(repository.Repository, []); newResult[repository.Repository].Add(item); } diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionMenu/Model/ActionMenus/CreatePullRequest/RepositoryActionAzureDevOpsCreatePullRequestV1MapperTests.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/ActionMenu/Model/ActionMenus/CreatePullRequest/RepositoryActionAzureDevOpsCreatePullRequestV1MapperTests.cs index 64ccb228..3da74431 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/ActionMenu/Model/ActionMenus/CreatePullRequest/RepositoryActionAzureDevOpsCreatePullRequestV1MapperTests.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/ActionMenu/Model/ActionMenus/CreatePullRequest/RepositoryActionAzureDevOpsCreatePullRequestV1MapperTests.cs @@ -10,7 +10,6 @@ namespace RepoM.Plugin.AzureDevOps.Tests.ActionMenu.Model.ActionMenus.CreatePull using RepoM.ActionMenu.Interface.ActionMenuFactory; using RepoM.ActionMenu.Interface.UserInterface; using RepoM.ActionMenu.Interface.YamlModel; -using RepoM.ActionMenu.Interface.YamlModel.Templating; using RepoM.Core.Plugin.Repository; using RepoM.Plugin.AzureDevOps.ActionMenu.Model.ActionMenus.CreatePullRequest; using VerifyXunit; @@ -91,7 +90,7 @@ public async Task Map_ShouldReturnEmpty_WhenToBranchDoesNotExist() const string TO_BRANCH = "feature/abc-def"; _action.ToBranch = TO_BRANCH; A.CallTo(() => _repository.HasLocalChanges).Returns(false); - A.CallTo(() => _repository.Branches).Returns(new[] { "feature/ABC-def", "feature/abc-defx", "main", }); + A.CallTo(() => _repository.Branches).Returns(["feature/ABC-def", "feature/abc-defx", "main",]); A.CallTo(() => _context.RenderStringAsync(A._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0])); // act @@ -108,9 +107,9 @@ public async Task Map_ShouldReturnEmpty_WhenToBranchIsSameAsCurrentBranch() const string TO_BRANCH = "feature/abc-def"; _action.ToBranch = TO_BRANCH; A.CallTo(() => _repository.HasLocalChanges).Returns(false); - A.CallTo(() => _repository.Branches).Returns(new[] { "feature/abc-def", }); + A.CallTo(() => _repository.Branches).Returns(["feature/abc-def",]); A.CallTo(() => _repository.CurrentBranch).Returns(TO_BRANCH); - A.CallTo(() => _context.RenderStringAsync((A._))).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0])); + A.CallTo(() => _context.RenderStringAsync(A._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0])); // act List result = await _sut.MapAsync(_action, _context, _repository).ToListAsync(); @@ -128,7 +127,7 @@ public async Task Map_ShouldReturnEmptySet_WhenProjectIdNotSet() _action.ToBranch = TO_BRANCH; _action.ProjectId = PROJECT_ID; A.CallTo(() => _repository.HasLocalChanges).Returns(false); - A.CallTo(() => _repository.Branches).Returns(new[] { "main", }); + A.CallTo(() => _repository.Branches).Returns(["main",]); A.CallTo(() => _repository.CurrentBranch).Returns("feature/x"); A.CallTo(() => _context.RenderStringAsync(A._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0])); @@ -150,12 +149,12 @@ public async Task Map_ShouldReturnResult_WhenAllOkayWithoutAutoComplete() _action.DraftPr = "false"; _action.IncludeWorkItems = "false"; _action.OpenInBrowser = "true"; - _action.ReviewerIds = new List { "def", "abc", }; + _action.ReviewerIds = ["def", "abc",]; _action.PrTitle = "pr title"; _action.Name = "pr name"; A.CallTo(() => _repository.HasLocalChanges).Returns(false); - A.CallTo(() => _repository.Branches).Returns(new[] { "main", }); + A.CallTo(() => _repository.Branches).Returns(["main",]); A.CallTo(() => _repository.CurrentBranch).Returns("feature/x"); A.CallTo(() => _context.RenderStringAsync(A._)).ReturnsLazily(call => Task.FromResult("evaluated: " + call.Arguments[0])); A.CallTo(() => _context.RenderStringAsync(TO_BRANCH)).ReturnsLazily(call => Task.FromResult(TO_BRANCH)); @@ -178,7 +177,7 @@ public async Task Map_ShouldReturnResult_WhenAllOkayWithAutoComplete() _action.DraftPr = "false"; _action.IncludeWorkItems = "false"; _action.OpenInBrowser = "true"; - _action.ReviewerIds = new List { "def", "abc", }; + _action.ReviewerIds = ["def", "abc",]; _action.PrTitle = "pr title"; _action.Name = "pr name"; _action.AutoComplete = new AutoCompleteOptionsV1 @@ -189,7 +188,7 @@ public async Task Map_ShouldReturnResult_WhenAllOkayWithAutoComplete() }; A.CallTo(() => _repository.HasLocalChanges).Returns(false); - A.CallTo(() => _repository.Branches).Returns(new[] { "main", }); + A.CallTo(() => _repository.Branches).Returns(["main",]); A.CallTo(() => _repository.CurrentBranch).Returns("feature/x"); A.CallTo(() => _context.RenderStringAsync(A._)).ReturnsLazily(call => Task.FromResult("evaluated: " + call.Arguments[0])); A.CallTo(() => _context.RenderStringAsync(TO_BRANCH)).ReturnsLazily(call => Task.FromResult(TO_BRANCH)); diff --git a/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs b/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs index c2de0379..b85b4d90 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs @@ -23,7 +23,7 @@ namespace RepoM.Plugin.Heidi.Tests.Internal; public class HeidiConfigurationServiceTests { private const string FILENAME = "heidi.portable.txt"; - private const string PATH = "C:\\heidi\\"; + private const string PATH = @"C:\heidi\"; private readonly string _fullFilename = Path.Combine(PATH, FILENAME); private readonly TimeSpan _initTimeout = TimeSpan.FromSeconds(30); @@ -60,14 +60,13 @@ public HeidiConfigurationServiceTests() A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); A.CallTo(() => _repository.Remotes) - .Returns(new List - { - new("bb", "http://github.com/a/b.git"), - new("origin", "http://github.com/coenm/RepoM.git"), - }); - - _heidis = new List - { + .Returns([ + new("bb", "http://github.com/a/b.git"), + new("origin", "http://github.com/coenm/RepoM.git"), + ]); + + _heidis = + [ new RepoHeidi("OSS/Github/RepoM-P") { Name = "RepoM Prod", @@ -75,22 +74,27 @@ public HeidiConfigurationServiceTests() Tags = [], Repository = "RepoM", }, - new RepoHeidi("OSS/Github/RepoM-D") { + + new RepoHeidi("OSS/Github/RepoM-D") + { Name = "RepoM Dev!!", Order = 5, Tags = [], Repository = "RepoM", }, - new RepoHeidi("OSS/Abc") { + + new RepoHeidi("OSS/Abc") + { Name = "Abc Prod", Order = 0, Tags = [], Repository = "Abc", }, - }; - _heidiConfigurationResult = new List - { + ]; + + _heidiConfigurationResult = + [ new HeidiSingleDatabaseConfiguration("OSS/Github/RepoM-P") { // Order = 23, @@ -98,6 +102,7 @@ public HeidiConfigurationServiceTests() // Name = "RepoM Prod", // Repositories = new []{ "RepoM", }, }, + new HeidiSingleDatabaseConfiguration("OSS/Github/RepoM-D") { // Order = 5, @@ -105,6 +110,7 @@ public HeidiConfigurationServiceTests() // Name = "RepoM Dev!!", // Repositories = new []{ "RepoM", "RepomTest", }, }, + new HeidiSingleDatabaseConfiguration("OSS/Abc") { // Order = 0, @@ -112,7 +118,8 @@ public HeidiConfigurationServiceTests() // Name = "Abc Prod", // Repositories = new []{ "Abc", }, }, - }; + + ]; } public static IEnumerable CtorNullArguments @@ -320,7 +327,11 @@ public async Task Events_ShouldNotBeProcessed_WhenWrongFilename() .Returns(Task.FromResult(new List())); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(1)); + var poked = mre.WaitOne(TimeSpan.FromSeconds(5)); + if (poked) + { + await Task.Delay(_sut.FileEventsThrottleTimeout.Add(TimeSpan.FromMilliseconds(100))); + } Fake.ClearRecordedCalls(_configReader); // act @@ -328,6 +339,7 @@ public async Task Events_ShouldNotBeProcessed_WhenWrongFilename() await Task.Delay(TimeSpan.FromSeconds(10)); // assert + poked.Should().BeTrue(); A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustNotHaveHappened(); } diff --git a/tests/RepoM.Plugin.Statistics.Tests/Ordering/IntegrationTest.cs b/tests/RepoM.Plugin.Statistics.Tests/Ordering/IntegrationTest.cs index 5c26513b..33fd7a5c 100644 --- a/tests/RepoM.Plugin.Statistics.Tests/Ordering/IntegrationTest.cs +++ b/tests/RepoM.Plugin.Statistics.Tests/Ordering/IntegrationTest.cs @@ -72,17 +72,4 @@ public async Task LastOpenedConfiguration() // assert await Verifier.Verify(result, _verifySettings); } - - [Fact] - public async Task LastOpenedConfiguration1() - { - // arrange - await _fileSystem.AddEasyFile("C:\\\\dir\\RepoM.Ordering.yaml", _testFileSettings); - - // act - Dictionary result =_sut.Configuration; - - // assert - await Verifier.Verify(result, _verifySettings); - } } \ No newline at end of file diff --git a/tests/RepoM.Plugin.Statistics.Tests/Ordering/TestFiles/IntegrationTest.LastOpenedConfiguration1.testfile.yml b/tests/RepoM.Plugin.Statistics.Tests/Ordering/TestFiles/IntegrationTest.LastOpenedConfiguration1.testfile.yml deleted file mode 100644 index 158e785d..00000000 --- a/tests/RepoM.Plugin.Statistics.Tests/Ordering/TestFiles/IntegrationTest.LastOpenedConfiguration1.testfile.yml +++ /dev/null @@ -1,3 +0,0 @@ -Name1: - type: last-opened-comparer@1 - weight: 123 \ No newline at end of file diff --git a/tests/RepoM.Plugin.Statistics.Tests/Ordering/Verified/IntegrationTest.LastOpenedConfiguration1.verified.txt b/tests/RepoM.Plugin.Statistics.Tests/Ordering/Verified/IntegrationTest.LastOpenedConfiguration1.verified.txt deleted file mode 100644 index 6627b75e..00000000 --- a/tests/RepoM.Plugin.Statistics.Tests/Ordering/Verified/IntegrationTest.LastOpenedConfiguration1.verified.txt +++ /dev/null @@ -1,7 +0,0 @@ -{ - Name1: { - $type: LastOpenedConfigurationV1, - Type: last-opened-comparer@1, - Weight: 123 - } -} \ No newline at end of file