public StringConstraintsSpeck() { Specify(x => StringConstraints.FromMember(Member)) // .Case("FromProperty without stringlength attribute", _ => _ .Given(StringLengthAttributeContext(false)) .It("should return null", x => x.Result.Should().BeNull())) // .Case("FromProperty without correct string length attribute", _ => _ .Given(StringLengthAttributeContext(true, 3, 5)) .It("should return correct min value", x => x.Result.MinLength.Should().Be(3)) .It("should return correct max value", x => x.Result.MaxLength.Should().Be(5))) .Case("FromProperty with correct min and max property", _ => _ .Given(MinAttributeContext(true, 3)) .Given(MaxAttributeContext(true, 5)) .It("should return correct min value", x => x.Result.MinLength.Should().Be(3)) .It("should return correct max value", x => x.Result.MaxLength.Should().Be(5))) .Case("FromProperty with correct min value", _ => _ .Given(MinAttributeContext(true, 3)) .It("should return correct min value", x => x.Result.MinLength.Should().Be(3)) .It("should return correct assumed max value", x => x.Result.MaxLength.Should().Be(103))) .Case("FromProperty with correct max attribute", _ => _ .Given(MaxAttributeContext(true, 103)) .It("should return correct assumed min value", x => x.Result.MinLength.Should().Be(3)) .It("should return correct max value", x => x.Result.MaxLength.Should().Be(103))) .Case("FromProperty with correct but low attribute", _ => _ .Given(MaxAttributeContext(true, 3)) .It("should return correct assumed min value", x => x.Result.MinLength.Should().Be(0)) .It("should return correct max value", x => x.Result.MaxLength.Should().Be(3))) .Case("FromProperty with invalid stringlength property", _ => _ .Given(StringLengthAttributeContext(true, 5, 3)).ItThrows(typeof(ArgumentOutOfRangeException))) .Case("FromProperty with invalid min and max attribute", _ => _ .Given(MinAttributeContext(true, 5)) .Given(MaxAttributeContext(true, 3)).ItThrows(typeof(ArgumentOutOfRangeException))); }
protected override StringConstrainedValueProviderContext CreateContext(ValueProviderObjectContext objectContext) { var stringConstraints = StringConstraints.FromMember(objectContext.Member) ?? new StringConstraints(_minWordLength, _maxWordLength); return(new StringConstrainedValueProviderContext(objectContext, stringConstraints)); }