From 5bbf671acd11cedc8c416cc964bffbd821247c30 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 22 Jul 2025 19:41:34 +0100 Subject: [PATCH] Refactored unit tests to use NUnit and added DI usage --- .../Generators/BotLootGenerator.cs | 2 +- .../SPTarkov.Server.Core.csproj | 4 + UnitTests/DI.cs | 25 +- UnitTests/MSTestSettings.cs | 1 - .../Extensions/ContainerExtensionsTests.cs | 43 +- UnitTests/Tests/Extensions/ItemTests.cs | 290 +++--- .../Generators/BotWeaponGeneratorTests.cs | 112 ++- .../Tests/Helpers/BotGeneratorHelperTests.cs | 866 +++++++++--------- .../Tests/Helpers/InventoryHelperTests.cs | 352 +++---- UnitTests/Tests/MongoIDTests.cs | 137 ++- UnitTests/Tests/Utils/JsonUtilTests.cs | 9 +- UnitTests/Tests/Utils/MathUtilTests.cs | 28 +- UnitTests/Tests/Utils/MongoIdTests.cs | 52 +- UnitTests/Tests/Utils/RandomUtilTests.cs | 40 +- UnitTests/UnitTests.csproj | 6 +- 15 files changed, 988 insertions(+), 979 deletions(-) delete mode 100644 UnitTests/MSTestSettings.cs diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs index 25f0457f..5d268182 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs @@ -493,7 +493,7 @@ public class BotLootGenerator( /// /// Total value of loot allowed in roubles /// Is bot being generated for a pmc - protected void AddLootFromPool( + protected internal void AddLootFromPool( Dictionary pool, HashSet equipmentSlots, double totalItemCount, diff --git a/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj b/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj index c77b3cfb..cf4b9b45 100644 --- a/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj +++ b/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj @@ -32,6 +32,10 @@ LOCAL + + + + ()) { + if (onLoad is FileLogHandler) + { + continue; + } onLoad.OnLoad().Wait(); } } - public static T GetService() - where T : notnull + public T GetService() where T : notnull { return _serviceProvider.GetRequiredService(); } diff --git a/UnitTests/MSTestSettings.cs b/UnitTests/MSTestSettings.cs deleted file mode 100644 index aaf278c8..00000000 --- a/UnitTests/MSTestSettings.cs +++ /dev/null @@ -1 +0,0 @@ -[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] diff --git a/UnitTests/Tests/Extensions/ContainerExtensionsTests.cs b/UnitTests/Tests/Extensions/ContainerExtensionsTests.cs index bd1de9ef..bc3ada4a 100644 --- a/UnitTests/Tests/Extensions/ContainerExtensionsTests.cs +++ b/UnitTests/Tests/Extensions/ContainerExtensionsTests.cs @@ -1,14 +1,15 @@ -using SPTarkov.Server.Core.Extensions; +using NUnit.Framework; +using SPTarkov.Server.Core.Extensions; namespace UnitTests.Tests.Extensions; -[TestClass] +[TestFixture] public partial class ContainerExtensionsTests { - [TestInitialize] + [SetUp] public void Initialize() { } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_1x1_Item_Fits_1x2_Container_At_0x0() { var container = new int[1, 2]; @@ -27,7 +28,7 @@ public partial class ContainerExtensionsTests Assert.IsTrue(result); } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_1x1_Item_Fails_1x2_Container_At_0x0_With_Item_At_0x0() { var container = new int[1, 2]; @@ -47,7 +48,7 @@ public partial class ContainerExtensionsTests Assert.IsFalse(result); } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_1x2_Item_Fits_1x2_Container_At_0x0() { var container = new int[2, 1]; @@ -66,7 +67,7 @@ public partial class ContainerExtensionsTests Assert.IsTrue(result); } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_1x2_Item_Fails_1x2_Container_At_0x0_With_Item_At_0x0() { var container = new int[1, 2]; @@ -86,7 +87,7 @@ public partial class ContainerExtensionsTests Assert.IsFalse(result); } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_2x2_Item_Fits_2x2_Container_At_0x0() { var container = new int[2, 2]; @@ -105,7 +106,7 @@ public partial class ContainerExtensionsTests Assert.IsTrue(result); } - [TestMethod] + [Test] public void CanItemBePlacedInContainerAtPosition_1x2_Item_Fits_2x2_Container_At_0x1() { var container = new int[2, 2]; @@ -127,7 +128,7 @@ public partial class ContainerExtensionsTests public partial class ContainerExtensionsTests { - [TestMethod] + [Test] public void FindSlotForItem_1x1_item_fits_1x1_container_no_rotation() { var container = new int[1, 1]; @@ -142,7 +143,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(result.Y, 0); } - [TestMethod] + [Test] public void FindSlotForItem_1x2_item_fits_3x3_container_rotated_with_items() { // |1|1|1| @@ -167,7 +168,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(result.Y, 1); } - [TestMethod] + [Test] public void FindSlotForItem_1x1_item_fails_1x1_container_no_space() { var container = new int[1, 1]; @@ -180,7 +181,7 @@ public partial class ContainerExtensionsTests Assert.IsFalse(result.Success); } - [TestMethod] + [Test] public void FindSlotForItem_1x2_item_fits_1x2_container_no_rotation() { var container = new int[2, 1]; @@ -195,7 +196,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(result.Y, 0); } - [TestMethod] + [Test] public void FindSlotForItem_1x2_item_fails_1x2_container_no_space() { var container = new int[1, 1]; @@ -209,7 +210,7 @@ public partial class ContainerExtensionsTests Assert.IsFalse(result.Success); } - [TestMethod] + [Test] public void FindSlotForItem_2x2_item_fits_2x2_container_no_rotation() { var container = new int[2, 2]; @@ -224,7 +225,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(result.Y, 0); } - [TestMethod] + [Test] public void FindSlotForItem_1x2_item_fits_2x2_container_no_rotation_with_item_at_0x0() { var container = new int[2, 2]; @@ -243,7 +244,7 @@ public partial class ContainerExtensionsTests public partial class ContainerExtensionsTests { - [TestMethod] + [Test] public void FillContainerMapWithItem_1x1_at_0x0_in_1x1_no_rotation() { var container = new int[1, 1]; @@ -266,7 +267,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(container[0, 0], 1); } - [TestMethod] + [Test] public void FillContainerMapWithItem_1x2_at_0x0_in_1x2_no_rotation() { var container = new int[2, 1]; @@ -290,7 +291,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(container[1, 0], 1); } - [TestMethod] + [Test] public void FillContainerMapWithItem_2x2_at_0x0_in_2x2_no_rotation() { var container = new int[2, 2]; @@ -314,7 +315,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(container[1, 1], 1); } - [TestMethod] + [Test] public void FillContainerMapWithItem_1x2_at_0x0_in_2x2_with_rotation() { var container = new int[2, 2]; @@ -338,7 +339,7 @@ public partial class ContainerExtensionsTests Assert.AreEqual(container[0, 1], 1); } - [TestMethod] + [Test] public void FillContainerMapWithItem_1x2_at_1x0_in_2x2_with_rotation_with_existing_item() { var container = new int[2, 2]; diff --git a/UnitTests/Tests/Extensions/ItemTests.cs b/UnitTests/Tests/Extensions/ItemTests.cs index 7c333b60..66a09cb3 100644 --- a/UnitTests/Tests/Extensions/ItemTests.cs +++ b/UnitTests/Tests/Extensions/ItemTests.cs @@ -1,162 +1,162 @@ -using SPTarkov.Server.Core.Extensions; +using NUnit.Framework; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; -namespace UnitTests.Tests.Extensions +namespace UnitTests.Tests.Extensions; + +[TestFixture] +public class ItemTests { - [TestClass] - public class ItemTests + [SetUp] + public void Initialize() { } + + [Test] + public void FindAndReturnChildrenAsItems_one_child_mods_only() { - [TestInitialize] - public void Initialize() { } - - [TestMethod] - public void FindAndReturnChildrenAsItems_one_child_mods_only() + var testData = new List(); + var rootItem = new Item { - var testData = new List(); - var rootItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, - }; - var childItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_127X33_COPPER, - ParentId = rootItem.Id, - }; - testData.Add(rootItem); - testData.Add(childItem); - - var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); - - Assert.AreEqual(result[1].Id, childItem.Id); - } - - [TestMethod] - public void FindAndReturnChildrenAsItems_mods_only_one_inventory_item() + Id = new MongoId(), + Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, + }; + var childItem = new Item { - var testData = new List(); - var rootItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, - }; - var childItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_127X33_COPPER, - ParentId = rootItem.Id, - Location = 1, - }; - var childItem2 = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_26X75_GREEN, - ParentId = rootItem.Id, - }; - testData.Add(rootItem); - testData.Add(childItem); - testData.Add(childItem2); + Id = new MongoId(), + Template = ItemTpl.AMMO_127X33_COPPER, + ParentId = rootItem.Id, + }; + testData.Add(rootItem); + testData.Add(childItem); - var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); + var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); - Assert.AreEqual(result[1].Id, childItem2.Id); - Assert.AreEqual(result.Count, 2); - } + Assert.AreEqual(result[1].Id, childItem.Id); + } - [TestMethod] - public void FindAndReturnChildrenAsItems_mods_and_inventory_item() + [Test] + public void FindAndReturnChildrenAsItems_mods_only_one_inventory_item() + { + var testData = new List(); + var rootItem = new Item { - var testData = new List(); - var rootItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, - }; - var childItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_127X33_COPPER, - ParentId = rootItem.Id, - Location = 1, - }; - var childItem2 = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_26X75_GREEN, - ParentId = rootItem.Id, - }; - testData.Add(rootItem); - testData.Add(childItem); - testData.Add(childItem2); - - var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, false); - - Assert.AreEqual(result[1].Id, childItem.Id); - Assert.AreEqual(result.Count, 3); - } - - [TestMethod] - public void FindAndReturnChildrenAsItems_mod_with_child() + Id = new MongoId(), + Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, + }; + var childItem = new Item { - var testData = new List(); - var rootItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, - }; - var childItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_127X33_COPPER, - ParentId = rootItem.Id, - }; - var childOfChild = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_26X75_GREEN, - ParentId = childItem.Id, - }; - testData.Add(rootItem); - testData.Add(childItem); - testData.Add(childOfChild); - - var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); - - Assert.AreEqual(result[1].Id, childItem.Id); - Assert.AreEqual(result.Count, 3); - } - - [TestMethod] - public void FindAndReturnChildrenAsItems_no_matching_children() + Id = new MongoId(), + Template = ItemTpl.AMMO_127X33_COPPER, + ParentId = rootItem.Id, + Location = 1, + }; + var childItem2 = new Item { - var testData = new List(); - var rootItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, - }; - var childItem = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_127X33_COPPER, - ParentId = new MongoId(), - }; - var childOfChild = new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_26X75_GREEN, - ParentId = childItem.Id, - }; - testData.Add(rootItem); - testData.Add(childItem); - testData.Add(childOfChild); + Id = new MongoId(), + Template = ItemTpl.AMMO_26X75_GREEN, + ParentId = rootItem.Id, + }; + testData.Add(rootItem); + testData.Add(childItem); + testData.Add(childItem2); - var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); + var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); - Assert.AreEqual(result[0].Id, rootItem.Id); - Assert.AreEqual(result.Count, 1); - } + Assert.AreEqual(result[1].Id, childItem2.Id); + Assert.AreEqual(result.Count, 2); + } + + [Test] + public void FindAndReturnChildrenAsItems_mods_and_inventory_item() + { + var testData = new List(); + var rootItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, + }; + var childItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_127X33_COPPER, + ParentId = rootItem.Id, + Location = 1, + }; + var childItem2 = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_26X75_GREEN, + ParentId = rootItem.Id, + }; + testData.Add(rootItem); + testData.Add(childItem); + testData.Add(childItem2); + + var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, false); + + Assert.AreEqual(result[1].Id, childItem.Id); + Assert.AreEqual(result.Count, 3); + } + + [Test] + public void FindAndReturnChildrenAsItems_mod_with_child() + { + var testData = new List(); + var rootItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, + }; + var childItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_127X33_COPPER, + ParentId = rootItem.Id, + }; + var childOfChild = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_26X75_GREEN, + ParentId = childItem.Id, + }; + testData.Add(rootItem); + testData.Add(childItem); + testData.Add(childOfChild); + + var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); + + Assert.AreEqual(result[1].Id, childItem.Id); + Assert.AreEqual(result.Count, 3); + } + + [Test] + public void FindAndReturnChildrenAsItems_no_matching_children() + { + var testData = new List(); + var rootItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMOBOX_127X33_COPPER_20RND, + }; + var childItem = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_127X33_COPPER, + ParentId = new MongoId(), + }; + var childOfChild = new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_26X75_GREEN, + ParentId = childItem.Id, + }; + testData.Add(rootItem); + testData.Add(childItem); + testData.Add(childOfChild); + + var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true); + + Assert.AreEqual(result[0].Id, rootItem.Id); + Assert.AreEqual(result.Count, 1); } } diff --git a/UnitTests/Tests/Generators/BotWeaponGeneratorTests.cs b/UnitTests/Tests/Generators/BotWeaponGeneratorTests.cs index 904779f7..9ad4712c 100644 --- a/UnitTests/Tests/Generators/BotWeaponGeneratorTests.cs +++ b/UnitTests/Tests/Generators/BotWeaponGeneratorTests.cs @@ -1,75 +1,69 @@ -using SPTarkov.Server.Core.Generators; +using NUnit.Framework; +using SPTarkov.Server.Core.Generators; using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Services; -using SPTarkov.Server.Core.Utils; -namespace UnitTests.Tests.Generators +namespace UnitTests.Tests.Generators; + +[TestFixture] +public class BotWeaponGeneratorTests { - [TestClass] - public class BotWeaponGeneratorTests - { - private BotWeaponGenerator _botWeaponGenerator; - private DatabaseService _databaseService; - private InventoryHelper _inventoryHelper; + private BotWeaponGenerator _botWeaponGenerator; + private DatabaseService _databaseService; + private InventoryHelper _inventoryHelper; - [TestInitialize] - public void Initialize() + [OneTimeSetUp] + public void Initialize() + { + _botWeaponGenerator = DI.GetInstance().GetService(); + _databaseService = DI.GetInstance().GetService(); + _inventoryHelper = DI.GetInstance().GetService(); + } + + [Test] + public void GenerateWeaponByTpl_generate_m4_pmc() + { + var usecTemplate = _databaseService.GetBots().Types["usec"]; + var botTemplateInventory = usecTemplate.BotInventory; + + var sessionId = new MongoId(); + var weaponTpl = ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE; + const string slotName = "FirstPrimaryWeapon"; + var weaponModChances = usecTemplate.BotChances.WeaponModsChances; + foreach (var (key, _) in weaponModChances) { - _botWeaponGenerator = DI.GetService(); - var databaseImporter = DI.GetService(); - _databaseService = DI.GetService(); - _inventoryHelper = DI.GetService(); - Task.Factory.StartNew(() => - { - databaseImporter.OnLoad(); - }); + // Set all mods to 100% + weaponModChances[key] = 100d; } - [TestMethod] - public void GenerateWeaponByTpl_generate_m4_pmc() + var weaponParentId = new MongoId(); + + for (var i = 0; i < 100; i++) { - var usecTemplate = _databaseService.GetBots().Types["usec"]; - var botTemplateInventory = usecTemplate.BotInventory; + var result = _botWeaponGenerator.GenerateWeaponByTpl( + sessionId, + weaponTpl, + slotName, + botTemplateInventory, + weaponParentId, + weaponModChances, + "pmcUSEC", + true, + 69 + ); - var sessionId = new MongoId(); - var weaponTpl = ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE; - const string slotName = "FirstPrimaryWeapon"; - var weaponModChances = usecTemplate.BotChances.WeaponModsChances; - foreach (var (key, _) in weaponModChances) - { - // Set all mods to 100% - weaponModChances[key] = 100d; - } + var itemSize = _inventoryHelper.GetItemSize( + weaponTpl, + result.Weapon[0].Id, + result.Weapon + ); - var weaponParentId = new MongoId(); + Assert.AreEqual(weaponTpl, result.WeaponTemplate.Id); - for (var i = 0; i < 100; i++) - { - var result = _botWeaponGenerator.GenerateWeaponByTpl( - sessionId, - weaponTpl, - slotName, - botTemplateInventory, - weaponParentId, - weaponModChances, - "pmcUSEC", - true, - 69 - ); - - var itemSize = _inventoryHelper.GetItemSize( - weaponTpl, - result.Weapon[0].Id, - result.Weapon - ); - - Assert.AreEqual(weaponTpl, result.WeaponTemplate.Id); - - // Ensure it's bigger than just weapon lower - Assert.AreNotEqual(2, itemSize.Item1); - Assert.AreNotEqual(1, itemSize.Item2); - } + // Ensure it's bigger than just weapon lower + Assert.AreNotEqual(2, itemSize.Item1); + Assert.AreNotEqual(1, itemSize.Item2); } } } diff --git a/UnitTests/Tests/Helpers/BotGeneratorHelperTests.cs b/UnitTests/Tests/Helpers/BotGeneratorHelperTests.cs index f9d48252..bccd1e1f 100644 --- a/UnitTests/Tests/Helpers/BotGeneratorHelperTests.cs +++ b/UnitTests/Tests/Helpers/BotGeneratorHelperTests.cs @@ -1,159 +1,403 @@ -using SPTarkov.Server.Core.Helpers; +using NUnit.Framework; +using SPTarkov.Server.Core.Generators; +using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Enums; -using SPTarkov.Server.Core.Utils; -namespace UnitTests.Tests.Helpers +namespace UnitTests.Tests.Helpers; + +[TestFixture] +public class BotGeneratorHelperTests { - [TestClass] - public class BotGeneratorHelperTests + private BotGeneratorHelper _botGeneratorHelper; + private BotLootGenerator _botLootGenerator; + + [OneTimeSetUp] + public void Initialize() { - private BotGeneratorHelper _botGeneratorHelper; + _botGeneratorHelper = DI.GetInstance().GetService(); + _botLootGenerator = DI.GetInstance().GetService(); + } - [TestInitialize] - public void Initialize() + #region AddItemWithChildrenToEquipmentSlot + + [Test] + public void AddItemWithChildrenToEquipmentSlot_fit_vertical() + { + var stashId = new MongoId(); + var equipmentId = new MongoId(); + var botInventory = new BotBaseInventory { - _botGeneratorHelper = DI.GetService(); - var databaseImporter = DI.GetService(); - Task.Factory.StartNew(() => - { - databaseImporter.OnLoad(); - }); - ; - } + Items = [], + Stash = stashId, + Equipment = equipmentId, + }; - #region AddItemWithChildrenToEquipmentSlot - - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_fit_vertical() + // Create backpack on player + var backpack = new Item { - var stashId = new MongoId(); - var equipmentId = new MongoId(); - var botInventory = new BotBaseInventory - { - Items = [], - Stash = stashId, - Equipment = equipmentId, - }; + Id = new MongoId(), + // Has a 3grids, first is a 3hx5v grid + Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, + ParentId = equipmentId, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); - // Create backpack on player - var backpack = new Item + var rootWeaponId = new MongoId(); + var weaponWithChildren = CreateMp18(rootWeaponId); + + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + weaponWithChildren, + botInventory + ); + + Assert.AreEqual(ItemAddedResult.SUCCESS, result); + + var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); + Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); + } + + private static List CreateMp18(MongoId rootWeaponId) + { + var weaponWithChildren = new List(); + var weaponRoot = new Item + { + Id = rootWeaponId, + Template = ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + }; + weaponWithChildren.Add(weaponRoot); + var weaponStock = new Item + { + Id = new MongoId(), + Template = ItemTpl.STOCK_MP18_WOODEN, + ParentId = weaponRoot.Id, + SlotId = "mod_stock", + }; + weaponWithChildren.Add(weaponStock); + var weaponBarrel = new Item + { + Id = new MongoId(), + Template = ItemTpl.BARREL_MP18_762X54R_600MM, + ParentId = weaponRoot.Id, + SlotId = "mod_barrel", + }; + weaponWithChildren.Add(weaponBarrel); + + return weaponWithChildren; + } + + [Test] + public void AddItemWithChildrenToEquipmentSlot_fit_horizontal() + { + var stashId = new MongoId(); + var equipmentId = new MongoId(); + var botInventory = new BotBaseInventory + { + Items = [], + Stash = stashId, + Equipment = equipmentId, + }; + + // Create backpack on player + var backpack = new Item + { + Id = new MongoId(), + Template = ItemTpl.BACKPACK_ANA_TACTICAL_BETA_2_BATTLE_BACKPACK_OLIVE_DRAB, + ParentId = equipmentId, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); + + var rootWeaponId = new MongoId(); + var weaponWithChildren = CreateMp18(rootWeaponId); + + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + weaponWithChildren, + botInventory + ); + + _botLootGenerator.AddLootFromPool(new Dictionary{{ItemTpl.BARTER_MALBORO_CIGARETTES, 1}, {ItemTpl.FOREGRIP_SAKO_TRG_M10_GRIP_PAD, 1}, {ItemTpl.BARTER_GOLD_SKULL_RING, 1}, {ItemTpl.BARTER_PACK_OF_NAILS, 1}}, [EquipmentSlots.Backpack], 4, botInventory, "assault", null); + + Assert.AreEqual(ItemAddedResult.SUCCESS, result); + + var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); + Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Horizontal); + } + + /// + /// Backpack with one bullet in top row, blocking gun from being placed at 0,0 + /// + [Test] + public void AddItemWithChildrenToEquipmentSlot_fit_vertical_with_items_in_backpack() + { + var botInventory = new BotBaseInventory { Items = [] }; + var backpack = new Item + { + Id = new MongoId(), + // Has a 3hx5v grid first + Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); + + botInventory.Items.Add( + new Item { Id = new MongoId(), - // Has a 3grids, first is a 3hx5v grid - Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, - ParentId = equipmentId, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 0, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + } + ); - var rootWeaponId = new MongoId(); - var weaponWithChildren = CreateMp18(rootWeaponId); + var rootWeaponId = new MongoId(); + var weaponWithChildren = CreateMp18(rootWeaponId); - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - weaponWithChildren, - botInventory - ); + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + weaponWithChildren, + botInventory + ); - Assert.AreEqual(ItemAddedResult.SUCCESS, result); + Assert.AreEqual(ItemAddedResult.SUCCESS, result); - var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); - Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); - } + var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); + Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 1); + Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); + } - private static List CreateMp18(MongoId rootWeaponId) + /// + /// No space for gun + /// + [Test] + public void AddItemWithChildrenToEquipmentSlot_no_space_in_first_grid_choose_second_grid() + { + var botInventory = new BotBaseInventory { Items = [] }; + var backpack = new Item { - var weaponWithChildren = new List(); - var weaponRoot = new Item - { - Id = rootWeaponId, - Template = ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - }; - weaponWithChildren.Add(weaponRoot); - var weaponStock = new Item + Id = new MongoId(), + // Has a 3hx5v grid first + Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); + + botInventory.Items.AddRange( + new Item { Id = new MongoId(), - Template = ItemTpl.STOCK_MP18_WOODEN, - ParentId = weaponRoot.Id, - SlotId = "mod_stock", - }; - weaponWithChildren.Add(weaponStock); - var weaponBarrel = new Item + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 0, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + }, + new Item { Id = new MongoId(), - Template = ItemTpl.BARREL_MP18_762X54R_600MM, - ParentId = weaponRoot.Id, - SlotId = "mod_barrel", - }; - weaponWithChildren.Add(weaponBarrel); + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 1, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + }, + new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 2, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + } + ); - return weaponWithChildren; - } + var rootWeaponId = new MongoId(); + var weaponWithChildren = CreateMp18(rootWeaponId); - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_fit_horizontal() + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + weaponWithChildren, + botInventory + ); + + Assert.AreEqual(ItemAddedResult.SUCCESS, result); + var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); + Assert.AreEqual("1", weaponRoot.SlotId); + Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); + Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); + } + + /// + /// No space for gun + /// + [Test] + public void AddItemWithChildrenToEquipmentSlot_no_space() + { + var botInventory = new BotBaseInventory { Items = [] }; + var backpack = new Item { - var stashId = new MongoId(); - var equipmentId = new MongoId(); - var botInventory = new BotBaseInventory - { - Items = [], - Stash = stashId, - Equipment = equipmentId, - }; + Id = new MongoId(), + // Has a 4hx5v grid first + Template = ItemTpl.BACKPACK_WARTECH_BERKUT_BB102_BACKPACK_ATACS_FG, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); - // Create backpack on player - var backpack = new Item + botInventory.Items.AddRange( + new Item { Id = new MongoId(), - Template = ItemTpl.BACKPACK_ANA_TACTICAL_BETA_2_BATTLE_BACKPACK_OLIVE_DRAB, - ParentId = equipmentId, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 0, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + }, + new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 1, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + }, + new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 2, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + }, + new Item + { + Id = new MongoId(), + Template = ItemTpl.AMMO_762X25TT_AKBS, + ParentId = backpack.Id, + SlotId = "main", + Location = new ItemLocation + { + X = 3, + Y = 0, + R = ItemRotation.Horizontal, + }, + Upd = new Upd { StackObjectsCount = 1 }, + } + ); - var rootWeaponId = new MongoId(); - var weaponWithChildren = CreateMp18(rootWeaponId); + var rootWeaponId = new MongoId(); + var weaponWithChildren = CreateMp18(rootWeaponId); - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - weaponWithChildren, - botInventory - ); + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + weaponWithChildren, + botInventory + ); - Assert.AreEqual(ItemAddedResult.SUCCESS, result); + Assert.AreEqual(ItemAddedResult.NO_SPACE, result); + } - var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); - Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Horizontal); - } - - /// - /// Backpack with one bullet in top row, blocking gun from being placed at 0,0 - /// - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_fit_vertical_with_items_in_backpack() + /// + /// Fill all slots except for a 2x6 rectangle, with the top right corner filled, result should be no space + /// + [Test] + public void AddItemWithChildrenToEquipmentSlot_custom_gun_no_space() + { + var botInventory = new BotBaseInventory { Items = [] }; + var backpack = new Item { - var botInventory = new BotBaseInventory { Items = [] }; - var backpack = new Item - { - Id = new MongoId(), - // Has a 3hx5v grid first - Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Id = new MongoId(), + // Has a 4hx5v grid first + Template = ItemTpl.BACKPACK_GRUPPA_99_T30_BACKPACK_BLACK, + SlotId = "Backpack", + }; + botInventory.Items.Add(backpack); + var takenSlots = new List + { + new() { X = 1, Y = 0 }, + new() { X = 2, Y = 0 }, + new() { X = 3, Y = 0 }, + new() { X = 4, Y = 0 }, + new() { X = 2, Y = 1 }, + new() { X = 3, Y = 1 }, + new() { X = 4, Y = 1 }, + new() { X = 2, Y = 2 }, + new() { X = 3, Y = 2 }, + new() { X = 4, Y = 2 }, + new() { X = 2, Y = 3 }, + new() { X = 3, Y = 3 }, + new() { X = 4, Y = 3 }, + new() { X = 2, Y = 4 }, + new() { X = 3, Y = 4 }, + new() { X = 4, Y = 4 }, + new() { X = 2, Y = 5 }, + new() { X = 3, Y = 5 }, + new() { X = 4, Y = 5 }, + }; + foreach (var takenSlot in takenSlots) + { botInventory.Items.Add( new Item { @@ -163,335 +407,89 @@ namespace UnitTests.Tests.Helpers SlotId = "main", Location = new ItemLocation { - X = 0, - Y = 0, + X = (int)takenSlot.X.Value, + Y = (int)takenSlot.Y.Value, R = ItemRotation.Horizontal, }, Upd = new Upd { StackObjectsCount = 1 }, } ); - - var rootWeaponId = new MongoId(); - var weaponWithChildren = CreateMp18(rootWeaponId); - - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - weaponWithChildren, - botInventory - ); - - Assert.AreEqual(ItemAddedResult.SUCCESS, result); - - var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); - Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 1); - Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); } - /// - /// No space for gun - /// - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_no_space_in_first_grid_choose_second_grid() + var rootWeaponId = new MongoId(); + var weaponWithChildren = new List(); + var root = new Item { - var botInventory = new BotBaseInventory { Items = [] }; - var backpack = new Item - { - Id = new MongoId(), - // Has a 3hx5v grid first - Template = ItemTpl.BACKPACK_EBERLESTOCK_G2_GUNSLINGER_II_BACKPACK_DRY_EARTH, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Id = rootWeaponId, + Template = ItemTpl.ASSAULTRIFLE_MOLOT_ARMS_VPO136_VEPRKM_762X39_CARBINE, + }; + weaponWithChildren.Add(root); - botInventory.Items.AddRange( - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 0, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - }, - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 1, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - }, - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 2, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - } - ); - - var rootWeaponId = new MongoId(); - var weaponWithChildren = CreateMp18(rootWeaponId); - - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - weaponWithChildren, - botInventory - ); - - Assert.AreEqual(ItemAddedResult.SUCCESS, result); - var weaponRoot = weaponWithChildren.FirstOrDefault(item => item.Id == rootWeaponId); - Assert.AreEqual("1", weaponRoot.SlotId); - Assert.AreEqual((weaponRoot.Location as ItemLocation).X, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).Y, 0); - Assert.AreEqual((weaponRoot.Location as ItemLocation).R, ItemRotation.Vertical); - } - - /// - /// No space for gun - /// - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_no_space() + var stock = new Item { - var botInventory = new BotBaseInventory { Items = [] }; - var backpack = new Item - { - Id = new MongoId(), - // Has a 4hx5v grid first - Template = ItemTpl.BACKPACK_WARTECH_BERKUT_BB102_BACKPACK_ATACS_FG, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Id = new MongoId(), + Template = ItemTpl.STOCK_VPO136_VEPRKM_WOODEN, + ParentId = root.Id, + SlotId = "mod_stock", + }; + weaponWithChildren.Add(stock); - botInventory.Items.AddRange( - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 0, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - }, - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 1, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - }, - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 2, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - }, - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = 3, - Y = 0, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - } - ); - - var rootWeaponId = new MongoId(); - var weaponWithChildren = CreateMp18(rootWeaponId); - - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, - weaponWithChildren, - botInventory - ); - - Assert.AreEqual(ItemAddedResult.NO_SPACE, result); - } - - /// - /// Fill all slots except for a 2x6 rectangle, with the top right corner filled, result should be no space - /// - [TestMethod] - public void AddItemWithChildrenToEquipmentSlot_custom_gun_no_space() + var magazine = new Item { - var botInventory = new BotBaseInventory { Items = [] }; - var backpack = new Item - { - Id = new MongoId(), - // Has a 4hx5v grid first - Template = ItemTpl.BACKPACK_GRUPPA_99_T30_BACKPACK_BLACK, - SlotId = "Backpack", - }; - botInventory.Items.Add(backpack); + Id = new MongoId(), + Template = ItemTpl.MAGAZINE_366TKM_AK_AL_10RND, + ParentId = root.Id, + SlotId = "mod_magazine", + }; + weaponWithChildren.Add(magazine); - var takenSlots = new List - { - new() { X = 1, Y = 0 }, - new() { X = 2, Y = 0 }, - new() { X = 3, Y = 0 }, - new() { X = 4, Y = 0 }, - new() { X = 2, Y = 1 }, - new() { X = 3, Y = 1 }, - new() { X = 4, Y = 1 }, - new() { X = 2, Y = 2 }, - new() { X = 3, Y = 2 }, - new() { X = 4, Y = 2 }, - new() { X = 2, Y = 3 }, - new() { X = 3, Y = 3 }, - new() { X = 4, Y = 3 }, - new() { X = 2, Y = 4 }, - new() { X = 3, Y = 4 }, - new() { X = 4, Y = 4 }, - new() { X = 2, Y = 5 }, - new() { X = 3, Y = 5 }, - new() { X = 4, Y = 5 }, - }; - foreach (var takenSlot in takenSlots) - { - botInventory.Items.Add( - new Item - { - Id = new MongoId(), - Template = ItemTpl.AMMO_762X25TT_AKBS, - ParentId = backpack.Id, - SlotId = "main", - Location = new ItemLocation - { - X = (int)takenSlot.X.Value, - Y = (int)takenSlot.Y.Value, - R = ItemRotation.Horizontal, - }, - Upd = new Upd { StackObjectsCount = 1 }, - } - ); - } - - var rootWeaponId = new MongoId(); - var weaponWithChildren = new List(); - var root = new Item - { - Id = rootWeaponId, - Template = ItemTpl.ASSAULTRIFLE_MOLOT_ARMS_VPO136_VEPRKM_762X39_CARBINE, - }; - weaponWithChildren.Add(root); - - var stock = new Item - { - Id = new MongoId(), - Template = ItemTpl.STOCK_VPO136_VEPRKM_WOODEN, - ParentId = root.Id, - SlotId = "mod_stock", - }; - weaponWithChildren.Add(stock); - - var magazine = new Item - { - Id = new MongoId(), - Template = ItemTpl.MAGAZINE_366TKM_AK_AL_10RND, - ParentId = root.Id, - SlotId = "mod_magazine", - }; - weaponWithChildren.Add(magazine); - - var muzzle = new Item - { - Id = new MongoId(), - Template = ItemTpl.SILENCER_AKM_HEXAGON_762X39_SOUND_SUPPRESSOR, - ParentId = root.Id, - SlotId = "mod_muzzle", - }; - weaponWithChildren.Add(muzzle); - - var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( - [EquipmentSlots.Backpack], - rootWeaponId, - root.Template, - weaponWithChildren, - botInventory - ); - - Assert.AreEqual(ItemAddedResult.NO_SPACE, result); - } - - #endregion - - #region GetBotEquipmentRole - - [TestMethod] - public void GetBotEquipmentRole_assault() + var muzzle = new Item { - var result = _botGeneratorHelper.GetBotEquipmentRole("assault"); + Id = new MongoId(), + Template = ItemTpl.SILENCER_AKM_HEXAGON_762X39_SOUND_SUPPRESSOR, + ParentId = root.Id, + SlotId = "mod_muzzle", + }; + weaponWithChildren.Add(muzzle); - Assert.AreEqual("assault", result); - } + var result = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot( + [EquipmentSlots.Backpack], + rootWeaponId, + root.Template, + weaponWithChildren, + botInventory + ); - [TestMethod] - public void GetBotEquipmentRole_pmcBEAR() - { - var result = _botGeneratorHelper.GetBotEquipmentRole("pmcBEAR"); - - Assert.AreEqual("pmc", result); - } - - [TestMethod] - public void GetBotEquipmentRole_pmcBEAR_lowercase() - { - var result = _botGeneratorHelper.GetBotEquipmentRole("pmcbear"); - - Assert.AreEqual("pmc", result); - } - - #endregion + Assert.AreEqual(ItemAddedResult.NO_SPACE, result); } + + #endregion + + #region GetBotEquipmentRole + + [Test] + public void GetBotEquipmentRole_assault() + { + var result = _botGeneratorHelper.GetBotEquipmentRole("assault"); + + Assert.AreEqual("assault", result); + } + + [Test] + public void GetBotEquipmentRole_pmcBEAR() + { + var result = _botGeneratorHelper.GetBotEquipmentRole("pmcBEAR"); + + Assert.AreEqual("pmc", result); + } + + [Test] + public void GetBotEquipmentRole_pmcBEAR_lowercase() + { + var result = _botGeneratorHelper.GetBotEquipmentRole("pmcbear"); + + Assert.AreEqual("pmc", result); + } + + #endregion } diff --git a/UnitTests/Tests/Helpers/InventoryHelperTests.cs b/UnitTests/Tests/Helpers/InventoryHelperTests.cs index ba6855b0..b3ed09ae 100644 --- a/UnitTests/Tests/Helpers/InventoryHelperTests.cs +++ b/UnitTests/Tests/Helpers/InventoryHelperTests.cs @@ -1,204 +1,204 @@ -using SPTarkov.Server.Core.Helpers; +using NUnit.Framework; +using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; -using SPTarkov.Server.Core.Utils; -namespace UnitTests.Tests.Helpers +namespace UnitTests.Tests.Helpers; + +[TestFixture] +public class InventoryHelperTests { - [TestClass] - public class InventoryHelperTests + private InventoryHelper _helper; + private PresetHelper _presetHelper; + + [OneTimeSetUp] + public void Initialize() { - private InventoryHelper _helper; - private PresetHelper _presetHelper; + _helper = DI.GetInstance().GetService(); + _presetHelper = DI.GetInstance().GetService(); + } - [TestInitialize] - public void Initialize() + [Test] + public void GetItemSize_vss_val() + { + var vssValPreset = _presetHelper.GetDefaultPreset( + ItemTpl.MARKSMANRIFLE_VSS_VINTOREZ_9X39_SPECIAL_SNIPER_RIFLE + ); + + var result = _helper.GetItemSize( + ItemTpl.MARKSMANRIFLE_VSS_VINTOREZ_9X39_SPECIAL_SNIPER_RIFLE, + vssValPreset.Parent, + vssValPreset.Items + ); + + Assert.AreEqual(5, result.Item1); + Assert.AreEqual(2, result.Item2); + } + + [Test] + public void GetItemSize_m4a1() + { + var vssValPreset = _presetHelper.GetDefaultPreset( + ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE + ); + + var result = _helper.GetItemSize( + ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE, + vssValPreset.Parent, + vssValPreset.Items + ); + + Assert.AreEqual(5, result.Item1); + Assert.AreEqual(2, result.Item2); + } + + [Test] + public void GetItemSize_glock_17() + { + var vssValPreset = _presetHelper.GetDefaultPreset(ItemTpl.PISTOL_GLOCK_17_9X19); + + var result = _helper.GetItemSize( + ItemTpl.PISTOL_GLOCK_17_9X19, + vssValPreset.Parent, + vssValPreset.Items + ); + + Assert.AreEqual(2, result.Item1); + Assert.AreEqual(1, result.Item2); + } + + [Test] + public void GetItemSize_custom_vpo_136_6x2() + { + var rootWeaponId = new MongoId(); + + var weaponWithChildren = new List(); + var root = new Item { - _helper = DI.GetService(); - var databaseImporter = DI.GetService(); - _presetHelper = DI.GetService(); - Task.Factory.StartNew(() => - { - databaseImporter.OnLoad(); - }); - } + Id = rootWeaponId, + Template = ItemTpl.ASSAULTRIFLE_MOLOT_ARMS_VPO136_VEPRKM_762X39_CARBINE, + }; + weaponWithChildren.Add(root); - [TestMethod] - public void GetItemSize_vss_val() + var stock = new Item { - var vssValPreset = _presetHelper.GetDefaultPreset( - ItemTpl.MARKSMANRIFLE_VSS_VINTOREZ_9X39_SPECIAL_SNIPER_RIFLE - ); + Id = new MongoId(), + Template = ItemTpl.STOCK_VPO136_VEPRKM_WOODEN, + ParentId = root.Id, + SlotId = "mod_stock", + }; + weaponWithChildren.Add(stock); - var result = _helper.GetItemSize( - ItemTpl.MARKSMANRIFLE_VSS_VINTOREZ_9X39_SPECIAL_SNIPER_RIFLE, - vssValPreset.Parent, - vssValPreset.Items - ); - - Assert.AreEqual(5, result.Item1); - Assert.AreEqual(2, result.Item2); - } - - [TestMethod] - public void GetItemSize_m4a1() + var magazine = new Item { - var vssValPreset = _presetHelper.GetDefaultPreset( - ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE - ); + Id = new MongoId(), + Template = ItemTpl.MAGAZINE_366TKM_AK_AL_10RND, + ParentId = root.Id, + SlotId = "mod_magazine", + }; + weaponWithChildren.Add(magazine); - var result = _helper.GetItemSize( - ItemTpl.ASSAULTRIFLE_COLT_M4A1_556X45_ASSAULT_RIFLE, - vssValPreset.Parent, - vssValPreset.Items - ); - - Assert.AreEqual(5, result.Item1); - Assert.AreEqual(2, result.Item2); - } - - [TestMethod] - public void GetItemSize_glock_17() + var muzzle = new Item { - var vssValPreset = _presetHelper.GetDefaultPreset(ItemTpl.PISTOL_GLOCK_17_9X19); + Id = new MongoId(), + Template = ItemTpl.SILENCER_AKM_HEXAGON_762X39_SOUND_SUPPRESSOR, + ParentId = root.Id, + SlotId = "mod_muzzle", + }; + weaponWithChildren.Add(muzzle); - var result = _helper.GetItemSize( - ItemTpl.PISTOL_GLOCK_17_9X19, - vssValPreset.Parent, - vssValPreset.Items - ); + var result = _helper.GetItemSize(root.Template, rootWeaponId, weaponWithChildren); - Assert.AreEqual(2, result.Item1); - Assert.AreEqual(1, result.Item2); - } + Assert.AreEqual(6, result.Item1); + Assert.AreEqual(2, result.Item2); + } - [TestMethod] - public void GetItemSize_custom_vpo_136_6x2() + [Test] + public void GetItemSize_uzi_unfolded() + { + var rootWeaponId = new MongoId(); + + var weaponWithChildren = new List(); + var root = new Item { - var rootWeaponId = new MongoId(); + Id = rootWeaponId, + Template = ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, + }; + weaponWithChildren.Add(root); - var weaponWithChildren = new List(); - var root = new Item - { - Id = rootWeaponId, - Template = ItemTpl.ASSAULTRIFLE_MOLOT_ARMS_VPO136_VEPRKM_762X39_CARBINE, - }; - weaponWithChildren.Add(root); - - var stock = new Item - { - Id = new MongoId(), - Template = ItemTpl.STOCK_VPO136_VEPRKM_WOODEN, - ParentId = root.Id, - SlotId = "mod_stock", - }; - weaponWithChildren.Add(stock); - - var magazine = new Item - { - Id = new MongoId(), - Template = ItemTpl.MAGAZINE_366TKM_AK_AL_10RND, - ParentId = root.Id, - SlotId = "mod_magazine", - }; - weaponWithChildren.Add(magazine); - - var muzzle = new Item - { - Id = new MongoId(), - Template = ItemTpl.SILENCER_AKM_HEXAGON_762X39_SOUND_SUPPRESSOR, - ParentId = root.Id, - SlotId = "mod_muzzle", - }; - weaponWithChildren.Add(muzzle); - - var result = _helper.GetItemSize(root.Template, rootWeaponId, weaponWithChildren); - - Assert.AreEqual(6, result.Item1); - Assert.AreEqual(2, result.Item2); - } - - [TestMethod] - public void GetItemSize_uzi_unfolded() + var stock = new Item { - var rootWeaponId = new MongoId(); + Id = new MongoId(), + Template = "6699249f3c4fda6471005cba", + ParentId = root.Id, + SlotId = "mod_stock", + }; + weaponWithChildren.Add(stock); - var weaponWithChildren = new List(); - var root = new Item - { - Id = rootWeaponId, - Template = ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, - }; - weaponWithChildren.Add(root); - - var stock = new Item - { - Id = new MongoId(), - Template = "6699249f3c4fda6471005cba", - ParentId = root.Id, - SlotId = "mod_stock", - }; - weaponWithChildren.Add(stock); - - var magazine = new Item - { - Id = new MongoId(), - Template = "669927203c4fda6471005cbe", - ParentId = root.Id, - SlotId = "mod_magazine", - }; - weaponWithChildren.Add(magazine); - - var result = _helper.GetItemSize( - ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, - rootWeaponId, - weaponWithChildren - ); - - Assert.AreEqual(3, result.Item1); - Assert.AreEqual(2, result.Item2); - } - - [TestMethod] - public void GetItemSize_uzi_folded() + var magazine = new Item { - var rootWeaponId = new MongoId(); + Id = new MongoId(), + Template = "669927203c4fda6471005cbe", + ParentId = root.Id, + SlotId = "mod_magazine", + }; + weaponWithChildren.Add(magazine); - var weaponWithChildren = new List(); - var root = new Item + var result = _helper.GetItemSize( + ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, + rootWeaponId, + weaponWithChildren + ); + + Assert.AreEqual(3, result.Item1); + Assert.AreEqual(2, result.Item2); + } + + [Test] + public void GetItemSize_uzi_folded() + { + var rootWeaponId = new MongoId(); + + var weaponWithChildren = new List(); + var root = new Item + { + Id = rootWeaponId, + Template = ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, + }; + weaponWithChildren.Add(root); + + var stock = new Item + { + Id = new MongoId(), + Template = "6699249f3c4fda6471005cba", + ParentId = root.Id, + SlotId = "mod_stock", + Upd = new Upd { - Id = rootWeaponId, - Template = ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, - }; - weaponWithChildren.Add(root); + Foldable = new UpdFoldable + { + Folded = true + } + }, + }; + weaponWithChildren.Add(stock); - var stock = new Item - { - Id = new MongoId(), - Template = "6699249f3c4fda6471005cba", - ParentId = root.Id, - SlotId = "mod_stock", - Upd = new Upd { Foldable = new UpdFoldable { Folded = true } }, - }; - weaponWithChildren.Add(stock); + var magazine = new Item + { + Id = new MongoId(), + Template = "669927203c4fda6471005cbe", + ParentId = root.Id, + SlotId = "mod_magazine", + }; + weaponWithChildren.Add(magazine); - var magazine = new Item - { - Id = new MongoId(), - Template = "669927203c4fda6471005cbe", - ParentId = root.Id, - SlotId = "mod_magazine", - }; - weaponWithChildren.Add(magazine); + var result = _helper.GetItemSize( + ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, + rootWeaponId, + weaponWithChildren + ); - var result = _helper.GetItemSize( - ItemTpl.SMG_IWI_UZI_9X19_SUBMACHINE_GUN, - rootWeaponId, - weaponWithChildren - ); - - Assert.AreEqual(2, result.Item1); - Assert.AreEqual(2, result.Item2); - } + Assert.AreEqual(2, result.Item1); + Assert.AreEqual(2, result.Item2); } } diff --git a/UnitTests/Tests/MongoIDTests.cs b/UnitTests/Tests/MongoIDTests.cs index 03063612..2756486e 100644 --- a/UnitTests/Tests/MongoIDTests.cs +++ b/UnitTests/Tests/MongoIDTests.cs @@ -1,82 +1,81 @@ using System.Collections.Concurrent; using System.Diagnostics; +using NUnit.Framework; using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Models.Common; -namespace UnitTests.Tests +namespace UnitTests.Tests; + +[TestFixture] +public class MongoIDTests { - [TestClass] - public class MongoIDTests + [OneTimeSetUp] + public void Initialize() { } + + [Test] + public void GenerateTest() { - [TestInitialize] - public void Initialize() { } - - [TestMethod] - public void GenerateTest() + // Generate 100 MongoId's + for (var i = 0; i < 100; i++) { - // Generate 100 MongoId's - for (var i = 0; i < 100; i++) - { - // Invalid mongoId character - var result = new MongoId(); + // Invalid mongoId character + var result = new MongoId(); - // Invalid mongoId length - var test = result.IsValidMongoId(); + // Invalid mongoId length + var test = result.IsValidMongoId(); - Assert.IsTrue(test, $"IsValidMongoId(): `{result}` is not a valid MongoId."); - } - } - - [TestMethod] - [DataRow( - "677ddb67406e9918a0264bbz", - false, - "677ddb67406e9918a0264bbz contains invalid char `z`, but result was true" - )] - [DataRow( - "677ddb67406e9918a0264bbcc", - false, - "677ddb67406e9918a0264bbcc is 25 characters, but result was true" - )] - [DataRow( - "677ddb67406e9918a0264bbc", - true, - "IsValidMongoId() `677ddb67406e9918a0264bbc` is a valid mongoId, but result was false" - )] - public void IsValidMongoIdTest(string mongoId, bool passes, string failMessage) - { - var result = new MongoId(mongoId); - Assert.AreEqual(passes, passes, result, failMessage); - } - - [TestMethod] - public void MultiThreadedMongoIDGenerationTest() - { - var concurrentBag = new ConcurrentBag(); - var random = new Random(); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Parallel.For( - 0, - 1000, - i => - { - Thread.Sleep(random.Next(0, 10)); - var mongoId = new MongoId(); - concurrentBag.Add(mongoId); - } - ); - - stopwatch.Stop(); - Console.WriteLine($"Elapsed time: {stopwatch.ElapsedMilliseconds} ms"); - var uniqueCount = concurrentBag.Distinct().Count(); - var totalCount = concurrentBag.Count; - Assert.AreEqual( - totalCount, - uniqueCount, - $"Expected all generated MongoId's to be unique, but found: {totalCount - uniqueCount} duplicates." - ); + Assert.IsTrue(test, $"IsValidMongoId(): `{result}` is not a valid MongoId."); } } + + [TestCase( + "677ddb67406e9918a0264bbz", + false, + "677ddb67406e9918a0264bbz contains invalid char `z`, but result was true" + )] + [TestCase( + "677ddb67406e9918a0264bbcc", + false, + "677ddb67406e9918a0264bbcc is 25 characters, but result was true" + )] + [TestCase( + "677ddb67406e9918a0264bbc", + true, + "IsValidMongoId() `677ddb67406e9918a0264bbc` is a valid mongoId, but result was false" + )] + public void IsValidMongoIdTest(string mongoId, bool passes, string failMessage) + { + var result = new MongoId(mongoId); + Assert.AreEqual(passes, passes, result, failMessage); + } + + [Test] + public void MultiThreadedMongoIDGenerationTest() + { + var concurrentBag = new ConcurrentBag(); + var random = new Random(); + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Parallel.For( + 0, + 1000, + i => + { + Thread.Sleep(random.Next(0, 10)); + var mongoId = new MongoId(); + concurrentBag.Add(mongoId); + } + ); + + stopwatch.Stop(); + Console.WriteLine($"Elapsed time: {stopwatch.ElapsedMilliseconds} ms"); + var uniqueCount = concurrentBag.Distinct().Count(); + var totalCount = concurrentBag.Count; + Assert.AreEqual( + totalCount, + uniqueCount, + $"Expected all generated MongoId's to be unique, but found: {totalCount - uniqueCount} duplicates." + ); + } } diff --git a/UnitTests/Tests/Utils/JsonUtilTests.cs b/UnitTests/Tests/Utils/JsonUtilTests.cs index 630919c5..04d7a36f 100644 --- a/UnitTests/Tests/Utils/JsonUtilTests.cs +++ b/UnitTests/Tests/Utils/JsonUtilTests.cs @@ -1,20 +1,21 @@ +using NUnit.Framework; using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Utils; namespace UnitTests.Tests.Utils; -[TestClass] +[TestFixture] public class JsonUtilTests { private JsonUtil _jsonUtil; - [TestInitialize] + [OneTimeSetUp] public void Initialize() { - _jsonUtil = DI.GetService(); + _jsonUtil = DI.GetInstance().GetService(); } - [TestMethod] + [Test] public void SerializeAndDeserialize_WithDictionaryOfETFEnum_ExpectCorrectParsing() { var value = new Dictionary diff --git a/UnitTests/Tests/Utils/MathUtilTests.cs b/UnitTests/Tests/Utils/MathUtilTests.cs index 8e94704b..bb879115 100644 --- a/UnitTests/Tests/Utils/MathUtilTests.cs +++ b/UnitTests/Tests/Utils/MathUtilTests.cs @@ -1,20 +1,21 @@ +using NUnit.Framework; using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Utils; namespace UnitTests.Tests.Utils; -[TestClass] +[TestFixture] public class MathUtilTests { private MathUtil _mathUtil; - [TestInitialize] + [OneTimeSetUp] public void Initialize() { - _mathUtil = DI.GetService(); + _mathUtil = DI.GetInstance().GetService(); } - [TestMethod] + [Test] public void ListSumTest() { var test = new List { 1.1f, 2.1f, 3.3f }; @@ -25,7 +26,7 @@ public class MathUtilTests Assert.AreEqual(expected, actual, $"ListSum() Expected: {expected}, Actual: {actual}"); } - [TestMethod] + [Test] public void ListCumSumTest() { var test = new List { 1f, 2f, 3f, 4f }; @@ -44,7 +45,7 @@ public class MathUtilTests } } - [TestMethod] + [Test] public void ListProductTest() { var test = new List { 1f, 2f, 3f, 4f }; @@ -63,7 +64,7 @@ public class MathUtilTests } } - [TestMethod] + [Test] public void ListAddTest() { var test = new List { 1f, 2f, 3f, 4f }; @@ -82,7 +83,7 @@ public class MathUtilTests } } - [TestMethod] + [Test] public void MapToRangeTest() { const double expected = 2; @@ -92,22 +93,21 @@ public class MathUtilTests Assert.AreEqual(expected, actual, $"MapToRange() Expected: {expected}, Actual: {actual}"); } - [TestMethod] - [DataRow( + [TestCase( 15d, new double[] { 1, 10, 20, 30, 40, 50, 60 }, new double[] { 11000, 20000, 32000, 45000, 58000, 70000, 82000 }, 26000d )] - [DataRow(5d, new double[] { 1, 10 }, new double[] { 0, 1000 }, 444.44444444444446d)] - [DataRow( + [TestCase(5d, new double[] { 1, 10 }, new double[] { 0, 1000 }, 444.44444444444446d)] + [TestCase( 12d, new double[] { 1, 10, 500, 510 }, new double[] { 0, 10, 20, 30 }, 10.040816326530612d )] - [DataRow(1d, new double[] { 1, 10, 500, 510 }, new double[] { 2, 10, 20, 30 }, 2d)] - [DataRow(11d, new double[] { 1, 10 }, new double[] { 2, 10 }, 10d)] + [TestCase(1d, new double[] { 1, 10, 500, 510 }, new double[] { 2, 10, 20, 30 }, 2d)] + [TestCase(11d, new double[] { 1, 10 }, new double[] { 2, 10 }, 10d)] public void InterpTest(double input, double[] x, double[] y, double expected) { var actual = _mathUtil.Interp1(input, x.ToList(), y.ToList()); diff --git a/UnitTests/Tests/Utils/MongoIdTests.cs b/UnitTests/Tests/Utils/MongoIdTests.cs index bd137668..c2cef3d9 100644 --- a/UnitTests/Tests/Utils/MongoIdTests.cs +++ b/UnitTests/Tests/Utils/MongoIdTests.cs @@ -1,39 +1,39 @@ -using SPTarkov.Server.Core.Extensions; +using NUnit.Framework; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Models.Common; -namespace UnitTests.Tests.Utils +namespace UnitTests.Tests.Utils; + +/// +/// Unit tests for the struct. +/// +[TestFixture] +public class MongoIdTests { /// - /// Unit tests for the struct. + /// Test that generates 1000 and ensures they are all valid.
+ /// Validity is checked by ensuring the ID is non-empty, exactly 24 characters, and matches the expected format. ///
- [TestClass] - public class MongoIdTests + [Test] + public void Generate_ShouldProduceValidMongoIds() { - /// - /// Test that generates 1000 and ensures they are all valid.
- /// Validity is checked by ensuring the ID is non-empty, exactly 24 characters, and matches the expected format. - ///
- [TestMethod] - public void Generate_ShouldProduceValidMongoIds() + var invalidIds = new List(); + + for (var i = 0; i < 1000; i++) { - var invalidIds = new List(); + var id = new MongoId(); + var idStr = id.ToString(); - for (var i = 0; i < 1000; i++) + if (string.IsNullOrWhiteSpace(idStr) || idStr.Length != 24 || !id.IsValidMongoId()) { - var id = new MongoId(); - var idStr = id.ToString(); - - if (string.IsNullOrWhiteSpace(idStr) || idStr.Length != 24 || !id.IsValidMongoId()) - { - invalidIds.Add(idStr); - } + invalidIds.Add(idStr); } - - Assert.AreEqual( - 0, - invalidIds.Count, - $"Invalid MongoIds found: {string.Join(", ", invalidIds)}" - ); } + + Assert.AreEqual( + 0, + invalidIds.Count, + $"Invalid MongoIds found: {string.Join(", ", invalidIds)}" + ); } } diff --git a/UnitTests/Tests/Utils/RandomUtilTests.cs b/UnitTests/Tests/Utils/RandomUtilTests.cs index c1abdb15..607e35f0 100644 --- a/UnitTests/Tests/Utils/RandomUtilTests.cs +++ b/UnitTests/Tests/Utils/RandomUtilTests.cs @@ -1,19 +1,21 @@ +using NUnit.Framework; using SPTarkov.Server.Core.Utils; namespace UnitTests.Tests.Utils; -[TestClass] +[TestFixture] +[TestFixture] public sealed class RandomUtilTests { private RandomUtil _randomUtil; - [TestInitialize] + [OneTimeSetUp] public void Initialize() { - _randomUtil = DI.GetService(); + _randomUtil = DI.GetInstance().GetService(); } - [TestMethod] + [Test] public void GetIntTest() { // Run 10000 test cases @@ -30,7 +32,7 @@ public sealed class RandomUtilTests } } - [TestMethod] + [Test] public void GetIntExTest() { // Run 10000 test cases @@ -45,7 +47,7 @@ public sealed class RandomUtilTests } } - [TestMethod] + [Test] public void GetDoubleTest() { // Run 10000 test cases @@ -62,7 +64,7 @@ public sealed class RandomUtilTests } } - [TestMethod] + [Test] public void GetPercentOfValueTest() { const float expected = 45.5f; @@ -76,7 +78,7 @@ public sealed class RandomUtilTests ); } - [TestMethod] + [Test] public void ReduceValueByPercentTest() { const float expected = 54.5f; @@ -90,7 +92,7 @@ public sealed class RandomUtilTests ); } - [TestMethod] + [Test] public void GetChance100Test() { for (var i = 0; i < 100; i++) @@ -120,7 +122,7 @@ public sealed class RandomUtilTests // TODO: Missing methods between these two - [TestMethod] + [Test] public void RandIntTest() { for (var i = 0; i < 100; i++) @@ -148,7 +150,7 @@ public sealed class RandomUtilTests } } - [TestMethod] + [Test] public void RandNumTest() { for (var i = 0; i < 10000; i++) @@ -190,7 +192,7 @@ public sealed class RandomUtilTests } } - [TestMethod] + [Test] public void ShuffleTest() { var testList = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; @@ -205,19 +207,17 @@ public sealed class RandomUtilTests ); } - [TestMethod] - [DataRow(0.1, 1)] - [DataRow(0.0001, 4)] - [DataRow(0, 0)] - [DataRow(10000000, 0)] - [DataRow(0.000_000_000_000_000_000_000_000_1D, 25)] + [TestCase(0.1, 1)] + [TestCase(0.0001, 4)] + [TestCase(0, 0)] + [TestCase(10000000, 0)] + [TestCase(0.000_000_000_000_000_000_000_000_1D, 25)] public void GetNumberPrecision_WithDoubles_ReturnsDecimalPoints(double value, int decimalPoints) { Assert.AreEqual(decimalPoints, _randomUtil.GetNumberPrecision(value)); } - [TestMethod] - [DataRow(new[] { "test" }, "test", "Expected first array value")] + [TestCase(new[] { "test" }, "test", "Expected first array value")] public void GetArrayValueTest(string[] input, string expectedOutput, string failMessage) { var result = _randomUtil.GetArrayValue(input); diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index c4dde9ba..20b99b9f 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -6,10 +6,8 @@ - - - - + +