public void ShouldReturnURLForRandomNumberMathFact() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); ArgumentsModel argumentsModel = argumentsModelBuilder.WithRandomNumber().WithMathFact().Build(); // Act string endpointUrl = NumfactsAPIClient.BuildAPIEndpointUrl(argumentsModel); // Assert Assert.AreEqual($"https://numbersapi.p.rapidapi.com/random/math", endpointUrl); }
public void ShouldCreateModelWithRandomNumberBoolean() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); argumentsModelBuilder.WithRandomNumber(); // Act ArgumentsModel argumentsModel = argumentsModelBuilder.Build(); // Assert Assert.AreEqual(int.MinValue, argumentsModel.Number); Assert.IsFalse(argumentsModel.NumberProvided); Assert.AreEqual(true, 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); }