Esempio n. 1
0
        public async Task Create_Get_Update_Delete_Tenant_Test()
        {
            var dto = new CreateTenantDto
            {
                DisplayName = "Tenant_TEST",
                IsActive    = true,
                TenancyName = "Tenant_TEST"
            };

            await _tenantAppService.CreateTenant(dto);

            var dtoEdit = await _tenantAppService.GetTenant(dto.TenancyName);

            dtoEdit.ShouldNotBe(null);
            dtoEdit.TenancyName.ShouldBe("Tenant_TEST");

            dtoEdit.TenancyName = "Tenant_TEST_UPDATE";

            await _tenantAppService.UpdateTenant(dtoEdit);

            var dtoGet = await _tenantAppService.GetTenant("Tenant_TEST_UPDATE");

            dtoGet.ShouldNotBe(null);
            dtoEdit.TenancyName.ShouldBe("Tenant_TEST_UPDATE");

            await _tenantAppService.DeleteTenant(new Abp.Application.Services.Dto.EntityRequestInput <Guid>(dtoGet.Id));

            var tenant = await _tenantAppService.GetTenant(new Abp.Application.Services.Dto.EntityRequestInput <Guid>(dtoGet.Id));

            tenant.ShouldBe(null);
        }
        private async Task CreateUpdateTenant(PaymentPeriodType paymentPeriodType, EditionPaymentType editionPaymentType, DateTime?subscriptionEndDate, DateTime updatedSubscriptionEndDate)
        {
            await _editionManager.CreateAsync(new SubscribableEdition
            {
                Name        = "CurrentEdition",
                DisplayName = "Current Edition"
            });

            await _editionManager.CreateAsync(new SubscribableEdition
            {
                Name        = "TargetEdition",
                DisplayName = "Target Edition"
            });

            var currentEditionId = (await _editionManager.FindByNameAsync("CurrentEdition")).Id;
            var targetEditionId  = (await _editionManager.FindByNameAsync("TargetEdition")).Id;

            // Create tenant
            await _tenantAppService.CreateTenant(
                new CreateTenantInput
            {
                TenancyName            = "testTenant",
                Name                   = "Tenant for test purpose",
                AdminEmailAddress      = "*****@*****.**",
                AdminPassword          = "******",
                IsActive               = true,
                EditionId              = currentEditionId,
                SubscriptionEndDateUtc = subscriptionEndDate
            });

            //Assert
            var tenant = await GetTenantOrNullAsync("testTenant");

            tenant.ShouldNotBe(null);
            tenant.Name.ShouldBe("Tenant for test purpose");
            tenant.IsActive.ShouldBe(true);
            tenant.EditionId.ShouldBe(currentEditionId);
            tenant.SubscriptionEndDateUtc = subscriptionEndDate?.ToUniversalTime();

            // Update Tenant -----------------------------

            var tenantForUpdate = _tenantManager.UpdateTenantAsync(
                tenant.Id,
                true,
                false,
                paymentPeriodType,
                targetEditionId,
                editionPaymentType
                );

            //Assert
            tenant = await tenantForUpdate;
            tenant.IsActive.ShouldBe(true);
            tenant.IsInTrialPeriod.ShouldBe(false);
            tenant.EditionId.ShouldBe(targetEditionId);
            tenant.SubscriptionEndDateUtc.ShouldNotBe(null);
            tenant.SubscriptionEndDateUtc?.Date.ShouldBe(updatedSubscriptionEndDate.ToUniversalTime().Date);
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateTenant([FromForm] CreateTenantDto input)
        {
            try
            {
                await _tenantAppService.CreateTenant(input);

                return(Ok("Created Tenant"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public async Task Create_Update_And_Delete_Tenant_Test()
        {
            //CREATE --------------------------------

            //Act
            await _tenantAppService.CreateTenant(
                new CreateTenantInput
            {
                TenancyName       = "testTenant",
                Name              = "Tenant for test purpose",
                AdminEmailAddress = "*****@*****.**",
                AdminPassword     = "******",
                IsActive          = true,
                ConnectionString  = "Server=localhost; Database=project56Test_" + Guid.NewGuid().ToString("N") + "; Trusted_Connection=True;"
            });

            //Assert
            var tenant = await GetTenantOrNullAsync("testTenant");

            tenant.ShouldNotBe(null);
            tenant.Name.ShouldBe("Tenant for test purpose");
            tenant.IsActive.ShouldBe(true);

            await UsingDbContext(tenant.Id, async context =>
            {
                //Check static roles
                var staticRoleNames = Resolve <IRoleManagementConfig>().StaticRoles.Where(r => r.Side == MultiTenancySides.Tenant).Select(role => role.RoleName).ToList();
                foreach (var staticRoleName in staticRoleNames)
                {
                    (await context.Roles.CountAsync(r => r.TenantId == tenant.Id && r.Name == staticRoleName)).ShouldBe(1);
                }

                //Check default admin user
                var adminUser = await context.Users.FirstOrDefaultAsync(u => u.TenantId == tenant.Id && u.UserName == User.AdminUserName);
                adminUser.ShouldNotBeNull();

                //Check notification registration
                (await context.NotificationSubscriptions.FirstOrDefaultAsync(ns => ns.UserId == adminUser.Id && ns.NotificationName == AppNotificationNames.NewUserRegistered)).ShouldNotBeNull();
            });

            //GET FOR EDIT -----------------------------

            //Act
            var editDto = await _tenantAppService.GetTenantForEdit(new EntityDto(tenant.Id));

            //Assert
            editDto.TenancyName.ShouldBe("testTenant");
            editDto.Name.ShouldBe("Tenant for test purpose");
            editDto.IsActive.ShouldBe(true);

            // UPDATE ----------------------------------

            editDto.Name     = "edited tenant name";
            editDto.IsActive = false;
            await _tenantAppService.UpdateTenant(editDto);

            //Assert
            tenant = await GetTenantAsync("testTenant");

            tenant.Name.ShouldBe("edited tenant name");
            tenant.IsActive.ShouldBe(false);

            // DELETE ----------------------------------

            //Act
            await _tenantAppService.DeleteTenant(new EntityDto((await GetTenantAsync("testTenant")).Id));

            //Assert
            (await GetTenantOrNullAsync("testTenant")).IsDeleted.ShouldBe(true);
        }
        public async Task Create_Update_And_Delete_Tenant_Test()
        {
            //CREATE --------------------------------

            //Act
            await _tenantAppService.CreateTenant(
                new CreateTenantInput
            {
                TenancyName       = "testTenant",
                Name              = "Tenant for test purpose",
                AdminEmailAddress = "*****@*****.**",
                AdminPassword     = "******",
                IsActive          = true
            });

            //Assert
            var tenant = await GetTenantOrNullAsync("testTenant");

            tenant.ShouldNotBe(null);
            tenant.Name.ShouldBe("Tenant for test purpose");
            tenant.IsActive.ShouldBe(true);

            await UsingDbContext(
                async context =>
            {
                //Check static roles
                var staticRoleNames = Resolve <IRoleManagementConfig>().StaticRoles.Select(role => role.RoleName).ToList();
                foreach (var staticRoleName in staticRoleNames)
                {
                    (await context.Roles.CountAsync(r => r.TenantId == tenant.Id && r.Name == staticRoleName)).ShouldBe(1);
                }

                //Check default admin user
                (await context.Users.CountAsync(u => u.TenantId == tenant.Id && u.UserName == User.AdminUserName)).ShouldBe(1);
            });

            //GET FOR EDIT -----------------------------

            //Act
            var editDto = await _tenantAppService.GetTenantForEdit(new EntityRequestInput(tenant.Id));

            //Assert
            editDto.TenancyName.ShouldBe("testTenant");
            editDto.Name.ShouldBe("Tenant for test purpose");
            editDto.IsActive.ShouldBe(true);

            // UPDATE ----------------------------------

            editDto.Name     = "edited tenant name";
            editDto.IsActive = false;
            await _tenantAppService.UpdateTenant(editDto);

            //Assert
            tenant = await GetTenantAsync("testTenant");

            tenant.Name.ShouldBe("edited tenant name");
            tenant.IsActive.ShouldBe(false);

            // DELETE ----------------------------------

            //Act
            await _tenantAppService.DeleteTenant(new EntityRequestInput((await GetTenantAsync("testTenant")).Id));

            //Assert
            (await GetTenantOrNullAsync("testTenant")).IsDeleted.ShouldBe(true);
        }
Esempio n. 6
0
        public async Task <IActionResult> New(CreateTenantInputDto inputDto)
        {
            await _tenantAppService.CreateTenant(inputDto);

            return(Ok());
        }