Skip to content

Commit

Permalink
try to fix test and update some code (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm authored Aug 27, 2024
1 parent 48cbd81 commit e09306c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/RepoM.Api/Common/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class AppSettings
/// This option determines if RepoM should prune branches when fetching from git.
/// </summary>
[UiConfigured]
public bool PruneOnFetch { get; set; } = false;
public bool PruneOnFetch { get; set; }

/// <summary>
/// Preferred menu sizes of the RepoM. Will be set when window is resized.
Expand Down
5 changes: 3 additions & 2 deletions src/RepoM.Plugin.Heidi/Internal/HeidiConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal sealed class HeidiConfigurationService : IHeidiConfigurationService, ID
private Dictionary<string, List<RepositoryHeidiConfiguration>> _repositoryHeidiConfigs = new();
private ImmutableArray<HeidiSingleDatabaseConfiguration> _rawDatabases;
private string? _heidiConfigFile;
internal readonly TimeSpan FileEventsThrottleTimeout = TimeSpan.FromSeconds(1);

public event EventHandler? ConfigurationUpdated;

Expand Down Expand Up @@ -55,7 +56,7 @@ public Task InitializeAsync()
.FromEventPattern<FileSystemEventArgs>(_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)));
Expand Down Expand Up @@ -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<RepositoryHeidiConfiguration>());
newResult.TryAdd(repository.Repository, []);
newResult[repository.Repository].Add(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0]));

// act
Expand All @@ -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<string>._))).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0]));
A.CallTo(() => _context.RenderStringAsync(A<string>._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0]));

// act
List<UserInterfaceRepositoryActionBase> result = await _sut.MapAsync(_action, _context, _repository).ToListAsync();
Expand All @@ -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<string>._)).ReturnsLazily(call => Task.FromResult(string.Empty + call.Arguments[0]));

Expand All @@ -150,12 +149,12 @@ public async Task Map_ShouldReturnResult_WhenAllOkayWithoutAutoComplete()
_action.DraftPr = "false";
_action.IncludeWorkItems = "false";
_action.OpenInBrowser = "true";
_action.ReviewerIds = new List<Text> { "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<string>._)).ReturnsLazily(call => Task.FromResult("evaluated: " + call.Arguments[0]));
A.CallTo(() => _context.RenderStringAsync(TO_BRANCH)).ReturnsLazily(call => Task.FromResult(TO_BRANCH));
Expand All @@ -178,7 +177,7 @@ public async Task Map_ShouldReturnResult_WhenAllOkayWithAutoComplete()
_action.DraftPr = "false";
_action.IncludeWorkItems = "false";
_action.OpenInBrowser = "true";
_action.ReviewerIds = new List<Text> { "def", "abc", };
_action.ReviewerIds = ["def", "abc",];
_action.PrTitle = "pr title";
_action.Name = "pr name";
_action.AutoComplete = new AutoCompleteOptionsV1
Expand All @@ -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<string>._)).ReturnsLazily(call => Task.FromResult("evaluated: " + call.Arguments[0]));
A.CallTo(() => _context.RenderStringAsync(TO_BRANCH)).ReturnsLazily(call => Task.FromResult(TO_BRANCH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -60,59 +60,66 @@ public HeidiConfigurationServiceTests()
A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true);

A.CallTo(() => _repository.Remotes)
.Returns(new List<Remote>
{
new("bb", "http://github.com/a/b.git"),
new("origin", "http://github.com/coenm/RepoM.git"),
});

_heidis = new List<RepoHeidi>
{
.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",
Order = 23,
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<HeidiSingleDatabaseConfiguration>
{
];

_heidiConfigurationResult =
[
new HeidiSingleDatabaseConfiguration("OSS/Github/RepoM-P")
{
// Order = 23,
// Environment = "Production",
// Name = "RepoM Prod",
// Repositories = new []{ "RepoM", },
},

new HeidiSingleDatabaseConfiguration("OSS/Github/RepoM-D")
{
// Order = 5,
// Environment = "Development",
// Name = "RepoM Dev!!",
// Repositories = new []{ "RepoM", "RepomTest", },
},

new HeidiSingleDatabaseConfiguration("OSS/Abc")
{
// Order = 0,
// Environment = "Production",
// Name = "Abc Prod",
// Repositories = new []{ "Abc", },
},
};

];
}

public static IEnumerable<object[]> CtorNullArguments
Expand Down Expand Up @@ -320,14 +327,19 @@ public async Task Events_ShouldNotBeProcessed_WhenWrongFilename()
.Returns(Task.FromResult(new List<HeidiSingleDatabaseConfiguration>()));

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
_changeEventDummyFileSystemWatcher.Change(PATH, FILENAME + "dummy");
await Task.Delay(TimeSpan.FromSeconds(10));

// assert
poked.Should().BeTrue();
A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustNotHaveHappened();
}

Expand Down
13 changes: 0 additions & 13 deletions tests/RepoM.Plugin.Statistics.Tests/Ordering/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, IRepositoriesComparerConfiguration> result =_sut.Configuration;

// assert
await Verifier.Verify(result, _verifySettings);
}
}

This file was deleted.

This file was deleted.

0 comments on commit e09306c

Please sign in to comment.