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 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);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            try
            {
                // Make sure the arguments are properly split apart before creating the argument model.
                string[] splitArgs = ArgumentsHandler.BreakApartArguments(args);

                // Create arguments model from passed in arguments.
                ArgumentsModel argumentsModel = ArgumentsHandler.CreateArgumentsModelFromUserInput(splitArgs);

                // Validate the arguments model before making the API request.
                ArgumentsHandler.ValidateArgumentsModel(argumentsModel);

                // Notify the user that we're about to make an API request.
                Console.WriteLine(OutputConstants.API_LOADING);

                // Make the API request.
                NumfactsAPIClient numfactsAPIClient = new NumfactsAPIClient(
                    new RestClient(
                        NumfactsAPIClient.BuildAPIEndpointUrl(argumentsModel)
                        )
                    );

                APIResponseModel apiResponseModel = numfactsAPIClient.GetNumFact();

                // Display the results to the user.
                if (apiResponseModel.Found)
                {
                    Console.WriteLine(OutputConstants.FACT_DISPLAY_TEMPLATE, MathOrTriviaFactPrefix(apiResponseModel), apiResponseModel.Number, apiResponseModel.Text);
                }
                else
                {
                    throw new Exception(ErrorConstants.NO_FACT_FOUND + apiResponseModel.Number);
                }
            } catch (Exception ex)
            {
                // Display the error to the user.
                Console.WriteLine(ex.Message);
            }
        }