-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathStoreCommandTests.cs
More file actions
77 lines (65 loc) · 2.86 KB
/
StoreCommandTests.cs
File metadata and controls
77 lines (65 loc) · 2.86 KB
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
using System.Collections.Generic;
using System.Threading.Tasks;
using GitCredentialManager.Commands;
using GitCredentialManager.Tests.Objects;
using Moq;
using Xunit;
namespace GitCredentialManager.Tests.Commands
{
public class StoreCommandTests
{
[Fact]
public async Task StoreCommand_ExecuteAsync_CallsHostProvider()
{
const string testUserName = "john.doe";
const string testPassword = "letmein123"; // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")]
var stdin = $"protocol=http\nhost=example.com\nusername={testUserName}\npassword={testPassword}\n\n";
var expectedInput = new InputArguments(new Dictionary<string, string>
{
["protocol"] = "http",
["host"] = "example.com",
["username"] = testUserName,
["password"] = testPassword
});
var providerMock = new Mock<IHostProvider>();
providerMock.Setup(x => x.StoreCredentialAsync(It.IsAny<InputArguments>()))
.Returns(Task.CompletedTask);
var providerRegistry = new TestHostProviderRegistry {Provider = providerMock.Object};
var context = new TestCommandContext
{
Streams = {In = stdin}
};
var command = new StoreCommand(context, providerRegistry);
await command.ExecuteAsync();
providerMock.Verify(
x => x.StoreCredentialAsync(It.Is<InputArguments>(y => AreInputArgumentsEquivalent(expectedInput, y))),
Times.Once);
}
[Fact]
public async Task StoreCommand_SaveConfigurationAsync_SavesConfiguration()
{
const string filePath = "test-config.json";
var context = new TestCommandContext();
var command = new StoreCommand(context, new TestHostProviderRegistry());
await command.SaveConfigurationAsync(filePath);
// Add assertions to verify that the configuration was saved correctly
}
[Fact]
public async Task StoreCommand_LoadConfigurationAsync_LoadsConfiguration()
{
const string filePath = "test-config.json";
var context = new TestCommandContext();
var command = new StoreCommand(context, new TestHostProviderRegistry());
await command.LoadConfigurationAsync(filePath);
// Add assertions to verify that the configuration was loaded correctly
}
bool AreInputArgumentsEquivalent(InputArguments a, InputArguments b)
{
return a.Protocol == b.Protocol &&
a.Host == b.Host &&
a.Path == b.Path &&
a.UserName == b.UserName &&
a.Password == b.Password;
}
}
}