public void GivenRemoteQueryWhenExecuteRemoteAsyncThenShouldReturnIRemoteQueryable()
        {
            var query = DbClientContext <TestThingContext> .Query(context => context.Things)
                        .Take(5);

            var actual = query.ExecuteRemote();

            Assert.IsAssignableFrom <IRemoteQueryable <TestThing> >(actual);
        }
        public void GivenExpressionOfCorrectTypeThenShouldBuildQueryWithContext()
        {
            var query = DbClientContext <TestThingContext> .Query(t => t.Things);

            Assert.NotNull(query);
            var remote  = query as IRemoteQuery;
            var context = remote.CustomProvider.Context;

            Assert.Same(typeof(TestThingContext), context.Context);
            var prop = typeof(TestThingContext).GetProperty(nameof(TestThingContext.Things));

            Assert.Same(prop, context.Collection);
        }
        public async Task GivenQueryThenCountAsyncReturnsCount()
        {
            ServiceHost.Reset();
            ServiceHost.Initialize(
                registration => registration.RegisterSingleton <IRemoteQueryClient>(
                    new MockRemoteQueryClient()));
            ServiceHost.GetService <IClientHttpConfiguration>()
            .SetClientFactory(
                () => new MockRemoteQueryClient
            {
                QueryType = QueryTestCase.Count
            });
            var actual = await DbClientContext <TestThingContext> .Query(
                context => context.Things)
                         .ExecuteRemote()
                         .CountAsync();

            Assert.Equal(5, actual);
        }
        public async Task GivenQueryThenSingleAsyncReturnsSingle()
        {
            ServiceHost.Reset();
            ServiceHost.Initialize(
                registration => registration.RegisterSingleton <IRemoteQueryClient>(
                    new MockRemoteQueryClient
            {
                QueryType = QueryTestCase.Single
            }));
            ServiceHost.GetService <IClientHttpConfiguration>()
            .SetClientFactory(
                () => ServiceHost.GetService <IRemoteQueryClient>());
            var actual = await DbClientContext <TestThingContext> .Query(
                context => context.Things)
                         .ExecuteRemote()
                         .FirstOrSingleAsync();

            Assert.NotNull(actual);
            Assert.IsType <TestThing>(actual);
        }
 public void GivenExpressionOnDifferentContextWhenQueryCalledThenShouldThrowArgument()
 {
     Assert.Throws <ArgumentException>(
         () => DbClientContext <TestThingContext> .Query(q => new AltContext().AltThings));
 }
 public void GivenExpressionReferencesNonDbSetWenQueryCalledThenShouldThrowArgument()
 {
     Assert.Throws <ArgumentException>(
         () => DbClientContext <TestThingContext> .Query(q => (object)q.NotThings as DbSet <object>));
 }
 public void GivenEmptyExpressionWhenQueryCalledThenShouldThrowArgumentNull()
 {
     Assert.Throws <ArgumentNullException>(
         () => DbClientContext <TestThingContext> .Query <TestThingContext>(null));
 }