public void ShouldThrowAProperExceptionWhenNoSuitableMethodFound()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            ODataOperationResolver.For(operation).Method(new IncompleteEntityRepository());
        }
        public void ShouldThrowAProperExceptionWhenTheRepositoryIsNotFound()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            ODataOperationResolver.For(operation).Repository(s => null);
        }
        public void ShouldGetArgumentsForGetAllOpertionWhenGivenMethodHasQueryOperation()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };
            var method    = ODataOperationResolver.For(operation).Method(new RepositoryStub());
            var arguments = ODataOperationResolver.For(operation).Arguments(method);

            Assert.AreEqual(arguments.First(), operation);
        }
        public void ShouldGetArgumentsForGetOneOpertionWhenGivenMethodHasNoArguments()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };
            var method    = ODataOperationResolver.For(operation).Method(new CustomRepositoryStub());
            var arguments = ODataOperationResolver.For(operation).Arguments(method);

            Assert.IsNull(arguments);
        }
        public void ShouldGetMethodInfoForODataRootCountQueryOperationWhenCollectionCountAttribute()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute), IsCountRequest = true
            };

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

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("MockEntityWithCollectionCountAttributeCount", method.Name);
        }
        public void ShouldGetMethodInfoForODataQueryOperation()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntity)
            };

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

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("GetAll", method.Name);
        }
        public void ShouldGetArgumentsForGetOneOpertionWhenGivenMethodHasStringAsOpertion()
        {
            var operation = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute), Keys = new Dictionary <string, string> {
                    { "key", "key" }
                }
            };
            var method    = ODataOperationResolver.For(operation).Method(new CustomRepositoryStub());
            var arguments = ODataOperationResolver.For(operation).Arguments(method);

            Assert.AreEqual(arguments.First(), "key");
        }
        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 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 ShouldResolveRepositoryForRootCollectionOneTypeBasedOperation()
        {
            string resolvedTypeName = null;
            var    operation        = new ODataQueryOperation {
                OfType = typeof(MockEntity)
            };
            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 ShouldGetMethodInfoForODataSelectOneQueryOperation()
        {
            var operation = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase)
                {
                    { "key", "foo" }
                }
            };

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

            Assert.AreEqual("RepositoryStub", method.DeclaringType.Name);
            Assert.AreEqual("GetOne", method.Name);
        }
        public void ShouldThrowAProperExceptionWhenNoSuitableMethodFoundWithANiceMessage()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            try
            {
                ODataOperationResolver.For(operation).Method(new IncompleteEntityRepository());
            }
            catch (Exception e)
            {
                Assert.AreEqual("The method GetAll cannot be found on the repository IncompleteEntityRepository.", e.Message);
            }
        }
        public void ShouldThrowAProperExceptionWhenNoRepositoryFoundWithANiceMessage()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            try
            {
                ODataOperationResolver.For(operation).Repository(s => null);
            }
            catch (Exception e)
            {
                Assert.AreEqual("No repository found for MockEntityWithCollectionCountAttribute.", e.Message);
            }
        }
        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 ShouldGetOrderedArgumentsForExecutionWhenOneOfTheKeysIsNotRequiredOnTheMethod()
        {
            var operation = new ODataSelectOneQueryOperation
            {
                OfType = typeof(Entity),
                Keys   = new Dictionary <string, string> {
                    { "parameterTwo", "valueTwo" }, { "parameterOne", "valueOne" }
                }
            };

            var method    = ODataOperationResolver.For(operation).Method(new EntityRepository2());
            var arguments = ODataOperationResolver.For(operation).Arguments(method);

            Assert.AreEqual(arguments.First().ToString(), "valueTwo");
            Assert.AreEqual(arguments.Last().ToString(), "valueTwo");
        }
        public void ShouldResolveRepositoryForOneTypeBasedOperation()
        {
            string resolvedTypeName = null;
            var    operation        = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase)
                {
                    { "key", "foo" }
                }
            };
            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 ShouldGetOrderedArgumentsForExecutionWhenOneOfTheKeysIsSkippedRequiredOnTheMethod()
        {
            var operation = new ODataSelectOneQueryOperation
            {
                OfType = typeof(Entity),
                Keys   = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase)
                {
                    { "parameterTwo", "valueTwo" }, { "parameterOne", "valueOne" }, { "PaRaMeTeRThRee", "valueThree" }
                }
            };

            var method    = ODataOperationResolver.For(operation).Method(new EntityRepository3());
            var arguments = ODataOperationResolver.For(operation).Arguments(method);

            Assert.AreEqual(arguments.First().ToString(), "valueTwo");
            Assert.AreEqual(arguments.Last().ToString(), "valueThree");
        }