~ruther/NosSmooth

ref: c1f31ab17d05b3035b5f362e8e0ede56be9d1b40 NosSmooth/Tests/NosSmooth.Game.Tests/Modules/InventoryTests.cs -rw-r--r-- 3.9 KiB
c1f31ab1 — Rutherther tests: add basic inventory, group, charater tests 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
//  InventoryTests.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics;
using NosSmooth.Data.Abstractions.Enums;
using Xunit.Abstractions;

namespace NosSmooth.Game.Tests.Modules;

/// <summary>
/// Tests for Game.Inventory.
/// </summary>
public class InventoryTests
{
    private readonly ITestOutputHelper _testOutputHelper;

    /// <summary>
    /// Initializes a new instance of the <see cref="InventoryTests"/> class.
    /// </summary>
    /// <param name="testOutputHelper">The test output helper.</param>
    public InventoryTests(ITestOutputHelper testOutputHelper)
    {
        _testOutputHelper = testOutputHelper;
    }

    /// <summary>
    /// Tests empty inventory initialization.
    /// </summary>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    [Fact]
    public async Task Test_Initialize_Empty()
    {
        var data = PacketFileClient.CreateFor<InventoryTests>("init_empty", _testOutputHelper);

        await data.Client.ExecuteToEnd();

        data.Game.Inventory.ShouldNotBeNull();
        foreach (var bag in data.Game.Inventory)
        {
            foreach (var slot in bag)
            {
                throw new Exception("There is something in the inventory, but it should have been empty.");
            }
        }
    }

    /// <summary>
    /// Tests inventory initialization with a few things.
    /// </summary>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    [Fact]
    public async Task Test_Initialize_FewThings()
    {
        var data = PacketFileClient.CreateFor<InventoryTests>("init_move", _testOutputHelper);

        await data.Client.ExecuteUntilLabelAsync("AFTER_INVENTORY_INITIALIZED");

        data.Game.Inventory.ShouldNotBeNull();

        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(0).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(1).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(2).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(0).Item!.ItemVNum.ShouldBe(1);
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(1).Item!.ItemVNum.ShouldBe(2);
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(2).Item!.ItemVNum.ShouldBe(4);

        data.Game.Inventory.GetBag(BagType.Main).GetSlot(0).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Main).GetSlot(0).Item!.ItemVNum.ShouldBe(1012);
        data.Game.Inventory.GetBag(BagType.Main).GetSlot(0).Amount.ShouldBe((short)10);

        data.Game.Inventory.GetBag(BagType.Etc).GetSlot(0).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Etc).GetSlot(0).Item!.ItemVNum.ShouldBe(2018);
        data.Game.Inventory.GetBag(BagType.Etc).GetSlot(0).Amount.ShouldBe((short)10);
    }

    /// <summary>
    /// Tests inventory initialization with a few things.
    /// </summary>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    [Fact]
    public async Task Test_Move()
    {
        var data = PacketFileClient.CreateFor<InventoryTests>("init_move", _testOutputHelper);

        await data.Client.ExecuteUntilLabelAsync("AFTER_INVENTORY_MOVES");

        data.Game.Inventory.ShouldNotBeNull();

        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(6).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(7).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(8).Item.ShouldNotBeNull();
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(6).Item!.ItemVNum.ShouldBe(1);
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(7).Item!.ItemVNum.ShouldBe(2);
        data.Game.Inventory.GetBag(BagType.Equipment).GetSlot(8).Item!.ItemVNum.ShouldBe(4);
    }
}
Do not follow this link