< Summary

Information
Class: Elsa.Tenants.Endpoints.Tenants.Add.Endpoint
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: 15
Coverable lines: 15
Total lines: 39
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Configure()100%210%
HandleAsync()0%2040%

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
 09public class Endpoint(ITenantService tenantService, IIdentityGenerator identityGenerator, ITenantStore tenantStore) : El
 10{
 11    public override void Configure()
 12    {
 013        Post("/tenants");
 014        ConfigurePermissions("write:tenants");
 015    }
 16
 17    public override async Task HandleAsync(NewTenant req, CancellationToken ct)
 18    {
 019        var tenant = new Tenant
 020        {
 021            Id = req.IsDefault ? string.Empty : req.Id ?? identityGenerator.GenerateId(),
 022            TenantId = req.TenantId,
 023            Name = req.Name.Trim(),
 024            Configuration = Serializers.DeserializeConfiguration(req.Configuration)
 025        };
 026        await tenantStore.AddAsync(tenant, ct);
 027        await tenantService.RefreshAsync(ct);
 028        await Send.OkAsync(tenant, ct);
 029    }
 30}
 31
 32public class NewTenant
 33{
 34    public bool IsDefault { get; set; }
 35    public string? Id { get; set; }
 36    public string? TenantId { get; set; }
 37    public string Name { get; set; } = default!;
 38    public JsonElement? Configuration { get; set; }
 39}