예제 #1
0
        public void SqlCeConnectionFactory_treats_improperly_start_formed_environment_style_as_path_which_then_throws()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"AnyaLovesXander|", "");

            Assert.Equal(
                GenerateException(() => Path.Combine("|", "Willow")).Message,
                Assert.Throws <ArgumentException>(() => factory.CreateConnection("FakeDatabaseName")).Message);
        }
        public void SqlCeConnectionFactory_uses_database_name_as_sdf_filename_even_when_database_name_already_ends_in_sdf()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient");

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

            Assert.Equal("Data Source=|DataDirectory|FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
예제 #3
0
        public void SqlCeConnectionFactory_with_properly_formed_environment_style_is_concatenated_correctly()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"|BuffyLovesAngel|", "");

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

            Assert.Equal(@"Data Source=|BuffyLovesAngel|FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
예제 #4
0
        public void SqlCeConnectionFactory_uses_database_name_as_sdf_filename_even_when_database_name_already_ends_in_sdf()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient");

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

            Assert.Equal("Data Source=|DataDirectory|FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
예제 #5
0
        public void SqlCeConnectionFactory_uses_changed_base_connection_string_when_creating_connection_string()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", "", "Persist Security Info=False");

            Assert.Equal("Persist Security Info=False", factory.BaseConnectionString);

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

            Assert.Equal("Data Source=FakeDatabaseName.sdf; Persist Security Info=False", connection.ConnectionString);
        }
 public void SqlCeConnectionFactory_throws_when_a_connection_with_bad_database_path_is_used()
 {
     var factory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", @"//C:::\\\D:\\D::::D\\\", "");
     using (var connection = factory.CreateConnection("FakeDatabaseName"))
     {
         Assert.Throws<NotSupportedException>(() => connection.Open()).ValidateMessage(typeof(File).Assembly,
                                                                                       "Argument_PathFormatNotSupported",
                                                                                       null);
     }
 }
예제 #7
0
        public void SqlCeConnectionFactory_uses_changed_database_path_when_creating_connection_string()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"C:\VicAndBobs\Novelty Island", "");

            Assert.Equal(@"C:\VicAndBobs\Novelty Island", factory.DatabaseDirectory);

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

            Assert.Equal(@"Data Source=C:\VicAndBobs\Novelty Island\FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
     SqlCeConnectionFactory_creates_a_SQL_CE_connection_using_changed_database_path_and_base_connection_string()
 {
     var factory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", @"C:\VicAndBob\",
                                              "Persist Security Info=False");
     using (var connection = factory.CreateConnection("FakeDatabaseName"))
     {
         var sqlCeExceptionType = _sqlCeAssembly.Value.GetType("System.Data.SqlServerCe.SqlCeConnection");
         Assert.IsType(sqlCeExceptionType, connection);
         Assert.Equal(@"Data Source=C:\VicAndBob\FakeDatabaseName.sdf; Persist Security Info=False",
                      connection.ConnectionString);
     }
 }
예제 #9
0
        public void SqlCeConnectionFactory_throws_when_provider_returns_null_connection()
        {
            try
            {
                FakeSqlProviderFactory.Instance.ForceNullConnection = true;
                var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient");

                Assert.Equal(
                    Strings.DbContext_ProviderReturnedNullConnection,
                    Assert.Throws <InvalidOperationException>(() => factory.CreateConnection("FakeDatabaseName")).Message);
            }
            finally
            {
                FakeSqlProviderFactory.Instance.ForceNullConnection = false;
            }
        }
 public void SqlCeConnectionFactory_throws_when_a_base_connection_already_containing_a_data_source_is_used()
 {
     var factory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "",
                                              "Data Source=VicAndBobsDatabase.sdf");
     using (var connection = factory.CreateConnection("FakeDatabaseName"))
     {
         var sqlCeExceptionType = _sqlCeAssembly.Value.GetType("System.Data.SqlServerCe.SqlCeException");
         try
         {
             connection.Open();
             Assert.True(false);
         }
         catch (Exception ex)
         {
             Assert.IsType(sqlCeExceptionType, ex);
             Assert.True(ex.Message.Contains("VicAndBobsDatabase.sdf"));
         }
     }
 }
        public void SqlCeConnectionFactory_uses_changed_database_path_when_creating_connection_string()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"C:\VicAndBobs\Novelty Island", "");

            Assert.Equal(@"C:\VicAndBobs\Novelty Island", factory.DatabaseDirectory);

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

            Assert.Equal(@"Data Source=C:\VicAndBobs\Novelty Island\FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
        public void SqlCeConnectionFactory_throws_when_provider_returns_null_connection()
        {
            try
            {
                FakeSqlProviderFactory.Instance.ForceNullConnection = true;
                var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient");

                Assert.Equal(
                    Strings.DbContext_ProviderReturnedNullConnection,
                    Assert.Throws<InvalidOperationException>(() => factory.CreateConnection("FakeDatabaseName")).Message);
            }
            finally
            {
                FakeSqlProviderFactory.Instance.ForceNullConnection = false;
            }
        }
        public void SqlCeConnectionFactory_treats_improperly_start_formed_environment_style_as_path_which_then_throws()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"AnyaLovesXander|", "");

            Assert.Equal(
                GenerateException(() => Path.Combine("|", "Willow")).Message,
                Assert.Throws<ArgumentException>(() => factory.CreateConnection("FakeDatabaseName")).Message);
        }
        public void SqlCeConnectionFactory_uses_changed_base_connection_string_when_creating_connection_string()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", "", "Persist Security Info=False");

            Assert.Equal("Persist Security Info=False", factory.BaseConnectionString);

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

            Assert.Equal("Data Source=FakeDatabaseName.sdf; Persist Security Info=False", connection.ConnectionString);
        }
        public void SqlCeConnectionFactory_throws_when_a_bad_base_connection_string_is_used()
        {
            var factory = new SqlCeConnectionFactory(
                "System.Data.SqlServerCe.4.0", "",
                "Whats On The End Of The Stick Vic=Admiral Nelsons Final Flannel");

            Assert.Throws<ArgumentException>(() => factory.CreateConnection("Something")).ValidateMessage(
                _sqlCeAssembly.Value, "ADP_KeywordNotSupported", null, "whats on the end of the stick vic");
        }
        public void SqlCeConnectionFactory_with_properly_formed_environment_style_is_concatenated_correctly()
        {
            var factory = new SqlCeConnectionFactory("System.Data.FakeSqlClient", @"|BuffyLovesAngel|", "");

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

            Assert.Equal(@"Data Source=|BuffyLovesAngel|FakeDatabaseName.sdf; ", connection.ConnectionString);
        }
예제 #17
0
        public void DbContext_caches_models_for_two_providers()
        {
            // Ensure that the model is in use with a SQL connection
            using (var context = new SimpleModelContext())
            {
                context.Database.Initialize(force: false);
            }

            // Now try to use it with a CE connection; would throw in EF 4.1, will not now throw.
            var sqlCeConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0",
                                                                    AppDomain.CurrentDomain.BaseDirectory, "");
            using (var connection = sqlCeConnectionFactory.CreateConnection(DefaultDbName<SimpleModelContext>()))
            {
                using (var context = new SimpleModelContext(connection))
                {
                    context.Database.Initialize(force: false);
                }
            }
        }
예제 #18
0
        private static DbConnection CreateConnection()
        {
            if (!providerInitialized)
            {
                try
                {
                    using (var dataSet = (DataSet) System.Configuration.ConfigurationManager.GetSection("system.data"))
                    {
                        const string name = "Microsoft SQL Server Compact Data Provider";
                        const string invariant = "System.Data.SqlServerCe.4.0";
                        const string description = ".NET Framework Data Provider for Microsoft SQL Server Compact";
                        const string type =
                            "System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0";

                        DataRowCollection rows = dataSet.Tables[0].Rows;

                        if (!rows.Contains(invariant))
                            rows.Add(name, description, invariant, type);
                    }
                }
                catch (ConstraintException)
                {
                }
                providerInitialized = true;
            }

            var folder = AppDomain.CurrentDomain.BaseDirectory + @"\Database"; //"c:\\Temp";
            var databaseFile = "questions.sdf";
            var databaseName = "questions";

            var connectionStringBuilder = new SqlConnectionStringBuilder
                {
                    DataSource = Path.Combine(folder, databaseFile),
                    Password = "******"
                };

            var factory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", folder,
                                                     connectionStringBuilder.ToString());

            return factory.CreateConnection(databaseName);
        }