Files
gameauthapi/GameAuthApi.Tests/LocationControllerTests.cs

66 lines
2.2 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 CreateInventory_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.CreateInventory();
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);
}
[Fact]
public async Task Update_NotFound()
{
var svc = new Mock<LocationService>(config);
svc.Setup(l => l.GetByIdAsync("id")).ReturnsAsync((Location?)null);
var controller = new LocationController(svc.Object, new Mock<PlayerService>(config).Object);
var result = await controller.Update("id", new UpdateLocationRequest());
Assert.IsType<NotFoundObjectResult>(result);
}
}