Files
gameauthapi/GameAuthApi.Tests/LocationControllerTests.cs
T
2025-06-04 21:33:44 -05:00

41 lines
1.4 KiB
C#

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);
}
}