@@ -30,7 +30,7 @@ public void EraseCommand_CanExecuteAsync(string argString, bool expected)
30
30
}
31
31
32
32
[ Fact ]
33
- public async Task EraseCommand_ExecuteAsync_CredentialExists_ErasesCredential ( )
33
+ public async Task EraseCommand_ExecuteAsync_NoInputUserPass_CredentialExists_ErasesCredential ( )
34
34
{
35
35
const string testCredentialKey = "test-cred-key" ;
36
36
@@ -57,6 +57,90 @@ public async Task EraseCommand_ExecuteAsync_CredentialExists_ErasesCredential()
57
57
Assert . True ( context . CredentialStore . ContainsKey ( "git:credential2" ) ) ;
58
58
}
59
59
60
+ [ Fact ]
61
+ public async Task EraseCommand_ExecuteAsync_InputUserPass_CredentialExists_UserNotMatch_DoesNothing ( )
62
+ {
63
+ const string testUserName = "john.doe" ;
64
+ const string testPassword = "letmein123" ;
65
+ const string testCredentialKey = "test-cred-key" ;
66
+ string stdIn = $ "username={ testUserName } \n password={ testPassword } \n \n ";
67
+
68
+ var provider = new TestHostProvider { CredentialKey = testCredentialKey } ;
69
+ var providerRegistry = new TestHostProviderRegistry { Provider = provider } ;
70
+ var context = new TestCommandContext
71
+ {
72
+ StdIn = stdIn ,
73
+ CredentialStore =
74
+ {
75
+ [ $ "git:{ testCredentialKey } "] = new GitCredential ( "different-username" , testPassword ) ,
76
+ }
77
+ } ;
78
+
79
+ string [ ] cmdArgs = { "erase" } ;
80
+ var command = new EraseCommand ( providerRegistry ) ;
81
+
82
+ await command . ExecuteAsync ( context , cmdArgs ) ;
83
+
84
+ Assert . Equal ( 1 , context . CredentialStore . Count ) ;
85
+ Assert . True ( context . CredentialStore . ContainsKey ( $ "git:{ testCredentialKey } ") ) ;
86
+ }
87
+
88
+ [ Fact ]
89
+ public async Task EraseCommand_ExecuteAsync_InputUserPass_CredentialExists_PassNotMatch_DoesNothing ( )
90
+ {
91
+ const string testUserName = "john.doe" ;
92
+ const string testPassword = "letmein123" ;
93
+ const string testCredentialKey = "test-cred-key" ;
94
+ string stdIn = $ "username={ testUserName } \n password={ testPassword } \n \n ";
95
+
96
+ var provider = new TestHostProvider { CredentialKey = testCredentialKey } ;
97
+ var providerRegistry = new TestHostProviderRegistry { Provider = provider } ;
98
+ var context = new TestCommandContext
99
+ {
100
+ StdIn = stdIn ,
101
+ CredentialStore =
102
+ {
103
+ [ $ "git:{ testCredentialKey } "] = new GitCredential ( testUserName , "different-password" ) ,
104
+ }
105
+ } ;
106
+
107
+ string [ ] cmdArgs = { "erase" } ;
108
+ var command = new EraseCommand ( providerRegistry ) ;
109
+
110
+ await command . ExecuteAsync ( context , cmdArgs ) ;
111
+
112
+ Assert . Equal ( 1 , context . CredentialStore . Count ) ;
113
+ Assert . True ( context . CredentialStore . ContainsKey ( $ "git:{ testCredentialKey } ") ) ;
114
+ }
115
+
116
+ [ Fact ]
117
+ public async Task EraseCommand_ExecuteAsync_InputUserPass_CredentialExists_UserPassMatch_ErasesCredential ( )
118
+ {
119
+ const string testUserName = "john.doe" ;
120
+ const string testPassword = "letmein123" ;
121
+ const string testCredentialKey = "test-cred-key" ;
122
+ string stdIn = $ "username={ testUserName } \n password={ testPassword } \n \n ";
123
+
124
+ var provider = new TestHostProvider { CredentialKey = testCredentialKey } ;
125
+ var providerRegistry = new TestHostProviderRegistry { Provider = provider } ;
126
+ var context = new TestCommandContext
127
+ {
128
+ StdIn = stdIn ,
129
+ CredentialStore =
130
+ {
131
+ [ $ "git:{ testCredentialKey } "] = new GitCredential ( testUserName , testPassword ) ,
132
+ }
133
+ } ;
134
+
135
+ string [ ] cmdArgs = { "erase" } ;
136
+ var command = new EraseCommand ( providerRegistry ) ;
137
+
138
+ await command . ExecuteAsync ( context , cmdArgs ) ;
139
+
140
+ Assert . Equal ( 0 , context . CredentialStore . Count ) ;
141
+ Assert . False ( context . CredentialStore . ContainsKey ( $ "git:{ testCredentialKey } ") ) ;
142
+ }
143
+
60
144
[ Fact ]
61
145
public async Task EraseCommand_ExecuteAsync_NoCredential_DoesNothing ( )
62
146
{
0 commit comments