Files

65 lines
2.2 KiB
C#

using GameAuthApi.Services;
using GameAuthApi.Models;
using Microsoft.Extensions.Configuration;
public class AdminServiceTests
{
[Fact]
public async Task ResetLocations_DeletesWorldLocationsOnly()
{
var worldLocs = new List<Location> { new() { Id = "1", LocationType = "World" } };
var cfg = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"MongoDB:ConnectionString", "mongodb://localhost"},
{"MongoDB:DatabaseName", "test"}
}).Build();
var locSvc = new Mock<LocationService>(cfg);
locSvc.Setup(l => l.GetByTypeAsync("World")).ReturnsAsync(worldLocs);
locSvc.Setup(l => l.DeleteByTypeAsync("World")).Returns(Task.CompletedTask).Verifiable();
locSvc.Setup(l => l.CreateAsync(It.IsAny<Location>())).Returns(Task.CompletedTask);
var itemSvc = new Mock<ItemService>(cfg);
itemSvc.Setup(i => i.DeleteByLocationAsync("1")).Returns(Task.CompletedTask).Verifiable();
var playerSvc = new Mock<PlayerService>(cfg);
playerSvc.Setup(p => p.GetAllAsync()).ReturnsAsync(new List<Player>());
var adminSvc = new AdminService(locSvc.Object, itemSvc.Object, playerSvc.Object);
await adminSvc.ResetLocationsAsync();
locSvc.Verify();
itemSvc.Verify();
}
[Fact]
public async Task ClearItems_RemovesAllItemsFromLocations()
{
var cfg = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"MongoDB:ConnectionString", "mongodb://localhost"},
{"MongoDB:DatabaseName", "test"}
}).Build();
var locSvc = new Mock<LocationService>(cfg);
locSvc.Setup(l => l.ClearAllItemsAsync()).Returns(Task.CompletedTask).Verifiable();
var itemSvc = new Mock<ItemService>(cfg);
itemSvc.Setup(i => i.DeleteAllAsync()).Returns(Task.CompletedTask).Verifiable();
var playerSvc = new Mock<PlayerService>(cfg);
var adminSvc = new AdminService(locSvc.Object, itemSvc.Object, playerSvc.Object);
await adminSvc.ClearItemsAsync();
locSvc.Verify();
itemSvc.Verify();
}
}