Example #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);
        }
        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);
        }
Example #4
0
        public async Task <Tenant> UpdateTenant([FromForm] UpdateTenantDto input)
        {
            var result = await _tenantAppService.UpdateTenant(input);

            return(result);
        }