public void Can_initialize_database_when_using_secure_connection_string_with_sql_server_authentication_and_CommitFailureHandler()
        {
            EnsureEfTestUserExists();
            var connectionString
                = SimpleConnectionStringWithCredentials <PersistSecurityInfoContext>(
                      "EFTestUser",
                      "Password1");

            var context = new PersistSecurityInfoContext(connectionString);

            MutableResolver.AddResolver <Func <TransactionHandler> >(
                new TransactionHandlerResolver(() => new CommitFailureHandler(), null, null));

            try
            {
                context.Database.Delete();
                context.Database.Initialize(true);

                CommitFailureHandler.FromContext(context).ClearTransactionHistory();
            }
            finally
            {
                MutableResolver.ClearResolvers();
                context.Database.Delete();
            }
        }
        public void Can_initialize_database_when_using_secure_connection_string_with_sql_server_authentication_and_eager_connection()
        {
            EnsureEfTestUserExists();
            var connectionString
                = SimpleConnectionStringWithCredentials <PersistSecurityInfoContext>(
                      "EFTestUser",
                      "Password1");

            var context = new PersistSecurityInfoContext(new SqlConnection(connectionString), true);

            try
            {
                context.Database.Delete();

                context.Database.Initialize(true);
            }
            finally
            {
                context.Database.Delete();
            }

            Assert.Equal(
                new SqlConnectionStringBuilder(connectionString).Password,
                new SqlConnectionStringBuilder(context.Database.Connection.ConnectionString).Password);
        }
示例#3
0
        public void Can_use_ddl_ops_when_using_secure_connection_string_with_sql_server_authentication_and_eager_context()
        {
            var connectionStringBuilder
                = new SqlConnectionStringBuilder
                {
                DataSource          = ".\\sqlexpress",
                UserID              = "EFTestUser",
                Password            = "******",
                InitialCatalog      = "PersistSecurityInfoContext",
                PersistSecurityInfo = false
                };

            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <PersistEntity>().ToTable(DateTime.Now.Ticks.ToString());
            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);
            var entityConnection
                = new EntityConnection(model.DatabaseMapping.ToMetadataWorkspace(), new SqlConnection(connectionStringBuilder.ToString()));

            var objectContext = new ObjectContext(entityConnection);

            var context = new PersistSecurityInfoContext(objectContext, true);

            if (context.Database.Exists())
            {
                context.Database.Delete();
            }

            context.Database.Create();

            context.Set <PersistEntity>().ToList();

            context.Database.Delete();
        }
示例#4
0
        public void Can_initialize_database_when_using_secure_connection_string_with_sql_server_authentication_and_lazy_connection()
        {
            var connectionStringBuilder
                = new SqlConnectionStringBuilder
                {
                DataSource          = ".\\sqlexpress",
                UserID              = "EFTestUser",
                Password            = "******",
                InitialCatalog      = "PersistSecurityInfoContext",
                PersistSecurityInfo = false
                };

            var context = new PersistSecurityInfoContext(connectionStringBuilder.ToString());

            context.Database.Initialize(true);

            context.Database.Delete();
        }
        public void Can_use_ddl_ops_when_using_secure_connection_string_with_sql_server_authentication_and_eager_context()
        {
            EnsureEfTestUserExists();
            var connectionString
                = SimpleConnectionStringWithCredentials <PersistSecurityInfoContext>(
                      "EFTestUser",
                      "Password1");

            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <PersistEntity>().ToTable(DateTime.Now.Ticks.ToString());
            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);
            var entityConnection
                = new EntityConnection(model.DatabaseMapping.ToMetadataWorkspace(), new SqlConnection(connectionString));

            var objectContext = new ObjectContext(entityConnection);

            var context = new PersistSecurityInfoContext(objectContext, true);

            try
            {
                context.Database.Delete();

                context.Database.Create();

                Assert.Equal(
                    new SqlConnectionStringBuilder(connectionString).Password,
                    new SqlConnectionStringBuilder(context.Database.Connection.ConnectionString).Password);

                context.Set <PersistEntity>().ToList();

                context.Database.Delete();
            }
            finally
            {
                context.Database.Delete();
            }
        }
示例#6
0
        public void Can_initialize_database_when_using_secure_connection_string_with_SqlCredential_and_eager_connection()
        {
            EnsureEfTestUserExists();

            var connectionString = new SqlConnectionStringBuilder()
            {
                DataSource     = @".\SQLEXPRESS",
                InitialCatalog = DefaultDbName <PersistSecurityInfoContext>()
            }.ConnectionString;

            var password = new SecureString();

            foreach (var c in "Password1".ToCharArray())
            {
                password.AppendChar(c);
            }
            password.MakeReadOnly();

            var credential = new SqlCredential("EFTestUser", password);
            var connection = new SqlConnection(connectionString, credential);

            var context = new PersistSecurityInfoContext(connection, true);

            try
            {
                context.Database.Delete();
                context.Database.Initialize(force: true);
                Assert.True(context.Database.CompatibleWithModel(true));
            }
            finally
            {
                Assert.True(connection.State == ConnectionState.Closed);
                context.Database.Delete();
                context.Dispose();
            }
        }