Example #1
0
        public void GetProviderFactory_caches_factory_instances_on_net40()
        {
            var mockFinder = new Mock<ProviderRowFinder>
                {
                    CallBase = true
                };

            var service = new Net40DefaultDbProviderFactoryResolver(mockFinder.Object);

            Assert.Equal(SqlClientFactory.Instance, service.ResolveProviderFactory(new SqlConnection()));
            mockFinder.Verify(
                m => m.FindRow(It.IsAny<Type>(), It.IsAny<Func<DataRow, bool>>(), It.IsAny<IEnumerable<DataRow>>()), Times.Once());

            Assert.Equal(SqlClientFactory.Instance, service.ResolveProviderFactory(new SqlConnection()));
            // Finder not called again
            mockFinder.Verify(
                m => m.FindRow(It.IsAny<Type>(), It.IsAny<Func<DataRow, bool>>(), It.IsAny<IEnumerable<DataRow>>()), Times.Once());
        }
        public void GetProviderFactory_caches_factory_instances_on_net40()
        {
            var mockFinder = new Mock <ProviderRowFinder>
            {
                CallBase = true
            };

            var service = new Net40DefaultDbProviderFactoryResolver(mockFinder.Object);

            Assert.Equal(SqlClientFactory.Instance, service.ResolveProviderFactory(new SqlConnection()));
            mockFinder.Verify(
                m => m.FindRow(It.IsAny <Type>(), It.IsAny <Func <DataRow, bool> >(), It.IsAny <IEnumerable <DataRow> >()), Times.Once());

            Assert.Equal(SqlClientFactory.Instance, service.ResolveProviderFactory(new SqlConnection()));
            // Finder not called again
            mockFinder.Verify(
                m => m.FindRow(It.IsAny <Type>(), It.IsAny <Func <DataRow, bool> >(), It.IsAny <IEnumerable <DataRow> >()), Times.Once());
        }
Example #3
0
 public DbProviderFactory GetProviderFactory(
     DbConnection connection,
     IEnumerable <DataRow> dataRows)
 {
     return(this._cache.GetOrAdd(connection.GetType(), (Func <Type, DbProviderFactory>)(t =>
     {
         DataRow providerRow = this._finder.FindRow(t, (Func <DataRow, bool>)(r => Net40DefaultDbProviderFactoryResolver.ExactMatch(r, t)), dataRows) ?? this._finder.FindRow((Type)null, (Func <DataRow, bool>)(r => Net40DefaultDbProviderFactoryResolver.ExactMatch(r, t)), dataRows) ?? this._finder.FindRow(t, (Func <DataRow, bool>)(r => Net40DefaultDbProviderFactoryResolver.AssignableMatch(r, t)), dataRows) ?? this._finder.FindRow((Type)null, (Func <DataRow, bool>)(r => Net40DefaultDbProviderFactoryResolver.AssignableMatch(r, t)), dataRows);
         if (providerRow == null)
         {
             throw new NotSupportedException(Strings.ProviderNotFound((object)connection.ToString()));
         }
         return DbProviderFactories.GetFactory(providerRow);
     })));
 }