Ejemplo n.º 1
0
 public IEnumerable <MyAlphaEntity> GetAll(ODataQueryOperation operation)
 {
     for (int i = 0; i < 5; i++)
     {
         yield return(GetOne(Guid.NewGuid().ToString()));
     }
 }
        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 ShouldThrowAProperExceptionWhenTheRepositoryIsNotFound()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            ODataOperationResolver.For(operation).Repository(s => null);
        }
        public void ShouldThrowAProperExceptionWhenNoSuitableMethodFound()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntityWithCollectionCountAttribute)
            };

            ODataOperationResolver.For(operation).Method(new IncompleteEntityRepository());
        }
        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 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 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 ItShouldRemoteCountMockEntity2WhenCollectionCountSupportsIt()
        {
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntity2), IsCountRequest = true
            };
            var provider = new ODataQueryProvider <MockEntity>(n => new MockRepository2());
            var result   = (long)provider.ExecuteQuery(operation);

            Assert.AreEqual(result, 1);
        }
        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 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 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 ItShouldNotThrowWhenRepositoryReturnsNullOnGetAll()
        {
            var repository = new Mock <IRepository <MockEntity> >();

            repository.Setup(r => r.GetAll()).Returns(default(MockEntity[]));
            var provider  = new ODataQueryProvider <MockEntity>(n => repository.Object);
            var operation = new ODataQueryOperation {
                OfType = typeof(MockEntity)
            };
            var result = provider.ExecuteQuery(operation);

            Assert.IsNull(result);
        }
        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 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 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 object GetAll(ODataQueryOperation operation)
 {
     throw new NotImplementedException();
 }
 public object GetAll(ODataQueryOperation operation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
 public long MockEntity2Count(ODataQueryOperation query)
 {
     return 1;
 }
Ejemplo n.º 20
0
        public void ItShouldRemoteCountMockEntity2WhenCollectionCountSupportsIt()
        {
            var operation = new ODataQueryOperation { OfType = typeof(MockEntity2), IsCountRequest = true };
            var provider = new ODataQueryProvider<MockEntity>(n => new MockRepository2());
            var result = (long)provider.ExecuteQuery(operation);

            Assert.AreEqual(result, 1);
        }
Ejemplo n.º 21
0
 public object MockEntityWithCollectionCountAttributeCount(ODataQueryOperation operation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 22
0
 public abstract object GetAll(ODataQueryOperation operation);
        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 ItShouldNotThrowWhenRepositoryReturnsNullOnGetAll()
        {
            var repository = new Mock<IRepository<MockEntity>>();
            repository.Setup(r => r.GetAll()).Returns(default(MockEntity[]));
            var provider = new ODataQueryProvider<MockEntity>(n => repository.Object);
            var operation = new ODataQueryOperation { OfType = typeof(MockEntity) };
            var result = provider.ExecuteQuery(operation);

            Assert.IsNull(result);
        }
        public void ShouldThrowAProperExceptionWhenTheRepositoryIsNotFound()
        {
            var operation = new ODataQueryOperation { OfType = typeof(MockEntityWithCollectionCountAttribute) };

            ODataOperationResolver.For(operation).Repository(s => null);
        }
        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 ShouldThrowAProperExceptionWhenNoSuitableMethodFound()
        {
            var operation = new ODataQueryOperation { OfType = typeof(MockEntityWithCollectionCountAttribute) };

            ODataOperationResolver.For(operation).Method(new IncompleteEntityRepository());
        }
        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 long MockEntity2Count(ODataQueryOperation query)
 {
     return(1);
 }