Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #14

Merged
merged 5 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/dist/
/Walrus.CLI/Properties/launchSettings.json
/.idea/
/Walrus.sln.DotSettings.user
2 changes: 1 addition & 1 deletion Walrus.CLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ protected BaseCommand(IWalrusService walrus)
public abstract string Description { get; }

/// <inheritdoc />
public Command Command { get; private set; }
public Command Command { get; }
}
}
1 change: 1 addition & 0 deletions Walrus.CLI/Commands/QueryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public QueryCommand(IWalrusService walrus, ILogger<QueryCommand> logger) : base(

Command.Handler = CommandHandler.Create((WalrusQuery query) =>
{
// Inject config into the query so we can resolve user aliases
query.AddConfiguration(walrus.Config);

HandleQuery(query);
Expand Down
14 changes: 4 additions & 10 deletions Walrus.CLI/Commands/ShowCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ public ShowCommand(IWalrusService walrus, ILogger<ShowCommand> logger) : base(wa
{
new Command("config", "Show configuration")
{
Handler = CommandHandler.Create(() =>
{
ShowConfig();
})
Handler = CommandHandler.Create(ShowConfig)
},
new Command("repos", "Show known repositories")
{
Handler = CommandHandler.Create(() =>
{
ShowRepositories();
})
Handler = CommandHandler.Create(ShowRepositories)
},
};

Expand Down Expand Up @@ -73,8 +67,8 @@ private void ShowConfig()
private void ShowRepositories()
{
_logger.LogDebug("ShowRepositories");

var repos = Walrus.GetRepositories();
var repos = Walrus.GetAllRepositories(null, false);
var count = 0;
foreach (var repo in repos)
{
Expand Down
5 changes: 3 additions & 2 deletions Walrus.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static ServiceProvider ConfigureServices()
var configuration = new ConfigurationBuilder()
.AddJsonFile(configFile, optional: true)
.Build();

var services = new ServiceCollection()
.AddLogging(configure =>
{
Expand All @@ -99,8 +99,9 @@ private static ServiceProvider ConfigureServices()
});

services.AddSingleton<IConfiguration>(configuration);
services.AddSingleton(p => p.GetRequiredService<IConfiguration>().Get<WalrusConfig>() ??
services.AddSingleton<IWalrusConfig>(p => p.GetRequiredService<IConfiguration>().Get<WalrusConfig>() ??
WalrusConfig.Default);
services.AddTransient<IRepositoryProvider, RepositoryProvider>();
services.AddTransient<IWalrusService, WalrusService>();

services.AddCliCommands();
Expand Down
2 changes: 1 addition & 1 deletion Walrus.CLI/Walrus.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<SemVer>0.1.7</SemVer>
<SemVer>0.1.8</SemVer>
<Suffix></Suffix>
</PropertyGroup>

Expand Down
18 changes: 18 additions & 0 deletions Walrus.Core.Tests/ConstantDateTimes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Walrus.Core.Tests
{
using System;

/// <summary>
/// Provides fixed datetime values for test consistency
/// </summary>
public static class ConstantDateTimes
{
public static DateTime Today = new DateTime(2021, 8, 25, 19, 35, 00);

public static DateTime Tomorrow = Today.AddDays(1);

public static DateTime Yesterday = Today.AddDays(-1);

public static DateTime LastWeek = Today.AddDays(-7);
}
}
84 changes: 84 additions & 0 deletions Walrus.Core.Tests/MockRepoProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace Walrus.Core.Tests
{
using System.Collections.Generic;

/// <summary>
/// Repo provider for unit tests
/// </summary>
public class MockRepoProvider : IRepositoryProvider
{
/// <inheritdoc />
public IEnumerable<WalrusRepository> GetRepositories(string rootDirectory, int scanDepth, bool allBranches)
{
return new[]
{
new WalrusRepository("/home/user/code/project_1", new[]
{
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] fix issue #3133",
Sha = "0ee099f5a57d3149f49baadf61e6ace3eb635314",
Timestamp = ConstantDateTimes.LastWeek,
AuthorEmail = "[email protected]",
RepoName = "project_1",
RepoPath = "/home/user/code/project_1"
},
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] revert fix for issue #3133",
Sha = "8ea142ee47e99a2641a0e64cbc75cc0e0d373115",
Timestamp = ConstantDateTimes.Yesterday,
AuthorEmail = "[email protected]",
RepoName = "project_1",
RepoPath = "/home/user/code/project_1"
},
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] really fix issue #3133",
Sha = "2fe245c4374fcd72304333cead412926faa1dd2f",
Timestamp = ConstantDateTimes.Today,
AuthorEmail = "[email protected]",
RepoName = "project_1",
RepoPath = "/home/user/code/project_1"
}
}),
new WalrusRepository("/home/user/code/project_2", new[]
{
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] fix issue #2252",
Sha = "f47fb2990a0d9596e908a23a25e248b0b10a1f37",
Timestamp = ConstantDateTimes.LastWeek,
AuthorEmail = "[email protected]",
RepoName = "project_2",
RepoPath = "/home/user/code/project_2"
},
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] revert fix for issue #2252",
Sha = "515fec7ad07d728044271e7fa6a93a34217613b3",
Timestamp = ConstantDateTimes.Yesterday,
AuthorEmail = "[email protected]",
RepoName = "project_2",
RepoPath = "/home/user/code/project_2"
},
new WalrusCommit
{
Branch = "main",
Message = "[bugfix] really fix issue #2252",
Sha = "0335f9a11ec0c5f83c0f412ed49e816f815d9089",
Timestamp = ConstantDateTimes.Today,
AuthorEmail = "[email protected]",
RepoName = "project_2",
RepoPath = "/home/user/code/project_2"
}
})
};
}
}
}
13 changes: 0 additions & 13 deletions Walrus.Core.Tests/UnitTest1.cs

This file was deleted.

5 changes: 5 additions & 0 deletions Walrus.Core.Tests/Walrus.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -19,4 +20,8 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Walrus.Core\Walrus.Core.csproj" />
</ItemGroup>

</Project>
Loading