public void LoadOperationArgumentsTest() { Program._dieExceptionCallback = (Exception e) => Assert.Fail($"Error: {e.ToString()}"); Program._dieMessageCallback = (string m) => Assert.Fail($"Error: {m}"); Program._exitCallback = (int e, string m) => Assert.Fail($"Error: {e} {m}"); var envvars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) } }; var gitconfig = new Git.Configuration.Impl(); var targetUri = new Authentication.TargetUri("https://example.visualstudio.com/"); Mock <OperationArguments> opargsMock = new Mock <OperationArguments>(); opargsMock.Setup(r => r.EnvironmentVariables) .Returns(envvars); opargsMock.Setup(r => r.GitConfiguration) .Returns(gitconfig); opargsMock.Setup(r => r.LoadConfiguration()); opargsMock.Setup(r => r.TargetUri) .Returns(targetUri); opargsMock.Setup(r => r.QueryUri) .Returns(targetUri); var opargs = opargsMock.Object; Program.LoadOperationArguments(opargs); Assert.IsNotNull(opargs); }
public void TryReadBooleanTest() { bool?yesno; var envvars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) }, { Program.EnvironPreserveCredentialsKey, "no" }, }; var gitconfig = new Git.Configuration.Impl(); var targetUri = new Authentication.TargetUri("https://example.visualstudio.com/"); var opargsMock = new Mock <OperationArguments>(); opargsMock.Setup(r => r.EnvironmentVariables) .Returns(envvars); opargsMock.Setup(r => r.GitConfiguration) .Returns(gitconfig); opargsMock.Setup(r => r.LoadConfiguration()); opargsMock.Setup(r => r.TargetUri) .Returns(targetUri); opargsMock.Setup(r => r.QueryUri) .Returns(targetUri); var program = new Program(); Assert.False(CommonFunctions.TryReadBoolean(program, opargsMock.Object, "notFound", "notFound", out yesno)); Assert.False(yesno.HasValue); Assert.True(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno)); Assert.True(yesno.HasValue); Assert.False(yesno.Value); envvars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) }, { Program.EnvironPreserveCredentialsKey, "yes" }, }; opargsMock.Setup(r => r.EnvironmentVariables) .Returns(envvars); Assert.True(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno)); Assert.True(yesno.HasValue); Assert.True(yesno.Value); envvars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) }, { Program.EnvironPreserveCredentialsKey, string.Empty }, }; opargsMock.Setup(r => r.EnvironmentVariables) .Returns(envvars); Assert.False(CommonFunctions.TryReadBoolean(program, opargsMock.Object, Program.ConfigPreserveCredentialsKey, Program.EnvironPreserveCredentialsKey, out yesno)); Assert.False(yesno.HasValue); }
public void LoadOperationArgumentsTest() { var program = new Program(); program._dieException = (Program caller, Exception e, string path, int line, string name) => Assert.False(true, $"Error: {e.ToString()}"); program._dieMessage = (Program caller, string m, string path, int line, string name) => Assert.False(true, $"Error: {m}"); program._exit = (Program caller, int e, string m, string path, int line, string name) => Assert.False(true, $"Error: {e} {m}"); var configs = new Dictionary <Git.ConfigurationLevel, Dictionary <string, string> > { { Git.ConfigurationLevel.Local, new Dictionary <string, string>(StringComparer.Ordinal) { { "credential.validate", "true" }, { "credential.useHttpPath", "true" }, { "credential.not-match.com.useHttpPath", "false" }, } }, { Git.ConfigurationLevel.Global, new Dictionary <string, string>(StringComparer.Ordinal) { { "credential.validate", "false" }, } }, { Git.ConfigurationLevel.Xdg, new Dictionary <string, string>(StringComparer.Ordinal) { } }, { Git.ConfigurationLevel.System, new Dictionary <string, string>(StringComparer.Ordinal) { } }, { Git.ConfigurationLevel.Portable, new Dictionary <string, string>(StringComparer.Ordinal) { } }, }; var envvars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) }, }; var gitconfig = new Git.Configuration.Impl(configs); var targetUri = new Authentication.TargetUri("https://example.visualstudio.com/"); var opargsMock = new Mock <OperationArguments>(MockBehavior.Strict); opargsMock.Setup(r => r.EnvironmentVariables) .Returns(envvars); opargsMock.Setup(r => r.GitConfiguration) .Returns(gitconfig); opargsMock.Setup(r => r.LoadConfiguration()); opargsMock.Setup(r => r.TargetUri) .Returns(targetUri); opargsMock.Setup(r => r.QueryUri) .Returns(targetUri); opargsMock.SetupProperty(r => r.UseHttpPath); opargsMock.SetupProperty(r => r.ValidateCredentials); var opargs = opargsMock.Object; program.LoadOperationArguments(opargs); Assert.NotNull(opargs); Assert.True(opargs.ValidateCredentials, "credential.validate"); Assert.True(opargs.UseHttpPath, "credential.useHttpPath"); }