Skip to content

Commit

Permalink
add test fixture for territory instances, to fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy committed Jul 28, 2024
1 parent 669c506 commit 16aa0ab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ScoutHelper/Utils/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ Func<IEnumerable<T>, IEnumerable<U>, R> transform
.AsPairs()
.AsList();

public static IEnumerable<(A first, B second)> PairWith<A, B>(
this IEnumerable<A> source,
Func<A, B> secondSelector
) =>
source.Select(first => (first, secondSelector(first)));

#endregion

#region tuples
Expand Down
25 changes: 25 additions & 0 deletions ScoutHelperTests/TestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ScoutHelper;
using ScoutHelper.Config;
using ScoutHelper.Models;
using static ScoutHelper.Utils.Utils;

namespace ScoutHelperTests;

public class TestFixture : IDisposable {
public Configuration Conf { get; }

public TestFixture() {
Conf = new Configuration();
var territoryIds = GetEnumValues<Territory>()
.PairWith(territory => (uint)territory)
.AsList();
territoryIds
.Select(territoryId => (territoryId.second, territoryId.first.DefaultInstances()))
.UseToUpdate(Conf.Instances);
TerritoryExtensions.SetTerritoryInstances(Conf, territoryIds);
}

public void Dispose() {
// nothing to dispose yet
}
}
6 changes: 5 additions & 1 deletion ScoutHelperTests/Utils/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

namespace ScoutHelperTests.Utils;

public class UtilsTests {
public class UtilsTests : IClassFixture<TestFixture> {
private readonly TestFixture _fixture;

public UtilsTests(TestFixture fixture) {
_fixture = fixture;
}

[Fact]
public void WorldName_NoPlayer() {
Expand Down

0 comments on commit 16aa0ab

Please sign in to comment.