< Summary

Information
Class: TicTacToeApp.API.Data.Configuration.GameMapping
Assembly: TicTacToeApp.API
File(s): /home/runner/work/TicTacToe/TicTacToe/TicTacToeApp.API/Data/Configuration/GameMapping.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 58
Line coverage: 100%
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
Configure(...)100%11100%

File(s)

/home/runner/work/TicTacToe/TicTacToe/TicTacToeApp.API/Data/Configuration/GameMapping.cs

#LineLine coverage
 1using System.Text.Json;
 2using Microsoft.EntityFrameworkCore;
 3using Microsoft.EntityFrameworkCore.ChangeTracking;
 4using Microsoft.EntityFrameworkCore.Metadata.Builders;
 5using TicTacToeApp.API.Data.Converters;
 6using TicTacToeApp.API.Entity;
 7
 8namespace TicTacToeApp.API.Data.Configuration;
 9
 10public class GameMapping : IEntityTypeConfiguration<Game>
 11{
 12    public void Configure(EntityTypeBuilder<Game> builder)
 13    {
 114        builder.ToTable("Games").HasKey(g => g.Id);
 115        builder.Property(g => g.CreatedAt)
 116                .HasColumnType("timestamp with time zone");
 17        //.HasConversion(new DateTimeToCharConverter());
 18
 119        builder.Property(g => g.Status).HasConversion<string>();
 120        builder.Property(g => g.Result).HasConversion<string>();
 121        builder.Property(g => g.CurrentMove).HasConversion<string>();
 122        builder.Property(g => g.Board).HasConversion(
 123            v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
 124            v => JsonSerializer.Deserialize<string?[][]>(v, (JsonSerializerOptions?)null)!);
 25
 126        builder.Property(g => g.Board)
 127            .HasConversion(
 128                v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
 129                v => JsonSerializer.Deserialize<string?[][]>(v, (JsonSerializerOptions?)null)!)
 130            .Metadata.SetValueComparer(
 131                new ValueComparer<string?[][]>(
 132                    (c1, c2) => c1!.SequenceEqual(c2!), // Сравниваем массивы поэлементно
 133                    c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), // Вычисляем хеш-код
 134                    c => c.Select(x => x.ToArray()).ToArray())); // Создаем глубокую копию для snapshot
 35
 36
 37        // builder.HasOne(g => g.User)
 38        //        .WithMany(user => user.Games)
 39        //        .HasPrincipalKey(g =>g.Id)
 40        //        .HasForeignKey(u => u.UserId);
 41
 42        // Seed
 143         builder.HasData(
 144             new Game
 145             {
 146                 Id = new Guid("b8aa36a5-9094-4dbd-80a5-444fcb92d3a4"), // Укажите явный Id (если есть)
 147                 Board = new string?[][]
 148                 {
 149                     new string?[] { "X", "O", null },
 150                     new string?[] { null, "X", "O" },
 151                     new string?[] { "O", null, "X" }
 152                 },
 153                 CreatedAt = new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc)
 154
 155             }
 156         );
 157    }
 58}