示例#1
0
        public void GetItem_DontFindGenerator_ReturnsNull()
        {
            var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry();

            var result = methodCallSqlGeneratorRegistry.GetItem(_methodInfo);

            Assert.That(result, Is.Null);
        }
示例#2
0
        public void GetTransformer_DontFindGenerator_ReturnsNull()
        {
            var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry();
            var methodCallExpression           = Expression.Call(_methodInfo, Expression.Constant("a"), Expression.Constant("b"));

            var result = methodCallSqlGeneratorRegistry.GetTransformer(methodCallExpression);

            Assert.That(result, Is.Null);
        }
示例#3
0
        public void GetItem()
        {
            var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry();

            methodCallSqlGeneratorRegistry.Register(_methodInfo, _transformerStub);

            var result = methodCallSqlGeneratorRegistry.GetItem(_methodInfo);

            Assert.That(result, Is.SameAs(_transformerStub));
        }
示例#4
0
        private void AssertAllMethodsRegistered(MethodInfoBasedMethodCallTransformerRegistry registry, Type type)
        {
            var methodInfos = (MethodInfo[])type.GetField("SupportedMethods").GetValue(null);

            Assert.That(methodInfos.Length, Is.GreaterThan(0));

            foreach (var methodInfo in methodInfos)
            {
                Assert.That(registry.GetItem(methodInfo), Is.TypeOf(type));
            }
        }
示例#5
0
        public void GetTransformer()
        {
            var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry();

            methodCallSqlGeneratorRegistry.Register(_methodInfo, _transformerStub);
            var methodCallExpression = Expression.Call(_methodInfo, Expression.Constant("a"), Expression.Constant("b"));

            var result = methodCallSqlGeneratorRegistry.GetTransformer(methodCallExpression);

            Assert.That(result, Is.SameAs(_transformerStub));
        }
示例#6
0
        public void CreateDefault()
        {
            MethodInfoBasedMethodCallTransformerRegistry registry = MethodInfoBasedMethodCallTransformerRegistry.CreateDefault();

            AssertAllMethodsRegistered(registry, typeof(ContainsMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(EndsWithMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(IndexOfMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(LowerMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(RemoveMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(ReplaceMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(StartsWithMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(SubstringMethodCallTransformer));
            AssertAllMethodsRegistered(registry, typeof(UpperMethodCallTransformer));
        }
示例#7
0
        public void VisitMethodCallExpression_ExpressionPropertiesVisitedBeforeTransformation()
        {
            var method = MethodCallTransformerUtility.GetInstanceMethod(typeof(object), "ToString");
            var methodCallExpression = Expression.Call(_cookQuerySourceReferenceExpression, method);

            var transformerMock = MockRepository.GenerateMock <IMethodCallTransformer>();

            transformerMock
            .Expect(mock => mock.Transform(Arg.Is(methodCallExpression)))
            .Return(methodCallExpression);
            transformerMock.Replay();

            var registry = new MethodInfoBasedMethodCallTransformerRegistry();

            registry.Register(method, transformerMock);

            SqlPreparationExpressionVisitor.TranslateExpression(methodCallExpression, _context, _stageMock, registry);

            transformerMock.VerifyAllExpectations();
        }
示例#8
0
        public RelinqNorthwindDataProvider()
        {
            _manager   = new NorthwindConnectionManager();
            _context   = new NorthwindDataContext(_manager.GetConnectionString());
            _resolver  = new MappingResolver(_context.Mapping);
            _retriever = new QueryResultRetriever(_manager, _resolver);

            _resultOperatorHandlerRegistry = ResultOperatorHandlerRegistry.CreateDefault();

            var methodBasedTransformerRegistry = MethodInfoBasedMethodCallTransformerRegistry.CreateDefault();
            var nameBasedTransformerRegistry   = NameBasedMethodCallTransformerRegistry.CreateDefault();

            _methodCallTransformerProvider = new CompoundMethodCallTransformerProvider(methodBasedTransformerRegistry, nameBasedTransformerRegistry);
            methodBasedTransformerRegistry.Register(
                typeof(SqlMethods).GetMethod("Like", new[] { typeof(string), typeof(string) }),
                new LikeMethodCallTransformer());
            methodBasedTransformerRegistry.Register(DateDiffDayMethodCallTransformer.SupportedMethods, new DateDiffDayMethodCallTransformer());

            foreach (var userDefinedFunction in _context.GetType().GetMethods().Where(mi => mi.IsDefined(typeof(FunctionAttribute), false)))
            {
                methodBasedTransformerRegistry.Register(userDefinedFunction, new UserDefinedFunctionTransformer());
            }

            var customNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry();

            customNodeTypeRegistry.Register(new[] { typeof(EntitySet <>).GetMethod("Contains") }, typeof(ContainsExpressionNode));

            var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider();

            nodeTypeProvider.InnerProviders.Add(customNodeTypeRegistry);

            var transformerRegistry  = ExpressionTransformerRegistry.CreateDefault();
            var processor            = ExpressionTreeParser.CreateDefaultProcessor(transformerRegistry);
            var expressionTreeParser = new ExpressionTreeParser(nodeTypeProvider, processor);

            _queryParser = new QueryParser(expressionTreeParser);

            _executor = new QueryExecutor(_resolver, _retriever, _resultOperatorHandlerRegistry, _methodCallTransformerProvider, false);
        }
    public void GetTransformer_DontFindGenerator_ReturnsNull ()
    {
      var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry ();
      var methodCallExpression = Expression.Call (_methodInfo, Expression.Constant ("a"), Expression.Constant ("b"));

      var result = methodCallSqlGeneratorRegistry.GetTransformer (methodCallExpression);

      Assert.That (result, Is.Null);
    }
 public void SetUp ()
 {
   _methodInfo = typeof (string).GetMethod ("Concat", new[] { typeof (string), typeof (string) });
   _methodCallTransformerRegistry = new MethodInfoBasedMethodCallTransformerRegistry ();
   _transformerStub = MockRepository.GenerateStub<IMethodCallTransformer> ();
 }
    private void AssertAllMethodsRegistered (MethodInfoBasedMethodCallTransformerRegistry registry, Type type)
    {
      var methodInfos = (MethodInfo[]) type.GetField ("SupportedMethods").GetValue (null);
      Assert.That (methodInfos.Length, Is.GreaterThan (0));

      foreach (var methodInfo in methodInfos)
        Assert.That (registry.GetItem (methodInfo), Is.TypeOf (type));
    }
    public void GetItem ()
    {
      var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry ();
      methodCallSqlGeneratorRegistry.Register (_methodInfo, _transformerStub);

      var result = methodCallSqlGeneratorRegistry.GetItem (_methodInfo);

      Assert.That (result, Is.SameAs (_transformerStub));
    }
    public void GetTransformer ()
    {
      var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry ();
      methodCallSqlGeneratorRegistry.Register (_methodInfo, _transformerStub);
      var methodCallExpression = Expression.Call (_methodInfo, Expression.Constant ("a"), Expression.Constant ("b"));

      var result = methodCallSqlGeneratorRegistry.GetTransformer (methodCallExpression);

      Assert.That (result, Is.SameAs (_transformerStub));
    }
    public void GetItem_DontFindGenerator_ReturnsNull ()
    {
      var methodCallSqlGeneratorRegistry = new MethodInfoBasedMethodCallTransformerRegistry ();

      var result = methodCallSqlGeneratorRegistry.GetItem (_methodInfo);

      Assert.That (result, Is.Null);
    }
示例#15
0
 public void SetUp()
 {
     _methodInfo = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) });
     _methodCallTransformerRegistry = new MethodInfoBasedMethodCallTransformerRegistry();
     _transformerStub = MockRepository.GenerateStub <IMethodCallTransformer> ();
 }