using Manager.DTOs; using ManagerService.Controllers; using ManagerService.Data; using ManagerService.Data.SubSection; using ManagerService.DTOs; using ManagerService.Tests.Infrastructure; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging.Abstractions; using System.Collections.Generic; using System.Linq; using Xunit; namespace ManagerService.Tests.Controllers { public class SectionMapControllerTests { private static SectionMapController BuildController(MyInfoMateDbContext db) { var controller = new SectionMapController( FakeMongoConfig.Create(), NullLogger.Instance, db); FakeUser.SetUser(controller, FakeUser.Create("Manager.contenteditor", "inst-test")); return controller; } private static GeoPoint EmptyGeoPoint() => new GeoPoint { Title = new List(), Description = new List(), Contents = new List(), Schedules = new List(), Prices = new List(), Phone = new List(), Email = new List(), Site = new List() }; private static GeoPointDTO EmptyGeoPointDTO() => new GeoPointDTO { title = new List(), description = new List(), contents = new List(), schedules = new List(), prices = new List(), phone = new List(), email = new List(), site = new List() }; // ── GET POINTS ─────────────────────────────────────────────────────── [Fact] public void GetAllGeoPoints_ReturnsPointsForSection() { using var db = DbContextFactory.Create(); var section = new SectionMap { Id = "sm-1", InstanceId = "inst-test", Label = "Map", Type = SectionType.Map, ConfigurationId = "c1", Title = new List(), Description = new List(), MapPoints = new List { EmptyGeoPoint(), EmptyGeoPoint() }, MapCategories = new List() }; db.Sections.Add(section); db.SaveChanges(); var result = BuildController(db).GetAllGeoPointsFromSection("sm-1"); var ok = Assert.IsType(result); var points = Assert.IsAssignableFrom>(ok.Value); Assert.Equal(2, points.Count()); } [Fact] public void GetAllGeoPoints_UnknownSection_Returns404() { using var db = DbContextFactory.Create(); var result = BuildController(db).GetAllGeoPointsFromSection("unknown"); Assert.IsType(result); } // ── CREATE POINT ───────────────────────────────────────────────────── [Fact] public void Create_ValidPoint_Persists() { using var db = DbContextFactory.Create(); db.Sections.Add(new SectionMap { Id = "sm-1", InstanceId = "inst-test", Label = "Map", Type = SectionType.Map, ConfigurationId = "c1", Title = new List(), Description = new List(), MapPoints = new List(), MapCategories = new List() }); db.SaveChanges(); var result = BuildController(db).Create("sm-1", EmptyGeoPointDTO()); Assert.IsType(result); Assert.Equal(1, db.GeoPoints.Count()); } // ── DELETE POINT ───────────────────────────────────────────────────── [Fact] public void Delete_ExistingGeoPoint_Returns202() { using var db = DbContextFactory.Create(); db.GeoPoints.Add(EmptyGeoPoint()); db.SaveChanges(); int id = (int)db.GeoPoints.First().Id!; var result = BuildController(db).Delete(id); var obj = Assert.IsType(result); Assert.Equal(202, obj.StatusCode); Assert.Equal(0, db.GeoPoints.Count()); } [Fact] public void Delete_UnknownGeoPoint_Returns404() { using var db = DbContextFactory.Create(); var result = BuildController(db).Delete(999); Assert.IsType(result); } } }