forked from JohnnyCrazy/SpotifyAPI-NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotifyWebAPITest.cs
More file actions
80 lines (66 loc) · 2.59 KB
/
SpotifyWebAPITest.cs
File metadata and controls
80 lines (66 loc) · 2.59 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
71
72
73
74
75
76
77
78
79
80
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using SpotifyAPI.Web.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace SpotifyAPI.Web.Tests;
[TestFixture]
public class SpotifyWebAPITest
{
private static readonly string _fixtureDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../fixtures/");
private Mock<IClient> _mock;
private SpotifyWebAPI _spotify;
[SetUp]
public void SetUp()
{
_mock = new Mock<IClient>();
_spotify = new SpotifyWebAPI
{
WebClient = _mock.Object,
UseAuth = false,
Token = new Token()
};
}
private static T GetFixture<T>(string file)
{
return JsonConvert.DeserializeObject<T>(File.ReadAllText(Path.Combine(_fixtureDir, file)));
}
private static bool ContainsValues(string str, params string[] values)
{
return values.All(str.Contains);
}
[Test]
public void ShouldGetPrivateProfile_WithoutAuth()
{
_spotify.UseAuth = false;
Assert.Throws<InvalidOperationException>(() => _spotify.GetPrivateProfile());
}
[Test]
public void ShouldGetPrivateProfile_WithAuth()
{
var profile = GetFixture<PrivateProfile>("private-user.json");
_mock.Setup(client => client.DownloadJson<PrivateProfile>(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>()))
.Returns(new Tuple<ResponseInfo, PrivateProfile>(ResponseInfo.Empty, profile));
_spotify.UseAuth = true;
Assert.That(_spotify.GetPrivateProfile(), Is.EqualTo(profile));
_mock.Verify(client => client.DownloadJson<PrivateProfile>(
It.Is<string>(str => ContainsValues(str, "/me")),
It.IsNotNull<Dictionary<string, string>>()), Times.Exactly(1));
}
[Test]
public void ShouldGetPublicProfile()
{
var profile = GetFixture<PublicProfile>("public-user.json");
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>()))
.Returns(new Tuple<ResponseInfo, PublicProfile>(ResponseInfo.Empty, profile));
_spotify.UseAuth = false;
Assert.That(_spotify.GetPublicProfile("wizzler"), Is.EqualTo(profile));
_mock.Verify(client => client.DownloadJson<PublicProfile>(
It.Is<string>(str => ContainsValues(str, "/users/wizzler")),
It.Is<Dictionary<string, string>>(headers => headers.Count == 0)), Times.Exactly(1));
}
//Will add more tests once I decided if this is worth the effort (propably not?)
}