public void ShouldThrowExceptionWhenTriviaFactIsProvidedButNumberIsNot() { // Arrange string[] args = new string[1] { "/t" }; // Act ArgumentsModel argumentsModel = ArgumentsHandler.CreateArgumentsModelFromUserInput(args); // Assert bool modelIsValid = ArgumentsHandler.ValidateArgumentsModel(argumentsModel); }
public void ShouldThrowExceptionWhenBothNumberAndRandomNumberAreRequested() { // Arrange string[] args = new string[2] { "33", "/r" }; // Act ArgumentsModel argumentsModel = ArgumentsHandler.CreateArgumentsModelFromUserInput(args); // Assert bool modelIsValid = ArgumentsHandler.ValidateArgumentsModel(argumentsModel); }
public void ShouldThrowExceptionWhenBothMathAndTriviaFactsAreRequested() { // Arrange string[] args = new string[2] { "/m", "/t" }; // Act ArgumentsModel argumentsModel = ArgumentsHandler.CreateArgumentsModelFromUserInput(args); // Assert bool modelIsValid = ArgumentsHandler.ValidateArgumentsModel(argumentsModel); }
public void ShouldConsiderModelValidWithRandomNumberAndTriviaFact() { // Arrange string[] args = new string[2] { "/r", "/t" }; ArgumentsModel argumentsModel = ArgumentsHandler.CreateArgumentsModelFromUserInput(args); // Act bool modelIsValid = ArgumentsHandler.ValidateArgumentsModel(argumentsModel); // Assert Assert.IsTrue(modelIsValid); }
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); } }