public void ValidateCancelTest() #if NO_CANCELLATION_TOKEN { var context = new TestValidationContext(); Assert.False(context.Context.IsCancelled); // Must use a type with multiple types as cancellation is checked at the start of processing each type var validator = ValidatorBuilder.Create() .AddKnownType <TestClass1>() .AddPropertyFilter <TestClass2>() .AddConstraint(_ => new DelegateConstraint(() => { context.Context.Cancel(); })) .Build(); var instance = new TestClass1 { Instance = new TestClass2(), }; Assert.Throws <OperationCanceledException>(() => validator.Validate(instance, context.Context)); Assert.True(context.Context.IsCancelled); }