public void TestLocalVcs() { InitializeGitRepository(); var configRepository = new ConfigRepositoryVcs { Type = "vcs", Uri = fileSystem.Root, }; var tester = new TesterIOConsole(); var io = tester.Mock(AbstractTester.OptionVerbosity(OutputOptions.VerbosityVeryVerbose)); var repository = new RepositoryVcs(configRepository, io, config); var packages = repository.GetPackages(); CollectionAssert.AreEqual( new[] { "a/b 1.0.0", "a/b 1.0.x-dev", "a/b dev-feature/a", "a/b dev-master", }, Arr.Map(packages, (package) => $"{package.GetName()} {package.GetVersionPretty()}")); }
public void TestExecuteWithFileArgument() { var file = Helper.Fixtrue("Command/validate-normal.json"); var tester = new TesterCommand(new CommandValidate()); Assert.AreEqual(GameBox.Console.ExitCodes.Normal, tester.Execute(file, AbstractTester.OptionDecorated(false))); StringAssert.Contains(tester.GetDisplay(), "is valid."); }
public void Initialize() { tester = new TesterIOConsole(); reporter = new ReporterSuggestedPackages(tester.Mock(AbstractTester.OptionStdErrorSeparately(true))); repositoryInstalled = new Mock <IRepositoryInstalled>(); package = new Mock <IPackage>(); package.Setup((o) => o.GetNamePretty()).Returns("foo"); }
public void Initialize() { repository = new Mock <IRepositoryInstalled>(); tester = new TesterIOConsole(); io = tester.Mock(AbstractTester.OptionStdErrorSeparately(true)); installer = new InstallerMetaPackage(io); package = new Mock <IPackage>(); package.Setup((o) => o.Clone()).Returns(package.Object); }
public void TestDoesntHidePorts() { var tester = new TesterIOConsole(); var process = new BucketProcessExecutor(tester.Mock(AbstractTester.OptionVerbosity(OutputOptions.VerbosityDebug))); process.Execute("echo https://localhost:1234/"); StringAssert.Contains(tester.GetDisplay(), "Executing command (CWD): echo https://localhost:1234/"); }
public void TestHidenSensitive() { var tester = new TesterIOConsole(); var process = new BucketProcessExecutor(tester.Mock(AbstractTester.OptionVerbosity(OutputOptions.VerbosityDebug))); process.Execute("echo https://foo:[email protected]/ && echo http://[email protected] && echo http://abcdef1234567890234578:[email protected]/", out string stdout); StringAssert.Contains(tester.GetDisplay(), "Executing command (CWD): echo https://foo:***@example.org/ && echo http://[email protected] && echo http://***:***@github.com/"); }
public void TestHasLocalChangeDisabledInteractWithUser() { var config = new Config(); var merged = new JObject { ["config"] = new JObject(), }; merged["config"][Settings.DiscardChanges] = true; config.Merge(merged); var packageMock = new Mock <IPackage>(); packageMock.Setup((o) => o.GetSourceReference()) .Returns("ref"); packageMock.Setup((o) => o.GetSourceUris()) .Returns(new[] { "https://github.com/bucket/bucket" }); packageMock.Setup((o) => o.GetVersion()) .Returns("1.0.0.0"); var processMock = new Mock <IProcessExecutor>(); var expectedGitCommand = WinCompat("git show-ref --head -d"); processMock.Setup(expectedGitCommand, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git status --porcelain --untracked-files=no"); var stdout = @" M foo/bar.cs M foo/baz.cs "; processMock.Setup(expectedGitCommand, actualOut: stdout, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git reset --hard"); processMock.Setup(expectedGitCommand, expectedCwd: WinCompat(root)); if (!Directory.Exists(root + "/.git")) { Directory.CreateDirectory(root + "/.git"); } io = tester.Mock( AbstractTester.OptionVerbosity(OutputOptions.VerbosityVerbose), AbstractTester.Interactive(false)); var downloader = CreateDownloaderMock(config: config, process: processMock.Object); downloader.Update(packageMock.Object, packageMock.Object, root); processMock.VerifyAll(); }
public void Initialize() { bucket = new Bucket(); tester = new TesterIOConsole(); eventArgs = new Mock <EventArgs>(); fileSystem = new Mock <IFileSystem>(); process = new Mock <IProcessExecutor>(); io = tester.Mock( AbstractTester.OptionVerbosity(OutputOptions.VerbosityVeryVerbose), AbstractTester.OptionStdErrorSeparately(true)); dispatcher = new BEventDispatcher(bucket, io, process.Object, fileSystem.Object); package = new Mock <IPackageRoot>(); config = new Config(); bucket.SetPackage(package.Object); bucket.SetConfig(config); }
public void TestTesterIOConsoleMock() { var tester = new TesterIOConsole(); tester.SetInputs(new[] { "menghanyu" }); var io = tester.Mock(AbstractTester.OptionStdErrorSeparately(true)); Assert.AreEqual("menghanyu", (string)io.Ask("what's your name?", "miaomiao")); io.Write("hello world"); Assert.AreEqual( @"hello world ", tester.GetDisplay()); io.WriteError("hello world error"); Assert.AreEqual( @"what's your name?hello world error ", tester.GetDisplayError()); }
public void TestInitialize() { root = Helper.Fixtrue("Plugin"); repositoryInstalled = new Mock <IRepositoryInstalled>(); tester = new TesterIOConsole(); io = tester.Mock(AbstractTester.OptionVerbosity(OutputOptions.VerbosityDebug)); bucket = new Bucket(); config = new Config(); dispatcher = new BEventDispatcher(bucket, io); pluginManager = new PluginManager(io, bucket); repositoryManager = new Mock <RepositoryManager>(io, config, dispatcher, null); repositoryInstalled = new Mock <IRepositoryInstalled>(); installationManager = new Mock <InstallationManager>(); repositoryManager.Setup((o) => o.GetLocalInstalledRepository()).Returns(repositoryInstalled.Object); installationManager.Setup((o) => o.GetInstalledPath(It.IsAny <IPackage>())) .Returns(root); bucket.SetConfig(config); bucket.SetPluginManager(pluginManager); bucket.SetEventDispatcher(dispatcher); bucket.SetRepositoryManager(repositoryManager.Object); bucket.SetInstallationManager(installationManager.Object); }
public void TestHasLocalChangeInteractWithUser() { var packageMock = new Mock <IPackage>(); packageMock.Setup((o) => o.GetSourceReference()) .Returns("ref"); packageMock.Setup((o) => o.GetSourceUris()) .Returns(new[] { "https://github.com/bucket/bucket" }); packageMock.Setup((o) => o.GetVersion()) .Returns("1.0.0.0"); var processMock = new Mock <IProcessExecutor>(); var expectedGitCommand = WinCompat("git show-ref --head -d"); processMock.Setup(expectedGitCommand, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git status --porcelain --untracked-files=no"); var stdout = @" M 1-foo/bar.cs M 2-foo/baz.cs M 3-foobar.json M 4-foo/aux/bar.cs M 5-foobar.json M 6-foo/aux/bar.cs M 7-foo/aux/bar.cs M 8-foo/aux/bar.cs M 9-foo/aux/bar.cs M 10-foo/aux/bar.cs M 11-foo/aux/bar.cs M 12-foo/aux/bar.cs "; processMock.Setup(expectedGitCommand, actualOut: stdout, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git stash --include-untracked"); processMock.Setup(expectedGitCommand, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git diff HEAD"); stdout = @"index 8ba5bbe..9cda3f0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ foobarbaz foobarbaz +foo foobarbaz foobarbaz "; processMock.Setup(expectedGitCommand, actualOut: stdout, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git stash pop"); processMock.Setup(expectedGitCommand, expectedCwd: WinCompat(root)); expectedGitCommand = WinCompat("git log ref..ref --pretty=format:'%h - %an: %s'"); stdout = @"c5bd155 - foo: bar ccf0f2f - bar: baz ac027b9 - foo: baz"; processMock.Setup(expectedGitCommand, actualOut: stdout, expectedCwd: WinCompat(root)); if (!Directory.Exists(root + "/.git")) { Directory.CreateDirectory(root + "/.git"); } tester.SetInputs(new[] { "v", "d", "?", "s" }); io = tester.Mock(AbstractTester.OptionVerbosity(OutputOptions.VerbosityVerbose)); var downloader = CreateDownloaderMock(process: processMock.Object); downloader.Update(packageMock.Object, packageMock.Object, root); var display = tester.GetDisplay(); StringAssert.Contains(display, "The package has modified files"); StringAssert.Contains(display, "2 more files modified, choose \"v\" to view the full list."); StringAssert.Contains(display, "Discard changes [y,n,v,d,s,?,h]?"); StringAssert.Contains(display, "stash changes and try to reapply them after the update."); StringAssert.Contains(display, "Re-applying stashed changes"); StringAssert.Contains(display, "Pulling in changes:"); processMock.VerifyAll(); }