Skip to content

Commit

Permalink
Merge pull request #62 from xin9le/feature/refactor-test
Browse files Browse the repository at this point in the history
Refactor unit testing
  • Loading branch information
xin9le authored Dec 26, 2024
2 parents 13bcb7e + 3cfd19e commit 2c166c6
Show file tree
Hide file tree
Showing 14 changed files with 2,812 additions and 2,384 deletions.
944 changes: 512 additions & 432 deletions src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.cs

Large diffs are not rendered by default.

122 changes: 66 additions & 56 deletions src/insights/FastEnum.UnitTests/Cases/Generators/BasicTests.tt

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions src/insights/FastEnum.UnitTests/Cases/Generators/EmptyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,49 @@ public void IsDefined()
[TestMethod]
public void Parse()
{
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>((string?)null)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("")).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>(" ")).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("ABCDE")).Should().Throw<ArgumentException>();
FastEnum.Parse<TEnum, TBooster>("123").Should().Be((TEnum)123);
const bool ignoreCase = false;
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>((string?)null, ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("", ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>(" ", ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("ABCDE", ignoreCase)).Should().Throw<ArgumentException>();
FastEnum.Parse<TEnum, TBooster>("123", ignoreCase).Should().Be((TEnum)123);
}


[TestMethod]
public void ParseIgnoreCase()
{
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>((string?)null)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("", true)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>(" ", true)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("ABCDE", true)).Should().Throw<ArgumentException>();
FastEnum.Parse<TEnum, TBooster>("123").Should().Be((TEnum)123);
const bool ignoreCase = true;
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>((string?)null, ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("", ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>(" ", ignoreCase)).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => FastEnum.Parse<TEnum, TBooster>("ABCDE", ignoreCase)).Should().Throw<ArgumentException>();
FastEnum.Parse<TEnum, TBooster>("123", ignoreCase).Should().Be((TEnum)123);
}


[TestMethod]
public void TryParse()
{
FastEnum.TryParse<TEnum, TBooster>((string?)null, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("", out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>(" ", out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("ABCDE", out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("123", out var r).Should().BeTrue();
const bool ignoreCase = false;
FastEnum.TryParse<TEnum, TBooster>((string?)null, ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>(" ", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("ABCDE", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("123", ignoreCase, out var r).Should().BeTrue();
r.Should().Be((TEnum)123);
}


[TestMethod]
public void TryParseIgnoreCase()
{
FastEnum.TryParse<TEnum, TBooster>((string?)null, true, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("", true, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>(" ", true, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("ABCDE", true, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("123", true, out var r).Should().BeTrue();
const bool ignoreCase = true;
FastEnum.TryParse<TEnum, TBooster>((string?)null, ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>(" ", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("ABCDE", ignoreCase, out var _).Should().BeFalse();
FastEnum.TryParse<TEnum, TBooster>("123", ignoreCase, out var r).Should().BeTrue();
r.Should().Be((TEnum)123);
}

Expand Down
Loading

0 comments on commit 2c166c6

Please sign in to comment.