forked from JohnnyCrazy/SpotifyAPI-NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestParamsTest.cs
More file actions
126 lines (105 loc) · 3.14 KB
/
RequestParamsTest.cs
File metadata and controls
126 lines (105 loc) · 3.14 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NUnit.Framework;
namespace SpotifyAPI.Web.Tests
{
[TestFixture]
public class RequestParamsTest
{
[Test]
public void CacheDoesNotInterfereQuery()
{
var first = new FirstRequestModel { First = true };
var firstParams = first.BuildQueryParams();
var second = new SecondRequestModel { Second = false };
var secondParams = second.BuildQueryParams();
Assert.AreEqual(1, firstParams.Keys.Count);
Assert.AreEqual("true", firstParams["first"]);
Assert.AreEqual(1, secondParams.Keys.Count);
Assert.AreEqual("false", secondParams["second"]);
}
[Test]
public void CacheDoesNotInterfereBody()
{
var first = new FirstRequestModel { First = true };
var firstParams = first.BuildBodyParams();
var second = new SecondRequestModel { Second = false };
var secondParams = second.BuildBodyParams();
Assert.AreEqual("{\"first\":true}", firstParams.ToString(Formatting.None));
Assert.AreEqual("{\"second\":false}", secondParams.ToString(Formatting.None));
}
[Test]
public void EmptyListIsSkippedInQueryParams()
{
var first = new EmptyListExampleRequestModel();
Assert.AreEqual(new Dictionary<string, string> { }, first.BuildQueryParams());
first.List.Add("hello_world");
Assert.AreEqual(new Dictionary<string, string> { { "list", "hello_world" } }, first.BuildQueryParams());
}
[Test]
public void EnumWithoutFlagsDoesNotHaveMultipleValues()
{
var enumModel = new EnumWithoutFlagsRequestModel
{
AnEnumParam = EnumWithoutFlagsRequestModel.AnEnum.Two
};
var result = enumModel.BuildQueryParams();
Assert.AreEqual(1, result.Keys.Count);
Assert.AreEqual("two", result["an_enum"]);
}
[Test]
public void EnumWithFlagsDoesHaveMultipleValues()
{
var enumModel = new EnumWitFlagsRequestModel
{
AnEnumParam = EnumWitFlagsRequestModel.AnEnum.Two | EnumWitFlagsRequestModel.AnEnum.One
};
var result = enumModel.BuildQueryParams();
Assert.AreEqual(1, result.Keys.Count);
Assert.AreEqual("one,two", result["an_enum"]);
}
}
public class FirstRequestModel : RequestParams
{
[BodyParam("first")]
[QueryParam("first")]
public bool? First { get; set; }
}
public class SecondRequestModel : RequestParams
{
[BodyParam("second")]
[QueryParam("second")]
public bool? Second { get; set; }
}
public class EmptyListExampleRequestModel : RequestParams
{
[QueryParam("list")]
public IList<string> List { get; set; } = new List<string>();
}
public class EnumWithoutFlagsRequestModel : RequestParams
{
[QueryParam("an_enum")]
public AnEnum AnEnumParam { get; set; }
public enum AnEnum
{
[String("one")]
One,
[String("two")]
Two,
}
}
public class EnumWitFlagsRequestModel : RequestParams
{
[QueryParam("an_enum")]
public AnEnum AnEnumParam { get; set; }
[Flags]
public enum AnEnum
{
[String("one")]
One = 1,
[String("two")]
Two = 2,
}
}
}