public void ShouldConnectSetCredentialsAndClear() { const string connectionsCachePath = @"c:\UserCachePath\"; const string connectionsCacheFile = @"c:\UserCachePath\connections.json"; const string username = "******"; const string password = "******"; var hostUri = new UriString("https://github.com/"); var fileSystem = SubstituteFactory.CreateFileSystem(); NPath.FileSystem = fileSystem; var environment = SubstituteFactory.CreateEnvironment(); environment.UserCachePath.Returns(info => connectionsCachePath.ToNPath()); environment.FileSystem.Returns(fileSystem); var credentialManager = Substitute.For <ICredentialManager>(); credentialManager.Delete(Args.UriString).Returns(info => TaskEx.FromResult(0)); credentialManager.Save(Arg.Any <ICredential>()).Returns(info => TaskEx.FromResult(0)); var keychain = new Keychain(environment, credentialManager); keychain.Initialize(); fileSystem.Received(1).FileExists(connectionsCacheFile); fileSystem.DidNotReceive().ReadAllText(Args.String); fileSystem.DidNotReceive().ReadAllLines(Args.String); fileSystem.DidNotReceive().WriteAllText(Args.String, Args.String); fileSystem.DidNotReceive().FileDelete(Args.String); fileSystem.ClearReceivedCalls(); credentialManager.DidNotReceive().Load(Args.UriString); credentialManager.DidNotReceive().HasCredentials(); credentialManager.DidNotReceive().Delete(Args.UriString); credentialManager.DidNotReceive().Save(Arg.Any <ICredential>()); keychain.HasKeys.Should().BeFalse(); keychain.Hosts.Should().BeEmpty(); var keychainAdapter = keychain.Connect(hostUri); keychainAdapter.Credential.Should().BeNull(); keychainAdapter.OctokitCredentials.Should().NotBeNull(); keychainAdapter.OctokitCredentials.AuthenticationType.Should().Be(AuthenticationType.Anonymous); keychainAdapter.OctokitCredentials.Login.Should().BeNull(); keychainAdapter.OctokitCredentials.Password.Should().BeNull(); keychain.SetCredentials(new Credential(hostUri, username, password)); keychainAdapter.Credential.Should().NotBeNull(); keychainAdapter.Credential.Host.Should().Be(hostUri); keychainAdapter.Credential.Username.Should().Be(username); keychainAdapter.Credential.Token.Should().Be(password); keychainAdapter.OctokitCredentials.AuthenticationType.Should().Be(AuthenticationType.Basic); keychainAdapter.OctokitCredentials.Login.Should().Be(username); keychainAdapter.OctokitCredentials.Password.Should().Be(password); keychain.Clear(hostUri, false).Wait(); keychainAdapter.Credential.Should().BeNull(); keychainAdapter.OctokitCredentials.AuthenticationType.Should().Be(AuthenticationType.Anonymous); keychainAdapter.OctokitCredentials.Login.Should().BeNull(); keychainAdapter.OctokitCredentials.Password.Should().BeNull(); fileSystem.DidNotReceive().FileExists(Args.String); fileSystem.DidNotReceive().FileDelete(Args.String); fileSystem.DidNotReceive().ReadAllText(Args.String); fileSystem.DidNotReceive().ReadAllLines(Args.String); // we never saved fileSystem.DidNotReceive().WriteAllText(Args.String, Args.String); credentialManager.DidNotReceive().Load(Args.UriString); credentialManager.DidNotReceive().HasCredentials(); credentialManager.DidNotReceive().Delete(Args.UriString); credentialManager.DidNotReceive().Save(Arg.Any <ICredential>()); }
public void Cleanup() { underTest.Clear(); }