Skip to content

[Feature request] Improve testability #424

@leonard-thieu

Description

@leonard-thieu

SteamKit doesn't seem to offer any options for testing of consuming code. Given that this library hits the network, it's important to be able to mock away that behavior. I'm finding that I have to write a lot of wrapper types since most types aren't mockable. Take for example:

sealed class SteamUserStatsAdapter : ISteamUserStats
{
    public SteamUserStatsAdapter(SteamUserStats steamUserStats)
    {
        this.steamUserStats = steamUserStats ?? throw new ArgumentNullException(nameof(steamUserStats), $"{nameof(steamUserStats)} is null.");
    }

    readonly SteamUserStats steamUserStats;

    public IAsyncJob<LeaderboardEntriesCallback> GetLeaderboardEntries(uint appId, int id, int rangeStart, int rangeEnd, ELeaderboardDataRequest dataRequest)
    {
        var asyncJob = steamUserStats.GetLeaderboardEntries(appId, id, rangeStart, rangeEnd, dataRequest);

        return new AsyncJobAdapter<LeaderboardEntriesCallback>(asyncJob);
    }
}
public interface ISteamUserStats
{
    IAsyncJob<LeaderboardEntriesCallback> GetLeaderboardEntries(uint appId, int id, int rangeStart, int rangeEnd, ELeaderboardDataRequest dataRequest);
}

SteamUserStatsAdapter and ISteamUserStats makes it possible for me to test code that consumes SteamUserStats. However, this pattern results in 2 additional types for each type I use.

Could representative interfaces be added for SteamKit types so that they become mockable? I realize it'd be a breaking change but it'd vastly improve testability.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions