Files

57 lines
2.0 KiB
C#

using GameAuthApi.Controllers;
using GameAuthApi.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using GameAuthApi.Models;
public class AdminControllerTests
{
[Fact]
public async Task GetStatus_ReturnsOk()
{
var expected = new Dictionary<string, string> { { "status", "ok" } };
var mockService = new Mock<AdminService>((LocationService)null, (ItemService)null, (PlayerService)null);
mockService.Setup(s => s.GetStatusAsync()).ReturnsAsync(expected);
var controller = new AdminController(mockService.Object);
var result = await controller.GetStatus();
var ok = Assert.IsType<OkObjectResult>(result);
Assert.Equal(expected, ok.Value);
}
[Fact]
public async Task ResetLocations_ReturnsOk()
{
var newLoc = new Location { LocationType = "World", X = 0, Y = 0, Z = 0 };
var mockService = new Mock<AdminService>((LocationService)null, (ItemService)null, (PlayerService)null);
mockService.Setup(s => s.ResetLocationsAsync()).ReturnsAsync(newLoc);
var controller = new AdminController(mockService.Object);
var result = await controller.ResetLocations();
var ok = Assert.IsType<OkObjectResult>(result);
var origin = Assert.IsType<Location>(ok.Value);
Assert.Equal("World", origin.LocationType);
Assert.Equal(0, origin.X);
Assert.Equal(0, origin.Y);
Assert.Equal(0, origin.Z);
}
[Fact]
public async Task ClearItems_ReturnsOk()
{
var mockService = new Mock<AdminService>((LocationService)null, (ItemService)null, (PlayerService)null);
mockService.Setup(s => s.ClearItemsAsync()).Returns(Task.CompletedTask).Verifiable();
var controller = new AdminController(mockService.Object);
var result = await controller.ClearItems();
var ok = Assert.IsType<OkObjectResult>(result);
Assert.Equal("All items cleared.", ok.Value);
mockService.Verify();
}
}