public void CustomBinaryExpressionConverterTest()
        {
            var datumConverterFactory = Substitute.For<IDatumConverterFactory>();
            var expresionConverterFactory = new DefaultExpressionConverterFactory();
            expresionConverterFactory.RegisterBinaryExpressionMapping<DateTime, DateTime>(ExpressionType.Subtract, CustomBinaryExpressionConverter);

            var expressionConverter = expresionConverterFactory.CreateExpressionConverter<TimeSpan>(datumConverterFactory);
            var term = expressionConverter.CreateFunctionTerm(() => DateTime.Now - DateTime.Now);
            Assert.That(term, Is.Not.Null);
            Assert.That(term.type, Is.EqualTo(Term.TermType.DATUM)); // not SUB; our custom converter was involved
        }
        public void CustomUnaryExpressionConverterTest()
        {
            var datumConverterFactory = Substitute.For<IDatumConverterFactory>();
            var expresionConverterFactory = new DefaultExpressionConverterFactory();
            expresionConverterFactory.RegisterUnaryExpressionMapping<bool>(ExpressionType.Not, CustomUnaryExpressionConverter);

            bool value = new Random().NextDouble() > 0.5;
            var expressionConverter = expresionConverterFactory.CreateExpressionConverter<bool>(datumConverterFactory);
            var term = expressionConverter.CreateFunctionTerm(() => !value);
            Assert.That(term, Is.Not.Null);
            Assert.That(term.type, Is.EqualTo(Term.TermType.DATUM)); // not NOT; our custom converter was involved
        }
Exemple #3
0
        public void CustomBinaryExpressionConverterTest()
        {
            var datumConverterFactory     = Substitute.For <IDatumConverterFactory>();
            var expresionConverterFactory = new DefaultExpressionConverterFactory();

            expresionConverterFactory.RegisterBinaryExpressionMapping <DateTime, DateTime>(ExpressionType.Subtract, CustomBinaryExpressionConverter);

            var expressionConverter = expresionConverterFactory.CreateExpressionConverter <TimeSpan>(datumConverterFactory);
            var term = expressionConverter.CreateFunctionTerm(() => DateTime.Now - DateTime.Now);

            Assert.That(term, Is.Not.Null);
            Assert.That(term.type, Is.EqualTo(Term.TermType.DATUM)); // not SUB; our custom converter was involved
        }
Exemple #4
0
        public void CustomUnaryExpressionConverterTest()
        {
            var datumConverterFactory     = Substitute.For <IDatumConverterFactory>();
            var expresionConverterFactory = new DefaultExpressionConverterFactory();

            expresionConverterFactory.RegisterUnaryExpressionMapping <bool>(ExpressionType.Not, CustomUnaryExpressionConverter);

            bool value = new Random().NextDouble() > 0.5;
            var  expressionConverter = expresionConverterFactory.CreateExpressionConverter <bool>(datumConverterFactory);
            var  term = expressionConverter.CreateFunctionTerm(() => !value);

            Assert.That(term, Is.Not.Null);
            Assert.That(term.type, Is.EqualTo(Term.TermType.DATUM)); // not NOT; our custom converter was involved
        }