public void ShouldCreateModelWithMathFactBoolean() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); argumentsModelBuilder.WithMathFact(); // Act ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); // Assert Assert.AreEqual(int.MinValue, argumentsModel.Number); Assert.IsFalse(argumentsModel.NumberProvided); Assert.AreEqual(false, argumentsModel.RandomNumber); Assert.AreEqual(true, argumentsModel.MathFact); Assert.AreEqual(false, argumentsModel.TriviaFact); }
public static ArgumentsModel CreateArgumentsModelFromUserInput(string[] args) { // Create the model builder and begin the building process. Check for errors along the way. ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); // Loop through each argument and add it to the builder for (int i = 0; i < args.Length; i++) { // If this is the first argument, try to parse it as an integer. if (i == 0) { bool numberSuccessfullyParsed = int.TryParse(args[i], out int passedInNumber); if (numberSuccessfullyParsed) { argumentsModelBuilder.WithNumber(passedInNumber); continue; } } // Check for valid options and update model build accordingly. switch (args[i]) { case FlagConstants.RANDOM_NUMBER_FLAG: argumentsModelBuilder.WithRandomNumber(); break; case FlagConstants.MATH_FACT_FLAG: argumentsModelBuilder.WithMathFact(); break; case FlagConstants.TRIVIA_FACT_FLAG: argumentsModelBuilder.WithTriviaFact(); break; default: throw new ArgumentException(ErrorConstants.INVALID_INPUT + args[i]); } } ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); return(argumentsModel); }