示例#1
0
        public void InstantiateNotString_FormatArgs_FormatResolver()
        {
            var args = new FormatScalarResolverArgs("myVar", new Dictionary <string, ITestVariable>());

            var factory = new ScalarResolverFactory(null);
            var ex      = Assert.Throws <ArgumentException>(() => factory.Instantiate <object>(args));
        }
示例#2
0
        public string GetValue()
        {
            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <string>(Args);

            return(resolver.Execute());
        }
示例#3
0
        private IDictionary <string, ITestVariable> BuildVariables(IEnumerable <GlobalVariableXml> variables)
        {
            var instances       = new Dictionary <string, ITestVariable>();
            var resolverFactory = new ScalarResolverFactory();
            var factory         = new TestVariableFactory();

            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, $"{variables.Count()} variable{(variables.Count()>1 ? "s" : string.Empty)} defined in the test-suite.");
            foreach (var variable in variables)
            {
                var builder = new ScalarResolverArgsBuilder();
                builder.Setup(instances); //Pass the catalog that we're building to itself
                if (variable.Script != null)
                {
                    builder.Setup(variable.Script);
                }
                else if (variable.QueryScalar != null)
                {
                    variable.QueryScalar.Settings = TestSuiteManager.TestSuite.Settings;
                    variable.QueryScalar.Default  = TestSuiteManager.TestSuite.Settings.GetDefault(Xml.Settings.SettingsXml.DefaultScope.Variable);
                    builder.Setup(variable.QueryScalar);
                }
                builder.Build();
                var args = builder.GetArgs();

                var resolver = resolverFactory.Instantiate <object>(args);

                var instance = factory.Instantiate(resolver);
                instances.Add(variable.Name, instance);
            }

            return(instances);
        }
示例#4
0
        public void Instantiate_EnvironmentArgs_EnvironmentResolver()
        {
            var args = new EnvironmentScalarResolverArgs("myVar");

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <EnvironmentScalarResolver <object> >());
        }
示例#5
0
        public void Instantiate_CSharpArgs_CSharpResolver()
        {
            var args = new CSharpScalarResolverArgs("DateTime.Now.Year");

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <CSharpScalarResolver <object> >());
        }
示例#6
0
        public void Instantiate_QueryArgs_QueryResolver()
        {
            var args = new QueryScalarResolverArgs(new EmbeddedQueryResolverArgs("select * from table;", "connStr", null, null, new TimeSpan()));

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <QueryScalarResolver <object> >());
        }
示例#7
0
        public void Instantiate_LiteralArgs_LiteralResolver()
        {
            var args = new LiteralScalarResolverArgs("myValue");

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <LiteralScalarResolver <object> >());
        }
示例#8
0
        public void Instantiate_FormatArgs_FormatResolver()
        {
            var args = new FormatScalarResolverArgs("myVar", new Dictionary <string, ITestVariable>());

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <string>(args);

            Assert.That(resolver, Is.TypeOf <FormatScalarResolver>());
        }
示例#9
0
        public void Instantiate_FunctionArgs_FunctionResolver()
        {
            var args = new FunctionScalarResolverArgs(new LiteralScalarResolver <string>("myVar"), new INativeTransformation[] { });

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <FunctionScalarResolver <object> >());
        }
示例#10
0
        public void Instantiate_NCalcArgs_NcalcResolver()
        {
            var context = new Context(null);
            var args    = new NCalcScalarResolverArgs("a * b - 2", context);

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate(args);

            Assert.That(resolver, Is.TypeOf <NCalcScalarResolver <object> >());
        }
示例#11
0
        public void Instantiate_ProjectionResultSetArgs_ProjectionResultSetResolver()
        {
            var args = new RowCountResultSetScalarResolverArgs(new ResultSetResolverArgs());
            var stub = new Mock <ServiceLocator>();

            stub.Setup(x => x.GetResultSetResolverFactory()).Returns(new ResultSetResolverFactory(stub.Object));

            var factory  = new ScalarResolverFactory(stub.Object);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <ProjectionResultSetScalarResolver <object> >());
        }
示例#12
0
        public void Instantiate_GlobalVariableArgs_GlobalVariableResolver()
        {
            var args = new GlobalVariableScalarResolverArgs("myVar", new Dictionary <string, ITestVariable>()
            {
                { "myVar", null }
            });

            var factory  = new ScalarResolverFactory(null);
            var resolver = factory.Instantiate <object>(args);

            Assert.That(resolver, Is.TypeOf <GlobalVariableScalarResolver <object> >());
        }
示例#13
0
        public void Instantiate_ContextArgs_ContextResolver()
        {
            using (var dt = new DataTable())
            {
                var context = Context.None;
                context.Switch(dt.NewRow());
                var args = new ContextScalarResolverArgs(context, new ColumnOrdinalIdentifier(0));

                var factory  = new ScalarResolverFactory(null);
                var resolver = factory.Instantiate(args);

                Assert.That(resolver, Is.TypeOf <ContextScalarResolver <object> >());
            }
        }
示例#14
0
        public IEnumerable <IQueryParameter> BuildParameters(IEnumerable <QueryParameterXml> parametersXml)
        {
            foreach (var parameterXml in parametersXml)
            {
                var stringWithoutSpecialChars = parameterXml.StringValue.Replace("\r", "").Replace("\n", "").Replace("\t", "").Trim();

                var builder = new ScalarResolverArgsBuilder();
                builder.Setup(stringWithoutSpecialChars);
                builder.Setup(globalVariables);
                builder.Build();
                var args = builder.GetArgs();

                var factory  = new ScalarResolverFactory();
                var resolver = factory.Instantiate <object>(args);
                yield return(new QueryParameter(parameterXml.Name, parameterXml.SqlType, resolver));
            }
        }
示例#15
0
        protected virtual DifferedConstraint BuildChildConstraint(PredicateXml xml)
        {
            var builder = new ScalarResolverArgsBuilder();

            if (!string.IsNullOrEmpty(xml.Value))
            {
                if (xml.Value.Trim().EndsWith("%"))
                {
                    builder.Setup(xml.Value.Trim().Substring(0, xml.Value.Trim().IndexOf("%")));
                }
                else
                {
                    builder.Setup(xml.Value);
                }
            }

            if (xml.QueryScalar != null)
            {
                builder.Setup(xml.QueryScalar);
            }

            if (xml.Projection != null)
            {
                builder.Setup(xml.Projection);
            }

            builder.Setup(ConstraintXml.Settings);
            builder.Setup(Variables);
            builder.Build();
            var args = builder.GetArgs();

            var factory  = new ScalarResolverFactory();
            var resolver = factory.Instantiate <decimal>(args);

            Type ctrType = null;

            if (xml is LessThanXml)
            {
                if (((LessThanXml)xml).OrEqual)
                {
                    ctrType = typeof(NUnitCtr.LessThanOrEqualConstraint);
                }
                else
                {
                    ctrType = typeof(NUnitCtr.LessThanConstraint);
                }
            }
            else if (xml is MoreThanXml)
            {
                if (((MoreThanXml)xml).OrEqual)
                {
                    ctrType = typeof(NUnitCtr.GreaterThanOrEqualConstraint);
                }
                else
                {
                    ctrType = typeof(NUnitCtr.GreaterThanConstraint);
                }
            }
            else if (xml is EqualXml)
            {
                ctrType = typeof(NUnitCtr.EqualConstraint);
            }

            if (ctrType == null)
            {
                throw new ArgumentException();
            }

            return(new DifferedConstraint(ctrType, resolver));
        }