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);
                }
            }
        }
Esempio n. 2
0
        private ManagedTenant UpdateTenant(IManagedPlatform platform, RemoteTenantInfo tenant, ICollection <IEntity> entities, ICollection <ManagedApp> existingApps)
        {
            using (Profiler.Measure("PlatformService.UpdateTenant"))
            {
                IManagedTenant mt = null;

                if (platform != null)
                {
                    mt = platform.ContainsTenants.FirstOrDefault(t => t.RemoteId == tenant.RemoteId.ToString());
                }

                if (mt != null)
                {
                    mt = mt.AsWritable <ManagedTenant>();
                }
                else
                {
                    mt          = CastEntityHelper.CreateTenant();
                    mt.RemoteId = tenant.RemoteId.ToString();
                }

                mt.Name     = tenant.Name;
                mt.Disabled = tenant.Disabled;

                var userRoles = UpdateRoles(mt, tenant.Roles, entities);
                mt.Roles.AddRange(userRoles);

                var users = UpdateUsers(mt, tenant.Users, entities);
                mt.Users.AddRange(users);

                var apps = UpdateInstalledApps(mt, tenant.Apps, entities, existingApps);
                mt.HasAppsInstalled.AddRange(apps);

                if (platform != null)
                {
                    mt.Platform = platform;
                }

                return((ManagedTenant)mt);
            }
        }
Esempio n. 3
0
        public IManagedTenant CreateOrUpdateTenant(string databaseId, RemoteTenantInfo ti)
        {
            using (Profiler.Measure("PlatformService.CreateOrUpdateTenant"))
            {
                if (ti == null)
                {
                    throw new ArgumentException("Tenant information was invalid.");
                }

                var entities = new EntityCollection <IEntity>();

                IManagedTenant mt;

                try
                {
                    var mp = GetPlatformByDatabaseId(databaseId);
                    if (mp != null)
                    {
                        mp = mp.AsWritable <ManagedPlatform>();

                        entities.Add(mp);
                    }

                    var apps = GetApps().ToList();

                    mt = UpdateTenant(mp, ti, entities, apps);

                    entities.Add(mt);
                }
                finally
                {
                    CastEntityHelper.Save(entities);
                }

                return(mt);
            }
        }