Example #1
0
        public void GivenTargetNullWhenIsPartOfCalledThenShouldReturnFalse()
        {
            var source = IQueryableExtensions.CreateQueryTemplate <IdType>()
                         .Take(5);

            Assert.False(eq.IsPartOf(source.Expression, null));
        }
Example #2
0
 private IQueryable <QueryHelper> TestQuery() =>
 IQueryableExtensions.CreateQueryTemplate <QueryHelper>()
 .Where(q => q.Id == nameof(QueryHelper) &&
        q.Created > DateTime.Now.AddDays(-1))
 .Skip(2)
 .Take(3)
 .OrderBy(q => q.Created);
        public void MultipleSelectManyProjectionWorks()
        {
            Reset();

            var dataQuery = TestableThing.MakeQuery(5);

            IQueryable <Tuple <string, string, string> > SelectMany(IQueryable <TestableThing> query) =>
            query.SelectMany(t => t.ChildThings, (t, c) => new
            {
                parentId = t.Id,
                childId  = c.Id,
                children = c.ChildThings
            }).SelectMany(tc => tc.children, (tc, tcc) => new
            {
                tc.parentId,
                tc.childId,
                grandChildId = tcc.Id
            }).Select(t => Tuple.Create(t.parentId, t.childId, t.grandChildId));

            var query = SelectMany(IQueryableExtensions.CreateQueryTemplate <TestableThing>());

            var json = Serializer.Serialize(query);

            // make sure we're not just pulling from the cache
            Reset();

            var newQuery = Serializer.DeserializeQuery <Tuple <string, string, string> >(json, dataQuery);

            var expected = SelectMany(dataQuery).ToList();
            var actual   = newQuery.ToList();

            Assert.NotNull(actual);
            Assert.Equal(expected, actual);
        }
        public void GivenNonRemoteQueryWhenExecuteRemoteAsyncThenShouldThrowNullReference()
        {
            var query = IQueryableExtensions.CreateQueryTemplate <TestThing>();

            Assert.Throws <NullReferenceException>(
                () => query.ExecuteRemote());
        }
 /// <summary>
 /// Deserializes a query from the raw json.
 /// </summary>
 /// <typeparam name="T">The type of the query.</typeparam>
 /// <param name="json">The json text.</param>
 /// <param name="host">The <see cref="IQueryable{T}"/> host to create the query.</param>
 /// <param name="config">The optional configuration.</param>
 /// <returns>The deserialized <see cref="IQueryable{T}"/>.</returns>
 public static IQueryable <T> DeserializeQuery <T>(
     string json,
     IQueryable <T> host = null,
     Action <IConfigurationBuilder> config = null)
 {
     host = host ?? IQueryableExtensions.CreateQueryTemplate <T>();
     return(DeserializeQuery(host, json, config) as IQueryable <T>);
 }
Example #6
0
 /// <summary>
 /// Deserializes a query from the raw json.
 /// </summary>
 /// <typeparam name="T">The type of the query.</typeparam>
 /// <param name="root">The serialization root.</param>
 /// <param name="host">The <see cref="IQueryable{T}"/> host to create the query.</param>
 /// <param name="config">The optional configuration.</param>
 /// <param name="stateCallback">Register a callback to inspect the state.</param>
 /// <returns>The deserialized <see cref="IQueryable{T}"/>.</returns>
 public static IQueryable <T> DeserializeQuery <T>(
     SerializationRoot root,
     IQueryable host = null,
     Action <IConfigurationBuilder> config     = null,
     Action <SerializationState> stateCallback = null)
 {
     host = host ?? IQueryableExtensions.CreateQueryTemplate <T>();
     return(DeserializeQuery(host, root, config, stateCallback) as IQueryable <T>);
 }
        private IQueryable <TestThing> GetQuery(bool remote = true)
        {
            var core = IQueryableExtensions.CreateQueryTemplate <TestThing>();

            if (remote)
            {
                core = core.AsRemoteQueryable(context);
            }
            return(core.OrderBy(t => EF.Property <string>(t, nameof(TestThing.Id))).Take(5));
        }
Example #8
0
        /// <summary>
        /// Creates a trackable query based on the <see cref="DbContext"/> reference.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/> of the query.</typeparam>
        /// <param name="template">A template to access the property.</param>
        /// <returns>A new <see cref="IQueryable"/> to usee.</returns>
        /// <exception cref="ArgumentNullException">Thrown when template is null.</exception>
        /// <exception cref="ArgumentException">Thrown when template does not refer to the right context.</exception>
        public static IQueryable <T> Query <T>(
            Expression <Func <TContext, DbSet <T> > > template)
            where T : class
        {
            VerifyTemplate(template);
            var memberExpression = template.AsEnumerable().OfType <MemberExpression>().First();

            return(IQueryableExtensions.CreateQueryTemplate <T>()
                   .AsRemoteQueryable(new RemoteContext(
                                          typeof(TContext),
                                          memberExpression.Member as PropertyInfo)));
        }
Example #9
0
        /// <summary>
        /// Creates a trackable query based on the <see cref="DbContext"/> reference.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/> of the query.</typeparam>
        /// <param name="template">A template to access the property.</param>
        /// <returns>A new <see cref="IQueryable"/> to usee.</returns>
        /// <exception cref="ArgumentNullException">Thrown when template is null.</exception>
        /// <exception cref="ArgumentException">Thrown when template does not refer to the right context.</exception>
        public static IQueryable <T> Query <T>(
            Expression <Func <TContext, DbSet <T> > > template)
            where T : class
        {
            Ensure.NotNull(() => template);
            var memberExpression = template.AsEnumerable().OfType <MemberExpression>().First();

            if (memberExpression.Member.DeclaringType != typeof(TContext))
            {
                throw new ArgumentException($"{typeof(DbContext)} <> {template}", nameof(template));
            }

            return(IQueryableExtensions.CreateQueryTemplate <T>()
                   .AsRemoteQueryable(new RemoteContext(
                                          typeof(TContext),
                                          memberExpression.Member as PropertyInfo)));
        }
Example #10
0
        public void CreateQueryTemplateUsesEmptyList()
        {
            var target = IQueryableExtensions.CreateQueryTemplate <IdType>();

            Assert.False(target.Any());
        }
 public void GivenNullRemoteContextWhenRemoteQueryProviderInstantiatedThenShouldThrowArgumentNull()
 {
     Assert.Throws <ArgumentNullException>(() => new RemoteQueryProvider <TestThing>(
                                               IQueryableExtensions.CreateQueryTemplate <TestThing>(), null));
 }