Esempio n. 1
0
        public IDocumentFinderQueryBuilder WhereEquals <T1, T2>(Expression <Func <T1, T2> > property, T2 value) where T1 : class
        {
            var path = DocumentPropertyPathProvider.GetFor(property);

            Criteria.Add(d =>
            {
                var a = DocumentPropertyFinder.GetFor(d, path);

                if (a == null)
                {
                    if (value == null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                return(a.Equals(value));
            });

            return(this);
        }
Esempio n. 2
0
        public IDocumentFinderQueryBuilder WhereExists <T1, T2>(Expression <Func <T1, T2> > property) where T1 : class
        {
            var path = DocumentPropertyPathProvider.GetFor(property);

            Criteria.Add(d => DocumentPropertyFinder.Exists(d, path));

            return(this);
        }
Esempio n. 3
0
        public void ThrowsOnParameterCountBeingOtherThanOne()
        {
            var sut = new DocumentPropertyPathProvider(Mock.Of <ICoreInterfaceProvider>());

            Assert.Throws <OnlyOneParameterAllowedInExpressionException>(() => sut.GetFor((Expression <Func <string> >)(() => string.Empty)));
            Assert.Throws <OnlyOneParameterAllowedInExpressionException>(() => sut.GetFor((Expression <Func <object, object, string> >)((d1, d2) => string.Empty)));
            Assert.Throws <OnlyOneParameterAllowedInExpressionException>(() => sut.GetFor((Expression <Func <object, object, object, string> >)((d1, d2, d3) => string.Empty)));
        }
Esempio n. 4
0
        public void CoreInterfaceGlobalProperty()
        {
            Expression <Func <MyCoreInterface, string> > expression = d => d.Lorem;

            var coreInterfaceProvider = Mock.Of <ICoreInterfaceProvider>();

            Mock.Get(coreInterfaceProvider).Setup(p => p.GetFor(typeof(MyCoreInterface))).Returns(new CoreInterfaceDescriptor("MyCoreInterfaceId", typeof(MyCoreInterface), new List <PropertyDefinitionDescriptor> {
                new PropertyDefinitionDescriptor(nameof(MyCoreInterface.Lorem), typeof(string), o => o, (o, v) => { }, Enumerable.Empty <object>())
            }));

            var result = new DocumentPropertyPathProvider(coreInterfaceProvider).GetFor(expression);

            Assert.Equal("GlobalFacet.Interfaces.MyCoreInterfaceId.Properties.Lorem", result);
        }
Esempio n. 5
0
        public IDocumentFinderQueryBuilder WhereIn <T1, T2>(Expression <Func <T1, T2> > property, IEnumerable <T2> values) where T1 : class
        {
            var path = DocumentPropertyPathProvider.GetFor(property);

            Criteria.Add(d =>
            {
                var a = DocumentPropertyFinder.GetFor(d, path);

                if (a == null)
                {
                    return(false);
                }

                if (!(a is T2))
                {
                    return(false);
                }

                return(values.Contains((T2)a));
            });

            return(this);
        }
        public IDocumentFinderQueryBuilder WhereExists <T1, T2>(Expression <Func <T1, T2> > property) where T1 : class
        {
            Filters.Add(Builders <Document> .Filter.Exists(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property))));

            return(this);
        }
        public IDocumentFinderQueryBuilder WhereIn <T1, T2>(Expression <Func <T1, T2> > property, IEnumerable <T2> values) where T1 : class
        {
            Filters.Add(Builders <Document> .Filter.In(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property)), values));

            return(this);
        }
        public IDocumentFinderQueryBuilder WhereEquals <T1, T2>(Expression <Func <T1, T2> > property, T2 value) where T1 : class
        {
            if (value == null)
            {
                Filters.Add(
                    Builders <Document> .Filter.And(
                        Builders <Document> .Filter.Exists(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property))),
                        Builders <Document> .Filter.Eq(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property)), value)
                        )
                    );
            }
            else
            {
                Filters.Add(
                    Builders <Document> .Filter.Eq(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property)), value)
                    );
            }

            return(this);
        }
        public IDocumentFinderQueryBuilder Select <T1, T2>(Expression <Func <T1, T2> > property) where T1 : class
        {
            if (Projection == null)
            {
                Projection = Builders <Document> .Projection.Include(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property)));
            }
            else
            {
                Projection = Projection.Include(new StringFieldDefinition <Document, T2>(DocumentPropertyPathProvider.GetFor(property)));
            }

            return(this);
        }