You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.1 KiB
66 lines
2.1 KiB
using API.Controllers;
|
|
using API.DTO;
|
|
using AppContext.Entities;
|
|
using DbServices;
|
|
using FluentAssertions;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Model;
|
|
using StubContext;
|
|
|
|
namespace UnitTests;
|
|
|
|
public class TacticsControllerTest
|
|
{
|
|
private static (TacticController, AppContext.AppContext) GetController(int userId)
|
|
{
|
|
var connection = new SqliteConnection("Data Source=:memory:");
|
|
connection.Open();
|
|
var context = new StubAppContext(
|
|
new DbContextOptionsBuilder<AppContext.AppContext>()
|
|
.UseSqlite(connection)
|
|
.Options
|
|
);
|
|
context.Database.EnsureCreated();
|
|
var controller = new TacticController(
|
|
new DbTacticService(context),
|
|
new ManualContextAccessor(userId)
|
|
);
|
|
|
|
return (controller, context);
|
|
}
|
|
|
|
[Fact]
|
|
public async void UpdateName()
|
|
{
|
|
var (controller, context) = GetController(1);
|
|
var result = await controller.UpdateName(1, new("Stade de France"));
|
|
result.Should().BeEquivalentTo(controller.Ok());
|
|
|
|
var tactic = await context.Tactics.FindAsync(1);
|
|
tactic.Name.Should().BeEquivalentTo("Stade de France");
|
|
|
|
result = await controller.UpdateName(-1, new("Stade de France"));
|
|
result.Should().BeEquivalentTo(controller.Unauthorized());
|
|
}
|
|
|
|
[Fact]
|
|
public async void GetTacticInfoTest()
|
|
{
|
|
var (controller, context) = GetController(1);
|
|
var result = await controller.GetTacticInfo(1);
|
|
result.Should().BeEquivalentTo(controller.Ok(new Tactic(1, "New tactic", 1, CourtType.Plain, new DateTime(2024, 5, 31)).ToDto()));
|
|
|
|
result = await controller.GetTacticInfo(100);
|
|
result.Should().BeEquivalentTo(controller.Unauthorized());
|
|
}
|
|
|
|
[Fact]
|
|
public async void GetTacticStepsRoot()
|
|
{
|
|
var (controller, context) = GetController(1);
|
|
var result = await controller.GetTacticStepsRoot(1);
|
|
result.Should().BeEquivalentTo(controller.Ok(new TacticController.GetTacticStepsTreeResponse(new TacticStep(1, null, [], "{}").ToDto())));
|
|
}
|
|
|
|
} |