Implemented a property that will allow a spawnable to be acted on a variable number of times before being consumed.
This commit is contained in:
@@ -186,4 +186,36 @@ public class PlayerControllerTests
|
||||
locSvc.Verify();
|
||||
itemSvc.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PerformAction_DecrementsUses()
|
||||
{
|
||||
var playerSvc = new Mock<PlayerService>(cfg);
|
||||
var player = new Player { Id = "p", UserId = "u", LocationId = "loc", InventoryLocationId = "inv" };
|
||||
playerSvc.Setup(p => p.GetByUserIdAsync("u")).ReturnsAsync(player);
|
||||
var locSvc = new Mock<LocationService>(cfg);
|
||||
var loc = new Location { Id = "loc", Content = new List<string> { "i" } };
|
||||
locSvc.Setup(l => l.GetByIdAsync("loc")).ReturnsAsync(loc);
|
||||
var itemSvc = new Mock<ItemService>(cfg);
|
||||
var item = new Item { Id = "i", Name = "wood", UsesRemaining = 2 };
|
||||
itemSvc.Setup(i => i.GetByIdAsync("i")).ReturnsAsync(item);
|
||||
itemSvc.Setup(i => i.UpdateAsync(It.Is<Item>(it => it.UsesRemaining == 1))).Returns(Task.CompletedTask).Verifiable();
|
||||
var spawnSvc = new Mock<SpawnableService>(cfg);
|
||||
spawnSvc.Setup(s => s.GetByNameAsync("wood")).ReturnsAsync(new Spawnable
|
||||
{
|
||||
Name = "wood",
|
||||
CollectAction = "chop",
|
||||
CollectResults = new List<CollectOutcome> { new() { Result = "log", SuccessRate = 100 } },
|
||||
ConsumeOnSuccess = false
|
||||
});
|
||||
|
||||
var controller = new PlayerController(playerSvc.Object, locSvc.Object, spawnSvc.Object, itemSvc.Object)
|
||||
{
|
||||
ControllerContext = ContextWithUser("u")
|
||||
};
|
||||
|
||||
await controller.PerformAction(new PerformActionRequest { Action = "chop" });
|
||||
|
||||
itemSvc.Verify();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user