mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-27 00:16:26 +00:00
789 B
789 B
id | title |
---|---|
unit_testing | 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 loggedin 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));
}