/// <summary> /// Performs the validation logic asynchronously and returns a task of <see cref="RuleResult"/>. /// </summary> /// <param name="validated">The object being validated</param> /// <param name="context">Contextual information about the validation</param> /// <param name="token">An object which may be used to cancel the process</param> /// <returns>A task which provides a result object, indicating the result of validation</returns> public Task <RuleResult> GetResultAsync(ICollection <T> validated, RuleContext context, CancellationToken token = default) { // Because both NotNull & NotEmpty<T> are synchronous, it is safe to use .Result var notNullResult = notNull.GetResultAsync(validated, context, token).Result; var notEmptyResult = notEmpty.GetResultAsync(validated, context, token).Result; return(notNullResult.IsPass && notEmptyResult.IsPass ? PassAsync() : FailAsync()); }
public void GetResultAsyncShouldReturnFailForNull(NotNull sut, [RuleContext] RuleContext context) { Assert.That(() => sut.GetResultAsync(null, context), Is.FailingValidationResult); }
public void GetResultAsyncShouldReturnPassForANonNullInteger(NotNull sut, [RuleContext] RuleContext context, int value) { Assert.That(() => sut.GetResultAsync(value, context), Is.PassingValidationResult); }
public void GetResultAsyncShouldReturnFailForANullInteger(NotNull sut, [RuleContext] RuleContext context) { int?value = null; Assert.That(() => sut.GetResultAsync(value, context), Is.FailingValidationResult); }