internal static string GetLink( this HttpRequest request, TestTarget testTarget, TestDefinition testDefinition) { var scheme = request.Scheme; var host = request.Host; return($"{scheme}://{host}/tests/{testTarget.Environment}/{testTarget.Application}/{testDefinition.TestName}"); }
internal static string GetLinkWithQuery( this HttpRequest request, TestTarget testTarget, TestDefinition testDefinition, ParameterSet parameters) { var query = parameters.GetQueryString(); query = string.IsNullOrWhiteSpace(query) ? string.Empty : $"?{query}"; return($"{request.GetLink(testTarget, testDefinition)}{query}"); }
public DetailsForTarget(TestTarget target) { this.target = target ?? throw new ArgumentNullException(nameof(target)); try { Initialize(); } catch (Exception exception) { Log.Warning("Dependency resolution error while trying to instantiate {type}", exception, typeof(T)); // return true which will allow the test execution error to be displayed IsApplicable = true; } }
public static IEnumerable <Test> CreateTests(TestTarget testTarget, TestDefinition definition, HttpRequest request) { var testCases = testTarget .DependencyRegistry .GetParameterSetsFor(definition.TestMethod); if (testCases.Any()) { foreach (var testCase in testCases) { yield return(new Test { Environment = testTarget.Environment, Application = testTarget.Application, Url = request.GetLinkWithQuery(testTarget, definition, testCase), Tags = definition.Tags, Parameters = testCase.ToArray() }); } } else { yield return(new Test { Environment = testTarget.Environment, Application = testTarget.Application, Url = definition.Parameters.Any() ? request.GetLinkWithQuery(testTarget, definition, definition.Parameters) : request.GetLink(testTarget, definition), Tags = definition.Tags, Parameters = definition.Parameters.Any() ? definition.Parameters.ToArray() : Array.Empty <Parameter>() }); } }
public override bool AppliesTo(TestTarget target) => applicabilityCache.GetOrAdd(target, t => new DetailsForTarget(t)) .IsApplicable;
internal override async Task <object> Run(HttpContext context, Func <Type, object> resolve, TestTarget target) { var executeTestMethod = defaultExecuteTestMethod; var methodParameters = TestMethod.GetParameters(); var queryParameters = context.Request.Query; if (queryParameters.Keys.Any(p => methodParameters.Select(pp => pp.Name).Contains(p))) { executeTestMethod = BuildTestMethodExpression( TestMethod, methodParameters .Select(p => { var value = queryParameters[p.Name].FirstOrDefault() ?? p.DefaultValue; try { object castedValue; if (p.ParameterType.IsEnum && value != null) { castedValue = Enum.Parse(p.ParameterType, value.ToString(), true); } else { castedValue = Convert.ChangeType(value, p.ParameterType); } return(Expression.Constant(castedValue)); } catch (FormatException e) { throw new ParameterFormatException(p.Name, p.ParameterType, e); } })); } var testClassInstance = (T)resolve(typeof(T)); switch (testClassInstance) { case IParameterizedTestCases parameterizedTest: parameterizedTest.RegisterTestCasesTo(target.DependencyRegistry); break; } return(executeTestMethod(testClassInstance)); }
internal abstract Task <object> Run(HttpContext httpContext, Func <Type, object> resolve, TestTarget target);