public void InputCoordinatesConversion() { var actual = UserInputReader.ReadCoordinates("A2"); Assert.AreEqual(0, actual.RowIndex); Assert.AreEqual(1, actual.ColumnIndex); }
public void GetNumericInputInclusive_UpperBoundInput_ReturnsInput() { Mock <IOutputWriter> mockOutputWriter = new Mock <IOutputWriter>(); Mock <IInputReader> mockInputReader = new Mock <IInputReader>(); mockInputReader.Setup(m => m.ReadLine()).Returns("2"); UserInputReader cut = new UserInputReader(mockInputReader.Object, mockOutputWriter.Object); int input = cut.GetNumericInputInclusive(2); Assert.AreEqual(2, input); }
/// <summary> /// Search for and download the specified gitignore, fails if not found /// </summary> /// <param name="ignore"></param> /// <returns>The downloaded .gitignore contents as a string</returns> /// <exception cref="FileNotFoundException">File was not found in the repository</exception> /// <Example> /// Input: "Visual Studio Code" -- Downloads visualstudiocode.gitignore and returns contents /// </Example> public string download(string ignore) { if (cache.Data.ContainsKey(ignore)) { if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {ignore}"); } return(WebFetch.fetch(cache.Data[ignore])); } else { Console.WriteLine($"Exact match to {ignore} not found. "); IList <String> searchResults = search(ignore); if (searchResults.Count > 1) { int choice = UserInputReader.EnumerateChoices( $"There are {searchResults.Count} .gitignore files similar to your choice.", "Enter a selection:", searchResults ); if (choice > -1) { // In the case that search adds extra lines for information, clean it up string choiceName = new StringReader(searchResults[choice]).ReadLine(); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {choiceName}"); } return(WebFetch.fetch(cache.Data[choiceName])); } } else if (searchResults.Count == 1) { if (UserInputReader.GetConfirmation($".gitignore {ignore} not found. Did you mean {searchResults[0]}?", false)) { string choiceName = new StringReader(searchResults[0]).ReadLine(); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {choiceName}"); } return(WebFetch.fetch(cache.Data[choiceName])); } } } throw new System.IO.FileNotFoundException("Specified .gitignore was not found in the Repository."); }
static void Main() { var userInputReader = new UserInputReader(); var messageWriter = new MessageWriter(); var messageProvider = new MessageProvider(); var guessValidator = new GuessValidator(); var guessEvaluator = new GuessEvaluator(); var game = new Game(userInputReader, messageWriter, messageProvider, guessValidator, guessEvaluator); game.Play(); }
public void GetNumericInputInclusive_NegativeAttempt_ReturnsSecondValidInput() { Mock <IOutputWriter> mockOutputWriter = new Mock <IOutputWriter>(); Mock <IInputReader> mockInputReader = new Mock <IInputReader>(); mockInputReader.SetupSequence(m => m.ReadLine()) .Returns("-3") .Returns("2"); UserInputReader cut = new UserInputReader(mockInputReader.Object, mockOutputWriter.Object); int input = cut.GetNumericInputInclusive(2); Assert.AreEqual(2, input); }
public void Start() { do { Console.WriteLine("============Welcome to Employee Management Program============\n "); Console.WriteLine( "To Register new Employee press R\n" + "To List Available Employee press L\n " + "To Delete a registered Employee press D\n" + "To exit press any key\n"); Console.WriteLine("============================================================== "); Console.Write("Enter your choice: "); var choice = Console.ReadLine(); switch (choice) { case "R": case "r": { var emp = new Employee(UserInputReader.ReadString(), UserInputReader.ReadDouble(), UserInputReader.ReadInt()); AddEmployee(emp); break; } case "L": case "l": DisplayEmployees(); break; case "D": case "d": { //Console.Write("Please enter the employee Id: "); var id = UserInputReader.ReadInt(); DeleteEmployee(id); break; } default: { Console.WriteLine("Exiting the Program..."); Environment.Exit(1); break; } } } while (true); }
public static ISourceReader GetAppropriateReader(ReaderType readerType) { ISourceReader reader = null; switch (readerType) { case ReaderType.UserInputText: reader = new UserInputReader(); break; case ReaderType.TextFromFile: reader = new FileContentReader(); break; default: break; } return(reader); }
static void Main(string[] args) { IOutputWriter outputWriter = new ConsoleWriter(); IInputReader inputReader = new ConsoleReader(); StoryWriter storyWriter = new StoryWriter(outputWriter); UserInputReader userInputReader = new UserInputReader(inputReader, outputWriter); storyWriter.Title(); storyWriter.AllDays(); for (int input = userInputReader.GetNumericInputInclusive(MaxMenuOptions); input != MaxMenuOptions; input = userInputReader.GetNumericInputInclusive(MaxMenuOptions)) { switch (input) { case 1: FuelCounterUpper fuelCounterUpper = new FuelCounterUpper(outputWriter); fuelCounterUpper.Initialize(); break; case 2: IntcodeComputer intcodeComputer = new IntcodeComputer(outputWriter); intcodeComputer.Initialize(); break; case 3: FuelManager fuelManager = new FuelManager(outputWriter); fuelManager.Initialize(); break; case 4: VenusFuelDepot fuelDepot = new VenusFuelDepot(outputWriter); fuelDepot.Initialize(); break; } inputReader.ReadLine(); storyWriter.AllDays(); } }