1
- using System . IO ;
2
- using System . Net ;
3
- using FluentAssertions ;
1
+ using FluentAssertions ;
4
2
using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
3
using Moq ;
6
4
using SSLLWrapper ;
7
5
using SSLLWrapper . Interfaces ;
8
6
using SSLLWrapper . Models ;
9
7
using SSLLWrapper . Models . Response ;
8
+ using SSLLWrapper . Tests ;
10
9
11
10
namespace given_that_I_make_a_info_request
12
11
{
13
12
[ TestClass ]
14
- public class when_the_api_is_online
13
+ public class when_the_api_is_online : GenericPositiveTests < Info >
15
14
{
16
- private static Info _infoResponse ;
17
-
18
15
[ ClassInitialize ]
19
16
public static void Setup ( TestContext testContext )
20
17
{
@@ -30,45 +27,31 @@ public static void Setup(TestContext testContext)
30
27
mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
31
28
32
29
var ssllService = new SSLLService ( "https://api.dev.ssllabs.com/api/fa78d5a4/" , mockedApiProvider . Object ) ;
33
- _infoResponse = ssllService . Info ( ) ;
34
- }
35
-
36
- [ TestMethod ]
37
- public void then_the_error_count_should_be_zero ( )
38
- {
39
- _infoResponse . Errors . Count . Should ( ) . Be ( 0 ) ;
40
- }
41
-
42
- [ TestMethod ]
43
- public void then_the_HasErrorOccurred_should_be_false ( )
44
- {
45
- _infoResponse . HasErrorOccurred . Should ( ) . BeFalse ( ) ;
30
+ Response = ssllService . Info ( ) ;
46
31
}
47
32
48
33
[ TestMethod ]
49
34
public void then_the_api_should_be_marked_as_online ( )
50
35
{
51
- _infoResponse . Online . Should ( ) . BeTrue ( ) ;
36
+ Response . Online . Should ( ) . BeTrue ( ) ;
52
37
}
53
38
54
39
[ TestMethod ]
55
40
public void then_the_info_response_should_be_populated_with_a_engine_number ( )
56
41
{
57
- _infoResponse . engineVersion . Should ( ) . NotBeNullOrEmpty ( ) ;
42
+ Response . engineVersion . Should ( ) . NotBeNullOrEmpty ( ) ;
58
43
}
59
44
60
45
[ TestMethod ]
61
46
public void then_the_info_response_header_status_code_should_be_200 ( )
62
47
{
63
- _infoResponse . Header . statusCode . Should ( ) . Be ( 200 ) ;
48
+ Response . Header . statusCode . Should ( ) . Be ( 200 ) ;
64
49
}
65
50
}
66
51
67
52
[ TestClass ]
68
- public class when_the_api_is_offline
53
+ public class when_the_api_is_offline : SharedNegativeTests
69
54
{
70
- private static Info _infoResponse ;
71
-
72
55
[ ClassInitialize ]
73
56
public static void Setup ( TestContext testContext )
74
57
{
@@ -84,31 +67,50 @@ public static void Setup(TestContext testContext)
84
67
mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
85
68
86
69
var ssllService = new SSLLService ( "https://api.dev.ssllabs.com/api/fa78d5a4/" , mockedApiProvider . Object ) ;
87
- _infoResponse = ssllService . Info ( ) ;
70
+ Response = ssllService . Info ( ) ;
88
71
}
89
72
90
73
[ TestMethod ]
91
- public void then_the_error_count_should_be_zero ( )
74
+ public void then_the_info_response_header_status_code_should_be_400 ( )
92
75
{
93
- _infoResponse . Errors . Count . Should ( ) . BeGreaterOrEqualTo ( 1 ) ;
76
+ Response . Header . statusCode . Should ( ) . Be ( 400 ) ;
94
77
}
95
78
96
79
[ TestMethod ]
97
- public void then_the_HasErrorOccurred_should_be_true ( )
80
+ public void then_the_info_response_header_status_description_should_match_api ( )
98
81
{
99
- _infoResponse . HasErrorOccurred . Should ( ) . BeTrue ( ) ;
82
+ Response . Header . statusDescription . Should ( ) . Be ( "Bad Request" ) ;
100
83
}
84
+ }
101
85
102
- [ TestMethod ]
103
- public void then_the_api_should_be_marked_as_offline ( )
86
+ [ TestClass ]
87
+ public class when_the_api_url_is_invalid : SharedNegativeTests
88
+ {
89
+ [ ClassInitialize ]
90
+ public static void Setup ( TestContext testContext )
104
91
{
105
- _infoResponse . Online . Should ( ) . BeFalse ( ) ;
92
+ var mockedApiProvider = new Mock < IApiProvider > ( ) ;
93
+ var webResponseModel = new WebResponseModel ( )
94
+ {
95
+ Payloay = "" ,
96
+ StatusCode = 0 ,
97
+ StatusDescription = "" ,
98
+ Url = ""
99
+ } ;
100
+
101
+ mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
102
+
103
+ var ssllService = new SSLLService ( "https://blah-blah.dev.ssllabs.com/api/blah/" , mockedApiProvider . Object ) ;
104
+ Response = ssllService . Info ( ) ;
106
105
}
106
+ }
107
107
108
+ public abstract class SharedNegativeTests : GenericNegativeTests < Info >
109
+ {
108
110
[ TestMethod ]
109
- public void then_the_info_response_header_status_code_should_be_400 ( )
111
+ public void then_the_api_should_be_marked_as_offline ( )
110
112
{
111
- _infoResponse . Header . statusCode . Should ( ) . Be ( 400 ) ;
113
+ Response . Online . Should ( ) . BeFalse ( ) ;
112
114
}
113
115
}
114
116
}
0 commit comments