Пример #1
0
        public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.Any(wrapped, predicate.AsFunc());

            // Act
            var result = ReadOnlyList
                         .Any <Wrap.ValueReadOnlyList <int>, int>(wrapped, predicate);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
Пример #2
0
        public void Any_Predicate_With_Null_Must_Throw()
        {
            // Arrange
            var source    = new int[0];
            var wrapped   = Wrap.AsValueReadOnlyList(source);
            var predicate = (Predicate <int>)null;

            // Act
            Action action = () => _ = ReadOnlyList
                                      .Any <Wrap.ValueReadOnlyList <int>, int>(wrapped, predicate);

            // Assert
            _ = action.Must()
                .Throw <ArgumentNullException>()
                .EvaluateTrue(exception => exception.ParamName == "predicate");
        }
Пример #3
0
        public AggregateEntity(Point location, ReadOnlyList <Entity> children, CadColor?color = null, object tag = null)
            : base(color, tag)
        {
            if (children == null)
            {
                throw new ArgumentNullException("children");
            }
            this.location = location;
            this.children = children;

            if (children.Any(c => c.Kind == EntityKind.Aggregate))
            {
                throw new ArgumentOutOfRangeException("children", "Aggregate entities cannot contain other aggregate entities");
            }
            var offset = (Vector)location;

            this.primitives  = children.SelectMany(c => c.GetPrimitives().Select(p => p.Move(offset))).ToArray();
            this.snapPoints  = children.SelectMany(c => c.GetSnapPoints().Select(p => p.Move(offset))).ToArray();
            this.boundingBox = BoundingBox.Includes(children.Select(c => c.BoundingBox));
        }
Пример #4
0
 public bool IsMapped(ShapeNode leftNode1, Ngram <Segment> target1, ShapeNode rightNode1, ShapeNode leftNode2, Ngram <Segment> target2, ShapeNode rightNode2)
 {
     return(_segmentMappingsComponents.Any(sm => sm.IsMapped(leftNode1, target1, rightNode1, leftNode2, target2, rightNode2)));
 }
Пример #5
0
        /// <inheritdoc/>
        public override void UpdateState()
        {
            base.UpdateState();

            ancestors          = new ReadOnlyList <TypeInfo>(GetAncestors());
            targetAssociations = new ReadOnlyList <AssociationInfo>(GetTargetAssociations());
            ownerAssociations  = new ReadOnlyList <AssociationInfo>(GetOwnerAssociations());

            int adapterIndex = 0;

            foreach (FieldInfo field in Fields)
            {
                if (field.IsStructure || field.IsEntitySet)
                {
                    field.AdapterIndex = adapterIndex++;
                }
            }

            affectedIndexes.UpdateState();
            indexes.UpdateState();
            columns.UpdateState();

            CreateTupleDescriptor();

            columns.UpdateState();
            fields.UpdateState();

            structureFieldMapping = BuildStructureFieldMapping();

            if (IsEntity)
            {
                if (HasVersionRoots)
                {
                    versionFields  = new ReadOnlyList <FieldInfo>(new List <FieldInfo>());
                    versionColumns = new ReadOnlyList <ColumnInfo>(new List <ColumnInfo>());
                }
                else
                {
                    versionFields  = new ReadOnlyList <FieldInfo>(GetVersionFields());
                    versionColumns = new ReadOnlyList <ColumnInfo>(GetVersionColumns());
                }
                HasVersionFields         = versionFields.Any();
                HasExplicitVersionFields = versionFields.Any(f => f.ManualVersion || f.AutoVersion);
            }

            if (IsInterface)
            {
                // Collect mapping information from the first implementor (if any)
                // We'll check that all implementors are mapped to the same database later.
                // MappingSchema is not important: it's copied for consistency.
                var firstImplementor = GetImplementors().FirstOrDefault();
                if (firstImplementor != null)
                {
                    MappingDatabase = firstImplementor.MappingDatabase;
                    MappingSchema   = firstImplementor.MappingSchema;
                }
            }

            HasValidators = validators.Count > 0 || fields.Any(f => f.HasValidators);

            // Selecting master parts from paired associations & single associations
            var associations = model.Associations.Find(this)
                               .Where(a => a.IsMaster)
                               .ToList();

            typeIdField = Fields.FirstOrDefault(f => f.IsTypeId && f.IsSystem);

            BuildTuplePrototype();
            BuildVersionExtractor();

            if (associations.Count == 0)
            {
                removalSequence = ReadOnlyList <AssociationInfo> .Empty;
                return;
            }

            overridenAssociations = associations
                                    .Where(a =>
                                           (a.Ancestors.Count > 0 && ((a.OwnerType == this && a.Ancestors.All(an => an.OwnerType != this) || (a.TargetType == this && a.Ancestors.All(an => an.TargetType != this))))) ||
                                           (a.Reversed != null && (a.Reversed.Ancestors.Count > 0 && ((a.Reversed.OwnerType == this && a.Reversed.Ancestors.All(an => an.OwnerType != this) || (a.Reversed.TargetType == this && a.Reversed.Ancestors.All(an => an.TargetType != this)))))))
                                    .SelectMany(a => a.Ancestors.Concat(a.Reversed == null ? Enumerable.Empty <AssociationInfo>() : a.Reversed.Ancestors))
                                    .ToList();
            var ancestor = GetAncestor();

            if (ancestor != null && ancestor.overridenAssociations != null)
            {
                overridenAssociations.AddRange(ancestor.overridenAssociations);
            }

            foreach (var ancestorAssociation in overridenAssociations)
            {
                associations.Remove(ancestorAssociation);
            }

            //
            //Commented action sequence bellow may add dublicates to "sequence".
            //Besides, it takes 6 times enumeration of "associations"
            //

            //var sequence = new List<AssociationInfo>(associations.Count);
            //sequence.AddRange(associations.Where(a => a.OnOwnerRemove == OnRemoveAction.Deny && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)));
            //sequence.AddRange(associations.Where(a => a.OnTargetRemove == OnRemoveAction.Deny && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)));
            //sequence.AddRange(associations.Where(a => a.OnOwnerRemove == OnRemoveAction.Clear && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)));
            //sequence.AddRange(associations.Where(a => a.OnTargetRemove == OnRemoveAction.Clear && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)));
            //sequence.AddRange(associations.Where(a => a.OnOwnerRemove == OnRemoveAction.Cascade && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)));
            //sequence.AddRange(associations.Where(a => a.OnTargetRemove == OnRemoveAction.Cascade && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)));

            //
            // Code bellow adds the same associations, but without dublicates.
            // Also it takes only one enumeration of associations sequence.
            //
            var sequence = new List <AssociationInfo>(associations.Count);
            var b        = associations.Where(
                a => (a.OnOwnerRemove == OnRemoveAction.Deny && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)) ||
                (a.OnTargetRemove == OnRemoveAction.Deny && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)) ||
                (a.OnOwnerRemove == OnRemoveAction.Clear && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)) ||
                (a.OnTargetRemove == OnRemoveAction.Clear && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)) ||
                (a.OnOwnerRemove == OnRemoveAction.Cascade && a.OwnerType.UnderlyingType.IsAssignableFrom(UnderlyingType)) ||
                (a.OnTargetRemove == OnRemoveAction.Cascade && a.TargetType.UnderlyingType.IsAssignableFrom(UnderlyingType)));

            sequence.AddRange(b);

            var first = sequence.Where(a => a.Ancestors.Count > 0).ToList();

            if (first.Count == 0)
            {
                removalSequence = new ReadOnlyList <AssociationInfo>(sequence);
            }
            else
            {
                var second = sequence.Where(a => a.Ancestors.Count == 0).ToList();
                removalSequence = new ReadOnlyList <AssociationInfo>(first.Concat(second).ToList());
            }
        }
Пример #6
0
 /// <summary>
 /// Determines whether a specified character is a whitespace character
 /// </summary>
 /// <param name="test"></param>
 /// <returns></returns>
 public static bool IsWhitespace(char test)
 => All.Any(x => x.Character == test);