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 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 IEnumerable<BuildDefinition> GetBuildDefinitionsByProject(ODataSelectManyQueryOperation operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }

            return this.proxy.GetBuildDefinitionsByProject(operation.Key);
        }
        public void ShouldGetMethodInfoForODataCountQueryOperationIfThereIsAttributeWithoutNameSpecified()
        {
            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "foo" } }, NavigationProperty = "RemoteCountedNavigationProperty", IsCountRequest = true };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("CountRemoteCountedNavigationPropertyByMockEntity", method.Name);
        }
        public void ItShouldRemoteDecoratedCountNavigationProperties()
        {
            var operation = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "key" }
                }, NavigationProperty = "RemoteCountedNavigationProperty", IsCountRequest = true
            };
            var provider = new ODataQueryProvider <MockEntity>(n => new RepositoryStub());
            var result   = (long)provider.ExecuteQuery(operation);

            Assert.IsNotNull(result);
            Assert.AreEqual(result, 10);
        }
        public void ShouldGetMethodInfoForODataSelectManyQueryOperationIfThereIsNoAttribute()
        {
            var operation = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "foo" }
                }, NavigationProperty = "NavigationProperty"
            };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("GetOne", method.Name);
        }
        public void ShouldGetMethodInfoForODataCountQueryOperationIfThereIsAttributeWithNameSpecified()
        {
            var operation = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "foo" }
                }, NavigationProperty = "RemoteCountedNavigationPropertyWithMethodName", IsCountRequest = true
            };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("CountRemoteCountedProperties", method.Name);
        }
        public void ItShouldReturnNavigationPropertyAsPropertyInfoOutOfType()
        {
            var operation = new ODataSelectManyQueryOperation
                                {
                                    OfType = typeof(MockEntity),
                                    Keys = new Dictionary<string, string> { { "key", "key" } },
                                    NavigationProperty = "NavigationProperty"
                                };

            var expectedProperty = typeof(MockEntity).GetProperty("NavigationProperty");
            Assert.AreEqual(operation.NavigationPropertyType, typeof(MockNavigationProperty));
            Assert.AreEqual(expectedProperty, operation.NavigationPropertyInfo);
        }
        public void ShouldGetMethodInfoForODataSelectManyQueryOperationIfThereIsAttributeWithNameSpecified()
        {
            var operation = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase)
                {
                    { "key", "foo" }
                }, NavigationProperty = "DecoratedNavigationPropertyWithMethodName"
            };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("MockMethodForDecoratedNavigationProperty", method.Name);
        }
        public void ItShouldReturnNavigationPropertyAsPropertyInfoOutOfType()
        {
            var operation = new ODataSelectManyQueryOperation
            {
                OfType = typeof(MockEntity),
                Keys   = new Dictionary <string, string> {
                    { "key", "key" }
                },
                NavigationProperty = "NavigationProperty"
            };

            var expectedProperty = typeof(MockEntity).GetProperty("NavigationProperty");

            Assert.AreEqual(operation.NavigationPropertyType, typeof(MockNavigationProperty));
            Assert.AreEqual(expectedProperty, operation.NavigationPropertyInfo);
        }
        public void ShouldResolveRepositoryForSelectManyCountTypeBasedOperationWhenNavPropIsNotDecorated()
        {
            string resolvedTypeName = null;
            var    operation        = new ODataSelectManyQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase)
                {
                    { "key", "foo" }
                }, NavigationProperty = "NavigationProperty", IsCountRequest = true
            };
            Func <string, object> resolver = a => { resolvedTypeName = a; return(new RepositoryStub()); };

            var repository = ODataOperationResolver.For(operation).Repository(resolver);

            Assert.AreEqual(resolvedTypeName, typeof(MockEntity).FullName);
            Assert.IsInstanceOfType(repository, typeof(RepositoryStub));
        }
        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 ItShouldSortUsingLinq2ObjectsImplementationWhenTheRepositoryDoesntProvideIt()
        {
            var entity = new MockEntity
            {
                NavigationProperties = new[]
                {
                    new MockNavigationProperty {
                        Value = "2. provided"
                    },
                    new MockNavigationProperty {
                        Value = "1. provided"
                    }
                }
            };

            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, string> > order = e => e.Value;

            var operation = new ODataSelectManyQueryOperation
            {
                OfType = typeof(MockEntity),
                Keys   = new Dictionary <string, string> {
                    { "key", "key" }
                },
                NavigationProperty = "NavigationProperties",
                OrderStack         = new Stack <ODataOrderExpression>(new[] { new ODataOrderExpression {
                                                                                  OrderMethodName = "OrderBy", Expression = order
                                                                              } })
            };

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

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

            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, bool> > filter = e => e.Value == "provided_one";

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

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

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "provided_one");
            Assert.AreEqual(result.Count(), 1);
        }
        public void ItShouldExecuteTopWithLinq2ObjectWhenTheUnderlyingMethodDoesntProvideIt()
        {
            var entity = new MockEntity
            {
                NavigationProperties = new[]
                {
                    new MockNavigationProperty {
                        Value = "2. provided"
                    },
                    new MockNavigationProperty {
                        Value = "1. provided"
                    }
                }
            };

            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",
                TopCount           = 1
            };

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

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "2. provided");
            Assert.AreEqual(result.Count(), 1);
        }
        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 ItShouldSortUsingLinq2ObjectsImplementationWhenTheRepositoryDoesntProvideIt()
        {
            var entity = new MockEntity
            {
                NavigationProperties = new[]
                {
                    new MockNavigationProperty { Value = "2. provided" },
                    new MockNavigationProperty { Value = "1. provided" }
                }
            };

            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, string>> order = e => e.Value;

            var operation = new ODataSelectManyQueryOperation
                                {
                                    OfType = typeof(MockEntity),
                                    Keys = new Dictionary<string, string> { { "key", "key" } },
                                    NavigationProperty = "NavigationProperties",
                                    OrderStack = new Stack<ODataOrderExpression>(new[] { new ODataOrderExpression { OrderMethodName = "OrderBy", Expression = order } })
                                };

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

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "1. provided");
        }
        public void ItShouldRemoteDecoratedCountNavigationProperties()
        {
            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "key" } }, NavigationProperty = "RemoteCountedNavigationProperty", IsCountRequest = true };
            var provider = new ODataQueryProvider<MockEntity>(n => new RepositoryStub());
            var result = (long)provider.ExecuteQuery(operation);

            Assert.IsNotNull(result);
            Assert.AreEqual(result, 10);
        }
        public void ItShouldPerformLinq2ObjectsFilteringWhenMethodDoesntProvidedOutOfTheBox()
        {
            var entity = new MockEntity
            {
                NavigationProperties = new[]
                {
                    new MockNavigationProperty { Value = "provided_one" },
                    new MockNavigationProperty { Value = "provided_two" }
                }
            };

            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, bool>> filter = e => e.Value == "provided_one";

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

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

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "provided_one");
            Assert.AreEqual(result.Count(), 1);
        }
Example #20
0
 public object CountRemoteCountedProperties(ODataSelectManyQueryOperation operation)
 {
     throw new NotImplementedException();
 }
Example #21
0
 public object GetDecoratedNavigationPropertyByMockEntity(ODataSelectManyQueryOperation operation)
 {
     throw new NotImplementedException();
 }
Example #22
0
 public object MockMethodForDecoratedNavigationProperty(ODataSelectManyQueryOperation operation)
 {
     throw new NotImplementedException();
 }
        public void ShouldResolveRepositoryForSelectManyTypeBasedOperationWhenNavPropIsNotDecorated()
        {
            string resolvedTypeName = null;
            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) { { "key", "foo" } }, NavigationProperty = "NavigationProperty" };
            Func<string, object> resolver = a => { resolvedTypeName = a; return new RepositoryStub(); };

            var repository = ODataOperationResolver.For(operation).Repository(resolver);

            Assert.AreEqual(resolvedTypeName, typeof(MockEntity).FullName);
            Assert.IsInstanceOfType(repository, typeof(RepositoryStub));
        }
        public void ShouldGetMethodInfoForODataSelectManyQueryOperationIfThereIsAttributeWithNameSpecified()
        {
            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) { { "key", "foo" } }, NavigationProperty = "DecoratedNavigationPropertyWithMethodName" };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("MockMethodForDecoratedNavigationProperty", method.Name);
        }
        public void ItShouldExecuteSkipWithLinq2ObjectWhenTheUnderlyingMethodDoesntProvideIt()
        {
            var entity = new MockEntity
            {
                NavigationProperties = new[]
                {
                    new MockNavigationProperty { Value = "2. provided" },
                    new MockNavigationProperty { Value = "1. provided" }
                }
            };

            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",
                                    SkipCount = 1
                                };

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

            repository.VerifyAll();
            Assert.AreEqual(result.First().Value, "1. provided");
            Assert.AreEqual(result.Count(), 1);
        }
        public void ShouldGetMethodInfoForODataSelectManyQueryOperationIfThereIsNoAttribute()
        {
            var operation = new ODataSelectManyQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "foo" } }, NavigationProperty = "NavigationProperty" };

            var method = ODataOperationResolver.For(operation).Method(new RepositoryStub());

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("GetOne", method.Name);
        }
Example #27
0
 public long CountRemoteCountedNavigationPropertyByMockEntity(ODataSelectManyQueryOperation operation)
 {
     return(10);
 }