示例#1
0
        public void SecureDataRoundTrip( )
        {
            var    ticks   = DateTime.UtcNow.Ticks;
            string oldName = $"TenantExportImportTests Old {ticks}";
            string newName = $"TenantExportImportTests New {ticks}";

            using (new GlobalAdministratorContext())
            {
                long oldTenantId = 0;
                long newTenantId = 0;
                var  filePath    = Path.GetTempFileName() + ".db";

                try
                {
                    oldTenantId = TestHelper.CreateTenant(oldName, null);
                    AppManager.DeployApp(oldName, Applications.CoreApplicationId.ToString("B"));

                    // Set some custom info

                    var secureDataId = Factory.SecuredData.Create(oldTenantId, "test", "testValue");

                    // Export and Import
                    TenantManager.ExportTenant(oldName, filePath, false);

                    newTenantId = TenantManager.ImportTenant(filePath, newName);

                    using (new TenantAdministratorContext(newTenantId))
                    {
                        var securedData = Factory.SecuredData.Read(secureDataId);
                        Assert.That(securedData, Is.EqualTo("testValue"));
                    }
                }
                finally
                {
                    if (oldTenantId > 0)
                    {
                        TenantHelper.DeleteTenant(oldTenantId);
                    }

                    if (newTenantId > 0)
                    {
                        TenantHelper.DeleteTenant(newTenantId);
                        File.Delete(filePath);
                    }
                }
            }
        }