public void SetUp()
 {
     _methodName = "Concat";
     _methodInfo = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) });
     _methodCallTransformerRegistry = new NameBasedMethodCallTransformerRegistry();
     _transformerStub = MockRepository.GenerateStub <IMethodCallTransformer> ();
 }
 public void SetUp ()
 {
   _methodName = "Concat";
   _methodInfo = typeof (string).GetMethod ("Concat", new[] { typeof (string), typeof (string) });
   _methodCallTransformerRegistry = new NameBasedMethodCallTransformerRegistry ();
   _transformerStub = MockRepository.GenerateStub<IMethodCallTransformer> ();
 }
        public void CreateDefault()
        {
            NameBasedMethodCallTransformerRegistry registry = NameBasedMethodCallTransformerRegistry.CreateDefault();

            registry.Register("Test", new TestNameBasedMethodCallTransformer());

            AssertAllMethodsRegistered(registry, typeof(TestNameBasedMethodCallTransformer));
        }
        private void AssertAllMethodsRegistered(NameBasedMethodCallTransformerRegistry registry, Type type)
        {
            var methodNames = (string[])type.GetField("SupportedMethodNames").GetValue(null);

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

            foreach (var methodName in methodNames)
            {
                Assert.That(registry.GetItem(methodName), Is.TypeOf(type));
            }
        }
Ejemplo n.º 5
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);
        }
    private void AssertAllMethodsRegistered (NameBasedMethodCallTransformerRegistry registry, Type type)
    {
      var methodNames = (string[]) type.GetField ("SupportedMethodNames").GetValue (null);
      Assert.That (methodNames.Length, Is.GreaterThan (0));

      foreach (var methodName in methodNames)
         Assert.That (registry.GetItem(methodName), Is.TypeOf (type));
    }