public void TestEnable() { const string test = "foo"; try { // Arrange var ts = new TenantService(); using (new GlobalAdministratorContext()) { var id = TenantHelper.CreateTenant(test); id.Should().BeGreaterThan(0); var tenant = Entity.Get <Tenant>(id).AsWritable <Tenant>(); tenant.IsTenantDisabled = true; tenant.Save(); } // Act ts.Enable(test); // Assert using (new GlobalAdministratorContext()) { var tid = TenantHelper.GetTenantId(test); tid.Should().BeGreaterThan(0); var result = Entity.Get <Tenant>(tid); result.Should().NotBeNull(); result.IsTenantDisabled.Should().BeFalse(); } Action a1 = () => ts.Enable(null); a1.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid."); Action a2 = () => ts.Enable(string.Empty); a2.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid."); var notATenant = Guid.NewGuid().ToString(); Action a3 = () => ts.Enable(notATenant); a3.ShouldThrow <Exception>().WithMessage("Tenant " + notATenant + " not found."); } finally { using (new GlobalAdministratorContext()) { var testId = TenantHelper.GetTenantId(test); if (testId > 0) { TenantHelper.DeleteTenant(testId); } } } }
public void AddTenant() { long tenantId = 0; try { tenantId = TenantHelper.CreateTenant("TenantHelperTests_AddTenant"); } finally { if (tenantId != 0) { TenantHelper.DeleteTenant(tenantId); } } }
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); } } } }
/// <summary> /// Deletes the tenant. /// </summary> /// <param name="tenantName">Name of the tenant.</param> /// <remarks></remarks> public static void DeleteTenant(string tenantName) { using (new GlobalAdministratorContext( )) { long tenantId = TenantHelper.GetTenantId(tenantName); if (tenantId == -1) { ///// // Fail, the tenant does not exist. ///// Console.WriteLine(@"The tenant {0} does not exist.", tenantName); return; } TenantHelper.DeleteTenant(tenantId); } }
public void TestDelete() { const string test = "foo"; try { // Arrange var ts = new TenantService(); using (new GlobalAdministratorContext()) { var id = TenantHelper.CreateTenant(test); id.Should().BeGreaterThan(0); } // Act ts.Delete(test); // Assert using (new GlobalAdministratorContext()) { TenantHelper.GetTenantId(test).Should().BeLessThan(0); } Action a1 = () => ts.Delete(null); a1.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: tenantName"); Action a2 = () => ts.Delete(string.Empty); a2.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: tenantName"); } finally { using (new GlobalAdministratorContext()) { var testId = TenantHelper.GetTenantId(test); if (testId > 0) { TenantHelper.DeleteTenant(testId); } } } }
public void TestRename() { const string test = "foo"; const string name = "new"; try { // Arrange var ts = new TenantService(); long id; using (new GlobalAdministratorContext()) { id = TenantHelper.CreateTenant(test); } id.Should().BeGreaterThan(0); // Act ts.Rename(id, name); // Assert long nid; using (new GlobalAdministratorContext()) { var tid = TenantHelper.GetTenantId(test); tid.Should().BeLessThan(0); nid = TenantHelper.GetTenantId(name); nid.Should().BeGreaterThan(0); } Action a1 = () => ts.Rename(-1, null); a1.ShouldThrow <ArgumentException>().WithMessage("New tenant name may not be null or empty.\r\nParameter name: name"); Action a2 = () => ts.Rename(-1, string.Empty); a2.ShouldThrow <ArgumentException>().WithMessage("New tenant name may not be null or empty.\r\nParameter name: name"); Action a3 = () => ts.Rename(-1, name); a3.ShouldThrow <Exception>().WithMessage("Tenant not found."); Action a4 = () => ts.Rename(nid, name); // same a4.ShouldNotThrow(); } finally { using (new GlobalAdministratorContext()) { var testId = TenantHelper.GetTenantId(test); if (testId > 0) { TenantHelper.DeleteTenant(testId); } var newId = TenantHelper.GetTenantId(name); if (newId > 0) { TenantHelper.DeleteTenant(newId); } } } }