public void Annotation_Name_InObjectValueContractTest() { var contract = VerifiableObjectContractManager.Resolve <NiceBoat>(); contract.IncludeAnnotations.ShouldBeTrue(); var value1 = contract.GetMemberContract("Name"); value1.IncludeAnnotations.ShouldBeTrue(); value1.Attributes.Count.ShouldBe(1); var a101 = value1.GetFlagAnnotations().ToList(); a101.Count.ShouldBe(1); a101[0].GetType().ShouldBe(typeof(NotWhiteSpaceAttribute)); var a102 = value1.GetParameterAnnotations().ToList(); a102.Count.ShouldBe(1); a102[0].GetType().ShouldBe(typeof(NotWhiteSpaceAttribute)); a102[0].Name.ShouldBe("Not-WhiteSpace Annotation"); var a103 = value1.GetVerifiableAnnotations().ToList(); a103.Count.ShouldBe(0); var a104 = value1.GetQuietVerifiableAnnotations().ToList(); a104.Count.ShouldBe(0); var a105 = value1.GetStrongVerifiableAnnotations().ToList(); a105.Count.ShouldBe(0); var a106 = value1.GetObjectContextVerifiableAnnotations().ToList(); a106.Count.ShouldBe(0); }
public void Annotation_Length_InObjectValueContractTest() { var contract = VerifiableObjectContractManager.Resolve <NiceBoat>(); contract.IncludeAnnotations.ShouldBeTrue(); var value2 = contract.GetMemberContract("Length"); value2.IncludeAnnotations.ShouldBeTrue(); value2.Attributes.Count.ShouldBe(1); var a201 = value2.GetFlagAnnotations().ToList(); a201.Count.ShouldBe(1); a201[0].GetType().ShouldBe(typeof(NotNegativeAttribute)); var a202 = value2.GetParameterAnnotations().ToList(); a202.Count.ShouldBe(1); a202[0].GetType().ShouldBe(typeof(NotNegativeAttribute)); a202[0].Name.ShouldBe("Not-Negative Annotation"); var a203 = value2.GetVerifiableAnnotations().ToList(); a203.Count.ShouldBe(0); var a204 = value2.GetQuietVerifiableAnnotations().ToList(); a204.Count.ShouldBe(0); var a205 = value2.GetStrongVerifiableAnnotations().ToList(); a205.Count.ShouldBe(0); var a206 = value2.GetObjectContextVerifiableAnnotations().ToList(); a206.Count.ShouldBe(0); }
public void AunnCoo_StringExprFunc_RegexExprToken_ShouldBeValid() { var model = new AunnCoo { Name = "Alice", AunnRegexExpression = @"^(Al)\w+(e)$" }; var context = VerifiableObjectContractManager.Resolve <AunnCoo>().WithInstance(model); var member = context.GetValue("Name"); var contract = member.ExposeContract(); Func <object, string> expression = obj => { if (obj is AunnCoo aunnCoo) { return(aunnCoo.AunnRegexExpression); } return(string.Empty); }; var token = new ValueRegularExpressionToken(contract, expression); token.Valid(context).IsSuccess.ShouldBeTrue(); token.Valid(member).IsSuccess.ShouldBeTrue(); }