< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Persistence.EntityConfiguration.Channel.ChannelEntityConfiguration
Assembly: NLightning.Infrastructure.Persistence
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Persistence/EntityConfiguration/Channel/ChannelEntityConfiguration.cs
Tag: 36_15743069263
Line coverage
0%
Covered lines: 0
Uncovered lines: 67
Coverable lines: 67
Total lines: 87
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConfigureChannelEntity(...)0%620%
OptimizeConfigurationForSqlServer(...)100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Persistence/EntityConfiguration/Channel/ChannelEntityConfiguration.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.EntityFrameworkCore.Metadata.Builders;
 3
 4namespace NLightning.Infrastructure.Persistence.EntityConfiguration.Channel;
 5
 6using Domain.Bitcoin.Transactions.Constants;
 7using Domain.Channels.Constants;
 8using Domain.Crypto.Constants;
 9using Entities.Channel;
 10using Enums;
 11using ValueConverters;
 12
 13public static class ChannelEntityConfiguration
 14{
 15    public static void ConfigureChannelEntity(this ModelBuilder modelBuilder, DatabaseType databaseType)
 16    {
 017        modelBuilder.Entity<ChannelEntity>(entity =>
 018        {
 019            // Set PrimaryKey
 020            entity.HasKey(e => e.ChannelId);
 021
 022            // Set required props
 023            entity.Property(e => e.FundingOutputIndex).IsRequired();
 024            entity.Property(e => e.FundingAmountSatoshis).IsRequired();
 025            entity.Property(e => e.IsInitiator).IsRequired();
 026            entity.Property(e => e.LocalNextHtlcId).IsRequired();
 027            entity.Property(e => e.RemoteNextHtlcId).IsRequired();
 028            entity.Property(e => e.LocalRevocationNumber).IsRequired();
 029            entity.Property(e => e.RemoteRevocationNumber).IsRequired();
 030            entity.Property(e => e.State).IsRequired();
 031            entity.Property(e => e.Version).IsRequired();
 032            entity.Property(e => e.LocalBalanceSatoshis).IsRequired();
 033            entity.Property(e => e.RemoteBalanceSatoshis).IsRequired();
 034            entity.Property(e => e.ChannelId)
 035                  .HasConversion<ChannelIdConverter>()
 036                  .IsRequired();
 037            entity.Property(e => e.FundingTxId)
 038                  .HasConversion<TxIdConverter>()
 039                  .IsRequired();
 040            entity.Property(e => e.RemoteNodeId)
 041                  .HasConversion<CompactPubKeyConverter>()
 042                  .IsRequired();
 043
 044            // Nullable properties
 045            entity.Property(e => e.LastSentSignature).IsRequired(false);
 046            entity.Property(e => e.LastReceivedSignature).IsRequired(false);
 047
 048            // Configure the relationship with ChannelConfig (1:1)
 049            entity.HasOne(e => e.Config)
 050                  .WithOne()
 051                  .HasForeignKey<ChannelConfigEntity>(c => c.ChannelId)
 052                  .OnDelete(DeleteBehavior.Cascade);
 053
 054            // Configure the relationship with HTLCs (1:many)
 055            entity.HasMany(e => e.Htlcs)
 056                  .WithOne()
 057                  .HasForeignKey(h => h.ChannelId)
 058                  .OnDelete(DeleteBehavior.Cascade);
 059
 060            // Configure the relationship with KeySets (1:many)
 061            entity.HasMany(e => e.KeySets)
 062                  .WithOne()
 063                  .HasForeignKey(h => h.ChannelId)
 064                  .OnDelete(DeleteBehavior.Cascade);
 065
 066            // Configure the relationship with WatchedTransactions (1:many)
 067            entity.HasMany(e => e.WatchedTransactions)
 068                  .WithOne()
 069                  .HasForeignKey(wt => wt.ChannelId)
 070                  .OnDelete(DeleteBehavior.Cascade);
 071
 072            if (databaseType == DatabaseType.MicrosoftSql)
 073                OptimizeConfigurationForSqlServer(entity);
 074        });
 075    }
 76
 77    private static void OptimizeConfigurationForSqlServer(EntityTypeBuilder<ChannelEntity> entity)
 78    {
 079        entity.Property(e => e.LocalBalanceSatoshis).HasColumnType("bigint");
 080        entity.Property(e => e.RemoteBalanceSatoshis).HasColumnType("bigint");
 081        entity.Property(e => e.ChannelId).HasColumnType($"varbinary({ChannelConstants.ChannelIdLength})");
 082        entity.Property(e => e.FundingTxId).HasColumnType($"varbinary({TransactionConstants.TxIdLength})");
 083        entity.Property(e => e.RemoteNodeId).HasColumnType($"varbinary({TransactionConstants.TxIdLength})");
 084        entity.Property(e => e.LastSentSignature).HasColumnType($"varbinary({CryptoConstants.MaxSignatureSize})");
 085        entity.Property(e => e.LastReceivedSignature).HasColumnType($"varbinary({CryptoConstants.MaxSignatureSize})");
 086    }
 87}