Esempio n. 1
0
        public static void should_have_stored_member_in_indexes_table <T>(this ITestDbUtils db, IStructureSchema structureSchema, object structureId, Expression <Func <T, object> > memberExpression, Type memberType)
        {
            var memberPath = GetMemberPath(memberExpression);

            structureSchema.IndexAccessors.Count(iac => iac.Path == memberPath).ShouldBeGreaterThan(0);

            var tablename = structureSchema.GetIndexesTableNames().GetNameByType(DataTypeConverter.Convert(memberType, memberPath));

            db.RowCount(tablename, "{0} = '{1}' and {2} = '{3}'".Inject(
                            IndexStorageSchema.Fields.StructureId.Name, structureId,
                            IndexStorageSchema.Fields.MemberPath.Name, memberPath)).ShouldBeGreaterThan(0);
        }
        protected virtual MemberNode CreateNewMemberNode(MemberExpression e)
        {
            var graph = new Graph();

            if (IsFlatteningMembers)
            {
                graph.AddRange(VirtualPrefixMembers);

                if (!graph.Last().Equals(e))
                {
                    graph.AddIfNotNull(e);
                }
            }
            else
            {
                graph.AddIfNotNull(e);
            }

            MemberNode previousNode = null;

            for (var c = 0; c < graph.Count; c++)
            {
                var memberExpression = graph[c];
                var isLast           = c == (graph.Count - 1);
                var path             = previousNode == null?memberExpression.ToPath() : string.Format("{0}.{1}", previousNode.Path, memberExpression.ToPath());

                if (isLast && memberExpression.Type.IsEnumerableType())
                {
                    var elementType = memberExpression.Type.GetEnumerableElementType();
                    previousNode = new MemberNode(path, elementType, DataTypeConverter.Convert(elementType, path));
                }
                else
                {
                    previousNode = new MemberNode(path, memberExpression.Type, DataTypeConverter.Convert(memberExpression.Type, path));
                }
            }

            if (e != null && previousNode != null)
            {
                if (e.Type.IsNullablePrimitiveType())
                {
                    return(new NullableMemberNode(previousNode.Path, e.Type, DataTypeConverter.Convert(e.Type, previousNode.Path)));
                }

                if (e.Expression.Type.IsNullablePrimitiveType())
                {
                    return(new NullableMemberNode(previousNode.Path, e.Expression.Type, DataTypeConverter.Convert(e.Expression.Type, previousNode.Path)));
                }
            }

            return(previousNode);
        }
Esempio n. 3
0
        public void Equals_WhenSameStructureIdNameAndValue_ReturnsTrue()
        {
            var          structureId = StructureId.Create(Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887"));
            const string thevalue    = "TheValue";

            var structure1 = new StructureIndex(structureId, "TheName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));
            var structure2 = new StructureIndex(structureId, "TheName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));

            Assert.AreEqual(structure1, structure2);
        }
        public void Ctor_WhenIndexesContainsNonUniqueUniqueIndex_ThrowsSisoDbException()
        {
            var structureId  = StructureId.Create(1);
            var dataType     = typeof(string);
            var dataTypeCode = _converter.Convert(CreateProperty(dataType));
            var indexes      = new List <IStructureIndex>
            {
                new StructureIndex(structureId, "UniqueIndex1", "Value1", dataType, dataTypeCode, StructureIndexType.UniquePerInstance),
                new StructureIndex(structureId, "UniqueIndex1", "Value1", dataType, dataTypeCode, StructureIndexType.UniquePerInstance)
            };

            Assert.Throws <SisoDbException>(() => new Structure("Name", structureId, indexes.ToArray()));
        }
Esempio n. 5
0
        public virtual IParsedLambda Parse(OrderByExpression[] orderByExpressions)
        {
            Ensure.That(orderByExpressions, "orderByExpressions").HasItems();

            var nodesContainer = new NodesCollection();

            foreach (var orderByExpression in orderByExpressions.Where(e => e != null))
            {
                var memberExpression = orderByExpression.InnerLambdaExpression.Body.GetRightMostMember();
                if (memberExpression == null)
                {
                    throw new SisoDbException(ExceptionMessages.OrderByExpressionDoesNotTargetMember.Inject(orderByExpression.ToString()));
                }

                var callExpression = (orderByExpression.InnerLambdaExpression.Body is UnaryExpression)
                    ? ((UnaryExpression)orderByExpression.InnerLambdaExpression.Body).Operand as MethodCallExpression
                                        : orderByExpression.InnerLambdaExpression.Body as MethodCallExpression;

                if (callExpression != null)
                {
                    throw new SisoDbException(ExceptionMessages.OrderByParser_UnsupportedMethodForSortingDirection);
                }

                var memberType = memberExpression.Type;
                if (memberType.IsEnumerableType())
                {
                    memberType = memberType.GetEnumerableElementType();
                }

                var sortDirection = orderByExpression is OrderByAscExpression ? SortDirections.Asc : SortDirections.Desc;
                var memberPath    = memberExpression.ToPath();
                var sortingNode   = new SortingNode(memberPath, memberType, DataTypeConverter.Convert(memberType, memberPath), sortDirection);
                nodesContainer.AddNode(sortingNode);
            }

            return(new ParsedLambda(nodesContainer.ToArray()));
        }
 public void Convert_TypeIsUnsignedIntegerFamily_ReturnsUnsignedIntegerNumber(Type type)
 {
     Assert.AreEqual(DataTypeCode.UnsignedIntegerNumber, _converter.Convert(CreateProperty(type)));
 }
Esempio n. 7
0
 internal static IIndexAccessor CreateFor(IStructureProperty property)
 {
     return(new IndexAccessor(property, DataTypeConverter.Convert(property)));
 }
 private DataTypeCode GetAsDataTypeCode(Type type, string memberName = null)
 {
     return(_dataTypeConverter.Convert(type, memberName ?? "Foo"));
 }
Esempio n. 9
0
 private SortingNode CreateSortingNode(string memberPath, Type type)
 {
     return(new SortingNode(memberPath, type, _dataTypeConverter.Convert(type, memberPath)));
 }