Constraint

We found 10 examples in language CSharp for this search. You will see 40 fragments of code.

Other methods


        [Fact]
        public void ResolveConstraint_RequiredConstraint_ResolvesCorrectly()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint("required");

            // Assert
            Assert.IsType<RequiredRouteConstraint>(constraint);
        }

        [Fact]
        public void ResolveConstraint_IntConstraint_ResolvesCorrectly()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint("int");

            // Assert
            Assert.IsType<IntRouteConstraint>(constraint);
        }

        [Fact]
        public void ResolveConstraint_AlphaConstraint()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint("alpha");

            // Assert
            Assert.IsType<AlphaRouteConstraint>(constraint);
        }

        [Fact]
        public void ResolveConstraint_RegexInlineConstraint_WithAComma_PassesAsASingleArgument()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint("regex(ab,1)");

            // Assert
            Assert.IsType<RegexInlineRouteConstraint>(constraint);
        }

        [Fact]
        public void ResolveConstraint_RegexInlineConstraint_WithCurlyBraces_Balanced()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint(
                @"regex(\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b)");

            // Assert
            Assert.IsType<RegexInlineRouteConstraint>(constraint);
        }

        [Fact]
        public void ResolveConstraint_BoolConstraint()
        {
            // Arrange & Act
            var constraint = _constraintResolver.ResolveConstraint("bool");

            // Assert
            Assert.IsType<BoolRouteConstraint>(constraint);
        }

        #endregion

        #region Constraints with an expected value

        #region Equality and Identity
        /// <summary>
        /// Resolves the chain of constraints using an
        /// EqualConstraint as base.
        /// </summary>
        public Constraint EqualTo(object expected)
        {
            return Resolve(new EqualConstraint(expected));
        }

        /// <summary>
        /// Resolves the chain of constraints using a
        /// SameAsConstraint as base.
        /// </summary>
        public Constraint SameAs(object expected)
        {
            return Resolve(new SameAsConstraint(expected));
        }
        #endregion

        #region Comparison Constraints
        /// <summary>
        /// Resolves the chain of constraints using a
        /// LessThanConstraint as base.
        /// </summary>
        public Constraint LessThan(IComparable expected)
        {
            return Resolve(new LessThanConstraint(expected));
        }

        /// <summary>
        /// Resolves the chain of constraints using a
        /// GreaterThanConstraint as base.
        /// </summary>
        public Constraint GreaterThan(IComparable expected)
        {
            return Resolve(new GreaterThanConstraint(expected));
        }

        /// <summary>
        /// Resolves the chain of constraints using a
        /// LessThanOrEqualConstraint as base.
        /// </summary>
        public Constraint LessThanOrEqualTo(IComparable expected)
        {
            return Resolve(new LessThanOrEqualConstraint(expected));
        }

        /// <summary>
        /// Resolves the chain of constraints using a
        /// LessThanOrEqualConstraint as base.
        /// </summary>
        public Constraint AtMost(IComparable expected)
        {
            return Resolve(new LessThanOrEqualConstraint(expected));
        }


        /// <summary>
        /// Adds the constraint to the collection.
        /// </summary>
        public void Add(Constraint constraint) => Add(constraint, true);

        private void AddForeignKeyConstraint(ForeignKeyConstraint constraint)
        {
            if (!constraint.CanEnableConstraint())
            {
                throw ExceptionBuilder.ConstraintParentValues();
            }
            constraint.CheckCanAddToCollection(this);
        }

        private bool AutoGenerated(Constraint constraint)
        {
            ForeignKeyConstraint fk = (constraint as ForeignKeyConstraint);
            if (null != fk)
            {
                return XmlTreeGen.AutoGenerated(fk, false);
            }
            else
            {
                UniqueConstraint unique = (UniqueConstraint)constraint;
                return XmlTreeGen.AutoGenerated(unique);
            }
        }

        /// <summary>
        ///  Adds the constraint to the constraints array.
        /// </summary>
        private void ArrayAdd(Constraint constraint)
        {
            Debug.Assert(constraint != null, "Attempt to add null constraint to constraint array");
            List.Add(constraint);
        }

        private void ArrayRemove(Constraint constraint)
        {
            List.Remove(constraint);
        }

        /// <summary>
        /// Indicates if a <see cref='System.Data.Constraint'/> can be removed.
        /// </summary>
        // PUBLIC because called by design-time... need to consider this.
        public bool CanRemove(Constraint constraint)
        {
            return CanRemove(constraint, fThrowException: false);
        }


        [Test]
        public void TestGetters ()
        {
            using (var constraint = FbxConstraintPosition.Create (Manager, "posConstraint")) {
                TestGetter (constraint.AffectX);
                TestGetter (constraint.AffectY);
                TestGetter (constraint.AffectZ);
                TestGetter (constraint.Translation);
            }
        }

        [Test]
        public void TestGetters ()
        {
            using (var constraint = FbxConstraintRotation.Create (Manager, "rConstraint")) {
                TestGetter (constraint.AffectX);
                TestGetter (constraint.AffectY);
                TestGetter (constraint.AffectZ);
                TestGetter (constraint.Rotation);
            }
        }

        [Test]
        public void TestGetters ()
        {
            using (var constraint = FbxConstraintScale.Create (Manager, "sConstraint")) {
                TestGetter (constraint.AffectX);
                TestGetter (constraint.AffectY);
                TestGetter (constraint.AffectZ);
                TestGetter (constraint.Scaling);
            }
        }

            /// <summary>
            /// Constructs a constraint required no other surfaces be included in this shape
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_NoOtherSurface()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.NoOtherSurface;
                return constraint;
            }

            /// <summary>
            /// Constructs a constraint requiring the shape to be away from all walls
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_AwayFromWalls()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.AwayFromWalls;
                return constraint;
            }

            /// <summary>
            /// Constructs a constraint required no other surfaces be included in this shape
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_NoOtherSurface()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.NoOtherSurface;
                return constraint;
            }

            /// <summary>
            /// Constructs a constraint requiring the shape to be away from all walls
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_AwayFromWalls()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.AwayFromWalls;
                return constraint;
            }


		private void _handleBeforeConstraintNameChange (object sender, string newName)
		{
			if (newName == null || newName == "")
				throw new ArgumentException (
					"ConstraintName cannot be set to null or empty after adding it to a ConstraintCollection.");

			if (_isDuplicateConstraintName (newName, (Constraint) sender))
				throw new DuplicateNameException ("Constraint name already exists.");
		}

		private bool _isDuplicateConstraintName (string constraintName, Constraint excludeFromComparison)
		{
			foreach (Constraint cst in List) {
				if (cst == excludeFromComparison)
					continue;
				if (String.Compare (constraintName, cst.ConstraintName, false, Table.Locale) == 0)
					return true;
			}

			return false;
		}

		public
#if !NET_2_0
		virtual
#endif
		Constraint Add (string name, DataColumn column, bool primaryKey)
		{
			UniqueConstraint uc = new UniqueConstraint (name, column, primaryKey);
			Add (uc);
			return uc;
		}

		public
#if !NET_2_0
		virtual
#endif
		Constraint Add (string name, DataColumn primaryKeyColumn, DataColumn foreignKeyColumn)
		{
			ForeignKeyConstraint fc = new ForeignKeyConstraint (name, primaryKeyColumn, foreignKeyColumn);
			Add (fc);
			return fc;
		}

		public
#if !NET_2_0
		virtual
#endif
		Constraint Add (string name, DataColumn[] columns, bool primaryKey)
		{
			UniqueConstraint uc = new UniqueConstraint (name, columns, primaryKey);
			Add (uc);
			return uc;
		}

		public
#if !NET_2_0
		virtual
#endif
		Constraint Add (string name, DataColumn[] primaryKeyColumns, DataColumn[] foreignKeyColumns)
		{
			ForeignKeyConstraint fc = new ForeignKeyConstraint (name, primaryKeyColumns, foreignKeyColumns);
			Add (fc);
			return fc;
		}


        [Fact]
        public void ParseRouteParameter_WithoutAConstraintName()
        {
            // Arrange & Act
            var templatePart = ParseParameter("param:");

            // Assert
            Assert.Equal("param", templatePart.Name);
            Assert.Null(templatePart.DefaultValue);
            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Empty(constraint.Constraint);
        }

        [Fact]
        public void ParseRouteParameter_WithoutAConstraintNameOrParameterName()
        {
            // Arrange & Act
            var templatePart = ParseParameter("param:=");

            // Assert
            Assert.Equal("param", templatePart.Name);
            Assert.Equal("", templatePart.DefaultValue);
            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Empty(constraint.Constraint);
        }

        [Fact]
        public void ParseRouteParameter_ConstraintAndDefault_ParsedCorrectly()
        {
            // Arrange & Act
            var templatePart = ParseParameter("param:int=111111");

            // Assert
            Assert.Equal("param", templatePart.Name);
            Assert.Equal("111111", templatePart.DefaultValue);

            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Equal("int", constraint.Constraint);
        }

        [Fact]
        public void ParseRouteParameter_ConstraintAndOptional_ParsedCorrectly()
        {
            // Arrange & Act
            var templatePart = ParseParameter(@"param:int?");

            // Assert
            Assert.Equal("param", templatePart.Name);
            Assert.True(templatePart.IsOptional);

            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Equal("int", constraint.Constraint);
        }

        [Fact]
        public void ParseRouteParameter_ConstraintWithArgumentsAndOptional_ParsedCorrectly()
        {
            // Arrange & Act
            var templatePart = ParseParameter(@"param:test(\d+)?");

            // Assert
            Assert.Equal("param", templatePart.Name);
            Assert.True(templatePart.IsOptional);

            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Equal(@"test(\d+)", constraint.Constraint);
        }

        [Fact]
        public void ParseRouteParameter_ConstraintWithClosingBraceInPattern_ClosingBraceIsParsedCorrectly()
        {
            // Arrange & Act
            var templatePart = ParseParameter(@"param:test(\})");

            // Assert
            Assert.Equal("param", templatePart.Name);

            var constraint = Assert.Single(templatePart.InlineConstraints);
            Assert.Equal(@"test(\})", constraint.Constraint);
        }


        private void Add(string key, IRouteConstraint constraint)
        {
            if (!_constraints.TryGetValue(key, out var list))
            {
                list = new List<IRouteConstraint>();
                _constraints.Add(key, list);
            }

            list.Add(constraint);
        }

            /// <summary>
            /// Constructs a constraint required no other surfaces be included in this shape
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_NoOtherSurface()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.NoOtherSurface;
                return constraint;
            }

            /// <summary>
            /// Constructs a constraint requiring the shape to be away from all walls
            /// </summary>
            /// <returns>Constructed shape constraint</returns>
            public static ShapeConstraint Create_AwayFromWalls()
            {
                ShapeConstraint constraint = new ShapeConstraint();
                constraint.Type = ShapeConstraintType.AwayFromWalls;
                return constraint;
            }

DocumentFormat.OpenXml.Drawing.Diagrams.Constraint : IEnumerable

Constructors :

public Constraint()
public Constraint(IEnumerable<OpenXmlElement> childElements = )
public Constraint(OpenXmlElement[] childElements = )
public Constraint(String outerXml = )

Methods :

public EnumValue<ConstraintValues> get_Type()
public Void set_Type(EnumValue<ConstraintValues> value = )
public EnumValue<ConstraintRelationshipValues> get_For()
public Void set_For(EnumValue<ConstraintRelationshipValues> value = )
public StringValue get_ForName()
public Void set_ForName(StringValue value = )
public EnumValue<ElementValues> get_PointType()
public Void set_PointType(EnumValue<ElementValues> value = )
public EnumValue<ConstraintValues> get_ReferenceType()
public Void set_ReferenceType(EnumValue<ConstraintValues> value = )
public EnumValue<ConstraintRelationshipValues> get_ReferenceFor()
public Void set_ReferenceFor(EnumValue<ConstraintRelationshipValues> value = )
public StringValue get_ReferenceForName()
public Void set_ReferenceForName(StringValue value = )
public EnumValue<ElementValues> get_ReferencePointType()
public Void set_ReferencePointType(EnumValue<ElementValues> value = )
public EnumValue<BoolOperatorValues> get_Operator()
public Void set_Operator(EnumValue<BoolOperatorValues> value = )
public DoubleValue get_Val()
public Void set_Val(DoubleValue value = )
public DoubleValue get_Fact()
public Void set_Fact(DoubleValue value = )
public ExtensionList get_ExtensionList()
public Void set_ExtensionList(ExtensionList value = )
public OpenXmlElement CloneNode(Boolean deep = )
public OpenXmlElement get_FirstChild()
public OpenXmlElement get_LastChild()
public Boolean get_HasChildren()
public String get_InnerText()
public Void set_InnerXml(String value = )
public Boolean AddChild(OpenXmlElement newChild = , Boolean throwOnError = True)
public T AppendChild(T newChild = )
public T InsertAfter(T newChild = , OpenXmlElement referenceChild = )
public T InsertBefore(T newChild = , OpenXmlElement referenceChild = )
public T InsertAt(T newChild = , Int32 index = )
public T PrependChild(T newChild = )
public T RemoveChild(T child = )
public Void RemoveAllChildren()
public T ReplaceChild(OpenXmlElement newChild = , T oldChild = )
public Void RemoveAllChildren()
public Void Remove()
public Boolean IsAfter(OpenXmlElement element = )
public Boolean IsBefore(OpenXmlElement element = )
public Void AddAnnotation(Object annotation = )
public T Annotation()
public Object Annotation(Type type = )
public IEnumerable<T> Annotations()
public IEnumerable<Object> Annotations(Type type = )
public Void RemoveAnnotations()
public Void RemoveAnnotations(Type type = )
public IEnumerator<OpenXmlElement> GetEnumerator()
public Object Clone()
public MarkupCompatibilityAttributes get_MCAttributes()
public Void set_MCAttributes(MarkupCompatibilityAttributes value = )
public String LookupNamespace(String prefix = )
public String LookupPrefix(String namespaceUri = )
public IFeatureCollection get_Features()
public OpenXmlElementContext get_OpenXmlElementContext()
public Boolean get_HasAttributes()
public IEnumerable<OpenXmlAttribute> get_ExtendedAttributes()
public OpenXmlElementList get_ChildElements()
public OpenXmlElement get_Parent()
public String get_NamespaceUri()
public String get_LocalName()
public String get_Prefix()
public IEnumerable<KeyValuePair<StringString>> get_NamespaceDeclarations()
public XmlQualifiedName get_XmlQualifiedName()
public XName get_XName()
public String get_InnerXml()
public String get_OuterXml()
public OpenXmlAttribute GetAttribute(String localName = , String namespaceUri = )
public IList<OpenXmlAttribute> GetAttributes()
public Void SetAttribute(OpenXmlAttribute openXmlAttribute = )
public Void RemoveAttribute(String localName = , String namespaceUri = )
public Void SetAttributes(IEnumerable<OpenXmlAttribute> openXmlAttributes = )
public Void ClearAllAttributes()
public Void AddNamespaceDeclaration(String prefix = , String uri = )
public Void RemoveNamespaceDeclaration(String prefix = )
public T GetFirstChild()
public OpenXmlElement PreviousSibling()
public T PreviousSibling()
public OpenXmlElement NextSibling()
public T NextSibling()
public IEnumerable<OpenXmlElement> Ancestors()
public IEnumerable<T> Ancestors()
public IEnumerable<T> Elements()
public IEnumerable<OpenXmlElement> Elements()
public IEnumerable<T> Descendants()
public IEnumerable<OpenXmlElement> Descendants()
public IEnumerable<OpenXmlElement> ElementsBefore()
public IEnumerable<OpenXmlElement> ElementsAfter()
public Void WriteTo(XmlWriter xmlWriter = )
public Void Append(IEnumerable<OpenXmlElement> newChildren = )
public Void Append(OpenXmlElement[] newChildren = )
public T InsertAfterSelf(T newElement = )
public T InsertBeforeSelf(T newElement = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()