1+ using Xunit ;
2+ using KuzzleSdk . API . Controllers ;
3+ using Newtonsoft . Json . Linq ;
4+ using System ;
5+
6+ namespace Kuzzle . Tests . API . Controllers
7+ {
8+ public class ServerControllerTest
9+ {
10+ private readonly ServerController _serverController ;
11+ private readonly KuzzleApiMock _api ;
12+
13+ public ServerControllerTest ( )
14+ {
15+ _api = new KuzzleApiMock ( ) ;
16+ _serverController = new ServerController ( _api . MockedObject ) ;
17+ }
18+
19+ [ Theory ]
20+ [ InlineData ( true ) ]
21+ [ InlineData ( false ) ]
22+ public async void AdminExistsTest ( bool returnValue )
23+ {
24+ _api . SetResult ( new JObject { {
25+ "result" , new JObject {
26+ { "exists" , returnValue }
27+ } }
28+ } ) ;
29+
30+ bool res = await _serverController . AdminExistsAsync ( ) ;
31+
32+ _api . Verify ( new JObject {
33+ { "controller" , "server" } ,
34+ { "action" , "adminExists" }
35+ } ) ;
36+
37+ Assert . Equal ( returnValue , res ) ;
38+ }
39+
40+
41+ [ Fact ]
42+ public async void NowTest ( )
43+ {
44+ _api . SetResult ( @"{result: {now: 1111111111111}}" ) ;
45+
46+ Int64 res = await _serverController . NowAsync ( ) ;
47+
48+ _api . Verify ( new JObject {
49+ { "controller" , "server" } ,
50+ { "action" , "now" }
51+ } ) ;
52+ Assert . Equal < Int64 > ( 1111111111111 , res ) ;
53+ }
54+
55+ [ Fact ]
56+ public async void InfoTest ( ) {
57+ JObject serverInfo = new JObject { { "kuzzle" , "installed" } } ;
58+ _api . SetResult ( new JObject { { "result" , new JObject { { "serverInfo" , serverInfo } } } } ) ;
59+
60+ JObject res = await _serverController . InfoAsync ( ) ;
61+
62+ _api . Verify ( new JObject {
63+ { "controller" , "server" } ,
64+ { "action" , "info" }
65+ } ) ;
66+ Assert . Equal < JObject > ( serverInfo , res ) ;
67+ }
68+
69+ [ Fact ]
70+ public async void ConfigTest ( ) {
71+ _api . SetResult ( @"{result: {limits: 'none'}}" ) ;
72+
73+ JObject res = await _serverController . GetConfigAsync ( ) ;
74+
75+ _api . Verify ( new JObject {
76+ { "controller" , "server" } ,
77+ { "action" , "getConfig" }
78+ } ) ;
79+ Assert . Equal < JObject > (
80+ new JObject { { "limits" , "none" } } ,
81+ res
82+ ) ;
83+ }
84+
85+ [ Fact ]
86+ public async void GetStatsTest ( ) {
87+ _api . SetResult ( @"{ result: { cake: 'lie'} }" ) ;
88+ long start = 0 ;
89+ long end = 1 ;
90+
91+ JObject res = await _serverController . GetStatsAsync ( start , end ) ;
92+
93+ _api . Verify ( new JObject {
94+ { "controller" , "server" } ,
95+ { "action" , "getStats" } ,
96+ { "startTime" , start } ,
97+ { "stopTime" , end }
98+ } ) ;
99+ Assert . Equal < JObject > (
100+ new JObject { { "cake" , "lie" } } ,
101+ res
102+ ) ;
103+ }
104+
105+ [ Fact ]
106+ public async void GetAllStatsTest ( ) {
107+ _api . SetResult ( @"{ result: { cake: 'lie'} }" ) ;
108+
109+ JObject res = await _serverController . GetAllStatsAsync ( ) ;
110+
111+ _api . Verify ( new JObject {
112+ { "controller" , "server" } ,
113+ { "action" , "getAllStats" }
114+ } ) ;
115+ Assert . Equal < JObject > (
116+ new JObject { { "cake" , "lie" } } ,
117+ res
118+ ) ;
119+ }
120+
121+ [ Fact ]
122+ public async void GetLastStatsTest ( ) {
123+ _api . SetResult ( @"{ result: { cake: 'lie'} }" ) ;
124+
125+ JObject res = await _serverController . GetLastStatsAsync ( ) ;
126+
127+ _api . Verify ( new JObject {
128+ { "controller" , "server" } ,
129+ { "action" , "getLastStats" }
130+ } ) ;
131+ Assert . Equal < JObject > (
132+ new JObject { { "cake" , "lie" } } ,
133+ res
134+ ) ;
135+ }
136+ }
137+ }
0 commit comments