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

28 lines
941 B
C#

using GameAuthApi.Controllers;
using GameAuthApi.Models;
using GameAuthApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
public class ItemControllerTests
{
private static IConfiguration config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string,string>
{
{"MongoDB:ConnectionString","mongodb://localhost"},
{"MongoDB:DatabaseName","test"}
}).Build();
[Fact]
public async Task Create_InvalidLocation_ReturnsBadRequest()
{
var loc = new Mock<LocationService>(config);
loc.Setup(l => l.GetByIdAsync("bad")).ReturnsAsync((Location?)null);
var controller = new ItemController(new Mock<ItemService>(config).Object, loc.Object);
var result = await controller.Create(new CreateItemRequest { LocationId = "bad", Name = "n" });
Assert.IsType<BadRequestObjectResult>(result);
}
}