1- using System ;
2- using Microsoft . VisualStudio . TestTools . UnitTesting ;
3- using SteamWebAPI2 . Interfaces ;
1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
42using Moq ;
5- using SteamWebAPI2 . Utilities ;
3+ using SteamWebAPI2 . Interfaces ;
4+ using SteamWebAPI2 . Models . SteamCommunity ;
65using SteamWebAPI2 . Models . SteamPlayer ;
6+ using SteamWebAPI2 . Utilities ;
7+ using System ;
8+ using System . Collections . Generic ;
79using System . Threading . Tasks ;
8- using SteamWebAPI2 . Models . SteamCommunity ;
910
1011namespace SteamWebAPI2 . Tests
1112{
1213 [ TestClass ]
1314 public class PlayerServiceTests
1415 {
16+ [ TestInitialize ]
17+ public void Initialize ( )
18+ {
19+ AutoMapperConfiguration . Initialize ( ) ;
20+ }
21+
1522 [ TestMethod ]
1623 [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
1724 public void PlayerService_Throw_Exception_If_Steam_API_Key_Is_Null_Or_Empty ( )
@@ -20,66 +27,222 @@ public void PlayerService_Throw_Exception_If_Steam_API_Key_Is_Null_Or_Empty()
2027 }
2128
2229 [ TestMethod ]
23- public async Task PlayerService_IsPlayingSharedGameAsync_Return_Empty_String_If_Web_Interface_Returns_Null ( )
30+ public async Task PlayerService_IsPlayingSharedGameAsync_Return_Null_If_Web_Interface_Returns_Null ( )
2431 {
2532 var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
2633
27- mockSteamWebRequest . Setup ( x => x . GetAsync < PlayingSharedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , null ) )
34+ mockSteamWebRequest . Setup ( x => x . GetAsync < PlayingSharedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
2835 . ReturnsAsync ( ( PlayingSharedGameResultContainer ) null ) ;
2936
3037 var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
31- var result = await service . IsPlayingSharedGameAsync ( 0 , 0 ) ;
38+ var result = await service . IsPlayingSharedGameAsync ( It . IsAny < ulong > ( ) , It . IsAny < uint > ( ) ) ;
3239
33- Assert . IsNotNull ( result ) ;
34- Assert . AreEqual ( result , String . Empty ) ;
40+ Assert . IsTrue ( ! result . HasValue ) ;
3541 }
3642
3743 [ TestMethod ]
38- public async Task PlayerService_IsPlayingSharedGameAsync_Return_Empty_String_If_Web_Interface_Result_Is_Null ( )
44+ public async Task PlayerService_IsPlayingSharedGameAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
3945 {
4046 var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
4147
42- mockSteamWebRequest . Setup ( x => x . GetAsync < PlayingSharedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , null ) )
48+ mockSteamWebRequest . Setup ( x => x . GetAsync < PlayingSharedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
4349 . ReturnsAsync ( new PlayingSharedGameResultContainer ( )
4450 {
4551 Result = null
4652 } ) ;
4753
4854 var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
49- var result = await service . IsPlayingSharedGameAsync ( 0 , 0 ) ;
55+ var result = await service . IsPlayingSharedGameAsync ( It . IsAny < ulong > ( ) , It . IsAny < uint > ( ) ) ;
5056
51- Assert . IsNotNull ( result ) ;
52- Assert . AreEqual ( result , String . Empty ) ;
57+ Assert . IsTrue ( ! result . HasValue ) ;
5358 }
5459
5560 [ TestMethod ]
56- public async Task PlayerService_GetBadgesAsync_Return_New_If_Web_Request_Is_Null ( )
61+ public async Task PlayerService_GetBadgesAsync_Return_Null_If_Web_Interface_Returns_Null ( )
5762 {
5863 var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
5964
60- mockSteamWebRequest . Setup ( x => x . GetAsync < BadgesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , null ) )
65+ mockSteamWebRequest . Setup ( x => x . GetAsync < BadgesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
6166 . ReturnsAsync ( ( BadgesResultContainer ) null ) ;
6267
6368 var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
64- var result = await service . GetBadgesAsync ( 0 ) ;
69+ var result = await service . GetBadgesAsync ( It . IsAny < ulong > ( ) ) ;
6570
66- Assert . IsNotNull ( result ) ;
67- Assert . IsNull ( result . Badges ) ;
71+ Assert . IsNull ( result ) ;
6872 }
6973
7074 [ TestMethod ]
71- public async Task PlayerService_GetCommunityBadgeProgressAsync_Return_Empty_If_Web_Request_Is_Null ( )
75+ public async Task PlayerService_GetBadgesAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
7276 {
7377 var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
7478
75- mockSteamWebRequest . Setup ( x => x . GetAsync < CommunityBadgeProgressResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , null ) )
79+ mockSteamWebRequest . Setup ( x => x . GetAsync < BadgesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
80+ . ReturnsAsync ( new BadgesResultContainer ( )
81+ {
82+ Result = null
83+ } ) ;
84+
85+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
86+ var result = await service . GetBadgesAsync ( It . IsAny < ulong > ( ) ) ;
87+
88+ Assert . IsNull ( result ) ;
89+ }
90+
91+ [ TestMethod ]
92+ public async Task PlayerService_GetCommunityBadgeProgressAsync_Return_Null_If_Web_Interface_Returns_Null ( )
93+ {
94+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
95+
96+ mockSteamWebRequest . Setup ( x => x . GetAsync < CommunityBadgeProgressResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
7697 . ReturnsAsync ( ( CommunityBadgeProgressResultContainer ) null ) ;
7798
7899 var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
79- var result = await service . GetCommunityBadgeProgressAsync ( 0 , 0 ) ;
100+ var result = await service . GetCommunityBadgeProgressAsync ( It . IsAny < uint > ( ) , It . IsAny < uint ? > ( ) ) ;
101+
102+ Assert . IsNull ( result ) ;
103+ }
104+
105+ [ TestMethod ]
106+ public async Task PlayerService_GetCommunityBadgeProgressAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
107+ {
108+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
109+
110+ mockSteamWebRequest . Setup ( x => x . GetAsync < CommunityBadgeProgressResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
111+ . ReturnsAsync ( new CommunityBadgeProgressResultContainer ( )
112+ {
113+ Result = null
114+ } ) ;
115+
116+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
117+ var result = await service . GetCommunityBadgeProgressAsync ( It . IsAny < uint > ( ) , It . IsAny < uint ? > ( ) ) ;
118+
119+ Assert . IsNull ( result ) ;
120+ }
121+
122+ [ TestMethod ]
123+ public async Task PlayerService_GetSteamLevelAsync_Return_Null_If_Web_Interface_Returns_Null ( )
124+ {
125+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
126+
127+ mockSteamWebRequest . Setup ( x => x . GetAsync < SteamLevelResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
128+ . ReturnsAsync ( ( SteamLevelResultContainer ) null ) ;
129+
130+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
131+ var result = await service . GetSteamLevelAsync ( It . IsAny < uint > ( ) ) ;
132+
133+ Assert . IsNull ( result ) ;
134+ }
135+
136+ [ TestMethod ]
137+ public async Task PlayerService_GetSteamLevelAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
138+ {
139+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
140+
141+ mockSteamWebRequest . Setup ( x => x . GetAsync < SteamLevelResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
142+ . ReturnsAsync ( new SteamLevelResultContainer ( )
143+ {
144+ Result = null
145+ } ) ;
146+
147+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
148+ var result = await service . GetSteamLevelAsync ( It . IsAny < uint > ( ) ) ;
149+
150+ Assert . IsNull ( result ) ;
151+ }
152+
153+ [ TestMethod ]
154+ public async Task PlayerService_GetOwnedGamesAsync_Return_Null_If_Web_Interface_Returns_Null ( )
155+ {
156+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
157+
158+ mockSteamWebRequest . Setup ( x => x . GetAsync < OwnedGamesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
159+ . ReturnsAsync ( ( OwnedGamesResultContainer ) null ) ;
160+
161+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
162+ var result = await service . GetOwnedGamesAsync ( It . IsAny < ulong > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < IReadOnlyCollection < uint > > ( ) ) ;
163+
164+ Assert . IsNull ( result ) ;
165+ }
166+
167+ [ TestMethod ]
168+ public async Task PlayerService_GetOwnedGamesAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
169+ {
170+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
171+
172+ mockSteamWebRequest . Setup ( x => x . GetAsync < OwnedGamesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
173+ . ReturnsAsync ( new OwnedGamesResultContainer ( )
174+ {
175+ Result = null
176+ } ) ;
177+
178+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
179+ var result = await service . GetOwnedGamesAsync ( It . IsAny < ulong > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < IReadOnlyCollection < uint > > ( ) ) ;
180+
181+ Assert . IsNull ( result ) ;
182+ }
183+
184+ [ TestMethod ]
185+ public async Task PlayerService_GetOwnedGamesAsync_Trim_Starting_And_Ending_Spaces_From_Owned_Game_Names ( )
186+ {
187+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
188+
189+ mockSteamWebRequest . Setup ( x => x . GetAsync < OwnedGamesResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
190+ . ReturnsAsync ( new OwnedGamesResultContainer ( )
191+ {
192+ Result = new OwnedGamesResult ( )
193+ {
194+ GameCount = 10 ,
195+ OwnedGames = new List < OwnedGame > ( )
196+ {
197+ new OwnedGame ( ) { Name = " Test Game 1 " } ,
198+ new OwnedGame ( ) { Name = " Test Game 2 " } ,
199+ new OwnedGame ( ) { Name = " Test Game 3 " } ,
200+ new OwnedGame ( ) { Name = " Test Game 4 " } ,
201+ new OwnedGame ( ) { Name = " Test Game 5 " } ,
202+ }
203+ }
204+ } ) ;
205+
206+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
207+ var result = await service . GetOwnedGamesAsync ( It . IsAny < ulong > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < bool ? > ( ) , It . IsAny < IReadOnlyCollection < uint > > ( ) ) ;
208+
209+ // Make sure all game names have been trimmed on the edges
210+ foreach ( var game in result . OwnedGames )
211+ {
212+ Assert . IsTrue ( ! game . Name . StartsWith ( " " ) ) ;
213+ Assert . IsTrue ( ! game . Name . EndsWith ( " " ) ) ;
214+ }
215+ }
216+
217+ [ TestMethod ]
218+ public async Task PlayerService_GetRecentlyPlayedGamesAsync_Return_Null_If_Web_Interface_Returns_Null ( )
219+ {
220+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
221+
222+ mockSteamWebRequest . Setup ( x => x . GetAsync < RecentlyPlayedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
223+ . ReturnsAsync ( ( RecentlyPlayedGameResultContainer ) null ) ;
224+
225+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
226+ var result = await service . GetRecentlyPlayedGamesAsync ( It . IsAny < ulong > ( ) ) ;
227+
228+ Assert . IsNull ( result ) ;
229+ }
230+
231+ [ TestMethod ]
232+ public async Task PlayerService_GetRecentlyPlayedGamesAsync_Return_Null_If_Web_Interface_Result_Is_Null ( )
233+ {
234+ var mockSteamWebRequest = new Mock < ISteamWebInterface > ( ) ;
235+
236+ mockSteamWebRequest . Setup ( x => x . GetAsync < RecentlyPlayedGameResultContainer > ( It . IsAny < string > ( ) , It . IsAny < int > ( ) , It . IsAny < IList < SteamWebRequestParameter > > ( ) ) )
237+ . ReturnsAsync ( new RecentlyPlayedGameResultContainer ( )
238+ {
239+ Result = null
240+ } ) ;
241+
242+ var service = new PlayerService ( String . Empty , mockSteamWebRequest . Object ) ;
243+ var result = await service . GetRecentlyPlayedGamesAsync ( It . IsAny < ulong > ( ) ) ;
80244
81- Assert . IsNotNull ( result ) ;
82- Assert . AreEqual ( result . Count , 0 ) ;
245+ Assert . IsNull ( result ) ;
83246 }
84247 }
85- }
248+ }
0 commit comments