/
ReleaseApplicationTests.cs
110 lines (85 loc) · 3.16 KB
/
ReleaseApplicationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.IO.Abstractions.TestingHelpers;
using FakeItEasy;
using Spectre.Console.Testing;
using Xenial.RTool;
namespace Xenial.Tests.RTool;
[UsesVerify]
public sealed class ReleaseApplicationTests
{
private MockFileSystem FileSystem { get; } = new MockFileSystem(
new Dictionary<string, MockFileData>()
);
private TestConsole Console { get; } = new TestConsole();
private IGitCommandRunner CommandRunner { get; } = A.Fake<IGitCommandRunner>();
private IHookCommandRunner HookCommandRunner { get; } = A.Fake<IHookCommandRunner>();
private ReleaseContext CreateTestContext(string? cd = null)
=> new ReleaseContext(
FileSystem,
Console,
CommandRunner,
HookCommandRunner,
cd ?? Environment.CurrentDirectory
);
private (ReleaseApplication app, ReleaseContext ctx) CreateApplication()
=> (new ReleaseApplication(
FileSystem,
Console,
CommandRunner,
HookCommandRunner
), CreateTestContext());
[Fact]
public async Task CheckForGitMustNotCallNextWhenNotInGitRepo()
{
var next = A.Fake<ReleaseApplicationDelegate>();
var detector = A.Fake<IGitRepositoryDetector>();
A.CallTo(() => detector.DetectGitRepository(A.Dummy<string>())).Returns(false);
var ctx = CreateTestContext("/var/www/");
await ReleaseApplication.CheckForGit(next, ctx, detector);
A.CallTo(next).MustNotHaveHappened();
await Verify(Console.Output);
}
[Fact]
public async Task CheckForGitMustCallNextWhenInGitRepo()
{
var next = A.Fake<ReleaseApplicationDelegate>();
var detector = A.Fake<IGitRepositoryDetector>();
A.CallTo(() => detector.DetectGitRepository(A<string>.Ignored)).Returns(true);
var ctx = CreateTestContext();
await ReleaseApplication.CheckForGit(next, ctx, detector);
A.CallTo(next).MustHaveHappened();
}
[Theory]
[InlineData("main", false, true)]
[InlineData("master", false, true)]
[InlineData("develop", true, false)]
[InlineData("topic/my-feature-123", true, true)]
public async Task ConfirmBranches(string currentBranch, bool mustConfirm, bool confirm)
{
var next = A.Fake<ReleaseApplicationDelegate>();
A.CallTo(() => CommandRunner.ReadCommand("branch --show-current", A<string>.Ignored))
.Returns(Task.FromResult(currentBranch));
if (mustConfirm)
{
Console.Input.PushTextWithEnter(confirm ? "y" : "n");
}
var (app, ctx) = CreateApplication();
await app.ConfirmBranch(next, ctx);
if (confirm)
{
A.CallTo(next).MustHaveHappened();
}
else
{
A.CallTo(next).MustNotHaveHappened();
}
await Verify(Console.Output)
.UseParameters(currentBranch, mustConfirm, confirm);
}
[Fact]
public async Task RunPreReleaseHooks()
{
var next = A.Fake<ReleaseApplicationDelegate>();
var (app, ctx) = CreateApplication();
//await app.RunPreReleaseHoocks(next, ctx);
}
}