forked from JohnnyCrazy/SpotifyAPI-NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestClass.cs
More file actions
70 lines (60 loc) · 2.21 KB
/
TestClass.cs
File metadata and controls
70 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.IO;
using System.Linq;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Models;
namespace SpotifyAPI.Tests
{
[TestFixture]
public class TestClass
{
private Mock<IClient> _mock;
private SpotifyWebAPI _spotify;
[SetUp]
public void SetUp()
{
_mock = new Mock<IClient>();
_spotify = new SpotifyWebAPI()
{
WebClient = _mock.Object,
UseAuth = false
};
}
private static T GetFixture<T>(string file)
{
return JsonConvert.DeserializeObject<T>(File.ReadAllText(Path.Combine("../../fixtures/", file)));
}
private static bool ContainsValues(string str, params string[] values)
{
return values.All(str.Contains);
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void ShouldGetPrivateProfile_WithoutAuth()
{
_spotify.UseAuth = false;
_spotify.GetPrivateProfile();
}
[Test]
public void ShouldGetPrivateProfile_WithAuth()
{
PrivateProfile profile = GetFixture<PrivateProfile>("private-user.json");
_mock.Setup(client => client.DownloadJson<PrivateProfile>(It.IsAny<string>())).Returns(profile);
_spotify.UseAuth = true;
Assert.AreEqual(profile, _spotify.GetPrivateProfile());
_mock.Verify(client => client.DownloadJson<PrivateProfile>(It.Is<string>(str => ContainsValues(str, "/me"))), Times.Exactly(1));
}
[Test]
public void ShouldGetPublicProfile()
{
PublicProfile profile = GetFixture<PublicProfile>("public-user.json");
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>())).Returns(profile);
Assert.AreEqual(profile, _spotify.GetPublicProfile("wizzler"));
_mock.Verify(client => client.DownloadJson<PublicProfile>(It.Is<string>(str => ContainsValues(str, "/users/wizzler"))), Times.Exactly(1));
}
//Will add more tests once I decided if this is worth the effort (propably not?)
}
}