generated from goatcorp/SamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first test for mob manager and get lumina mocking working
- Loading branch information
Showing
9 changed files
with
1,687 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Dalamud; | ||
using Dalamud.Plugin.Services; | ||
using FsCheck; | ||
using FsCheck.Xunit; | ||
using JetBrains.Annotations; | ||
using Lumina.Excel.GeneratedSheets2; | ||
using Moq; | ||
using ScoutHelper.Managers; | ||
using ScoutHelperTests.TestUtils.FsCheck; | ||
using ScoutHelperTests.TestUtils.MoqHelpers; | ||
|
||
namespace ScoutHelperTests.Managers; | ||
|
||
[TestSubject(typeof(MobManager))] | ||
public class MobManagerTest { | ||
private readonly Mock<IPluginLog> _log = new(MockBehavior.Strict); | ||
private readonly Mock<IDataManager> _dataManager = new(MockBehavior.Strict); | ||
|
||
[Property] | ||
public Property IndexContainsAllElements() => FsCheckUtils.ForAll( | ||
Arb.Default.UInt32().DistinctListOfPairsWith(Arbs.String()), | ||
(npcNames) => { | ||
// DATA | ||
var npcNameSheet = MockExcelSheet.Create<BNpcName>() | ||
.AddRows(npcNames.Select(name => MockBNpcName.Create(name.Item1, name.Item2))); | ||
// GIVEN | ||
_log.Setup(log => log.Debug(It.IsAny<string>())); | ||
_dataManager.Setup(dm => dm.GetExcelSheet<BNpcName>(It.IsAny<ClientLanguage>())) | ||
.Returns(npcNameSheet); | ||
// WHEN | ||
var actual = new MobManager(_log.Object, _dataManager.Object); | ||
// THEN | ||
_dataManager.Verify(manager => manager.GetExcelSheet<BNpcName>(ClientLanguage.English)); | ||
_log.Verify(log => log.Debug("Building mob data from game files...")); | ||
_log.Verify(log => log.Debug("Mob data built.")); | ||
_dataManager.VerifyNoOtherCalls(); | ||
_log.VerifyNoOtherCalls(); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ScoutHelperTests.TestUtils.MoqHelpers; | ||
|
||
/** | ||
* an interface for marking mock versions of excel sheet types. | ||
* used to limit scope of extension methods. | ||
*/ | ||
public interface IMockExcelRow { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Lumina.Excel.GeneratedSheets2; | ||
using ScoutHelper.Utils; | ||
|
||
namespace ScoutHelperTests.TestUtils.MoqHelpers; | ||
|
||
public class MockBNpcName : BNpcName, IMockExcelRow { | ||
private MockBNpcName(uint rowId, string singular) { | ||
RowId = rowId; | ||
this.SetProperty("Singular", singular.ToSeString()); | ||
} | ||
|
||
public static MockBNpcName Create(uint rowId, string singular) { | ||
return new MockBNpcName(rowId, singular); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections; | ||
using Lumina; | ||
using Lumina.Data; | ||
using Lumina.Data.Files.Excel; | ||
using Lumina.Excel; | ||
|
||
namespace ScoutHelperTests.TestUtils.MoqHelpers; | ||
|
||
public class MockExcelSheet<T> : ExcelSheet<T>, IEnumerable<T> where T : ExcelRow { | ||
private readonly List<T> _rows = new List<T>(); | ||
|
||
internal MockExcelSheet() : base(new ExcelHeaderFile(), "test sheet", Language.English, null) { } | ||
|
||
public new IEnumerator<T> GetEnumerator() => _rows.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
public MockExcelSheet<T> AddRow(T row) { | ||
_rows.Add(row); | ||
return this; | ||
} | ||
|
||
public MockExcelSheet<T> AddRows(IEnumerable<T> rows) { | ||
_rows.AddRange(rows); | ||
return this; | ||
} | ||
} | ||
|
||
public static class MockExcelSheet { | ||
public static MockExcelSheet<T> Create<T>() where T : ExcelRow => new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Lumina.Excel; | ||
|
||
namespace ScoutHelperTests.TestUtils.MoqHelpers; | ||
|
||
public static class MoqUtils { | ||
#region Mocks | ||
|
||
public static void SetProperty<T>(this T excelRow, string propertyName, object? value) | ||
where T : ExcelRow, IMockExcelRow { | ||
excelRow! | ||
.GetType()! | ||
.BaseType! | ||
.GetProperty(propertyName)! | ||
.GetSetMethod(true)! | ||
.Invoke(excelRow, new object?[] { value }); | ||
} | ||
|
||
#endregion | ||
} |
Oops, something went wrong.