Adding unit tests

This commit is contained in:
hz
2025-06-04 21:33:44 -05:00
parent 638d73561d
commit ec38498957
17 changed files with 468 additions and 33 deletions
+10 -10
View File
@@ -17,7 +17,7 @@ public class LocationService
_locations = db.GetCollection<Location>("Locations");
}
public async Task<Location> GetByIdAsync(string id)
public virtual async Task<Location> GetByIdAsync(string id)
{
if (!ObjectId.TryParse(id, out _))
return null; // prevent crash if id is invalid
@@ -25,43 +25,43 @@ public class LocationService
return await _locations.Find(x => x.Id == id).FirstOrDefaultAsync();
}
public async Task CreateAsync(Location loc) =>
public virtual async Task CreateAsync(Location loc) =>
await _locations.InsertOneAsync(loc);
public async Task DeleteAsync(string id) =>
public virtual async Task DeleteAsync(string id) =>
await _locations.DeleteOneAsync(loc => loc.Id == id);
public async Task UpdateAsync(Location loc) =>
public virtual async Task UpdateAsync(Location loc) =>
await _locations.ReplaceOneAsync(l => l.Id == loc.Id, loc);
public async Task AddPlayerToLocationAsync(string locationId, string playerId)
public virtual async Task AddPlayerToLocationAsync(string locationId, string playerId)
{
var update = Builders<Location>.Update.AddToSet(l => l.Players, playerId);
await _locations.UpdateOneAsync(l => l.Id == locationId, update);
}
public async Task<Location> GetByCoordinatesAsync(int x, int y, int z)
public virtual async Task<Location> GetByCoordinatesAsync(int x, int y, int z)
{
return await _locations.Find(loc => loc.X == x && loc.Y == y && loc.Z == z).FirstOrDefaultAsync();
}
public async Task<Location> GetSpawnLocationAsync()
public virtual async Task<Location> GetSpawnLocationAsync()
{
return await _locations.Find(loc => loc.X == 0 && loc.Y == 0).FirstOrDefaultAsync();
}
public async Task RemovePlayerFromLocationAsync(string locationId, string playerId)
public virtual async Task RemovePlayerFromLocationAsync(string locationId, string playerId)
{
var update = Builders<Location>.Update.Pull(l => l.Players, playerId);
await _locations.UpdateOneAsync(l => l.Id == locationId, update);
}
public async Task AddItemToLocationAsync(string locationId, string itemId)
public virtual async Task AddItemToLocationAsync(string locationId, string itemId)
{
var update = Builders<Location>.Update.Push(l => l.Content, itemId);
await _locations.UpdateOneAsync(l => l.Id == locationId, update);
}
public async Task RemoveItemFromLocationAsync(string locationId, string itemId)
public virtual async Task RemoveItemFromLocationAsync(string locationId, string itemId)
{
var update = Builders<Location>.Update.Pull(l => l.Content, itemId);
await _locations.UpdateOneAsync(l => l.Id == locationId, update);