Skip to content

Commit

Permalink
Merge pull request #537 from ze-dom/unit_test_jol_fix
Browse files Browse the repository at this point in the history
Fixed JoL unit tests: removed fail reduce option test, adjusted fail …
  • Loading branch information
sven-n authored Nov 24, 2024
2 parents 8720383 + 55088c6 commit 32b1550
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions tests/MUnique.OpenMU.Tests/ItemConsumptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ public async ValueTask JewelOfLifeAsync(int numberOfOptions, bool consumptionExp
}

/// <summary>
/// Tests if a failed Jewels of life reduces the option level (in case level > 1).
/// Tests if a failed Jewel of life removes the option at any level.
/// </summary>
[Test]
public async ValueTask JewelOfLifeFailReducesOptionLevelAsync()
/// <param name="numberOfOptions">The number of options.</param>
[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
public async ValueTask JewelOfLifeFailRemovesOptionAsync(int numberOfOptions)
{
var consumeHandler = new LifeJewelConsumeHandlerPlugIn();
consumeHandler.Configuration.SuccessChance = 1;
Expand All @@ -156,49 +159,18 @@ public async ValueTask JewelOfLifeFailReducesOptionLevelAsync()
var upgradableItemSlot = (byte)(ItemSlot + 1);
await player.Inventory!.AddItemAsync(upgradableItemSlot, upgradeableItem).ConfigureAwait(false);

// we're adding 3 options first
for (int i = 0; i < 3; i++)
for (int i = 0; i < numberOfOptions; i++)
{
var item = this.GetItem();
await player.Inventory.AddItemAsync(ItemSlot, item).ConfigureAwait(false);
item.Durability = 1;
var jol1 = this.GetItem();
await player.Inventory.AddItemAsync(ItemSlot, jol1).ConfigureAwait(false);
jol1.Durability = 1;

await consumeHandler.ConsumeItemAsync(player, item, upgradeableItem, FruitUsage.Undefined).ConfigureAwait(false);
await consumeHandler.ConsumeItemAsync(player, jol1, upgradeableItem, FruitUsage.Undefined).ConfigureAwait(false);
}

// then adding fails, so one option needs to be removed
consumeHandler.Configuration.SuccessChance = 0;
var jol = this.GetItem();
await player.Inventory.AddItemAsync(ItemSlot, jol).ConfigureAwait(false);
jol.Durability = 1;
var jolConsumed = await consumeHandler.ConsumeItemAsync(player, jol, upgradeableItem, FruitUsage.Undefined).ConfigureAwait(false);

Assert.That(jolConsumed, Is.True);
Assert.That(upgradeableItem.ItemOptions.Count, Is.EqualTo(1));
Assert.That(upgradeableItem.ItemOptions.First().Level, Is.EqualTo(2));
}

/// <summary>
/// Tests if a failed Jewels of life removes the option (in case level = 1).
/// </summary>
[Test]
public async ValueTask JewelOfLifeFailRemovesOptionAsync()
{
var consumeHandler = new LifeJewelConsumeHandlerPlugIn();
consumeHandler.Configuration.SuccessChance = 1;
var player = await this.GetPlayerAsync().ConfigureAwait(false);
var upgradeableItem = this.GetItemWithPossibleOption();
var upgradableItemSlot = (byte)(ItemSlot + 1);
await player.Inventory!.AddItemAsync(upgradableItemSlot, upgradeableItem).ConfigureAwait(false);

var jol = this.GetItem();
await player.Inventory.AddItemAsync(ItemSlot, jol).ConfigureAwait(false);
jol.Durability = 1;

await consumeHandler.ConsumeItemAsync(player, jol, upgradeableItem, FruitUsage.Undefined).ConfigureAwait(false);

Assert.That(upgradeableItem.ItemOptions.Count, Is.EqualTo(1));

// then adding fails, so one option needs to be removed
// then adding fails, so option needs to be removed
consumeHandler.Configuration.SuccessChance = 0;
var jol2 = this.GetItem();
await player.Inventory.AddItemAsync(ItemSlot, jol2).ConfigureAwait(false);
Expand Down

0 comments on commit 32b1550

Please sign in to comment.