public void TestCreateOrUpdateTenantThrows() { ManagedTenant t = null; try { // Arrange var ps = new PlatformService(); // Act Action f1 = () => { t = (ManagedTenant)ps.CreateOrUpdateTenant(null, null); }; // Assert f1.ShouldThrow <ArgumentException>().WithMessage("Tenant information was invalid."); Action f2 = () => { t = (ManagedTenant)ps.CreateOrUpdateTenant(null, new RemoteTenantInfo()); }; f2.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: id"); Action f3 = () => { t = (ManagedTenant)ps.CreateOrUpdateTenant(TestPlatformId, new RemoteTenantInfo()); }; f3.ShouldNotThrow(); } finally { if (t != null) { Entity.Delete(t); } } }
public void TestCreateOrUpdateTenant() { ManagedTenant t = null; try { // Arrange var ps = new PlatformService(); var ti = new RemoteTenantInfo { Name = TestTenantName }; // Act t = (ManagedTenant)ps.CreateOrUpdateTenant(TestPlatformId, ti); // Assert t.Should().NotBeNull(); t.Name.Should().Be(TestTenantName); t.RemoteId.Should().Be("0"); t.Disabled.Should().BeFalse(); t.Platform.Should().BeNull(); } finally { if (t != null) { Entity.Delete(t); } } }
public void TestDeleteUser() { ManagedPlatform p = null; ManagedTenant t = null; ManagedUser u = null; try { // Arrange var ps = new PlatformService(); p = CreateTestPlatform(); t = CreateTestTenant(p); u = CreateTestUser(t); p.Save(); p.Should().NotBeNull(); t.Should().NotBeNull(); u.Should().NotBeNull(); var pid = p.Id; var tid = t.Id; var uid = u.Id; // Act ps.DeleteUser(TestPlatformId, TestTenantName, TestUserName); // Assert var e1 = Entity.Get(pid); e1.Should().NotBeNull(); var e2 = Entity.Get(tid); e2.Should().NotBeNull(); var e3 = Entity.Get(uid); e3.Should().BeNull(); } finally { if (u != null) { Entity.Delete(u); } if (t != null) { Entity.Delete(t); } if (p != null) { Entity.Delete(p); } } }
/// <summary> /// Gets the platform that a customer should have its tenant(s) and subsequent applications /// deployed to. /// </summary> /// <param name="customer">The customer.</param> /// <param name="tenant">The specific tenant owned by the customer. (Optional.)</param> /// <returns>The managed platform that has been selected.</returns> public ManagedPlatform GetPlatform(ManagedCustomer customer, ManagedTenant tenant = null) { return(default(ManagedPlatform)); // ManagedPlatform platform = null; // // TODO: Maybe compare timezones first, then round-trip time or entity load? // var platforms = Entity.GetInstancesOfType<ManagedPlatform>().ToList(); //if ( platforms.Count > 0 ) // { // platform = platforms.Where(p => p.LastContact != null) // .OrderByDescending(p => p.LastContact) // .FirstOrDefault() ?? platforms.First(); // } // // writeable? bah. // return platform != null ? platform.AsWritable<ManagedPlatform>() : null; }
public void TestUpdateTenants() { // Arrange var p = CreateTestPlatform(); var t1 = new ManagedTenant { Name = "ContainsTenant", RemoteId = "1", Platform = p }; var t2 = new ManagedTenant { Name = "OldTenant", RemoteId = "2", Platform = p }; p.ContainsTenants.Add(t1); p.ContainsTenants.Add(t2); p.Save(); var pid = p.Id; var ps = new PlatformService(); // Act p = (ManagedPlatform)ps.CreateOrUpdate(new RemotePlatformInfo { Id = TestPlatformId, FrontEndHost = "test", FrontEndDomain = "platform.co", Database = "db", DatabaseServer = "ds", Tenants = new TenantList { new RemoteTenantInfo { Name = "NewTenant", RemoteId = 3 }, new RemoteTenantInfo { Name = "", RemoteId = 8 }, new RemoteTenantInfo { Name = "RenamedTenant", RemoteId = 2 }, new RemoteTenantInfo { Name = null, RemoteId = 9 }, new RemoteTenantInfo { Name = "ContainsTenant", RemoteId = 1 } } }); // Assert p.Should().NotBeNull(); p.Id.Should().Be(pid); var tenants = p.ContainsTenants.ToList(); tenants.Should().NotBeNull().And.NotBeEmpty(); tenants.Count.Should().Be(5); var v1 = p.ContainsTenants.FirstOrDefault(v => v.RemoteId == "1"); v1.Name.Should().Be("ContainsTenant"); v1.Should().NotBeNull(); var v2 = p.ContainsTenants.FirstOrDefault(v => v.RemoteId == "2"); v2.Name.Should().Be("RenamedTenant"); v2.Should().NotBeNull(); var v3 = p.ContainsTenants.FirstOrDefault(v => v.RemoteId == "3"); v3.Name.Should().Be("NewTenant"); v3.Should().NotBeNull(); var v4 = p.ContainsTenants.FirstOrDefault(v => v.RemoteId == "8"); v4.Name.Should().BeEmpty(); v4.Should().NotBeNull(); var v5 = p.ContainsTenants.FirstOrDefault(v => v.RemoteId == "9"); v5.Name.Should().BeNull(); v5.Should().NotBeNull(); }
public void TestUpdateInstalledApplications() { ManagedPlatform p = null; ManagedTenant t = null; ManagedAppVersion v = null; try { // Arrange var ps = new PlatformService(); // Act t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>()); // Assert t.Should().BeNull(); p = CreateTestPlatform(); t = CreateTestTenant(p); p.Save(); t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>()); t.Should().NotBeNull(); t.Name.Should().Be(TestTenantName); t.Platform.DatabaseId.Should().Be(TestPlatformId); t.HasAppsInstalled.Count.Should().Be(0); var tid = t.Id; t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication> { new InstalledApplication { ApplicationVersionId = TestAppVersionId } }); t.Should().NotBeNull(); t.Id.Should().Be(tid); t.Name.Should().Be(TestTenantName); t.Platform.DatabaseId.Should().Be(TestPlatformId); t.HasAppsInstalled.Count.Should().Be(1); v = t.HasAppsInstalled.First(); v.Name.Should().BeNull(); v.PublishDate.Should().NotHaveValue(); v.Version.Should().BeNull(); v.VersionId.Should().Be(TestAppVersionId); v.Application.Should().BeNull(); v.RequiredApps.Should().BeEmpty(); v.RequiredAppVersions.Should().BeEmpty(); var vid = v.Id; t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication> { new InstalledApplication { ApplicationVersionId = TestAppVersionId, Name = "Test App Version", ReleaseDate = new DateTime(2000, 10, 24), PackageVersion = "2.3.3.0", SolutionVersion = "1.7.7.0" } }); t.Should().NotBeNull(); t.Id.Should().Be(tid); t.Name.Should().Be(TestTenantName); t.Platform.DatabaseId.Should().Be(TestPlatformId); t.HasAppsInstalled.Count.Should().Be(1); v = t.HasAppsInstalled.First(); v.Id.Should().Be(vid); v.Name.Should().Be("Test App Version"); v.PublishDate.Should().HaveValue().And.Be(new DateTime(2000, 10, 24)); v.Version.Should().Be("1.7.7.0"); v.VersionId.Should().Be(TestAppVersionId); v.Application.Should().BeNull(); v.RequiredApps.Should().BeEmpty(); v.RequiredAppVersions.Should().BeEmpty(); } finally { if (v != null) { Entity.Delete(v); } if (t != null) { Entity.Delete(t); } if (p != null) { Entity.Delete(p); } } }
public void TestCreateOrUpdateUser() { ManagedPlatform p = null; ManagedTenant t = null; ManagedUser u = null; try { // Arrange var ps = new PlatformService(); var ui = new RemoteUserInfo { Name = TestUserName }; // Act u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui); // Assert u.Should().BeNull(); p = CreateTestPlatform(); t = CreateTestTenant(p); p.Save(); u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui); u.Should().BeNull(); ui.RemoteId = TestUserRemoteId; u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui); u.Should().NotBeNull(); u.Name.Should().Be(TestUserName); u.RemoteId.Should().Be(TestUserRemoteId.ToString()); u.Status_Enum.Should().Be(ManagedUserStatusEnumeration.Unknown); u.Tenant.Name.Should().Be(TestTenantName); u.Tenant.Platform.DatabaseId.Should().Be(TestPlatformId); var uid = u.Id; u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, new RemoteUserInfo { RemoteId = TestUserRemoteId, Name = "Another Name", Status = UserStatus.Expired }); u.Should().NotBeNull(); u.Id.Should().Be(uid); u.Name.Should().Be("Another Name"); u.RemoteId.Should().Be(TestUserRemoteId.ToString()); u.Status_Enum.Should().Be(ManagedUserStatusEnumeration.Expired); u.Tenant.Name.Should().Be(TestTenantName); u.Tenant.Platform.DatabaseId.Should().Be(TestPlatformId); } finally { if (u != null) { Entity.Delete(u); } if (t != null) { Entity.Delete(t); } if (p != null) { Entity.Delete(p); } } }