< Summary

Information
Class: Elsa.Tenants.Endpoints.Tenants.Add.NewTenant
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Endpoints/Tenants/Add/Endpoint.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 5
Coverable lines: 5
Total lines: 39
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsDefault()100%210%
get_Id()100%210%
get_TenantId()100%210%
get_Name()100%210%
get_Configuration()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Endpoints/Tenants/Add/Endpoint.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Abstractions;
 3using Elsa.Common.Multitenancy;
 4using Elsa.Common.Serialization;
 5using Elsa.Workflows;
 6
 7namespace Elsa.Tenants.Endpoints.Tenants.Add;
 8
 9public class Endpoint(ITenantService tenantService, IIdentityGenerator identityGenerator, ITenantStore tenantStore) : El
 10{
 11    public override void Configure()
 12    {
 13        Post("/tenants");
 14        ConfigurePermissions("write:tenants");
 15    }
 16
 17    public override async Task HandleAsync(NewTenant req, CancellationToken ct)
 18    {
 19        var tenant = new Tenant
 20        {
 21            Id = req.IsDefault ? string.Empty : req.Id ?? identityGenerator.GenerateId(),
 22            TenantId = req.TenantId,
 23            Name = req.Name.Trim(),
 24            Configuration = Serializers.DeserializeConfiguration(req.Configuration)
 25        };
 26        await tenantStore.AddAsync(tenant, ct);
 27        await tenantService.RefreshAsync(ct);
 28        await Send.OkAsync(tenant, ct);
 29    }
 30}
 31
 32public class NewTenant
 33{
 034    public bool IsDefault { get; set; }
 035    public string? Id { get; set; }
 036    public string? TenantId { get; set; }
 037    public string Name { get; set; } = default!;
 038    public JsonElement? Configuration { get; set; }
 39}