Adding unit tests
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user