public void ItShouldExecuteProjectionsOnSelectManyQueryOperation()
        {
            var navProp = new MockNavigationProperty { Value = "provided" };
            var entity = new MockEntity { NavigationProperties = new[] { navProp } };

            var repository = new Mock<MockeableRepository>();
            repository.Setup(r => r.GetOne(It.Is<ODataSelectOneQueryOperation>(o => o.Key == "key" && o.OfType == typeof(MockEntity))))
                      .Returns(entity);

            Expression<Func<MockNavigationProperty, dynamic>> projectionExpression = e => e == null ? null : new { e.Value };

            var operation = new ODataSelectManyQueryOperation
                                {
                                    OfType = typeof(MockEntity),
                                    Keys = new Dictionary<string, string> { { "key", "key" } },
                                    NavigationProperty = "NavigationProperties",
                                    ProjectionExpression = projectionExpression,
                                    ProjectedType = typeof(object)
                                };

            var provider = new ODataQueryProvider<MockEntity>(n => repository.Object);
            var result = (IEnumerable<dynamic>)provider.ExecuteQuery(operation);

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "provided");
        }
        public void ItShouldExecuteProjectionsOnSelectManyQueryOperation()
        {
            var navProp = new MockNavigationProperty {
                Value = "provided"
            };
            var entity = new MockEntity {
                NavigationProperties = new[] { navProp }
            };

            var repository = new Mock <MockeableRepository>();

            repository.Setup(r => r.GetOne(It.Is <ODataSelectOneQueryOperation>(o => o.Key == "key" && o.OfType == typeof(MockEntity))))
            .Returns(entity);

            Expression <Func <MockNavigationProperty, dynamic> > projectionExpression = e => e == null ? null : new { e.Value };

            var operation = new ODataSelectManyQueryOperation
            {
                OfType = typeof(MockEntity),
                Keys   = new Dictionary <string, string> {
                    { "key", "key" }
                },
                NavigationProperty   = "NavigationProperties",
                ProjectionExpression = projectionExpression,
                ProjectedType        = typeof(object)
            };

            var provider = new ODataQueryProvider <MockEntity>(n => repository.Object);
            var result   = (IEnumerable <dynamic>)provider.ExecuteQuery(operation);

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "provided");
        }
        public void ItShouldCountSelectManyOperationsWhenNavigationPropertyIsNotDecorated()
        {
            var navProp = new MockNavigationProperty {
                Value = "provided"
            };
            var entity = new MockEntity {
                NavigationProperties = new[] { navProp }
            };

            var repository = new Mock <MockeableRepository>();

            repository.Setup(r => r.GetOne(It.Is <ODataSelectOneQueryOperation>(o => o.Key == "key" && o.OfType == typeof(MockEntity))))
            .Returns(entity);

            var operation = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "key" }
                }, NavigationProperty = "NavigationProperties", IsCountRequest = true
            };

            var provider = new ODataQueryProvider <MockEntity>(n => repository.Object);
            var result   = (long)provider.ExecuteQuery(operation);

            repository.VerifyAll();
            Assert.AreEqual(result, 1);
        }
        public void ItShouldCountSelectManyOperationsWhenNavigationPropertyIsNotDecorated()
        {
            var navProp = new MockNavigationProperty { Value = "provided" };
            var entity = new MockEntity { NavigationProperties = new[] { navProp } };

            var repository = new Mock<MockeableRepository>();
            repository.Setup(r => r.GetOne(It.Is<ODataSelectOneQueryOperation>(o => o.Key == "key" && o.OfType == typeof(MockEntity))))
                      .Returns(entity);

            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "key" } }, NavigationProperty = "NavigationProperties", IsCountRequest = true };

            var provider = new ODataQueryProvider<MockEntity>(n => repository.Object);
            var result = (long)provider.ExecuteQuery(operation);

            repository.VerifyAll();
            Assert.AreEqual(result, 1);
        }