コード例 #1
0
            protected override void Act()
            {
                var adapter = new SqlConnectionStringBuilderAdapter();

                adapter.ConnectionString = @"Server=(local);Database=SomeDatabase;Trusted_Connection=True;Application Name=EdFi.Ods.WebApi;";
                _actualServerName        = adapter.ServerName;

                adapter.ServerName        = "ModifiedServerName";
                _actualModifiedServerName = adapter.ServerName;
            }
コード例 #2
0
            protected override void Act()
            {
                var adapter = new SqlConnectionStringBuilderAdapter();

                adapter.ConnectionString   = string.Format(SqlServerConnectionStringFormat, "OriginalDatabaseName");
                _actualInitialDatabaseName = adapter.DatabaseName;

                adapter.DatabaseName        = "ModifiedDatabaseName";
                _actualModifiedDatabaseName = adapter.DatabaseName;

                _actualFinalConnectionString = adapter.ConnectionString;
            }
コード例 #3
0
        public void Setup()
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(TestContext.CurrentContext.TestDirectory)
                                       .AddJsonFile("appsettings.json", true)
                                       .AddEnvironmentVariables(ConfigEnvironmentVariablesPrefix);

            var engine = configurationBuilder
                         .Build()
                         .GetValue <string>("Engine");

            DatabaseEngine = DatabaseEngine.TryParseEngine(engine);

            var configuration = configurationBuilder
                                .AddJsonFile($"appsettings.{(DatabaseEngine == DatabaseEngine.SqlServer ? "mssql" : "pgsql")}.json", true)
                                .AddEnvironmentVariables(ConfigEnvironmentVariablesPrefix)
                                .Build();

            var isStrictMode = configuration.GetValue <bool?>("StrictMode");

            if (isStrictMode is null)
            {
                throw new ApplicationException(
                          "Missing configuration entry: StrictMode");
            }

            var maintenanceConnectionString = configuration.GetConnectionString("EdFi_Master");

            if (string.IsNullOrWhiteSpace(maintenanceConnectionString))
            {
                throw new ApplicationException(
                          $"Missing configuration entry: ConnectionStrings{ConfigurationPath.KeyDelimiter}EdFi_Master");
            }

            var odsConnectionString = configuration.GetConnectionString("EdFi_Ods");

            if (string.IsNullOrWhiteSpace(odsConnectionString))
            {
                throw new ApplicationException(
                          $"Missing configuration entry: ConnectionStrings{ConfigurationPath.KeyDelimiter}EdFi_Ods");
            }

            var odsImplementationFolderPath = configuration.GetValue <string>("ODSImplementationFolderPath");

            if (string.IsNullOrWhiteSpace(odsImplementationFolderPath))
            {
                throw new ApplicationException(
                          $"Missing configuration entry: ODSImplementationFolderPath");
            }

            IDbConnectionStringBuilderAdapter connectionStringBuilder;

            if (DatabaseEngine == DatabaseEngine.SqlServer)
            {
                connectionStringBuilder = new SqlConnectionStringBuilderAdapter();
                _databaseHelper         = new MsSqlDatabaseHelper(configuration);
            }
            else
            {
                connectionStringBuilder = new NpgsqlConnectionStringBuilderAdapter();
                _databaseHelper         = new PgSqlDatabaseHelper(configuration);
            }

            try
            {
                BuildConnection(maintenanceConnectionString);
            }
            catch
            {
                // TODO implement [ODS-5110 Create Test Container] here

                var reason =
                    $"Couldn't connect to database server, verify ConnectionStrings{ConfigurationPath.KeyDelimiter}EdFi_Master";
                if (isStrictMode.Value)
                {
                    Assert.Fail(reason);
                }
                else
                {
                    Assert.Ignore(reason);
                }
            }

            try
            {
                BuildConnection(odsConnectionString);
            }
            catch
            {
                try
                {
                    _databaseHelper.DownloadAndRestoreDatabase(Path.GetFullPath(configuration.GetValue <string>("ODSImplementationFolderPath")));
                }
                catch (InvalidOperationException ex)
                {
                    if (isStrictMode.Value)
                    {
                        Assert.Fail(ex.Message);
                    }
                    else
                    {
                        Assert.Ignore(ex.Message);
                    }
                }
            }

            var testDbName = $"{TestDbPrefix}{Guid.NewGuid():N}";

            connectionStringBuilder.ConnectionString = odsConnectionString;

            _databaseHelper.CopyDatabase(connectionStringBuilder.DatabaseName, testDbName);
            _isTestDbCreated = true;

            connectionStringBuilder.DatabaseName = testDbName;
            TestDbConnectionString = connectionStringBuilder.ConnectionString;
        }
コード例 #4
0
            protected override void Act()
            {
                var builder = new SqlConnectionStringBuilderAdapter();

                builder.DatabaseName = "Database1";
            }