public static MethodDefinition FromRequest(string request, CodeBlockAnnotation annotation, DocFile source) { var method = new MethodDefinition { Request = request, RequestMetadata = annotation, Identifier = annotation.MethodName, SourceFile = source }; method.Title = method.Identifier; return method; }
public static ScenarioDefinition[] ScenariosForMethod(this IEnumerable<ScenarioDefinition> scenarios, MethodDefinition method) { var id = method.Identifier; var query = from p in scenarios where p.MethodName == id select p; if (method.Scenarios != null && method.Scenarios.Count > 0) { query = query.Union(method.Scenarios); } return query.ToArray(); }
private static async Task ValidateMethodWithScenarioAsync( MethodDefinition method, ScenarioDefinition scenario, IServiceAccount account, AuthenicationCredentials credentials, ValidationResults results) { if (null == method) throw new ArgumentNullException("method"); if (null == scenario) throw new ArgumentNullException("scenario"); if (null == account) throw new ArgumentNullException("account"); if (null == credentials) throw new ArgumentNullException("credentials"); if (null == results) throw new ArgumentNullException("results"); var actionName = scenario.Description; // Generate the tested request by "previewing" the request and executing // all test-setup procedures long startTicks = DateTimeOffset.UtcNow.Ticks; var requestPreviewResult = await method.GenerateMethodRequestAsync(scenario, account.BaseUrl, credentials, method.SourceFile.Parent); TimeSpan generateMethodDuration = new TimeSpan(DateTimeOffset.UtcNow.Ticks - startTicks); // Check to see if an error occured building the request, and abort if so. var generatorResults = results[actionName + " [test-setup requests]"]; generatorResults.AddResults(requestPreviewResult.Messages, requestPreviewResult.IsWarningOrError ? ValidationOutcome.Error : ValidationOutcome.Passed); generatorResults.Duration = generateMethodDuration; if (requestPreviewResult.IsWarningOrError) { return; } // We've done all the test-setup work, now we have the real request to make to the service HttpRequest requestPreview = requestPreviewResult.Value; results.AddResult( actionName, new ValidationMessage(null, "Generated Method HTTP Request:\r\n{0}", requestPreview.FullHttpText())); HttpParser parser = new HttpParser(); HttpResponse expectedResponse = null; if (!string.IsNullOrEmpty(method.ExpectedResponse)) { expectedResponse = parser.ParseHttpResponse(method.ExpectedResponse); } // Execute the actual tested method (the result of the method preview call, which made the test-setup requests) startTicks = DateTimeOffset.UtcNow.Ticks; var actualResponse = await requestPreview.GetResponseAsync(account.BaseUrl); TimeSpan actualMethodDuration = new TimeSpan(DateTimeOffset.UtcNow.Ticks - startTicks); var requestResults = results[actionName]; if (actualResponse.RetryCount > 0) { requestResults.AddResults( new ValidationError[] { new ValidationWarning(ValidationErrorCode.RequestWasRetried, null, "HTTP request was retried {0} times.", actualResponse.RetryCount) }); } requestResults.AddResults( new ValidationError[] { new ValidationMessage(null, "HTTP Response:\r\n{0}", actualResponse.FullText(false)) }); requestResults.Duration = actualMethodDuration; // Perform validation on the method's actual response ValidationError[] errors; method.ValidateResponse(actualResponse, expectedResponse, scenario, out errors); requestResults.AddResults(errors); // TODO: If the method is defined as a long running operation, we need to go poll the status // URL to make sure that the operation finished and the response type is valid. if (errors.WereErrors()) results.SetOutcome(actionName, ValidationOutcome.Error); else if (errors.WereWarnings()) results.SetOutcome(actionName, ValidationOutcome.Warning); else results.SetOutcome(actionName, ValidationOutcome.Passed); }
private static object SwaggerPropertyForResponse(MethodDefinition definition) { string customDataType = definition.ExpectedResponseMetadata.ResourceType; var type = new ParameterDataType(customDataType, true); string description = null; return MakeSwaggerProperty(type, description); }
private static object SwaggerPropertyForResponse(MethodDefinition definition) { JsonDataType type = JsonDataType.ODataType; string customDataType = definition.ExpectedResponseMetadata.ResourceType; string description = null; return MakeSwaggerProperty(type, customDataType, description); }
private static void SetFoundTablesOnMethod(IEnumerable<TableDefinition> foundTables, MethodDefinition onlyMethod) { foreach (var table in foundTables) { switch (table.Type) { case TableBlockType.Unknown: // Unknown table format, nothing we can do with it. break; case TableBlockType.EnumerationValues: // TODO: Support enumeration values Console.WriteLine("Enumeration that wasn't handled: {0} on method {1} ", table.Title, onlyMethod.RequestMetadata.MethodName); break; case TableBlockType.ErrorCodes: onlyMethod.Errors = table.Rows.Cast<ErrorDefinition>().ToList(); break; case TableBlockType.HttpHeaders: case TableBlockType.PathParameters: case TableBlockType.QueryStringParameters: onlyMethod.Parameters.AddRange(table.Rows.Cast<ParameterDefinition>()); break; case TableBlockType.RequestObjectProperties: onlyMethod.RequestBodyParameters.AddRange(table.Rows.Cast<ParameterDefinition>()); break; case TableBlockType.ResourcePropertyDescriptions: case TableBlockType.ResponseObjectProperties: Console.WriteLine("Object description that wasn't handled: {0} on method {1}", table.Title, onlyMethod.RequestMetadata.MethodName); break; default: Console.WriteLine("Something else that wasn't handled: type:{0}, title:{1} on method {2}", table.Type, table.Title, onlyMethod.RequestMetadata.MethodName); break; } } }