/// <summary> /// Register components. /// </summary> /// <param name="swaggerFile"> /// The contents of the swagger file. This cannot be null, empty or whitespace. /// </param> /// <param name="baseUrl"> /// The optional base URL to use for testing the web service. /// </param> public static void Register(string swaggerFile, Uri baseUrl = null) { if (string.IsNullOrWhiteSpace(swaggerFile)) { throw new ArgumentNullException(nameof(swaggerFile)); } Configuration = new JabTestConfiguration(swaggerFile, baseUrl); }
// TODO: How do we mock this? Should we make it a non extension method and do it the old fashioned way? /// <summary> /// Construct an <see cref="HttpClient"/> for the current <see cref="IJabTestConfiguration.BaseUrl"/>, if any. /// </summary> /// <param name="configuration"> /// The <see cref="IJabApiOperation"/> to extract the configuration from. This cannot be null. /// </param> /// <returns> /// An <see cref="HttpClient"/> initialized for the current <see cref="IJabTestConfiguration.BaseUrl"/> or null, /// if <see cref="IJabTestConfiguration.BaseUrl"/> is null. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="configuration"/> cannot be null. /// </exception> public static HttpClient GetClient(this IJabTestConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } return(configuration.BaseUrl != null ? new HttpClient() { BaseAddress = configuration.BaseUrl } : null); }
/// <summary> /// Enumerate the API operations. /// </summary> /// <returns>Collection of possible operations (string path, SwaggerOperationMethod method, SwaggerOperation operation)</returns> public static IEnumerable <TestCaseData> GetOperations(IJabTestConfiguration configurationSource, Predicate <IJabApiOperation> predicate = null) { IJabApiOperation jabApiOperation; foreach (KeyValuePair <string, SwaggerOperations> path in configurationSource.SwaggerService.Paths) { foreach (KeyValuePair <SwaggerOperationMethod, SwaggerOperation> operation in path.Value) { jabApiOperation = new JabApiOperation(configurationSource.SwaggerService, path.Key, operation.Key, operation.Value); if (predicate == null || predicate(jabApiOperation)) { yield return(new TestCaseData(jabApiOperation) .SetName($"{operation.Key.ToString().ToUpper()} {configurationSource.SwaggerService.BaseUrl}{path.Key}")); } } } }
/// <summary> /// Enumerate the API operations. /// </summary> /// <returns>A collection enumerator</returns> public static IEnumerable <TestCaseData> GetServices(IJabTestConfiguration configurationSource) { yield return(new TestCaseData(configurationSource.SwaggerService) .SetName(configurationSource.SwaggerService.BaseUrl)); }