public void ProvidingListArgumentListsPackageSources() { // Arrange var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource("FirstSource", "FirstName", isEnabled: false) }); var sourceCommand = new SourcesCommand() { SourceProvider = packageSourceProvider.Object }; sourceCommand.Arguments.Add("list"); var console = new MockConsole(); string expectedText = @"Registered Sources: 1. FirstName [Disabled] FirstSource "; sourceCommand.Console = console; // Act sourceCommand.ExecuteCommand(); // Assert Assert.Equal(expectedText, console.Output); }
public void WhenNestedShould_open_a_window_with_border_using_default_values() { _console = new MockConsole(10, 7); Window.HostConsole = _console; var parent = Window.OpenBox("parent"); var child = parent.OpenBox("child"); child.WriteLine("......"); child.WriteLine("......"); child.Write("......"); var expected = new[] { "┌ parent ┐", "│┌ child┐│", "││......││", "││......││", "││......││", "│└──────┘│", "└────────┘" }; _console.Buffer.Should().BeEquivalentTo(expected); }
public void write_relative_to_the_window_being_printed_to_not_the_parent() { var c = new MockConsole(6, 4); c.WriteLine("------"); c.WriteLine("------"); c.WriteLine("------"); c.Write("------"); var w = new Window(1, 1, 4, 2, c, K.Transparent); w.Write("X"); w.Write(" Y"); var expected = new[] { "------", "-X Y--", "------", "------" }; Console.WriteLine(c.BufferWrittenString); c.Buffer.Should().BeEquivalentTo(expected); }
public void update_the_display_using_the_new_max() { var console = new MockConsole(80, 20); var pb = new ProgressBar(10, console); pb.Refresh(2, "cats"); var expected1 = new[] { "Item 2 of 10 . (20 %) ########## ", "cats ", }; Assert.AreEqual(expected1, console.BufferWritten); pb.Max = 20; var expected2 = new[] { "Item 2 of 20 . (10 %) ########## ", "cats ", }; Assert.AreEqual(expected2, console.BufferWritten); }
public void draw_box_should_draw_box() { var console = new MockConsole(45, 10); // draw box 40 wide, and 6 high new Draw(console).Box(2, 2, 42, 8, "my test box", LineThickNess.Single); var expected = new[] { " ", " ", " ┌───────────── my test box ─────────────┐ ", " │ │ ", " │ │ ", " │ │ ", " │ │ ", " │ │ ", " └───────────────────────────────────────┘ ", " " }; console.Buffer.Should().BeEquivalentTo(expected); }
public void update_the_display_using_the_new_max_when_number_increases() { var console = new MockConsole(80, 20); var pb = new ProgressBar(console, PbStyle.DoubleLine, 10); pb.Refresh(2, "cats"); var expected1 = new[] { "Item 2 of 10 . (20 %) ########## ", "cats ", }; Assert.AreEqual(expected1, console.BufferWritten); pb.Max = 20; var expected2 = new[] { "Item 2 of 20 . (10 %) ##### ", "cats ", }; Assert.AreEqual(expected2, console.BufferWritten); }
public void print_public_properties_then_fields() { var console = new MockConsole(80, 20); var form = new Form(console); var cat = new Cat(10, "Tabby", "Fred"); console.WriteLine("line1"); form.Write(cat); console.WriteLine("line2"); var expected = new[] { "line1", " ┌──────────────────────────────────── Cat ────────────────────────────────────┐", " │ Breed : Tabby │", " │ Age : 10 │", " │ Name : Fred │", " │ Number Of Kittens : 3 │", " └─────────────────────────────────────────────────────────────────────────────┘", "line2" }; console.BufferWrittenTrimmed.Should().BeEquivalentTo(expected); }
public void ProvidingNoArgumentListsPackages() { // Arrange var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource("FirstSource", "FirstName") }); var sourceCommand = new SourcesCommand(packageSourceProvider.Object); string expectedText = @"Registered Sources: 1. FirstName [Enabled] FirstSource "; var stringBuilder = new StringBuilder(); var console = new MockConsole(); var sourcesCommand = new SourcesCommand(packageSourceProvider.Object); sourceCommand.Console = console; // Act sourceCommand.Execute(); // Assert Assert.Equal(expectedText, console.Output); }
public void support_defining_menu_without_shortcut_keys() { //Assert.Inconclusive("new feature"); var con = new MockConsole(40, 10); var output = new MockConsole(20, 20); int i = 0; var menu = new Menu(con, output, "TITLE", ConsoleKey.Escape, 20, new MenuItem("ONE", c => { c.WriteLine("cats"); }), new MenuItem("TWO", c => { c.WriteLine("dogs"); }), new MenuItem("TWO", c => { c.WriteLine("mice"); }), MenuItem.Quit("QUIT") ); menu.Keyboard = new MockKeyboard(ConsoleKey.DownArrow, ConsoleKey.Enter, ConsoleKey.DownArrow, ConsoleKey.Enter, ConsoleKey.DownArrow, ConsoleKey.Escape); menu.Run(); output.BufferWrittenTrimmed.ShouldBeEquivalentTo(new [] { "dogs", "mice" }); }
public void open_a_window_that_can_be_scrolled() { // this test fails because scrolling does not scroll the MockConsole buffer // the other test is faulty as it's asserting on the window and not on the mock window. var c = new MockConsole(10, 8); var w = Window.Open(0, 0, 10, 5, "title", LineThickNess.Double, ConsoleColor.White, ConsoleColor.Black, c); w.WriteLine("one"); w.WriteLine("two"); w.WriteLine("three"); w.WriteLine("four"); Console.WriteLine(c.BufferString); var expected = new[] { "╔════════╗", "║two ║", "║three ║", "║four ║", "╚════════╝" }; c.BufferWritten.ShouldBeEquivalentTo(expected); }
public void TestCopyAndPasteMultiFormats() { var program = new Program(); var con = new MockConsole(); // Copy var inputText = "Test"; var inputHtml = "<b>Test</b>"; var outputHtml = @"Version:1.0 StartHTML:00000097 EndHTML:00000197 StartFragment:00000153 EndFragment:00000164 <!DOCTYPE><HTML><HEAD></HEAD><BODY><!--StartFragment --><b>Test</b><!--EndFragment --></BODY></HTML>"; KeepPositionInvoke(con.Stdin.BaseStream, () => { con.Stdin.Write(String.Format("[{{\"cf\":\"text\", \"data\":\"{0}\"}}, {{\"cf\":\"html\", \"data\":\"{1}\"}}]", inputText, inputHtml)); }); program.RunAsync(new string[] { "copy" }).Wait(); // Paste { KeepPositionInvoke(con.Stdout.BaseStream, () => { program.RunAsync(new string[] { "paste" }).Wait(); }); Assert.AreEqual(con.Stdout.ReadToEnd(), inputText); } { KeepPositionInvoke(con.Stdout.BaseStream, () => { program.RunAsync(new string[] { "paste", "-f", "html" }).Wait(); }); Assert.AreEqual(con.Stdout.ReadToEnd(), outputHtml); } }
public void return_a_buffer_line_using_provided_char_to_indicate_any_printed_character_with_a_matching_background_color() { var normal = ConsoleColor.Black; var hilite = ConsoleColor.White; var console = new MockConsole(11, 5); console.ForegroundColor = ConsoleColor.Red; console.BackgroundColor = normal; console.WriteLine("menu item 1"); console.WriteLine("menu item 2"); console.Write("menu "); console.BackgroundColor = hilite; console.Write("item"); console.BackgroundColor = normal; console.WriteLine(" 3"); console.WriteLine("menu item 4"); // This last call is a write and not a writeLine to avoid window scrolling console.Write("menu item 5"); var expected = new[] { " m e n u i t e m 1", " m e n u i t e m 2", " m e n u #i#t#e#m 3", " m e n u i t e m 4", " m e n u i t e m 5" }; var hlBuffer = console.BufferHighlighted(hilite, '#', ' '); Assert.AreEqual(expected, hlBuffer); }
public void InstallCommandNoOps_ExcludingVersionIsTrue_VersionIsEmpty_ExistingPackageIsNewerOrSame( string installedVersion) { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"baz\baz.nupkg"); var baz = PackageUtility.CreatePackage("Baz", installedVersion); var packages = new List <IPackage> { baz }; var repository = new Mock <SharedPackageRepository>(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false), fileSystem, NullFileSystem.Instance) { CallBase = true }; repository.Setup(c => c.GetPackages()).Returns(packages.AsQueryable()); repository.Setup(c => c.Exists("Baz", new SemanticVersion(installedVersion))).Returns(true); repository.Setup(c => c.FindPackagesById("Baz")).Returns(packages); var packageManager = new PackageManager(GetFactory().CreateRepository("Some source"), new DefaultPackagePathResolver(fileSystem), fileSystem, repository.Object); var console = new MockConsole(); var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, packageManager) { Console = console, ExcludeVersion = true }; installCommand.Arguments.Add("Baz"); // Act installCommand.ExecuteCommand(); // Assert repository.Verify(); Assert.Equal("Package \"Baz\" is already installed." + Environment.NewLine, console.Output); }
public void TestSelectAlreadyVisibleCell() { /* * [1][1][░][░][░] * [*][1][░][1][1] * [1][1][░][1][*] * [░][░][░][2][2] * [░][░][░][1][*] */ // EXPECTED: var expected = File.ReadAllText("game_manager_output_4.txt").Replace("\r", ""); var boardOptions = new BoardOptions(new Vector2(5, 5), 3, 170023000); // All the commands that the user will send. var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Test User"); stringBuilder.AppendLine("S 0 0"); stringBuilder.AppendLine("S 0 0"); stringBuilder.AppendLine("E"); var input = new StringReader(stringBuilder.ToString()); // All the output that the console prints. var output = new StringWriter(); var mockedConsole = new MockConsole(input, output); MineSweeperConsole.SetConsoleWrapper(mockedConsole); _gameManager.Start(boardOptions); Console.WriteLine(output.ToString().Replace("\r", "")); Assert.AreEqual(expected, output.ToString().Replace("\r", "")); Assert.False(_gameManager.IsRunning()); }
public void AddToList_ShouldSeeItemInList() { //arrange var customDesc = "This is my custom thoughts on this movie"; var commandList = new List <string> { "3", "This is the title", customDesc, "42", "3", "4", "1", "6" }; var mockConsole = new MockConsole(commandList); var ui = new ProgramUI(mockConsole); //ACT ui.Run(); Console.WriteLine(mockConsole.Output); //Assert Assert.IsTrue(mockConsole.Output.Contains(customDesc)); }
public void overlapping_boxes_double_single() { var console = new MockConsole(12, 10); var line = new Draw(console, LineThickNess.Single, Merge); line.Box(0, 0, 8, 6, LineThickNess.Double); line.Box(3, 3, 11, 9, LineThickNess.Single); var expected = new[] { "╔═══════╗ ", "║ ║ ", "║ ║ ", "║ ┌────│──┐", "║ │ ║ │", "║ │ ║ │", "╚══╪════╝ │", " │ │", " │ │", " └───────┘" }; console.Buffer.Should().BeEquivalentTo(expected); }
public void execute_the_matching_menu_item() { var con = new MockConsole(15, 7); var seq = new List <char>(); var m = new Menu(con, "MENU", ConsoleKey.Q, 10, new MenuItem('A', "item 1", () => seq.Add('1')), new MenuItem('B', "item 2", () => seq.Add('2')), new MenuItem('C', "item 3", () => seq.Add('3')), new MenuItem('D', "item 4", () => seq.Add('4')), new MenuItem('E', "item 5", () => seq.Add('5')) ); m.Keyboard = new MockKeyboard('A', 'F', 'A', 'D', 'D', 'Q'); m.Run(); var actual = new string(seq.ToArray()); Console.WriteLine(); Console.WriteLine(con.BufferString); Assert.AreEqual("1144", actual); }
public void top_half_and_bottom_half__should_fill_the_parent_console_single_10() { var con = new MockConsole(10, 10); (var top, var bottom) = con.SplitTopBottom("top", "bot"); Fill(top); Fill(bottom); var expected = new[] { "┌── top ─┐", "│three │", "│four │", "│five │", "├── bot ─┤", "│two │", "│three │", "│four │", "│five │", "└────────┘", }; con.Buffer.Should().BeEquivalentTo(expected); }
public void WhenNestedInRows_return_one_console_per_numbered_input_and_one_console_for_the_zero_containing_the_balance() { var con = new MockConsole(20, 22); var top = con.SplitTop(); var bottom = con.SplitBottom(); var consoles = top.SplitRows( new Split(3, "headline", LineThickNess.Single, ConsoleColor.Yellow), new Split(0, "content", LineThickNess.Single), new Split(3, "status", LineThickNess.Single, ConsoleColor.Yellow) ); var headline = consoles[0]; var content = consoles[1]; var status = consoles[2]; headline.Write("my headline that scrolls because of wrapping"); content.Write("content goes here, and this content get's wrapped, and if long enough will cause a bit of scrolling."); status.Write("I get clipped & scroll off."); var expected = new[] { "┌──── headline ────┐", "│wrapping │", "└──────────────────┘", "┌───── content ────┐", "│ if long enough wi│", "│ll cause a bit of │", "│scrolling. │", "└──────────────────┘", "┌───── status ─────┐", "│roll off. │", "└──────────────────┘" }; con.Buffer.Take(11).Should().BeEquivalentTo(expected); }
public void InstallCommandPromptsForConsentIfRequireConsentIsSet() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock<IPackageManager>(MockBehavior.Strict); var repository = new MockPackageRepository { PackageUtility.CreatePackage("Abc") }; packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of<IPackageSourceProvider>(); var console = new MockConsole(); var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; installCommand.RequireConsent = true; // Act var exception = Assert.Throws<AggregateException>(() => installCommand.ExecuteCommand()); // Assert #pragma warning disable 0219 // mono compiler complains that innerException is assigned but not used. var innerException = Assert.IsAssignableFrom<InvalidOperationException>(exception.InnerException); #pragma warning restore 0219 // The culture can't be forced to en-US as the error message is generated in another thread. // Hence, only check the error message if the language is english. var culture = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; if (culture == "en" || culture == "iv") // english or invariant { string message = string.Format( CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageRestoreConsentNotFound, NuGet.Resources.NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", "")); Assert.Equal(message, exception.InnerException.Message); } }
public void InstallCommandDoesNotPromptForConsentIfRequireConsentIsNotSet() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock<IPackageManager>(MockBehavior.Strict); var package = PackageUtility.CreatePackage("Abc"); var repository = new MockPackageRepository { package }; packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); packageManager.Setup(p => p.InstallPackage(package, true, true, true)).Verifiable(); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of<IPackageSourceProvider>(); var console = new MockConsole(); var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; // Act installCommand.ExecuteCommand(); // Assert packageManager.Verify(); }
public void InstallCommandNoOpsIfExcludingVersionAndALowerVersionOfThePackageIsAlreadyInstalled() { // Arrange var fileSystem = new MockFileSystem(); var packages = new[] { PackageUtility.CreatePackage("A", "0.5") }; var repository = new Mock<LocalPackageRepository>(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false), fileSystem) { CallBase = true }; repository.Setup(c => c.FindPackagesById("A")).Returns(packages); repository.Setup(c => c.AddPackage(It.IsAny<IPackage>())).Throws(new Exception("Method should not be called")); repository.Setup(c => c.RemovePackage(It.IsAny<IPackage>())).Throws(new Exception("Method should not be called")); var packageManager = new PackageManager(GetFactory().CreateRepository("Some source"), new DefaultPackagePathResolver(fileSystem), fileSystem, repository.Object); var console = new MockConsole(); var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, packageManager) { Console = console, ExcludeVersion = true, Version = "0.4" }; installCommand.Arguments.Add("A"); // Act installCommand.ExecuteCommand(); // Assert // Ensure packages were not removed. Assert.Equal(1, packages.Length); Assert.Equal("Package \"A\" is already installed." + Environment.NewLine, console.Output); }
public void InstallCommandPromptsForConsentIfRequireConsentIsSet() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock<IPackageManager>(MockBehavior.Strict); var repository = new MockPackageRepository { PackageUtility.CreatePackage("Abc") }; packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of<IPackageSourceProvider>(); var console = new MockConsole(); var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; installCommand.RequireConsent = true; // Act var exception = Assert.Throws<AggregateException>(() => installCommand.ExecuteCommand()); // Assert Assert.Equal("Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.", exception.InnerException.Message); }
public ArrayManipulationNotOptimal(Queue <string> input) { Console = new MockConsole(input); }
public void TopHalf_and_BottomHalf_ShouldFillTheParentConsole(int test, int height) { // test to show how uneven lines are split between top and bottom windows. var c = new MockConsole(10, height); var top = c.SplitTop("top"); var bottom = c.SplitBottom("bot"); top.WriteLine("one"); top.WriteLine("two"); top.Write("three"); bottom.WriteLine("four"); bottom.WriteLine("five"); bottom.Write("six"); Console.WriteLine(c.BufferString); var _10Rows = new[] { "┌── top ─┐", "│one │", "│two │", "│three │", "└────────┘", "┌── bot ─┐", "│four │", "│five │", "│six │", "└────────┘" }; var _11Rows = new[] { "┌── top ─┐", "│one │", "│two │", "│three │", "└────────┘", "┌── bot ─┐", "│four │", "│five │", "│six │", "│ │", "└────────┘" }; var _12Rows = new[] { "┌── top ─┐", "│one │", "│two │", "│three │", "│ │", "└────────┘", "┌── bot ─┐", "│four │", "│five │", "│six │", "│ │", "└────────┘" }; var expecteds = new[] { _10Rows, _11Rows, _12Rows }; c.Buffer.Should().BeEquivalentTo(expecteds[test - 1]); }
public void should_support_drawing_any_positive_size_width_boxes() { var console = new MockConsole(50, 40); var line = new Draw(console); // range of box sizes, alternating double and single line. // ------------------------------------------------------- for (int i = 0; i < 10; i++) { var tl = new XY(0, 4 * i); var br = new XY(0 + i, 4 * i + 3); line.Box(tl.X, tl.Y, br.X, br.Y, "my test box", i % 2 == 0 ? LineThickNess.Single : LineThickNess.Double); } var actual = console.Buffer; var expected = new[] { "┐ ", "│ ", "│ ", "┘ ", "╔╗ ", "║║ ", "║║ ", "╚╝ ", "┌─┐ ", "│ │ ", "│ │ ", "└─┘ ", "╔ m╗ ", "║ ║ ", "║ ║ ", "╚══╝ ", "┌ my┐ ", "│ │ ", "│ │ ", "└───┘ ", "╔ my ╗ ", "║ ║ ", "║ ║ ", "╚════╝ ", "┌ my t┐ ", "│ │ ", "│ │ ", "└─────┘ ", "╔ my te╗ ", "║ ║ ", "║ ║ ", "╚══════╝ ", "┌ my tes┐ ", "│ │ ", "│ │ ", "└───────┘ ", "╔ my test╗ ", "║ ║ ", "║ ║ ", "╚════════╝ " }; // actual.Should().BeEquivalentTo(expected); }
public void Init() { console = new MockConsole(); Console.SetOut(console); progressBar = new ProgressBar(100, "Yo Dawg", 30); }
public void TestServer() { var program = new Program(); var con = new MockConsole(); }
public void not_be_trimmed() { var con = new MockConsole(10, 2); Assert.AreEqual(new[] { " ", " " }, con.Buffer); }
public void InstallCommandNoOps_ExcludingVersionIsTrue_VersionIsEmpty_ExistingPackageIsNewerOrSame( string installedVersion) { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"baz\baz.nupkg"); var baz = PackageUtility.CreatePackage("Baz", installedVersion); var packages = new List<IPackage> { baz }; var repository = new Mock<LocalPackageRepository>(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false), fileSystem) { CallBase = true }; repository.Setup(c => c.GetPackages()).Returns(packages.AsQueryable()); repository.Setup(c => c.Exists("Baz", new SemanticVersion(installedVersion))).Returns(true); repository.Setup(c => c.FindPackagesById("Baz")).Returns(packages); var packageManager = new PackageManager(GetFactory().CreateRepository("Some source"), new DefaultPackagePathResolver(fileSystem), fileSystem, repository.Object); var console = new MockConsole(); var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, packageManager) { Console = console, ExcludeVersion = true }; installCommand.Arguments.Add("Baz"); // Act installCommand.ExecuteCommand(); // Assert repository.Verify(); Assert.Equal("Package \"Baz\" is already installed." + Environment.NewLine, console.Output); }
public void run_selected_menu_item() { var c = new MockConsole(10, 4); //var m = new Menu(c,) }
public void SeperateThreadsForMenuAndTwoWindows() { var console = new MockConsole(); var client = Window.Open(35, 0, 40, 25, "client", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var server = Window.Open(77, 0, 40, 25, "server", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); // print two lines before the menu console.WriteLine("line 1"); console.WriteLine("line 2"); // create and run a menu inline, at the current cursor position var menu = new Menu(console, "Test samples", ConsoleKey.Escape, 30, new MenuItem('1', "cats", () => RunMenuItem(client, "client", "cats")), new MenuItem('2', "dogs", () => RunMenuItem(server, "server", "dogs")), new MenuItem('3', "item 1", () => {}), new MenuItem('4', "item 2", () => {}), new MenuItem('5', "item 3", () => {}), new MenuItem('6', "item 4", () => {}), new MenuItem('7', "item 5", () => {}) ); // line below should print after (below) the menu. console.WriteLine("line 3"); // console should continue working and cursor should be set to below the menu. var kb = new MockKeyboard(0, GetKeyInfos());; menu.Keyboard = kb; menu.Run(); Task.WaitAll(_tasks.ToArray()); var expected = new string[] { "line 1 ┌─────────────── client ───────────────┐ ┌─────────────── server ───────────────┐ ", "line 2 │cats 7978 │ │dogs 7978 │ ", " │cats 7979 │ │dogs 7979 │ ", " Test samples │cats 7980 │ │dogs 7980 │ ", " -------------------------- │cats 7981 │ │dogs 7981 │ ", " cats │cats 7982 │ │dogs 7982 │ ", " dogs │cats 7983 │ │dogs 7983 │ ", " item 1 │cats 7984 │ │dogs 7984 │ ", " item 2 │cats 7985 │ │dogs 7985 │ ", " item 3 │cats 7986 │ │dogs 7986 │ ", " item 4 │cats 7987 │ │dogs 7987 │ ", " item 5 │cats 7988 │ │dogs 7988 │ ", " │cats 7989 │ │dogs 7989 │ ", "line 3 │cats 7990 │ │dogs 7990 │ ", " │cats 7991 │ │dogs 7991 │ ", " │cats 7992 │ │dogs 7992 │ ", " │cats 7993 │ │dogs 7993 │ ", " │cats 7994 │ │dogs 7994 │ ", " │cats 7995 │ │dogs 7995 │ ", " │cats 7996 │ │dogs 7996 │ ", " │cats 7997 │ │dogs 7997 │ ", " │cats 7998 │ │dogs 7998 │ ", " │cats 7999 │ │dogs 7999 │ ", " │ │ │ │ ", " └──────────────────────────────────────┘ └──────────────────────────────────────┘ " }; var actual = console.BufferWritten; actual.Should().BeEquivalentTo(expected); }
public void WindowsWithFourBackgroundThreads() { int max = 8000; var console = new MockConsole(80, 20); var w1 = Window.Open(0, 0, 20, 20, "w1", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var w2 = Window.Open(20, 0, 20, 20, "w2", LineThickNess.Single, ConsoleColor.Red, ConsoleColor.DarkYellow, console); var w3 = Window.Open(40, 0, 20, 20, "w3", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); var w4 = Window.Open(60, 0, 20, 20, "w4", LineThickNess.Single, ConsoleColor.Black, ConsoleColor.White, console); Task t1 = Task.Run(() => { for (int i = 0; i < max; i++) { w1.Write(" {0} ", i.ToString()); } }); Task t2 = Task.Run(() => { for (int i = 0; i < max; i++) { w2.Write(" {0} ", i.ToString()); } }); Task t3 = Task.Run(() => { for (int i = 0; i < max; i++) { w3.Write(" {0} ", i.ToString()); } }); Task t4 = Task.Run(() => { for (int i = 0; i < max; i++) { w4.Write(" {0} ", i.ToString()); } }); Task.WaitAll(new[] { t1, t2, t3, t4 }); var expected = new[] { "┌─────── w1 ───────┐┌─────── w2 ───────┐┌─────── w3 ───────┐┌─────── w4 ───────┐", "│ 7948 7949 7950││ 7948 7949 7950││ 7948 7949 7950││ 7948 7949 7950│", "│ 7951 7952 7953││ 7951 7952 7953││ 7951 7952 7953││ 7951 7952 7953│", "│ 7954 7955 7956││ 7954 7955 7956││ 7954 7955 7956││ 7954 7955 7956│", "│ 7957 7958 7959││ 7957 7958 7959││ 7957 7958 7959││ 7957 7958 7959│", "│ 7960 7961 7962││ 7960 7961 7962││ 7960 7961 7962││ 7960 7961 7962│", "│ 7963 7964 7965││ 7963 7964 7965││ 7963 7964 7965││ 7963 7964 7965│", "│ 7966 7967 7968││ 7966 7967 7968││ 7966 7967 7968││ 7966 7967 7968│", "│ 7969 7970 7971││ 7969 7970 7971││ 7969 7970 7971││ 7969 7970 7971│", "│ 7972 7973 7974││ 7972 7973 7974││ 7972 7973 7974││ 7972 7973 7974│", "│ 7975 7976 7977││ 7975 7976 7977││ 7975 7976 7977││ 7975 7976 7977│", "│ 7978 7979 7980││ 7978 7979 7980││ 7978 7979 7980││ 7978 7979 7980│", "│ 7981 7982 7983││ 7981 7982 7983││ 7981 7982 7983││ 7981 7982 7983│", "│ 7984 7985 7986││ 7984 7985 7986││ 7984 7985 7986││ 7984 7985 7986│", "│ 7987 7988 7989││ 7987 7988 7989││ 7987 7988 7989││ 7987 7988 7989│", "│ 7990 7991 7992││ 7990 7991 7992││ 7990 7991 7992││ 7990 7991 7992│", "│ 7993 7994 7995││ 7993 7994 7995││ 7993 7994 7995││ 7993 7994 7995│", "│ 7996 7997 7998││ 7996 7997 7998││ 7996 7997 7998││ 7996 7997 7998│", "│ 7999 ││ 7999 ││ 7999 ││ 7999 │", "└──────────────────┘└──────────────────┘└──────────────────┘└──────────────────┘" }; var actual = console.BufferWritten; actual.Should().BeEquivalentTo(expected); }
public void SpecifyingFormatShortSwitchesNugetSourcesListOutputToScriptParsableOutput() { // Arrange var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource("DisabledSourceUri", "FirstName", isEnabled: false), new PackageSource("FirstEnabledSourceUri", "SecondName", isEnabled: true), new PackageSource("SecondEnabledSourceUri", "ThirdName", isEnabled: true), new PackageSource("OfficialDisabledSourceUri", "FourthName", isEnabled: false, isOfficial: true), new PackageSource("OfficialEnabledSourceUri", "FifthName", isEnabled: true, isOfficial: true), }); var sourceCommand = new SourcesCommand() { SourceProvider = packageSourceProvider.Object }; sourceCommand.Arguments.Add("list"); sourceCommand.Format = SourcesListFormat.Short; var console = new MockConsole(); string expectedText = @"D DisabledSourceUri E FirstEnabledSourceUri E SecondEnabledSourceUri DO OfficialDisabledSourceUri EO OfficialEnabledSourceUri "; sourceCommand.Console = console; // Act sourceCommand.ExecuteCommand(); // Assert Assert.Equal(expectedText, console.Output); }
public void WhenNested_draw_a_box_around_the_scrollable_window_with_a_centered_title_and_return_a_live_window_at_the_correct_screen_location() { var con = new MockConsole(20, 9); Window.HostConsole = con; var parent = Window.OpenBox("parent", 0, 0, 20, 8, new BoxStyle() { ThickNess = LineThickNess.Double }); var child = parent.OpenBox("c1", 7, 2, 8, 4); parent.WindowWidth.Should().Be(18); parent.WindowHeight.Should().Be(6); //var child = parent.OpenBox("c1", 7, 2, 8, 4); parent.WriteLine("line1"); parent.WriteLine("line2"); var expected = new[] { "╔═════ parent ═════╗", "║line1 ║", "║line2 ║", "║ ┌─ c1 ─┐ ║", "║ │ │ ║", "║ │ │ ║", "║ └──────┘ ║", "╚══════════════════╝", " " }; con.Buffer.Should().BeEquivalentTo(expected); child.WriteLine("cats"); child.Write("dogs"); expected = new[] { "╔═════ parent ═════╗", "║line1 ║", "║line2 ║", "║ ┌─ c1 ─┐ ║", "║ │cats │ ║", "║ │dogs │ ║", "║ └──────┘ ║", "╚══════════════════╝", " " }; con.Buffer.Should().BeEquivalentTo(expected); // should not interfere with original window cursor position so should still be able to continue writing as // if no new child window had been created. parent.WriteLine("line3"); parent.WriteLine("line4"); expected = new[] { "╔═════ parent ═════╗", "║line1 ║", "║line2 ║", "║line3 ┌─ c1 ─┐ ║", "║line4 │cats │ ║", "║ │dogs │ ║", "║ └──────┘ ║", "╚══════════════════╝", " " }; con.Buffer.Should().BeEquivalentTo(expected); }
public void InstallCommandFromConfigListsAllMessagesInAggregateException() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> <package id=""Efg"" version=""2.0.0"" /> <package id=""Pqr"" version=""3.0.0"" /> </packages>"); fileSystem.AddFile("Foo.1.8.nupkg"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock<IPackageManager>(MockBehavior.Strict); packageManager.Setup(p => p.InstallPackage("Efg", new SemanticVersion("2.0.0"), true, true)).Throws(new Exception("Efg exception!!")); packageManager.Setup(p => p.InstallPackage("Pqr", new SemanticVersion("3.0.0"), true, true)).Throws(new Exception("No package restore consent for you!")); packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); var repository = new MockPackageRepository(); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict); var console = new MockConsole(); // Act and Assert var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider.Object, fileSystem, packageManager.Object); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; ExceptionAssert.Throws<AggregateException>(installCommand.Execute); Assert.Contains("No package restore consent for you!", console.Output); Assert.Contains("Efg exception!!", console.Output); }
public OperatingSystemInfoDiagnosticsPluginTests() { Options = CommandLineOptions.ParseCommandLine(new string[] { }); Config = new AppSettingsSection { Settings = { new KeyValueConfigurationElement("ExecutablePath", @".\Gateway\rcp\Gateway_CDP_DEV.cmd"), new KeyValueConfigurationElement("OCAServerApi", "http://jboss-vm-61a46.dynamic.dcts.cloud.td.com:8080/td-gtw-phone-channel-2.0.0/v1"), new KeyValueConfigurationElement("ConfigFileName", "testvalue3"), new KeyValueConfigurationElement("SharedAppSettingsPath", @"P:\UnitySettings\Unity.appconfig"), new KeyValueConfigurationElement("MenuItemJsonPath", "./menuitems.json"), new KeyValueConfigurationElement("MenuItemUrlConfigJsonPath", "./MenuItemUrlConfig.json"), new KeyValueConfigurationElement("ClientSettingsProvider.ServiceUri", ""), new KeyValueConfigurationElement("ChromiumDisableGPU", "1"), new KeyValueConfigurationElement("ConfigFileName", "UnitySettings.config"), } }; Console = new MockConsole(); TestScreen1 = new Mock <IScreenInfo>(); TestScreen2 = new Mock <IScreenInfo>(); TestScreen3 = new Mock <IScreenInfo>(); //todo: refactor screen implementation TestScreen1.Setup(q => q.DeviceName).Returns(@"\\.\DISPLAY1"); TestScreen1.Setup(q => q.Bounds).Returns(new Rectangle(new Point(0, 0), new Size(1280, 720))); TestScreen1.Setup(q => q.Primary).Returns(true); TestScreen2.Setup(q => q.DeviceName).Returns(@"\\.\DISPLAY2"); TestScreen2.Setup(q => q.Bounds).Returns(new Rectangle(new Point(0, 0), new Size(1920, 1080))); TestScreen2.Setup(q => q.Primary).Returns(false); TestScreen3.Setup(q => q.DeviceName).Returns(@"\\.\DISPLAY3"); TestScreen3.Setup(q => q.Bounds).Returns(new Rectangle(new Point(0, 0), new Size(4096, 2160))); TestScreen3.Setup(q => q.Primary).Returns(false); MachineInfo = new Mock <IMachineInfoService>(); MachineInfo.Setup(q => q.MachineName).Returns("TestETAG"); MachineInfo.Setup(q => q.OperatingSystemArchitecture).Returns("Test Architecture"); MachineInfo.Setup(q => q.OperatingSystemName).Returns("Test OS"); MachineInfo.Setup(q => q.OperatingSystemServicePack).Returns("Test Service Pack"); MachineInfo.Setup(q => q.Processor).Returns("Test Processor"); MachineInfo.Setup(q => q.TotalRam).Returns(16000); MachineInfo.Setup(q => q.UserDomain).Returns("TESTDOMAIN"); MachineInfo.Setup(q => q.Username).Returns("TESTUSER"); var videoCard1 = new Mock <IDisplayAdapter>(); videoCard1.Setup(q => q.Name).Returns("Test Video Card A"); videoCard1.Setup(q => q.FullName).Returns("Test Video Card A Full Name"); videoCard1.Setup(q => q.DriverVersion).Returns("1.0"); videoCard1.Setup(q => q.Frequency).Returns("60hz"); var videoCard2 = new Mock <IDisplayAdapter>(); videoCard2.Setup(q => q.Name).Returns("Test Video Card B"); videoCard2.Setup(q => q.FullName).Returns("Test Video Card B Full Name"); videoCard2.Setup(q => q.DriverVersion).Returns("2.0"); videoCard2.Setup(q => q.Frequency).Returns("59hz"); MachineInfo.Setup(q => q.DisplayAdapters) .Returns(new List <IDisplayAdapter>() { videoCard1.Object, videoCard2.Object }); MachineInfo.Setup(q => q.Screens).Returns(new List <IScreenInfo> { TestScreen1.Object, TestScreen2.Object, TestScreen3.Object }); MachineInfo.Setup(q => q.LoadConfiguration(It.IsAny <FileInfo>())).Returns(Config); }
public void Setup() { _console = new MockConsole(10, 5); Window.HostConsole = _console; }