Beispiel #1
0
        /// <summary>
        /// Create a new tenant for a specific app.
        /// </summary>
        /// <param name="appId">Application Id.</param>
        /// <param name="tenantEditor">Editor object that contains the updated data.</param>
        public Tenant Create(int appId, TenantEditor tenantEditor)
        {
            var url = $"v2/apps/{appId}/tenants";

            var result = ExecutePost <Tenant>(url, tenantEditor);

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Update a tenant for a specific app.
        /// </summary>
        /// <param name="appId">Application Id.</param>
        /// <param name="tenantId">Tenant id to update.</param>
        /// <param name="tenantEditor">Editor object that contains the updated data.</param>
        public Tenant Update(int appId, int tenantId, TenantEditor tenantEditor)
        {
            var url = $"v2/apps/{appId}/tenants/{tenantId}";

            var result = ExecutePut <Tenant>(url, tenantEditor);

            return(result);
        }
Beispiel #3
0
        public void CreateUpdateDeleteTenant()
        {
            // creeate
            var tenantEditor = new TenantEditor
            {
                AppId        = TenantTestData.APP_ID,
                Description  = "New tenant from test.",
                Disabled     = false,
                DisplayName  = "My new tenant",
                DisplayOrder = 1,
                FirstName    = "John",
                LastName     = "Doe",
                Footer       = new Footer
                {
                    FooterType = FooterType.IconAndText,
                    FooterData = new List <FooterItem>()
                },
                Hidden            = false,
                IconUrl           = "https://appnotch.com",
                Phone             = "(314) 210-1234",
                SocialDescription = "My social description.",
                SplashUrl         = "https://appnotch.com",
                SupportEmail      = "*****@*****.**",
                SupportSite       = "https://appnotch.com/converter/api",
                Tag = "test_tenant",
                Url = "https://appnotch.com"
            };

            var newTenant = GetTenantApi().Create(TenantTestData.APP_ID, tenantEditor);

            Assert.IsTrue(newTenant.AppId > 0);

            // update
            const string updatedDescription = "Updated description";
            const string updatedDisplayName = "My updated tenant";

            tenantEditor.Description = updatedDescription;
            tenantEditor.DisplayName = updatedDisplayName;

            var updatedTenant = GetTenantApi().Update(TenantTestData.APP_ID, newTenant.Id, tenantEditor);

            Assert.IsTrue(updatedTenant.Description == updatedDescription);
            Assert.IsTrue(updatedTenant.DisplayName == updatedDisplayName);

            GetTenantApi().DeleteTenant(TenantTestData.APP_ID, updatedTenant.Id);

            var deletedApp = GetTenantApi().GetTenant(TenantTestData.APP_ID, updatedTenant.Id);

            Assert.IsNull(deletedApp);
        }
        private async Task FillOutTenantVariablesByConvention(
            TenantEditor tenantEditor,
            ProjectResource[] projects,
            EnvironmentResource[] environments,
            LibraryVariableSetResource[] libraryVariableSets)
        {
            var tenant                   = tenantEditor.Instance;
            var projectLookup            = projects.ToDictionary(p => p.Id);
            var libraryVariableSetLookup = libraryVariableSets.ToDictionary(l => l.Id);
            var environmentLookup        = environments.ToDictionary(e => e.Id);

            var tenantVariables = (await tenantEditor.Variables).Instance;

            // Library variables
            foreach (var libraryVariable in tenantVariables.LibraryVariables)
            {
                foreach (var template in libraryVariableSetLookup[libraryVariable.Value.LibraryVariableSetId].Templates)
                {
                    var value = TryFillLibraryVariableByConvention(template, tenant);
                    if (value != null)
                    {
                        libraryVariable.Value.Variables[template.Id] = value;
                    }
                }
            }

            // Project variables
            foreach (var projectVariable in tenantVariables.ProjectVariables)
            {
                foreach (var template in projectLookup[projectVariable.Value.ProjectId].Templates)
                {
                    foreach (var connectedEnvironmentId in tenant.ProjectEnvironments[projectVariable.Value.ProjectId])
                    {
                        var environment = environmentLookup[connectedEnvironmentId];
                        var value       = TryFillProjectVariableByConvention(template, tenant, environment);
                        if (value != null)
                        {
                            projectVariable.Value.Variables[connectedEnvironmentId][template.Id] = value;
                        }
                    }
                }
            }
        }