示例#1
0
 public MappingAccordances <TSource, TDestination> Register <TSourceValue, TDestinationValue>(
     [NotNull] Expression <Func <TSource, TSourceValue> > sourcePropertySelectorExpression,
     [NotNull] Expression <Func <TDestination, TDestinationValue> > destinationPropertySelectorExpression,
     [NotNull] ConstraintCreator <TSourceValue> createConstraintFromSourcePropertyValue,
     [NotNull] string assertionFailureMessage)
 => Register(
     sourcePropertySelectorExpression,
     destinationPropertySelectorExpression,
     createConstraintFromSourcePropertyValue,
     (sourceValue, destinationValue) => assertionFailureMessage);
示例#2
0
        public MappingAccordances <TSource, TDestination> Register <TSourceValue, TDestinationValue>(
            [NotNull] Expression <Func <TSource, TSourceValue> > sourcePropertySelectorExpression,
            [NotNull] Expression <Func <TDestination, TDestinationValue> > destinationPropertySelectorExpression,
            [NotNull] ConstraintCreator <TSourceValue> createConstraintFromSourcePropertyValue,
            [NotNull] MappingAccordances.AssertionFailedMessageCreator <TSourceValue, TDestinationValue>
            getAssertionFailureMessage)
        {
            Assert.That(sourcePropertySelectorExpression, Is.Not.Null);
            Assert.That(destinationPropertySelectorExpression, Is.Not.Null);
            Assert.That(createConstraintFromSourcePropertyValue, Is.Not.Null);
            Assert.That(getAssertionFailureMessage, Is.Not.Null);

            var sourcePropertySelector      = sourcePropertySelectorExpression.Compile();
            var destinationPropertySelector = destinationPropertySelectorExpression.Compile();

            var sourceExpression      = MappingAccordances.ToReadableString(sourcePropertySelectorExpression);
            var destinationExpression = MappingAccordances.ToReadableString(destinationPropertySelectorExpression);

            _assertions.Add(
                (source, destination, parentFailureMessage) =>
            {
                var sourcePropertyValue      = sourcePropertySelector(source);
                var destinationPropertyValue = destinationPropertySelector(destination);

                var constraint = createConstraintFromSourcePropertyValue(sourcePropertyValue);

                Assert.That(
                    constraint,
                    Is.Not.Null,
                    $@"A factory method specified in the argument '{
                            nameof(createConstraintFromSourcePropertyValue)}' returned an invalid value.");

                var baseFailureMessage = getAssertionFailureMessage(sourcePropertyValue, destinationPropertyValue);

                Assert.That(
                    baseFailureMessage,
                    Is.Not.Null.And.Not.Empty,
                    $@"A factory method specified in the argument '{
                            nameof(getAssertionFailureMessage)}' returned an invalid value.");

                var failureMessage = MappingAccordances.CreateDetailedFailureMessage(
                    baseFailureMessage,
                    sourceExpression,
                    destinationExpression,
                    parentFailureMessage);

                Assert.That(destinationPropertyValue, constraint, failureMessage);
            });

            return(this);
        }
示例#3
0
 public virtual ConstraintDefinition CreatePropertyUniquenessConstraint(string labelName, IList <string> propertyKeys)
 {
     using (Transaction tx = _database.Graph.beginTransaction(@implicit, AUTH_DISABLED))
     {
         ConstraintCreator creator = _database.Graph.schema().constraintFor(label(labelName));
         foreach (string propertyKey in propertyKeys)
         {
             creator = creator.AssertPropertyIsUnique(propertyKey);
         }
         ConstraintDefinition result = creator.Create();
         tx.Success();
         return(result);
     }
 }
示例#4
0
        private static bool UpdateCardinality(string rangeText, CardinalityConstraint constraint, ConstraintCreator creator)
        {
            LinkedElementCollection <CardinalityRange> ranges;
            int       rangeCount;
            Partition partition;

            if (constraint != null)
            {
                rangeCount = (ranges = constraint.RangeCollection).Count;
                partition  = constraint.Partition;
            }
            else
            {
                ranges     = null;
                rangeCount = 0;
                partition  = null;
            }
            int  nextRange = 0;
            bool retVal    = BasicRange.ParseRangeText(
                rangeText,
                delegate(BasicRange basicRange)
            {
                if (ranges == null)
                {
                    ranges    = (constraint = creator()).RangeCollection;
                    partition = constraint.Partition;
                }
                if (nextRange == rangeCount)
                {
                    ++rangeCount;
                    ranges.Add(new CardinalityRange(partition, new PropertyAssignment(CardinalityRange.LowerBoundDomainPropertyId, basicRange.LowerBound), new PropertyAssignment(CardinalityRange.UpperBoundDomainPropertyId, basicRange.UpperBound)));
                }
                else
                {
                    CardinalityRange range = ranges[nextRange];
                    range.LowerBound       = basicRange.LowerBound;
                    range.UpperBound       = basicRange.UpperBound;
                }
                ++nextRange;
            });

            if (nextRange < rangeCount)
            {
                ranges.RemoveRange(nextRange, rangeCount - nextRange);
            }
            return(retVal);
        }