< Summary

Information
Class: TicTacToeApp.API.Repositories.GameAsyncRepository
Assembly: TicTacToeApp.API
File(s): /home/runner/work/TicTacToe/TicTacToe/TicTacToeApp.API/Repositories/GameRepository.cs
Line coverage
18%
Covered lines: 4
Uncovered lines: 18
Coverable lines: 22
Total lines: 47
Line coverage: 18.1%
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%11100%
FindGameByGuidAsync()0%620%
GetGamesAsync()100%11100%
CreateGameAsync()0%620%
UpdateGameAsync()100%210%

File(s)

/home/runner/work/TicTacToe/TicTacToe/TicTacToeApp.API/Repositories/GameRepository.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using TicTacToeApp.API.Data;
 3using TicTacToeApp.API.Entity;
 4using TicTacToeApp.API.Exceptions;
 5using TicTacToeApp.API.Interfaces;
 6using TicTacToeApp.API.Services;
 7
 8namespace TicTacToeApp.API.Repositories;
 9
 210public sealed class GameAsyncRepository(TicTacToeContext db, ILogger<GameAsyncRepository> log) : IGameAsyncRepository
 11{
 12    public async Task<Game> FindGameByGuidAsync(Guid id, CancellationToken ct)
 13    {
 14        const string errorMessage = "Нет такой игры";
 015        var game = await db.Games.FirstOrDefaultAsync(g => g.Id == id, ct);
 016        log.LogError(errorMessage);
 017        return game ?? throw new NotFoundException(errorMessage);
 018    }
 19
 20    public async Task<IEnumerable<Game>> GetGamesAsync(CancellationToken ct)
 21    {
 122        log.LogInformation("Все игры получены!");
 123        return await db.Games.AsNoTracking().ToListAsync(ct);
 124    }
 25
 26    public async Task<Game> CreateGameAsync(int size, CancellationToken ct)
 27    {
 028        if (size < 3) throw new ArgumentException("Поле для игры должно быть минимум 3 на 3");
 29
 030        var game = new Game()
 031        {
 032            Board = GameService.CreateEmptyBoard(size)
 033        };
 034        await db.Games.AddAsync(game, ct);
 035        await db.SaveChangesAsync(ct);
 036        log.LogInformation($"Создана игра {game.Id}");
 037        return game;
 038    }
 39
 40    public async Task<bool> UpdateGameAsync(Game game, CancellationToken ct)
 41    {
 042        db.Games.Update(game);
 043        log.LogInformation($"Создана игра {game.Id}");
 044        return await db.SaveChangesAsync(ct) > 0;
 045    }
 46
 47}