public virtual void Use_provider_method_is_generated_correctly()
        {
            var codeGenerator = new MySqlCodeGenerator(new ProviderCodeGeneratorDependencies());

            var result = codeGenerator.GenerateUseProvider("Data Source=Test");

            Assert.Equal("UseMySql", result.Method);
            Assert.Collection(
                result.Arguments,
                a => Assert.Equal("Data Source=Test", a));
        }
        private string GenerateCode(string query, bool resolved)
        {
            var ss = CreateSelect(query);
            var w  = new StringWriter();

            var cg = new MySqlCodeGenerator();

            cg.ResolveNames = resolved;
            cg.Execute(w, ss);

            return(w.ToString());
        }
Exemplo n.º 3
0
        public virtual void Use_provider_method_is_generated_correctly()
        {
            var codeGenerator = new MySqlCodeGenerator(
                new ProviderCodeGeneratorDependencies(
                    Enumerable.Empty <IProviderCodeGeneratorPlugin>()));

            var result = codeGenerator.GenerateUseProvider("Data Source=Test", providerOptions: null);

            Assert.Equal("UseMySql", result.Method);
            Assert.Collection(
                result.Arguments,
                a => Assert.Equal("Data Source=Test", a));
            Assert.Null(result.ChainedCall);
        }
        private string[] GenerateMostRestrictiveTableQueryTestHelper(string sql, bool includePrimaryKey, int top)
        {
            var cg = new MySqlCodeGenerator();

            cg.ResolveNames = true;

            var ss = CreateSelect(sql);

            var res = new List <string>();

            foreach (var qs in ss.EnumerateQuerySpecifications())
            {
                // TODO: use qs.SourceTableReferences
                foreach (var tr in qs.EnumerateSourceTableReferences(true))
                {
                    res.Add(cg.GenerateMostRestrictiveTableQuery(tr, includePrimaryKey, top));
                }
            }

            return(res.ToArray());
        }
Exemplo n.º 5
0
        public virtual void Use_provider_method_is_generated_correctly_with_options()
        {
            var codeGenerator = new MySqlCodeGenerator(
                new ProviderCodeGeneratorDependencies(
                    Enumerable.Empty <IProviderCodeGeneratorPlugin>()));

            var providerOptions = new MethodCallCodeFragment("SetProviderOption");

            var result = codeGenerator.GenerateUseProvider("Data Source=Test", providerOptions);

            Assert.Equal("UseMySql", result.Method);
            Assert.Collection(
                result.Arguments,
                a => Assert.Equal("Data Source=Test", a),
                a =>
            {
                var nestedClosure = Assert.IsType <NestedClosureCodeFragment>(a);

                Assert.Equal("x", nestedClosure.Parameter);
                Assert.Same(providerOptions, nestedClosure.MethodCall);
            });
            Assert.Null(result.ChainedCall);
        }