public void ParameterPart_ParameterNameAndDefaultAndParameterKindAndEnumerableOfParameterPolicies_ShouldMakeCopyOfParameterPolicies() { // Arrange (going through hoops to get an enumerable of RoutePatternParameterPolicyReference) const string name = "Id"; var defaults = new { a = "13", }; var x = new InlineConstraint("x"); var y = new InlineConstraint("y"); var z = new InlineConstraint("z"); var constraints = new[] { x, y, z }; var templatePart = TemplatePart.CreateParameter("t", false, false, null, constraints); var routePatternParameterPart = (RoutePatternParameterPart)templatePart.ToRoutePatternPart(); var policies = routePatternParameterPart.ParameterPolicies.ToList(); // Act var parameterPart = RoutePatternFactory.ParameterPart(name, defaults, RoutePatternParameterKind.Standard, policies); policies[0] = null; policies.RemoveAt(1); // Assert Assert.NotNull(parameterPart.ParameterPolicies); Assert.Equal(3, parameterPart.ParameterPolicies.Count); Assert.NotNull(parameterPart.ParameterPolicies[0]); Assert.NotNull(parameterPart.ParameterPolicies[1]); Assert.NotNull(parameterPart.ParameterPolicies[2]); }
public void IsCompliant_GivenAPredicate_ShouldCallPredicate() { var called = false; var constraint = new InlineConstraint<string> ( p => called = true, null ); constraint.IsCompliant ( "value", null ); Assert.IsTrue ( called ); }
public void testMethodName() { var constraint = new InlineConstraint <GpraNonResponseTypeDto <int?> >(p => Comparer <GpraNonResponseTypeDto <int?> > .Default.Compare(p, 5) == 0); var isCompliant = constraint.IsCompliant(new GpraNonResponseTypeDto <int?> { Value = 5 }, null); }
public void IsCompliant_GivenAPredicate_ShouldCallPredicate() { var called = false; var constraint = new InlineConstraint <string> (p => called = true, null); constraint.IsCompliant("value", null); Assert.IsTrue(called); }
/// <summary> /// Adds an <see cref="InlineConstraint{TProperty}"/> to a rule. /// </summary> /// <typeparam name="TSubject">Type of subject of the rule.</typeparam> /// <typeparam name="TContext">Type of <see cref="IRuleEngineContext"/> of the rule.</typeparam> /// <typeparam name="TProperty">Type of property of the subject of the rule.</typeparam> /// <param name="propertyRuleBuilder"><see cref="IPropertyRuleBuilder{TContext,TSubject,TProperty}"/> currently configuring the rule.</param> /// <param name="predicate"><see cref="Predicate{T}"/> to use in the inline constraint.</param> /// <param name="message">Rule Violation Message for Constraint.</param> /// <returns>A <see cref="IPropertyRuleBuilder{TContext,TSubject,TProperty}"/>.</returns> public static IPropertyRuleBuilder <TContext, TSubject, TProperty> Constrain <TSubject, TContext, TProperty> ( this IPropertyRuleBuilder <TContext, TSubject, TProperty> propertyRuleBuilder, Predicate <TProperty> predicate, string message = null) where TContext : RuleEngineContext <TSubject> { var inlineConstraint = new InlineConstraint <TProperty> (predicate, message); propertyRuleBuilder.Constrain(inlineConstraint); return(propertyRuleBuilder); }
[InlineData(@"{p1:regex(([{{(])\w+)}", @"regex(([{(])\w+)")] // Not balanced { public void Parse_RegularExpressions(string template, string constraint) { // Arrange var expected = new RouteTemplate(template, new List <TemplateSegment>()); expected.Segments.Add(new TemplateSegment()); var c = new InlineConstraint(constraint); expected.Segments[0].Parts.Add( TemplatePart.CreateParameter("p1", false, false, defaultValue: null, inlineConstraints: new List <InlineConstraint> { c })); expected.Parameters.Add(expected.Segments[0].Parts[0]); // Act var actual = TemplateParser.Parse(template); // Assert Assert.Equal <RouteTemplate>(expected, actual, new TemplateEqualityComparer()); }
public void IsCompliant_GivenAWrongTypeValue_ShouldThrowArgumentException() { var constraint = new InlineConstraint<string> ( p => true, null ); constraint.IsCompliant ( 5, null ); }
public void testMethodName() { var constraint = new InlineConstraint<GpraNonResponseTypeDto<int?>>(p => Comparer<GpraNonResponseTypeDto<int?>>.Default.Compare(p, 5) == 0); var isCompliant = constraint.IsCompliant ( new GpraNonResponseTypeDto<int?> { Value = 5 }, null ); }
public void IsCompliant_GivenAWrongTypeValue_ShouldThrowArgumentException() { var constraint = new InlineConstraint <string> (p => true, null); constraint.IsCompliant(5, null); }