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