public void ShouldCreateModelWithBuilderDefaults() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); // Act ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); // Assert Assert.AreEqual(int.MinValue, argumentsModel.Number); Assert.AreEqual(false, argumentsModel.RandomNumber); Assert.AreEqual(false, argumentsModel.MathFact); Assert.AreEqual(false, argumentsModel.TriviaFact); }
public void ShouldCreateModelWithTriviaFactBoolean() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); argumentsModelBuilder.WithTriviaFact(); // Act ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); // Assert Assert.AreEqual(int.MinValue, argumentsModel.Number); Assert.IsFalse(argumentsModel.NumberProvided); Assert.AreEqual(false, argumentsModel.RandomNumber); Assert.AreEqual(false, argumentsModel.MathFact); Assert.AreEqual(true, argumentsModel.TriviaFact); }
public void ShouldCreateModelWithNumber() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); argumentsModelBuilder.WithNumber(33); // Act ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); // Assert Assert.AreEqual(33, argumentsModel.Number); Assert.IsTrue(argumentsModel.NumberProvided); Assert.AreEqual(false, argumentsModel.RandomNumber); Assert.AreEqual(false, 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); }