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 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 ItShouldExecuteProjectionEvenWhenItHandlesSelect()
        {
            Expression<Func<MockEntity, dynamic>> projectionExpression = e => e == null ? null : new { e.Value };

            var operation = new ODataSelectOneQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "key" } }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object) };
            var provider = new ODataQueryProvider<MockEntity>(n => new HandlesSelectRepository(new MockEntity { Value = "value" }));
            var result = (IEnumerable<object>)provider.ExecuteQuery(operation);

            dynamic item = result.FirstOrDefault();
            Assert.AreEqual(item.Value, "value");
            Assert.IsNotInstanceOfType(result.FirstOrDefault(), typeof(MockEntity));
        }
        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 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 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 ItShouldInvokeGetOneForODataGetOneQueryOperation()
        {
            var repository = new Mock <MockeableRepository>();
            var operation  = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "foo" }
                }
            };

            repository.Setup(r => r.GetOne(operation)).Returns(() => new MockEntity()).Verifiable();

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

            repository.VerifyAll();
            Assert.IsNotNull(result);
        }
        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");
        }
        public void ItShouldExecuteProjectionEvenWhenItHandlesAll()
        {
            Expression <Func <MockEntity, dynamic> > projectionExpression = e => e == null ? null : new { e.Value };

            var operation = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "key" }
                }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object)
            };
            var provider = new ODataQueryProvider <MockEntity>(n => new HandlesAllRepository(new MockEntity {
                Value = "value"
            }));
            var result = (IEnumerable <object>)provider.ExecuteQuery(operation);

            dynamic item = result.FirstOrDefault();

            Assert.AreEqual(item.Value, "value");
            Assert.IsNotInstanceOfType(result.FirstOrDefault(), typeof(MockEntity));
        }
        public void ItShouldUnwrapTargetOfInvocationExceptions()
        {
            Expression <Func <MockEntity, dynamic> > projectionExpression = e => e == null ? null : new { e.Value };
            var operation = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "key", "not_found" }
                }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object)
            };

            var repository = new Mock <MockeableRepository>();

            repository.Setup(r => r.GetOne(operation)).Throws(new WebException());

            var provider = new ODataQueryProvider <MockEntity>(n => repository.Object);

            provider.ExecuteQuery(operation);

            Assert.Inconclusive();
        }
        public void ItShouldInvokeGetOneForODataGetOneQueryOperationWithProjection()
        {
            var repository = new Mock <MockeableRepository>();

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

            var operation = new ODataSelectOneQueryOperation {
                OfType = typeof(MockEntity), Keys = new Dictionary <string, string> {
                    { "foo", "foo" }
                }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object)
            };

            repository.Setup(r => r.GetOne(operation)).Returns(() => new MockEntity {
                Value = "value"
            }).Verifiable();

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

            repository.VerifyAll();
            Assert.AreEqual(result.Cast <dynamic>().First().Value, "value");
            Assert.IsNotNull(result);
        }
Exemplo n.º 12
0
        public void ItShouldUnwrapTargetOfInvocationExceptions()
        {
            Expression<Func<MockEntity, dynamic>> projectionExpression = e => e == null ? null : new { e.Value };
            var operation = new ODataSelectOneQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "not_found" } }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object) };

            var repository = new Mock<MockeableRepository>();
            repository.Setup(r => r.GetOne(operation)).Throws(new WebException());

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

            Assert.Inconclusive();
        }
Exemplo n.º 13
0
        public void ItShouldInvokeGetOneForODataGetOneQueryOperationWithProjection()
        {
            var repository = new Mock<MockeableRepository>();

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

            var operation = new ODataSelectOneQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "foo", "foo" } }, ProjectionExpression = projectionExpression, ProjectedType = typeof(object) };
            repository.Setup(r => r.GetOne(operation)).Returns(() => new MockEntity { Value = "value" }).Verifiable();

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

            repository.VerifyAll();
            Assert.AreEqual(result.Cast<dynamic>().First().Value, "value");
            Assert.IsNotNull(result);
        }
Exemplo n.º 14
0
        public void ItShouldInvokeGetOneForODataGetOneQueryOperation()
        {
            var repository = new Mock<MockeableRepository>();
            var operation = new ODataSelectOneQueryOperation { OfType = typeof(MockEntity), Keys = new Dictionary<string, string> { { "key", "foo" } } };
            repository.Setup(r => r.GetOne(operation)).Returns(() => new MockEntity()).Verifiable();

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

            repository.VerifyAll();
            Assert.IsNotNull(result);
        }
Exemplo n.º 15
0
 public abstract object GetOne(ODataSelectOneQueryOperation operation);
        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 object GetOne(ODataSelectOneQueryOperation operation)
 {
     throw new NotImplementedException();
 }
 public object GetOne(ODataSelectOneQueryOperation operation)
 {
     return(this.result ?? new MockEntity());
 }
Exemplo n.º 19
0
 public object GetOne(ODataSelectOneQueryOperation operation)
 {
     return this.result ?? new MockEntity();
 }
        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 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");
        }
 public object GetOne(ODataSelectOneQueryOperation operation)
 {
     throw new NotImplementedException();
 }
        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");
        }