Skip to content

Commit

Permalink
use TheoryData
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikus1993 committed Jan 27, 2024
1 parent 29be1c2 commit 7c57e1d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async IAsyncEnumerable<XboxGame> Filter(IAsyncEnumerable<XboxGame> games,
ArgumentNullException.ThrowIfNull(games);
await foreach (var game in games.WithCancellation(cancellationToken))
{
if (game.PromotionPercentage >= _minimumPercentage)
if (game.PromotionPercentage() >= _minimumPercentage)
{
yield return game;
}
Expand Down
2 changes: 1 addition & 1 deletion src/XboxPromotionCheckerBot.App/Core/Types/XboxGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override int GetHashCode()
public Uri Link { get; }
public GamePrice GamePrice { get; }

public PromotionPercentage PromotionPercentage => GamePrice.CalculatePromotionPercentage();
public PromotionPercentage PromotionPercentage() => GamePrice.CalculatePromotionPercentage();

public static XboxGame Create(Title title, Uri link, GamePrice gamePrice)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ private static IEnumerable<Embed> MapEmbeds(IEnumerable<XboxGame> games)
}
}

private static Color GetColorByPromotionLevel(XboxGame game) => game.PromotionPercentage.Value switch
private static Color GetColorByPromotionLevel(XboxGame game) => game.PromotionPercentage() switch
{
> 90 => Color.Gold,
> 70 => Color.Red,
> 50 => Color.Green,
{ Value:> 90 } => Color.Gold,
{ Value:> 70 } => Color.Red,
{ Value:> 50 } => Color.Green,
_ => Color.Default,
};
}
26 changes: 13 additions & 13 deletions tests/XboxPromotionCheckerBot.App.Tests/Core/Types/XboxGameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ namespace XboxPromotionCheckerBot.App.Tests.Core.Types;
public class XboxGameTests
{
[Theory]
[MemberData(nameof(PromotionPercentageData))]
[ClassData(typeof(PromotionPercentageData))]
public void TestPromotionPercentage(XboxGame game, PromotionPercentage promotion)
{
var subject = game.PromotionPercentage;
var subject = game.PromotionPercentage();

Assert.Equal(promotion, subject);
}
public static IEnumerable<object[]> PromotionPercentageData =>
new List<object[]>
{
new object[] { XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(10, 20)), new PromotionPercentage(50d) },
new object[] { XboxGame.Create(Guid.NewGuid(),"x", new Uri("http://test.pl"), new GamePrice(10)), PromotionPercentage.Zero },
new object[] { XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(10, 100)), new PromotionPercentage(90d) },
new object[] { XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(134.99m, 269.99m)), new PromotionPercentage(50d) },
};
}

public sealed class PromotionPercentageData : TheoryData<XboxGame, PromotionPercentage>
{
public PromotionPercentageData()
{
Add(XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(10, 20)), new PromotionPercentage(50d));
Add(XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(10)), PromotionPercentage.Zero);
Add(XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(10, 100)), new PromotionPercentage(90d));
Add(XboxGame.Create(Guid.NewGuid(), "x", new Uri("http://test.pl"), new GamePrice(134.99m, 269.99m)), new PromotionPercentage(50d));
}
}

0 comments on commit 7c57e1d

Please sign in to comment.