Skip to content

Commit

Permalink
chore: small fixes (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoBaSs84 authored Jun 30, 2024
2 parents 0970fd7 + 10016d8 commit 84d6f3f
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PropertyGroup Condition="!$(MSBuildProjectName.EndsWith('Tests'))">
<Authors>BoBoBaSs84</Authors>
<Company>https://github.com/BoBoBaSs84</Company>
<Copyright>Copyright © $(VersionMajor) BoBoBaSs84</Copyright>
<Copyright>Copyright © $([System.DateTime]::UtcNow.Year) BoBoBaSs84</Copyright>
<Description>The "Steam Achievement Unlocker" or "SAU" offers the possibility to unlock Steam achievements that are no longer available, for example through online challenges.</Description>
<Product>BB84.SAU</Product>
<RepositoryType>git</RepositoryType>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ The "Steam Achievement Unlocker" or "SAU" offers the possibility to unlock Steam

- Get your self an steam api key
- Under settings enter **your** steam id and **your** api key
- Goto games and load the your games
- Goto games and load your games
- Select the game of your choice
- Load the achievements for the game
- Select the achievement you want to unlock
- Select the achievement you want to unlock or lock

## ⚖️ License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ISteamWebService
/// <param name="apiKey">The steam api key to use.</param>
/// <param name="cancellationToken">The cancellation token to cancel the request.</param>
/// <returns>A list of achievements.</returns>
Task<IEnumerable<AchievementModel>> GetAchievements(int appId, string apiKey, CancellationToken cancellationToken = default);
Task<IEnumerable<AchievementModel>> GetAchievementsAsync(int appId, string apiKey, CancellationToken cancellationToken = default);

/// <summary>
/// Returns a list of games a player owns along with some playtime information,
Expand All @@ -24,22 +24,22 @@ public interface ISteamWebService
/// <param name="apiKey">The steam api key to use.</param>
/// <param name="cancellationToken">The cancellation token to cancel the request.</param>
/// <returns>A list of games.</returns>
Task<IEnumerable<GameModel>> GetGames(long steamId, string apiKey, CancellationToken cancellationToken = default);
Task<IEnumerable<GameModel>> GetGamesAsync(long steamId, string apiKey, CancellationToken cancellationToken = default);

/// <summary>
/// Returns the application details for a given <paramref name="appId"/>.
/// </summary>
/// <param name="appId">The steam app id to use.</param>
/// <param name="cancellationToken">The cancellation token to cancel the request.</param>
/// <returns>The game with some more details.</returns>
Task<GameDetailModel?> GetGameDetails(int appId, CancellationToken cancellationToken = default);
Task<GameDetailModel?> GetGameDetailsAsync(int appId, CancellationToken cancellationToken = default);

/// <summary>
/// Returns basic profile information.
/// Returns basic profile user data information.
/// </summary>
/// <param name="steamId">The user steam id to use.</param>
/// <param name="apiKey">The steam api key to use.</param>
/// <param name="cancellationToken">The cancellation token to cancel the request.</param>
/// <returns>The profile information.</returns>
Task<UserDataModel?> GetUserProfile(long steamId, string apiKey, CancellationToken cancellationToken = default);
/// <returns>The profile user data.</returns>
Task<UserDataModel?> GetUserDataAsync(long steamId, string apiKey, CancellationToken cancellationToken = default);
}
8 changes: 4 additions & 4 deletions src/BB84.SAU.Application/Services/SteamWebService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal sealed class SteamWebService(ILoggerService<SteamWebService> loggerServ
private static readonly Action<ILogger, object, Exception?> LogExceptionWithParams =
LoggerMessage.Define<object>(LogLevel.Error, 0, "Exception occured. Params = {Parameters}");

public async Task<IEnumerable<AchievementModel>> GetAchievements(int appId, string apiKey, CancellationToken cancellationToken = default)
public async Task<IEnumerable<AchievementModel>> GetAchievementsAsync(int appId, string apiKey, CancellationToken cancellationToken = default)
{
List<AchievementModel> achievements = [];
try
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<IEnumerable<AchievementModel>> GetAchievements(int appId, stri
}
}

public async Task<IEnumerable<GameModel>> GetGames(long steamId, string apiKey, CancellationToken cancellationToken = default)
public async Task<IEnumerable<GameModel>> GetGamesAsync(long steamId, string apiKey, CancellationToken cancellationToken = default)
{
List<GameModel> games = [];
try
Expand Down Expand Up @@ -125,7 +125,7 @@ public async Task<IEnumerable<GameModel>> GetGames(long steamId, string apiKey,
}
}

public async Task<GameDetailModel?> GetGameDetails(int appId, CancellationToken cancellationToken = default)
public async Task<GameDetailModel?> GetGameDetailsAsync(int appId, CancellationToken cancellationToken = default)
{
try
{
Expand Down Expand Up @@ -170,7 +170,7 @@ public async Task<IEnumerable<GameModel>> GetGames(long steamId, string apiKey,
}
}

public async Task<UserDataModel?> GetUserProfile(long steamId, string apiKey, CancellationToken cancellationToken = default)
public async Task<UserDataModel?> GetUserDataAsync(long steamId, string apiKey, CancellationToken cancellationToken = default)
{
try
{
Expand Down
12 changes: 6 additions & 6 deletions src/BB84.SAU.Application/ViewModels/AchievementsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ private async Task LoadAchievements()
{
AchievementsAreLoading = true;

IEnumerable<AchievementModel> achievements = await _steamWebService.GetAchievements(Model.Id, _steamSettings.ApiKey)
IEnumerable<AchievementModel> achievementsData = await _steamWebService.GetAchievementsAsync(Model.Id, _steamSettings.ApiKey)
.ConfigureAwait(true);

foreach (AchievementModel achievement in achievements)
foreach (AchievementModel achievementData in achievementsData)
{
(bool achieved, DateTime? unlockTime) = _steamApiService.GetAchievement(achievement.Id);
(bool achieved, DateTime? unlockTime) = _steamApiService.GetAchievement(achievementData.Id);

if (achieved)
{
achievement.Unlocked = achieved;
achievement.UnlockedTime = unlockTime;
achievementData.Unlocked = achieved;
achievementData.UnlockedTime = unlockTime;
}

Model.Achievements.Add(achievement);
Model.Achievements.Add(achievementData);
}
}
finally
Expand Down
10 changes: 5 additions & 5 deletions src/BB84.SAU.Application/ViewModels/GamesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ private async Task LoadGames()
{
GamesAreLoading = true;

IEnumerable<GameModel> games = await _steamWebService.GetGames(_steamSettings.Id, _steamSettings.ApiKey)
IEnumerable<GameModel> gamesData = await _steamWebService.GetGamesAsync(_steamSettings.Id, _steamSettings.ApiKey)
.ConfigureAwait(true);

foreach (GameModel game in games)
foreach (GameModel gameData in gamesData)
{
GameDetailModel? gameDetail = await _steamWebService.GetGameDetails(game.Id)
GameDetailModel? gameDetailData = await _steamWebService.GetGameDetailsAsync(gameData.Id)
.ConfigureAwait(true);

if (gameDetail is not null)
Model.Games.Add(gameDetail);
if (gameDetailData is not null)
Model.Games.Add(gameDetailData);
}
}
finally
Expand Down
16 changes: 8 additions & 8 deletions src/BB84.SAU.Application/ViewModels/UserDataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ private async Task LoadUserDataAsync()
{
IsUserDataLoading = true;

UserDataModel? loadedModel = await _steamWebService.GetUserProfile(_steamSettings.Id, _steamSettings.ApiKey)
UserDataModel? userData = await _steamWebService.GetUserDataAsync(_steamSettings.Id, _steamSettings.ApiKey)
.ConfigureAwait(true);

if (loadedModel is null)
if (userData is null)
return;

Model.Name = loadedModel.Name;
Model.ImageUrl = loadedModel.ImageUrl;
Model.ProfileUrl = loadedModel.ProfileUrl;
Model.Created = loadedModel.Created;
Model.LastLogOff = loadedModel.LastLogOff;
Model.LastUpdate = loadedModel.LastUpdate;
Model.Name = userData.Name;
Model.ImageUrl = userData.ImageUrl;
Model.ProfileUrl = userData.ProfileUrl;
Model.Created = userData.Created;
Model.LastLogOff = userData.LastLogOff;
Model.LastUpdate = userData.LastUpdate;

Image = CreateImageFromUri(new(Model.ImageUrl));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task GetAchievementsShouldReturnEmptyResultWhenExceptionGetsThrown(
SteamWebService service = CreateMockedInstance();
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>())).Throws<HttpRequestException>();

IEnumerable<AchievementModel> result = await service.GetAchievements(APPID, APIKEY)
IEnumerable<AchievementModel> result = await service.GetAchievementsAsync(APPID, APIKEY)
.ConfigureAwait(false);

Assert.IsFalse(result.Any());
Expand All @@ -33,7 +33,7 @@ public async Task GetAchievementsShouldReturnEmptyResultWhenNotSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.NotFound));

IEnumerable<AchievementModel> result = await service.GetAchievements(APPID, APIKEY)
IEnumerable<AchievementModel> result = await service.GetAchievementsAsync(APPID, APIKEY)
.ConfigureAwait(false);

Assert.IsFalse(result.Any());
Expand All @@ -51,7 +51,7 @@ public async Task GetAchievementsShouldReturnOneResultWhenSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.OK, AchievmentsResponse));

IEnumerable<AchievementModel> result = await service.GetAchievements(APPID, APIKEY)
IEnumerable<AchievementModel> result = await service.GetAchievementsAsync(APPID, APIKEY)
.ConfigureAwait(false);

Assert.IsTrue(result.Any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task GetGameDetailsShouldReturnNullWhenExceptionGetsThrown()
SteamWebService service = CreateMockedInstance();
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>())).Throws<HttpRequestException>();

GameDetailModel? result = await service.GetGameDetails(APPID)
GameDetailModel? result = await service.GetGameDetailsAsync(APPID)
.ConfigureAwait(false);

Assert.IsNull(result);
Expand All @@ -33,7 +33,7 @@ public async Task GetGameDetailsShouldReturnNullWhenNotSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.NotFound));

GameDetailModel? result = await service.GetGameDetails(APPID)
GameDetailModel? result = await service.GetGameDetailsAsync(APPID)
.ConfigureAwait(false);

Assert.IsNull(result);
Expand All @@ -51,7 +51,7 @@ public async Task GetGameDetailsShouldReturnResultWhenSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.OK, GameDetailsResponse));

GameDetailModel? result = await service.GetGameDetails(APPID)
GameDetailModel? result = await service.GetGameDetailsAsync(APPID)
.ConfigureAwait(false);

Assert.IsNotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task GetGamesShouldReturnEmptyResultWhenExceptionGetsThrown()
SteamWebService service = CreateMockedInstance();
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>())).Throws<HttpRequestException>();

IEnumerable<GameModel> result = await service.GetGames(STEAMID, APIKEY)
IEnumerable<GameModel> result = await service.GetGamesAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsFalse(result.Any());
Expand All @@ -33,7 +33,7 @@ public async Task GetGamesShouldReturnEmptyResultWhenNotSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.NotFound));

IEnumerable<GameModel> result = await service.GetGames(STEAMID, APIKEY)
IEnumerable<GameModel> result = await service.GetGamesAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsFalse(result.Any());
Expand All @@ -51,7 +51,7 @@ public async Task GetGamesShouldReturnOneResultWhenSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.OK, GamesResponse));

IEnumerable<GameModel> result = await service.GetGames(STEAMID, APIKEY)
IEnumerable<GameModel> result = await service.GetGamesAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsTrue(result.Any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task GetUserDataShouldReturnNullWhenExceptionGetsThrown()
SteamWebService service = CreateMockedInstance();
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>())).Throws<HttpRequestException>();

UserDataModel? result = await service.GetUserProfile(STEAMID, APIKEY)
UserDataModel? result = await service.GetUserDataAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsNull(result);
Expand All @@ -33,7 +33,7 @@ public async Task GetUserDataShouldReturnNullWhenNotSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.NotFound));

UserDataModel? result = await service.GetUserProfile(STEAMID, APIKEY)
UserDataModel? result = await service.GetUserDataAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsNull(result);
Expand All @@ -51,7 +51,7 @@ public async Task GetUserDataShouldReturnResultWhenSuccessful()
_httpClientFactoryMock.Setup(x => x.CreateClient(It.IsAny<string>()))
.Returns(CreateMockedClient(HttpStatusCode.OK, UserDataResponse));

UserDataModel? result = await service.GetUserProfile(STEAMID, APIKEY)
UserDataModel? result = await service.GetUserDataAsync(STEAMID, APIKEY)
.ConfigureAwait(false);

Assert.IsNotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public async Task LoadGamesCommandShouldLoadGamesWhenLastUpdateIsSet()
List<GameModel> games = [new(appId, appTitle)];
GamesViewModel viewModel = CreateViewModelMock();
_ = _optionsMock.Setup(x => x.Value).Returns(SteamSettings);
_ = _steamWebServiceMock.Setup(x => x.GetGames(SteamSettings.Id, SteamSettings.ApiKey, default)).ReturnsAsync(games);
_ = _steamWebServiceMock.Setup(x => x.GetGameDetails(appId, default)).ReturnsAsync(game);
_ = _steamWebServiceMock.Setup(x => x.GetGamesAsync(SteamSettings.Id, SteamSettings.ApiKey, default)).ReturnsAsync(games);
_ = _steamWebServiceMock.Setup(x => x.GetGameDetailsAsync(appId, default)).ReturnsAsync(game);
viewModel.Model.LastUpdate = DateTime.MinValue;

await viewModel.LoadGamesCommand.ExecuteAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task LoadUserDataCommandTest()
UserDataModel userDataModel =
new("UnitTest", TestImageUrl, "UnitTestUrl", DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
Mock<ISteamWebService> steamWebApiServiceMock = new();
_ = steamWebApiServiceMock.Setup(x => x.GetUserProfile(id, apiKey, default).Result).Returns(userDataModel);
_ = steamWebApiServiceMock.Setup(x => x.GetUserDataAsync(id, apiKey, default).Result).Returns(userDataModel);
Mock<IOptions<SteamSettings>> optionsMock = new();
_ = optionsMock.Setup(x => x.Value).Returns(new SteamSettings() { Id = id, ApiKey = apiKey });
UserDataViewModel viewModel = new(steamWebApiServiceMock.Object, optionsMock.Object, new());
Expand All @@ -63,7 +63,7 @@ public async Task LoadUserDataCommandReturnNullTest()
UserDataModel userDataModel =
new("UnitTest", TestImageUrl, "UnitTestUrl", DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
Mock<ISteamWebService> steamWebApiServiceMock = new();
_ = steamWebApiServiceMock.Setup(x => x.GetUserProfile(id, apiKey, default).Result);
_ = steamWebApiServiceMock.Setup(x => x.GetUserDataAsync(id, apiKey, default).Result);
Mock<IOptions<SteamSettings>> optionsMock = new();
_ = optionsMock.Setup(x => x.Value).Returns(new SteamSettings() { Id = id, ApiKey = apiKey });
UserDataViewModel viewModel = new(steamWebApiServiceMock.Object, optionsMock.Object, new());
Expand Down

0 comments on commit 84d6f3f

Please sign in to comment.