Skip to content

Commit

Permalink
rearrange existing unit tests to match new namespace structure for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy committed Feb 3, 2024
1 parent 5c7ae95 commit 1f2fcbb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 56 deletions.
1 change: 1 addition & 0 deletions ScoutHelperTests/ScoutHelperTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="FsCheck" Version="2.16.6"/>
<PackageReference Include="FsCheck.Xunit" Version="2.16.6"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1"/>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="xunit" Version="2.4.2"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using FsCheck;
using ScoutHelper;
using ScoutHelper.Models;
using static ScoutHelper.Utils.Utils;

namespace ScoutHelperTests.Util.FsCheck;
namespace ScoutHelperTests.TestUtils.FsCheck;

public static class Arbs {
public static Arbitrary<string> NonEmptyString() =>
Expand All @@ -11,9 +12,7 @@ public static Arbitrary<string> NonEmptyString() =>
.Select(nes => nes.ToString())
.ToArbitrary();

public static Arbitrary<T> OfEnum<T>() where T : struct, Enum =>
Gen.Elements(Enum.GetValues<T>())
.ToArbitrary();
public static Arbitrary<T> OfEnum<T>() where T : struct, Enum => Gen.Elements(Enum.GetValues<T>()).ToArbitrary();

public static Arbitrary<List<T>> ListOf<T>(Gen<T> gen) =>
Gen.ListOf(gen)
Expand Down Expand Up @@ -60,7 +59,7 @@ public static Arbitrary<CopyTemplateArb> CopyTemplate() {
.Select(
arbs => (arbs, new List<(string?, string?)>() {
("{#}", arbs.a.Count.ToString()),
("{#max}", Utils.PatchMaxMarks[arbs.d].ToString()),
("{#max}", PatchMaxMarks[arbs.d].ToString()),
("{tracker}", arbs.b),
("{world}", arbs.c),
("{patch}", arbs.d.ToString()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FsCheck;
using Random = FsCheck.Random;

namespace ScoutHelperTests.Util.FsCheck;
namespace ScoutHelperTests.TestUtils.FsCheck;

public static class FsCheckUtils {
public static Gen<A> Zip<A>(Gen<A> a) => a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Collections.Immutable;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Plugin.Services;
using System.Collections.Immutable;
using FluentAssertions;
using FsCheck;
using FsCheck.Xunit;
using Moq;
using JetBrains.Annotations;
using ScoutHelper;
using ScoutHelperTests.Util.FsCheck;
using ScoutHelperTests.TestUtils.FsCheck;
using CollectionExtensions = ScoutHelper.CollectionExtensions;

namespace ScoutHelperTests;

public class UtilsTests {
namespace ScoutHelperTests.Utils;

[TestSubject(typeof(CollectionExtensions))]
public class CollectionExtensionsTest {
[Fact]
public void ForEach_EmptyEnumerable() {
// DATA
Expand Down Expand Up @@ -123,46 +122,4 @@ public Property VerifyEnumDictionary_ReturnsImmutableDictionary() => FsCheckUtil
actual.Should().BeAssignableTo<ImmutableDictionary<TestEnum, string>>();
}
);

[Fact]
public void WorldName_NoPlayer() {
// DATA
var clientState = new Mock<IClientState>();

// GIVEN
clientState.Setup(state => state.LocalPlayer).Returns(null as PlayerCharacter);

// WHEN
var worldName = clientState.Object.WorldName();

// THEN
worldName.Should().Be("Not Found");
}

[Property]
public Property FormatTemplate() => FsCheckUtils.ForAll(
Arbs.CopyTemplate(),
copyTemplate => {
// WHEN
var actual = Utils.FormatTemplate(
copyTemplate.Template,
copyTemplate.TrainList,
copyTemplate.Tracker,
copyTemplate.WorldName,
copyTemplate.HighestPatch,
copyTemplate.Link
);
// THEN
actual.Should().Be(copyTemplate.Expected);
}
);
}

internal enum TestEnum {
A,
B,
C,
D,
E
}
57 changes: 57 additions & 0 deletions ScoutHelperTests/Utils/UtilsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Plugin.Services;
using FluentAssertions;
using FsCheck;
using FsCheck.Xunit;
using Moq;
using ScoutHelper.Utils;
using ScoutHelperTests.TestUtils.FsCheck;
using static ScoutHelper.Utils.Utils;

namespace ScoutHelperTests.Utils;

public class UtilsTests {


[Fact]
public void WorldName_NoPlayer() {
// DATA
var clientState = new Mock<IClientState>();

// GIVEN
clientState.Setup(state => state.LocalPlayer).Returns(null as PlayerCharacter);

// WHEN
var worldName = clientState.Object.WorldName();

// THEN
worldName.Should().Be("Not Found");
}

[Property]
public Property FormatTemplate_FormatsCorrectly() => FsCheckUtils.ForAll(
Arbs.CopyTemplate(),
copyTemplate => {
// WHEN
var actual = FormatTemplate(
copyTemplate.Template,
copyTemplate.TrainList,
copyTemplate.Tracker,
copyTemplate.WorldName,
copyTemplate.HighestPatch,
copyTemplate.Link
);
// THEN
actual.Should().Be(copyTemplate.Expected);
}
);
}

internal enum TestEnum {
A,
B,
C,
D,
E
}

0 comments on commit 1f2fcbb

Please sign in to comment.