Exemple #1
0
        /// <summary>
        /// Constructor with connectionString and ProviderName
        /// </summary>
        /// <param name="connectionString">Eg "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"</param>
        /// <param name="providerName">ProviderInvariantName for the provider (eg System.Data.SqlClient or System.Data.OracleClient)</param>
        public SchemaReader(string connectionString, string providerName)
        {
            if (String.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", "connectionString must not be empty");
            }

            if (String.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName", "providerName must not be empty");
            }

            ConnectionString = connectionString;
            ProviderName     = providerName;
            ProviderType     = ProviderToSqlType.Convert(providerName);
            Factory          = FactoryTools.GetFactory(ProviderName);
        }
Exemple #2
0
        public void FactoryToolsTest()
        {
            const string providername = "System.Data.SqlClient";

            //this is normally used
            var provider = FactoryTools.GetFactory(providername);

            Assert.AreEqual("System.Data.SqlClient.SqlClientFactory", provider.GetType().FullName, "No override, returns SqlClient");

            //override with a repository
            FactoryTools.ProviderRepository = new DbProviderFactoryRepository();
            var manualDescription = new DbProviderFactoryDescription
            {
                Description           = ".NET Framework Data Provider for SuperDuperDatabase",
                InvariantName         = "SuperDuperDatabase",
                Name                  = "SuperDuperDatabase Data Provider",
                AssemblyQualifiedName = typeof(SuperDuperProviderFactory).AssemblyQualifiedName,
            };

            FactoryTools.ProviderRepository.Add(manualDescription);

            provider = FactoryTools.GetFactory(providername);
            Assert.AreEqual("System.Data.SqlClient.SqlClientFactory", provider.GetType().FullName, "Overridden, but returns underlying SqlClient");
            provider = FactoryTools.GetFactory("SuperDuperDatabase");
            Assert.AreEqual(typeof(SuperDuperProviderFactory), provider.GetType(), "Overridden, returns manually added provider");

            //override with a single provider
            FactoryTools.SingleProviderFactory = SqlClientFactory.Instance;
            provider = FactoryTools.GetFactory("Xxxx");
            Assert.AreEqual("System.Data.SqlClient.SqlClientFactory", provider.GetType().FullName, "Overridden, always returns SqlClient");

            ProviderChecker.Check(providername, ConnectionStrings.Northwind);

            var dr     = new DatabaseReader(ConnectionStrings.Northwind, "Xxxxx", 0);
            var tables = dr.TableList();

            Assert.IsTrue(tables.Count > 0, "We called the reader with a bogus provider type, but we got the overridden type");
        }