コード例 #1
0
        public async Task <IActionResult> ImportDatabaseAsync([FromBody] ImportDatabaseRequest request)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(ImportDatabaseAsync));

            var response = new ImportDatabaseResponse();

            try
            {
                var databaseFactory = new SqlServerDatabaseFactory
                {
                    DatabaseImportSettings = new DatabaseImportSettings
                    {
                        Name               = request.Name,
                        ConnectionString   = request.ConnectionString,
                        ImportTables       = request.ImportTables,
                        ImportViews        = request.ImportViews,
                        ExtendedProperties =
                        {
                            Tokens.MS_DESCRIPTION
                        }
                    }
                };

                var db = databaseFactory.Import();

                await DbService.SerializeAsync(databaseFactory.DatabaseImportSettings);

                await DbService.SerializeAsync(db);

                response.Message = "The database was imported successfully";
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response.ToHttpResponse());
        }
コード例 #2
0
        public async Task TestImportDatabase()
        {
            // Arrange
            var logger             = LoggingHelper.GetLogger <DocumentationController>();
            var hostingEnvironment = HostingEnvironmentMocker.GetHostingEnvironment();
            var apiConfig          = new ApiConfig();
            var dbService          = new DbService(hostingEnvironment, apiConfig);
            var controller         = new DocumentationController(logger, dbService);
            var request            = new ImportDatabaseRequest
            {
                Name             = "OnlineStore",
                ConnectionString = "server=(local);database=OnlineStore;integrated security=yes;",
                ImportTables     = true,
                ImportViews      = true
            };

            // Act
            var response = await controller.ImportDatabaseAsync(request) as ObjectResult;

            var value = response.Value as ImportDatabaseResponse;

            // Assert
            Assert.False(value.DidError);
        }