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 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 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 long MockEntity2Count(ODataQueryOperation query) { return 1; }
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 object MockEntityWithCollectionCountAttributeCount(ODataQueryOperation operation) { throw new NotImplementedException(); }
public abstract object GetAll(ODataQueryOperation operation);
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 long MockEntity2Count(ODataQueryOperation query) { return(1); }