public void ShouldReturnURLForProvidedNumberTriviaFact() { // Arrange ArgumentsModelBuilder argumentsModelBuilder = new ArgumentsModelBuilder(); ArgumentsModel argumentsModel = argumentsModelBuilder.WithNumber(33).WithTriviaFact().Build(); // Act string endpointUrl = NumfactsAPIClient.BuildAPIEndpointUrl(argumentsModel); // Assert Assert.AreEqual($"https://numbersapi.p.rapidapi.com/33/trivia", endpointUrl); }
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); }