Repository navigation
fix friend vr/br #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix friend vr/br #555
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,65 @@ | ||
| using System.Linq.Expressions; | ||
| using Microsoft.Extensions.Caching.Memory; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using WheelWizard.Models; | ||
| using WheelWizard.RrRooms; | ||
| using WheelWizard.Shared; | ||
| using WheelWizard.Shared.Services; | ||
|
|
||
| namespace WheelWizard.Test.Features.RrRooms; | ||
|
|
||
| public class RrLeaderboardTests | ||
| { | ||
| private const string FriendCode = "3137-3137-3137"; | ||
|
|
||
| private readonly IApiCaller<IRwfcApi> _apiCaller = Substitute.For<IApiCaller<IRwfcApi>>(); | ||
| private readonly RrLeaderboardSingletonService _service; | ||
|
|
||
| public RrLeaderboardTests() | ||
| { | ||
| _service = new(_apiCaller, new MemoryCache(new MemoryCacheOptions()), NullLogger<RrLeaderboardSingletonService>.Instance); | ||
| } | ||
|
|
||
| private Task<OperationResult<PlayerProfileResponse>> ReceivedPlayerCalls(int count) => | ||
| _apiCaller.Received(count).CallApiAsync(Arg.Any<Expression<Func<IRwfcApi, Task<PlayerProfileResponse>>>>()); | ||
|
|
||
| [Fact] | ||
| public async Task GetPlayerAsync_FetchesPlayerOnce() | ||
| { | ||
| _apiCaller | ||
| .CallApiAsync(Arg.Any<Expression<Func<IRwfcApi, Task<PlayerProfileResponse>>>>()) | ||
| .Returns(Ok(new PlayerProfileResponse { FriendCode = FriendCode, Vr = 29_367 })); | ||
|
|
||
| var first = await _service.GetPlayerAsync(FriendCode); | ||
| var second = await _service.GetPlayerAsync(FriendCode); | ||
|
|
||
| Assert.Equal(29_367, first.Value.Vr); | ||
| Assert.Equal(29_367, second.Value.Vr); | ||
| await ReceivedPlayerCalls(1); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetPlayerAsync_DoesNotRetryFailure() | ||
| { | ||
| _apiCaller.CallApiAsync(Arg.Any<Expression<Func<IRwfcApi, Task<PlayerProfileResponse>>>>()).Returns(Fail("Not found")); | ||
|
|
||
| Assert.True((await _service.GetPlayerAsync(FriendCode)).IsFailure); | ||
| Assert.True((await _service.GetPlayerAsync(FriendCode)).IsFailure); | ||
| await ReceivedPlayerCalls(1); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetPlayerAsync_SharesRequestStillLoading() | ||
| { | ||
| var response = new TaskCompletionSource<OperationResult<PlayerProfileResponse>>(); | ||
| _apiCaller.CallApiAsync(Arg.Any<Expression<Func<IRwfcApi, Task<PlayerProfileResponse>>>>()).Returns(response.Task); | ||
|
|
||
| var first = _service.GetPlayerAsync(FriendCode); | ||
| var second = _service.GetPlayerAsync(FriendCode); | ||
| response.SetResult(Ok(new PlayerProfileResponse { Vr = 29_367 })); | ||
|
|
||
| Assert.Equal(29_367, (await first).Value.Vr); | ||
| Assert.Equal(29_367, (await second).Value.Vr); | ||
| await ReceivedPlayerCalls(1); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
WheelWizard.Test/Features/WiiManagement/FriendRatingTests.cs
This file contains hidden or 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,34 @@ | ||
| using WheelWizard.WiiManagement.GameLicense; | ||
|
|
||
| namespace WheelWizard.Test.Features.WiiManagement; | ||
|
|
||
| public class FriendRatingTests | ||
| { | ||
| [Theory] | ||
| [InlineData(293u, 29_300u)] // Written by Retro Rewind for 29,367 VR | ||
| [InlineData(1u, 100u)] | ||
| [InlineData(10_000u, 1_000_000u)] // Highest rating | ||
| [InlineData(5000u, 5000u)] // Default written by older WheelWizard versions | ||
| [InlineData(29_367u, 29_367u)] // Full points written by older WheelWizard versions | ||
| public void FriendRatingFromRksys_ReturnsRatingPoints(uint stored, uint points) | ||
| { | ||
| Assert.Equal(points, GameLicenseSingletonService.FriendRatingFromRksys(stored)); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(29_367u, 293)] | ||
| [InlineData(5000u, 50)] | ||
| [InlineData(2_000_000u, 10_000)] // Above the highest rating | ||
| public void FriendRatingToRksys_StoresWholeHundreds(uint points, ushort stored) | ||
| { | ||
| Assert.Equal(stored, GameLicenseSingletonService.FriendRatingToRksys(points)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FriendRating_RoundTripsDefaultRating() | ||
| { | ||
| var stored = GameLicenseSingletonService.FriendRatingToRksys(5000); | ||
|
|
||
| Assert.Equal(5000u, GameLicenseSingletonService.FriendRatingFromRksys(stored)); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.