A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://johnnycrazy.github.io/SpotifyAPI-NET/docs/unit_testing below:

Website Navigation


Unit Testing | SpotifyAPI-NET

Unit Testing

The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:

public static async Task<bool> IsAdmin(IUserProfileClient userProfileClient)
{
// get logged in user
var user = await userProfileClient.Current();

// only my user id is an admin
return user.Id == "1122095781";
}

Using Moq, this can be tested without doing any network requests:

[Test]
public async Task IsAdmin_SuccessTest()
{
var userProfileClient = new Mock<IUserProfileClient>();
userProfileClient.Setup(u => u.Current()).Returns(
Task.FromResult(new PrivateUser
{
Id = "1122095781"
})
);

Assert.AreEqual(true, await IsAdmin(userProfileClient.Object));
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4