public void ShowThrowInvalidInputException_WhenGivenInvalidNumOfMineInput(string input) { MockConsoleReadLine(input); var consoleUi = new ConsoleUi(_mockRenderer.Object); Assert.Throws <InvalidInputException>(() => consoleUi.GetNumOfMines()); }
public void ShouldThrowInvalidInputException_WhenGivenInvalidDimensionInput(string input) { MockConsoleReadLine(input); var consoleUi = new ConsoleUi(_mockRenderer.Object); Assert.Throws <InvalidInputException>(consoleUi.GetDimension); }
static void Main(string[] args) { Console.WriteLine("Hello customer!"); var consoleUi = new ConsoleUi(); consoleUi.Start(); }
public void SetUp() { _output = new Mock <IOutput>(); _input = new Mock <IInput>(); _consoleUi = new ConsoleUi(_output.Object, _input.Object); }
static void Main(string[] args) { ConsoleUi ui = new ConsoleUi(); ui.WelcomeText(); ui.MainMenu(); }
public void ShouldThrowInvalidInputException_WhenReadInvalidCommandOption(string input) { MockConsoleReadLine(input); var consoleUiUnderTest = new ConsoleUi(_mockRenderer.Object); Assert.Throws <InvalidInputException>(consoleUiUnderTest.GetPlayerCommand); }
public static void Main() { var console = new Console(); var ui = new ConsoleUi(new Output(console, new Sleeper()), new Input(console)); ui.Run(); }
public void ShouldCallRenderMethod_WhenDisplayGameBoard() { var stubGameBoard = new Mock <GameBoard>(5, 5); var consoleUi = new ConsoleUi(_mockRenderer.Object); consoleUi.DisplayGameBoard(stubGameBoard.Object); _mockRenderer.Verify(r => r.Render(stubGameBoard.Object), Times.Once); }
public void ShouldReturnNumOfMineThatMatchInput() { MockConsoleReadLine("5"); var consoleUi = new ConsoleUi(_mockRenderer.Object); var result = consoleUi.GetNumOfMines(); Assert.Equal(5, result); }
public void ShouldCreateCorrectCommandObject_WhenGivenValidCommandOption(string input, Type expected) { MockConsoleReadLine(input); var consoleUiUnderTest = new ConsoleUi(_mockRenderer.Object); var action = consoleUiUnderTest.GetPlayerCommand(); Assert.IsType(expected, action); }
public static void Main(string[] args) { var wordCount = new WordCount(); var consoleUi = new ConsoleUi(); var text = consoleUi.GetText(); var numberOfWords = wordCount.CountWordsInText(text); consoleUi.ShowNumberOfWords(numberOfWords); }
public void Should_Wait_For_Input() { // Arrange ConsoleUi consoleUi = CreateConsoleUi(); // Act consoleUi.WaitForInput(); // Assert _subConsole.Received().ReadLine(); }
public void Should_Print_Lines_Of_Code_Summary_To_Console() { ConsoleUi consoleUi = CreateConsoleUi(); var linesOfCodeSummary = new LinesOfCodeSummary(10000, 5000); string expectedResult = $"Total{Environment.NewLine} Lines 10.000{Environment.NewLine} Lines of Code 5.000{Environment.NewLine}"; consoleUi.PrintLinesOfCodeSummaryToConsole( linesOfCodeSummary); (_mockConsole as MockConsoleWrapper).MockConsole.ToString().Should().Be(expectedResult); }
public CommandManager(ConsoleUi ui, ICatalogLoader catalogLoader, ShoppingCart shoppingCart) { _nextCommands = new Dictionary <Type, ICommand[]> { { ShowCatalogCmd.GetType(), new[] { AddToCartCmd, ExitCmd } }, { ExitCmd.GetType(), new ICommand[0] }, { AddToCartCmd.GetType(), new[] { ShowCatalogCmd, AddToCartCmd, ExitCmd } }, }; _commandContext = new CommandContext(ui, catalogLoader, shoppingCart); }
public void Should_Print_Lines_Of_Code_Stat_To_Console() { ConsoleUi consoleUi = CreateConsoleUi(); var linesOfCodeStat = new LinesOfCodeStat("filePath", 10, 5); string expectedResult = $"filePath 10 5{Environment.NewLine}"; consoleUi.PrintLinesOfCodeStatToConsole( linesOfCodeStat); (_mockConsole as MockConsoleWrapper).MockConsole.ToString().Should().Be(expectedResult); }
public void ShouldPrintCorrectResult(bool isWon, string expected) { var consoleUi = new ConsoleUi(_mockRenderer.Object); var consoleWriter = new StringWriter(); Console.SetOut(consoleWriter); consoleUi.PrintResult(isWon); var result = consoleWriter.GetStringBuilder().ToString(); Assert.Equal(expected, result); }
public void ShouldReturnGameBoardWithCorrectWidthAndHeight_WhenGivenValidConsoleInput() { MockConsoleReadLine("5 5"); var consoleUi = new ConsoleUi(_mockRenderer.Object); var result = consoleUi.GetDimension(); var resultJson = JsonConvert.SerializeObject(result); var expectedJson = JsonConvert.SerializeObject(new GameBoard(5, 5)); Assert.Equal(expectedJson, resultJson); }
static void Main(string[] args) { // Initialize UI var ui = new ConsoleUi(); ui.Initialize(); // Load the wordlist var wordList = new WordList(File.ReadAllLines(wordListFile).Select(w => w.Trim().ToLowerInvariant())); var cont = true; while (cont) { ui.WaitMessage("Think of a letter (a to z)."); // Initialize possible letters var possibles = "abcdefghijklmnopqrstuvwxyz"; // Try random words until at most maxWordLength remain while (possibles.Length > 1) { var word = wordList.GetRandomWord(possibles, maxWordLength); if (word == null) { possibles = string.Empty; break; } var responseYes = ui.AskYesOrNo("Is your letter in the word '{0}'?", word); if (responseYes) { possibles = new string(possibles.Intersect(word).ToArray()); } else { possibles = new string(possibles.Except(word).ToArray()); } } if (possibles.Length == 1) { ui.Message("Your letter was: {0}", possibles); } else { ui.Message("I give up. You win!"); } cont = ui.AskYesOrNo("Do you want to play again?"); } }
private void RunEngine() { var displaySize = new Size(60, 20); var consoleUi = new ConsoleUi(displaySize, new ConsolePresentationConfiguration()); var presentation = consoleUi as Presentation; var logger = consoleUi as Logger; _engine = new Engine(presentation, logger); _engineInitialized.Set(); _engine.Run(); _engine.AnounceResult(); }
public void Should_Get_Text_From_Console() { // Arrange ConsoleUi consoleUi = CreateConsoleUi(); _subConsole.ReadLine().Returns("My text"); // Act string result = consoleUi.GetTextFromConsole(); // Assert result.Should().Be("My text"); }
public void Should_Print_Result_To_Console(WordCountResult wordCountResult, bool isIndexOptionSet, string expectedResult) { // Arrange ConsoleUi consoleUi = CreateMockConsoleUi(); // Act consoleUi.PrintResultToConsole( wordCountResult, isIndexOptionSet); // Assert var consoleWrapper = consoleUi.GetConsole() as MockConsoleWrapper; consoleWrapper.MockConsole.ToString().Should().Be(expectedResult); }
private void RunEngine() { var displaySize = new Size(60, 20); var consoleUi = new ConsoleUi(displaySize, new ConsolePresentationConfiguration()); var presentation = consoleUi as Presentation; var logger = consoleUi as Logger; var configuration = ConfigurationFactory.FromFile <MapConfiguration>("mapConfiguration.json"); var dice = new YoloDice(); var mapFactory = new MapFactory(dice, new DefaultHealingHealingShrineFactory(dice)); _engine = new Engine(presentation, logger, mapFactory.GenerateMap(configuration), new YoloTeam(YoloTeamBaseHitpoints)); _engineInitialized.Set(); _engine.Run(); _engine.AnounceResult(); }
private static void Main(string[] args) { var consoleUi = new ConsoleUi(new ConsoleWrapper()); var interactor = new Interactor(); int totalLinesCount = 0; int totalLinesOfCodeCount = 0; string directory = args[0]; foreach (LinesOfCodeStat stat in interactor.GetLinesOfCodeStats(directory)) { totalLinesCount += stat.LinesCount; totalLinesOfCodeCount += stat.LinesOfCodeCount; consoleUi.PrintLinesOfCodeStatToConsole(stat); } consoleUi.PrintLinesOfCodeSummaryToConsole(new LinesOfCodeSummary(totalLinesCount, totalLinesOfCodeCount)); consoleUi.WaitForInput(); }
// ---------------------------------------------------------------------- static public void Execute(Assembly assembly, string[] args) { if (assembly == null) { throw new ArgumentNullException("assembly"); } bool waitAtEnd = false; bool waitBecauseOfError = false; Console.WriteLine("===== Test::begin ====="); try { if (args != null && args.Length > 0) { foreach (string arg in args) { if ("-wait".Equals(arg)) { waitAtEnd = true; } } } // ReSharper disable RedundantExplicitArrayCreation string[] nunitArgs = new string[] { assembly.GetName().Name + ".exe" }; // ReSharper restore RedundantExplicitArrayCreation ConsoleUi.Main(nunitArgs); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); waitBecauseOfError = true; } finally { Console.WriteLine("===== Test::end ====="); } if (waitAtEnd || waitBecauseOfError) { Console.WriteLine(Strings.ProgramPressAnyKeyToQuit); Console.ReadKey(true); } } // Execute
public static int Main(string[] args) { options = new ConsoleOptions(); options.ProcessArgs(args); args = options.RemainingArguments; NUnit.Core.TestDomain domain = new NUnit.Core.TestDomain(); if (args.Length < 1) { options.DoUsage(); return(1); } string assembly = args [0]; Console.WriteLine("ASSEMBLY: " + assembly); Test test; if (args.Length == 1) { test = domain.LoadAssembly(assembly); } else { test = domain.LoadAssembly(assembly, args [1]); } if (test == null) { Console.Error.WriteLine("\nERROR: Unable to load test suite from assembly {0}", assembly); return(1); } Directory.SetCurrentDirectory(new FileInfo(assembly).DirectoryName); string xmlResult = "result.xml"; XmlTextReader reader = GetTransformReader(); ConsoleUi consoleUi = new ConsoleUi(domain, xmlResult, reader); return(consoleUi.Execute()); }
public static void Main() { var consoleUi = new ConsoleUi(); consoleUi.Start(); }
public static int Main(string[] args) { options = new ConsoleOptions (); options.ProcessArgs (args); args = options.RemainingArguments; NUnit.Core.TestDomain domain = new NUnit.Core.TestDomain(); if (args.Length < 1) { options.DoUsage (); return 1; } string assembly = args [0]; Console.WriteLine ("ASSEMBLY: " + assembly); Test test; if (args.Length == 1) test = domain.LoadAssembly (assembly); else test = domain.LoadAssembly (assembly, args [1]); if (test == null) { Console.Error.WriteLine("\nERROR: Unable to load test suite from assembly {0}", assembly); return 1; } Directory.SetCurrentDirectory(new FileInfo(assembly).DirectoryName); string xmlResult = "result.xml"; XmlTextReader reader = GetTransformReader(); ConsoleUi consoleUi = new ConsoleUi(domain, xmlResult, reader); return consoleUi.Execute(); }
public CommandContext(ConsoleUi ui, ICatalogLoader catalogLoader, ShoppingCart shoppingCart) { Ui = ui; Loader = catalogLoader; ShoppingCart = shoppingCart; }