public void Ctor_StringEmpty_Error() { CustomAssert.ThrowsException<CodedArgumentNullOrWhiteSpaceException>(() => { RegexConstraint c = new RegexConstraint(string.Empty, RegexOptions.None); }); }
private static RegexConstraint GetConstraint(RegexConstraint constraint) { Precondition.Require(constraint, () => Error.ArgumentNull("constraint")); return(constraint); }
public void Ctor_String_Success() { RegexConstraint c = new RegexConstraint(Constants.RegexString, RegexOptions.IgnoreCase); Assert.AreEqual(Constraint.RegexConstraintName, c.Name); Assert.AreEqual(Constants.RegexString, c.RegularExpression); Assert.AreEqual(RegexOptions.IgnoreCase, c.Options); }
private static RegexConstraint GetConstraint(RegexConstraint constraint) { Precondition.Require(constraint, () => Error.ArgumentNull("constraint")); return constraint; }
public void Ctor_Void_Success() { RegexConstraint c = new RegexConstraint(); Assert.AreEqual(Constraint.RegexConstraintName, c.Name); Assert.AreEqual(".*", c.RegularExpression); Assert.AreEqual(RegexOptions.None, c.Options); }
public void MatchTest() { var constraint = new RegexConstraint("^[A-Z]+$"); Assert.IsTrue(constraint.IsValid(null, "HELLO", null)); Assert.IsFalse(constraint.IsValid(null, "99", null)); }
public void ConstraintsGenTypes() { var orderInt = new OrderedIntConstraint(Order.Equal, int.MinValue, DicomTag.SeriesNumber); var orderDouble = new OrderedDoubleConstraint(Order.Equal, double.MaxValue, DicomTag.SeriesNumber); var orderDateTime = new OrderedDateTimeConstraint(Order.Equal, DateTime.UtcNow, DicomTag.SeriesNumber); var orderString = new OrderedStringConstraint(Order.Equal, new OrderedString("hOOf", StringComparisonType.CulureInvariantCaseSensitive), DicomTag.SeriesNumber); var stringOrderUID = new UIDStringOrderConstraint(Order.Equal, DicomUID.CTImageStorage.UID, DicomTag.SOPClassUID); var timeOrder = new TimeOrderConstraint(Order.GreaterThanOrEqual, new TimeSpan(0, 0, 0), DicomTag.SeriesTime); var stringContains = new StringContainsConstraint(DicomTag.PatientPosition, "HFS"); var stringRegex = new RegexConstraint(DicomTag.SeriesDescription, "(hog)", RegexOptions.ECMAScript); var compareStrings = new[] { "HOOF", "LEAF", "FLOWER", "HOG" }.Select(t => new OrderedString(t)); var stringCompountGroup = new GroupConstraint(compareStrings.Select(c => new OrderedStringConstraint(Order.Equal, c, DicomTag.BodyPartExamined)).ToArray(), LogicalOperator.Or); var stringCompound = new GroupTagConstraint(stringCompountGroup, DicomTag.BodyPartExamined); DicomConstraint[] dc = new[] { new RequiredTagConstraint(TagRequirement.Optional, orderInt), new RequiredTagConstraint(TagRequirement.Optional, orderDouble), new RequiredTagConstraint(TagRequirement.Optional, orderDateTime), new RequiredTagConstraint(TagRequirement.Optional, orderString), new RequiredTagConstraint(TagRequirement.Optional, stringOrderUID), new RequiredTagConstraint(TagRequirement.PresentCanBeEmpty, timeOrder), new RequiredTagConstraint(TagRequirement.PresentCanBeEmpty, stringContains), new RequiredTagConstraint(TagRequirement.Optional, stringRegex), new RequiredTagConstraint(TagRequirement.PresentNotEmpty, stringOrderUID), new RequiredTagConstraint(TagRequirement.Optional, orderString), new RequiredTagConstraint(TagRequirement.Optional, stringCompound), }; var dc2 = new GroupConstraint(dc, LogicalOperator.Or) as DicomConstraint; JsonConvert.SerializeObject(dc2); }
public void Should_match_when_parameter_is_optional() { var constraint = new RegexConstraint(@"^[a-zA-Z0-9]+$", true); var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "alias", new RouteValueDictionary(), RouteDirection.IncomingRequest); Assert.True(matched); }
public void Should_not_match_when_pattern_does_not_match() { var constraint = new RegexConstraint(@"^[a-zA-Z0-9]+$"); var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "alias", new RouteValueDictionary { { "alias", "@#%" } }, RouteDirection.IncomingRequest); Assert.False(matched); }
public void ConstraintRegex() { var c0 = new RegexConstraint(DicomTag.SeriesDescription, @"(hog)", RegexOptions.ECMAScript); var c0R = new RequiredTagConstraint(TagRequirement.Optional, c0); DicomDataset ds = new DicomDataset(); ds.AddOrUpdate(DicomTag.SeriesDescription, @"hog protocol v1"); Assert.IsTrue(c0R.Check(ds).Result); }
public void NumericStringShouldNeverViolateConstraint() { // Fixture setup var generator = from n in Arb.Generate <uint>() select n.ToString(); var constraint = new RegexConstraint(pattern); // Exercise system and verify outcome Prop.ForAll( generator.ToArbitrary(), s => constraint.Check(s).Violated.Should().BeFalse()) .QuickCheckThrowOnFailure(); }
public void NotNumericStringStringShouldAlwaysViolateConstraint() { // Fixture setup var generator = from s in Arb.Generate <string>() where s != null && !s.Any(char.IsDigit) select s; var constraint = new RegexConstraint(pattern); // Exercise system and verify outcome Prop.ForAll(generator.ToArbitrary(), s => { var result = constraint.Check(s); result.Violated.Should().BeTrue(); result.Message.Should().Be($"String does not match pattern '{pattern}'."); }).QuickCheckThrowOnFailure(); }
public RegexConstraintDefinition(RegexConstraint constraint) : base(GetConstraint(constraint).ParameterName) { _pattern = constraint.Pattern.ToString(); }
public void ToString_Success() { RegexConstraint c = new RegexConstraint("[a-z]*", RegexOptions.IgnoreCase); Assert.AreEqual("[Regex('[a-z]*',IgnoreCase)]", c.ToString()); }
public void CaseInsensitiveByDefault() { var constraint = new RegexConstraint("^[A-Z]+$"); Assert.IsTrue(constraint.IsValid(null, "HelLo", null)); }
public void SetParameters_Success() { RegexConstraint c = new RegexConstraint(); c.SetParametersInternal(new string[] { Constants.RegexString, "IgnoreCase" }, ParameterDataType.String); Assert.AreEqual(Constants.RegexString, c.RegularExpression); Assert.AreEqual(RegexOptions.IgnoreCase, c.Options); }
public void Ctor_InvOptions_Error() { CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() => { RegexConstraint c = new RegexConstraint(Constants.RegexString, RegexOptions.ECMAScript | RegexOptions.Singleline); }); }
public void Ctor_SerializationInfo_Success() { RegexConstraint c = new RegexConstraint(Constants.RegexString, RegexOptions.IgnoreCase); System.IO.MemoryStream Buffer = SerializationHelper.Serialize(c); RegexConstraint c2 = SerializationHelper.Deserialize<RegexConstraint>(Buffer); Assert.AreEqual(Constraint.RegexConstraintName, c2.Name); Assert.AreEqual(Constants.RegexString, c2.RegularExpression); Assert.AreEqual(RegexOptions.IgnoreCase, c2.Options); }
public void SetParameters_InvRegex_Error() { CustomAssert.ThrowsException<ConstraintConfigurationException>(() => { RegexConstraint c = new RegexConstraint(); c.SetParametersInternal(new string[] { "[", "IgnoreCase" }, ParameterDataType.String); }); }
public void SetParameters_InvOptions_Error() { CustomAssert.ThrowsException<ConstraintConfigurationException>(() => { RegexConstraint c = new RegexConstraint(); c.SetParametersInternal(new string[] { Constants.RegexString, "ECMAScript", "Singleline" }, ParameterDataType.String); }); }
public void Validate_NoMatch_Success() { RegexConstraint c = new RegexConstraint(Constants.RegexString, RegexOptions.IgnoreCase); IEnumerable<ParameterValidationResult> res = c.Validate("Here there be dragons!", ParameterDataType.String, Constants.MemberName); Assert.IsNotNull(res); Assert.IsTrue(res.GetEnumerator().MoveNext()); }
public void Ctor_InvRegex_Error() { CustomAssert.ThrowsException<CodedArgumentException>(() => { RegexConstraint c = new RegexConstraint("[", RegexOptions.None); }); }
internal RegexValidatorInfo(RegexConstraint constraint) : this(constraint.Pattern, constraint.PatternDescription, RegexValidatorInfo.ConvertToJavaScriptOptions(constraint.Options)) { }