private TestValueResult InvokeMethood(object testObject, MethodInfo method, int currentIndex, BreakItOptions options, object[] list, TestValue testValue) { list[currentIndex] = testValue.Value; Exception invokeException = null; object returnValue = null; try { options?.SetUp?.Invoke(list); returnValue = method.Invoke(testObject, list); } catch (Exception ex) { invokeException = ex.InnerException; } var result = new TestValueResult { MemberPath = testValue.MemberPath, Exception = invokeException, TestingValue = testValue, IsSuccess = options?.Validation?.Invoke(testValue, returnValue, invokeException), ReturnValue = returnValue }; _logger?.Log(result); return(result); }
private string CheckValueTest(ValueTestBase valueTest, string value, TestValueResult testValueResult) { string expectedValue = null; string retVal = null; switch (valueTest) { case IsIntegerTest isIntegerTest: { var isInteger = int.TryParse(value, out var valueAsInteger); if (!isInteger) { return($"The value '{value}' is not an integer"); } if (isIntegerTest.CheckForNotZero && valueAsInteger == 0) { return($"The value is zero"); } expectedValue = "[Some whole number]"; break; } case IsDateTodayTest _ when string.IsNullOrEmpty(value): retVal = "The value is empty"; break; case IsDateTodayTest isDateTodayTest: { DateTime dateTime; try { dateTime = DateTime.ParseExact(value, isDateTodayTest.DateFormat, CultureInfo.InvariantCulture); } catch (Exception) { return($"The value '{value}' was not in the DateTime format {isDateTodayTest.DateFormat}"); } var date = DateTime.Now.Date; expectedValue = date.ToString(); retVal = dateTime.Date == date ? null : $"The date {dateTime.Date} is not today"; break; } case EqualsValueTest equalsValueTest: expectedValue = GetDependentValue(equalsValueTest.Value); retVal = expectedValue == value ? null : $"Expected value: '{expectedValue}' Actual Value: '{value}'"; break; default: throw new NotImplementedException(); } testValueResult.InfoItem = $"Expected: {expectedValue} Actual: {value}"; return(retVal); }
/// <inheritdoc /> public string GetFormat(TestValueResult result) { if (result.IsSuccess == null) { return($"{Tag} No validation done"); } return(result.IsSuccess.Value ? $"{Tag} Validation OK" : $"{Tag} Validation NOT OK"); }
/// <inheritdoc /> public string GetFormat(TestValueResult result) { if (result.Exception == null) { return($"{Tag} No exception"); } return($"{Tag} {result.Exception.Message}"); }
/// <inheritdoc /> public string GetFormat(TestValueResult result) { if (result.ReturnValue == null) { return($"{Tag} null or no return value"); } if (result.ReturnValue.IsNumeric()) { return($"{Tag} {result.ReturnValue}"); } if (result.ReturnValue is string) { return($"{Tag} \"{result.ReturnValue}\""); } return($"{Tag} Complex type"); }
private async Task PerformStepsAsync(StepList steps, ValueTestList valueTests) { _CurrentTestResult.UseCaseResults.Add(_CurrentUseCaseResult); foreach (var step in steps) { var stepResult = await RunStepAsync(step); _CurrentUseCaseResult.StepResults.Add(stepResult); if (step is IGetValueStep getValueStep) { if (string.IsNullOrEmpty(getValueStep.ValueKey)) { continue; } _CurrentUseCaseResult.TestValues.Add(getValueStep.ValueKey, stepResult.Value); var valueTestsForStep = valueTests.Where(vt => vt.ValueKey == getValueStep.ValueKey); foreach (var valueTest in valueTestsForStep) { var value = _CurrentUseCaseResult.TestValues[valueTest.ValueKey]; var dependentValue = GetDependentValue(value); var item = new TestValueResult(valueTest); item.ErrorMessage = CheckValueTest(valueTest, dependentValue, item); _CurrentUseCaseResult.TestValueResults.Add(item); if (valueTest.IsRequired && !string.IsNullOrEmpty(item.ErrorMessage)) { throw new Exception($"The test cannot continue because a required Value Test failed.\r\n {valueTest.ToString()}"); } } } } }
/// <inheritdoc /> public string GetFormat(TestValueResult result) { var combination = result.TestingValue; var tag = $"Testing parameter {combination.MemberPath} =>"; if (combination.LogValue == null) { return $"{tag} null"; } if (combination.LogValue is string) { var value = combination.LogValue; if (string.IsNullOrEmpty((string)value)) { return $"{tag} empty"; } return $"{tag} \"{value}\""; } return $"{tag} {combination.LogValue}"; }
public TestQueueForValueTask() { Source = new TestValueResult(); }
/// <summary> /// Log the test value result /// </summary> /// <param name="testValueResult">The test value result</param> public void Log(TestValueResult testValueResult) { Log(string.Join(", ", _logFormatters.Select(l => l.GetFormat(testValueResult)).ToArray())); }