Beispiel #1
0
            protected override void Act()
            {
                var adapter = new NpgsqlConnectionStringBuilderAdapter();

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

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

                _actualFinalConnectionString = adapter.ConnectionString;
            }
            protected override void Act()
            {
                var adapter = new NpgsqlConnectionStringBuilderAdapter
                {
                    ConnectionString = @"Host=localhost; Port=5432; Database=SomeDatabase; username=postgres; Application Name=EdFi.Ods.WebApi;"
                };

                _actualServerName = adapter.ServerName;

                adapter.ServerName        = "ModifiedServerName";
                _actualModifiedServerName = adapter.ServerName;
            }
        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;
        }
Beispiel #4
0
            protected override void Act()
            {
                var builder = new NpgsqlConnectionStringBuilderAdapter();

                builder.DatabaseName = "Database1";
            }