Adding unit tests

This commit is contained in:
hz
2025-06-04 21:33:44 -05:00
parent 638d73561d
commit ec38498957
17 changed files with 468 additions and 33 deletions
@@ -0,0 +1,40 @@
using GameAuthApi.Controllers;
using GameAuthApi.Models;
using GameAuthApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
public class LocationControllerTests
{
private static IConfiguration config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string,string>
{
{"MongoDB:ConnectionString","mongodb://localhost"},
{"MongoDB:DatabaseName","test"}
}).Build();
[Fact]
public async Task Create_ReturnsOk()
{
var mockLoc = new Mock<LocationService>(config);
mockLoc.Setup(l => l.CreateAsync(It.IsAny<Location>())).Returns(Task.CompletedTask).Verifiable();
var controller = new LocationController(mockLoc.Object, new Mock<PlayerService>(config).Object);
var result = await controller.Create(new CreateLocationRequest { X = 1, Y = 2, Z = 3 });
Assert.IsType<OkObjectResult>(result);
mockLoc.Verify();
}
[Fact]
public async Task GetById_NotFound()
{
var mockLoc = new Mock<LocationService>(config);
mockLoc.Setup(l => l.GetByIdAsync("id")).ReturnsAsync((Location?)null);
var controller = new LocationController(mockLoc.Object, new Mock<PlayerService>(config).Object);
var result = await controller.GetById("id");
Assert.IsType<NotFoundObjectResult>(result);
}
}