Example #1
0
        public void SqlConnectionFactory_throws_if_given_MDF_filename()
        {
            var factory = new SqlConnectionFactory();

            Assert.Equal(
                Strings.SqlConnectionFactory_MdfNotSupported("FakeDatabaseName.mdf"),
                Assert.Throws <NotSupportedException>(() => factory.CreateConnection("FakeDatabaseName.mdf")).Message);
        }
Example #2
0
        public void SqlConnectionFactory_creates_SqlConnection()
        {
            var factory = new SqlConnectionFactory();

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.IsType <SqlConnection>(connection);
        }
Example #3
0
        public void SqlConnectionFactory_uses_database_name_as_initial_catalog()
        {
            var factory = new SqlConnectionFactory();

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
            AssertConnectionStringHasDefaultParts(connection.ConnectionString);
        }
Example #4
0
        public void SqlConnectionFactory_replaces_any_initial_catalog_set_in_the_base_connection()
        {
            var factory = new SqlConnectionFactory(
                @"Data Source=.\SQLEXPRESS; Integrated Security=True; Initial Catalog=TheManWithTheStick");

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.False(connection.ConnectionString.Contains("Initial Catalog=TheManWithTheStick"));
            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
        }
Example #5
0
        public void SqlConnectionFactory_uses_changed_base_connection_string_when_creating_connection_string()
        {
            var factory = new SqlConnectionFactory("Data Source=190.190.200.100,1433");

            Assert.Equal("Data Source=190.190.200.100,1433", factory.BaseConnectionString);

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.True(connection.ConnectionString.Contains("Data Source=190.190.200.100,1433"));
            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
        }
Example #6
0
        public void SqlConnectionFactory_handles_no_provider_factory_found()
        {
            var factory = new SqlConnectionFactory
            {
                ProviderFactory = name => null
            };

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.Equal(typeof(SqlConnection), connection.GetType());
            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
        }
Example #7
0
        public void SqlConnectionFactory_handles_provider_factory_returning_null_connection()
        {
            var mockProviderFactory = new Mock <DbProviderFactory>();

            mockProviderFactory.Setup(m => m.CreateConnection()).Returns <DbConnection>(null);

            var factory = new SqlConnectionFactory
            {
                ProviderFactory = name => mockProviderFactory.Object
            };

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.Equal(typeof(SqlConnection), connection.GetType());
            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
        }
Example #8
0
        public void SqlConnectionFactory_uses_db_provider_factory()
        {
            var mockProviderFactory = new Mock <DbProviderFactory>();
            var mockConnection      = new Mock <DbConnection>();

            mockConnection.SetupProperty(c => c.ConnectionString);
            mockProviderFactory.Setup(m => m.CreateConnection()).Returns(mockConnection.Object);

            var factory = new SqlConnectionFactory
            {
                ProviderFactory = name => mockProviderFactory.Object
            };

            var connection = factory.CreateConnection("FakeDatabaseName");

            Assert.Same(mockConnection.Object, connection);
            Assert.True(connection.ConnectionString.Contains("Initial Catalog=FakeDatabaseName"));
        }