1
- using FluentAssertions ;
1
+ using System ;
2
+ using FluentAssertions ;
2
3
using Microsoft . VisualStudio . TestTools . UnitTesting ;
3
4
using Moq ;
4
5
using SSLLWrapper ;
@@ -84,14 +85,14 @@ public static void Setup(TestContext testContext)
84
85
TestHost = "https://www.ashleypoole.co.uk" ;
85
86
var webResponseModel = new WebResponseModel ( )
86
87
{
87
- Payloay = " {\" host\" :\" www.ashleypoole.co.uk\" ,\" port\" :443,\" protocol\" :\" HTTP\" ,\" isPublic\" :false,\" " +
88
+ Payloay = "{\" host\" :\" www.ashleypoole.co.uk\" ,\" port\" :443,\" protocol\" :\" HTTP\" ,\" isPublic\" :false,\" " +
88
89
"status\" :\" IN_PROGRESS\" ,\" startTime\" :1422479488403,\" engineVersion\" :\" 1.12.8\" ,\" criteriaVersion\" :\" 2009i\" " +
89
90
",\" endpoints\" :[{\" ipAddress\" :\" 104.28.6.2\" ,\" statusMessage\" :\" In progress\" ,\" statusDetails\" :\" TESTING_HTTPS\" " +
90
91
",\" statusDetailsMessage\" :\" Sending one complete HTTPS request\" ,\" progress\" :-1,\" eta\" :-1,\" delegation\" :3}," +
91
92
"{\" ipAddress\" :\" 104.28.7.2\" ,\" statusMessage\" :\" Pending\" ,\" progress\" :-1,\" eta\" :-1,\" delegation\" :3}]}" ,
92
93
StatusCode = 200 ,
93
94
StatusDescription = "Ok" ,
94
- Url = ( "https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost )
95
+ Url = ( "https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost + "&publish=on&clearCache=on&all=done" )
95
96
} ;
96
97
97
98
mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
@@ -108,14 +109,40 @@ public void then_the_scan_results_should_be_public()
108
109
}
109
110
}
110
111
112
+ [ TestClass ]
113
+ public class when_a_invalid_request_is_made_with_all_the_inputs_and_the_scan_is_unable_to_resolve_hostname : NegativeTests
114
+ {
115
+ [ ClassInitialize ]
116
+ public static void Setup ( TestContext testContext )
117
+ {
118
+ var mockedApiProvider = new Mock < IApiProvider > ( ) ;
119
+ TestHost = "https://www.ashleypoole.co.uk" ;
120
+ var webResponseModel = new WebResponseModel ( )
121
+ {
122
+ Payloay = "{\" host\" :\" www2.ashleypoole.co.uk\" ,\" port\" :443,\" protocol\" :\" HTTP\" ,\" isPublic\" :false,\" status\" :\" ERROR\" ," +
123
+ "\" statusMessage\" :\" Unable to resolve domain name\" ,\" startTime\" :1422478797953,\" testTime\" :1422478798017," +
124
+ "\" engineVersion\" :\" 1.12.8\" ,\" criteriaVersion\" :\" 2009i\" ,\" cacheExpiryTime\" :1422478858017}" ,
125
+ StatusCode = 500 ,
126
+ StatusDescription = "Bad Request" ,
127
+ Url = ( "https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost )
128
+ } ;
129
+
130
+ mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
131
+
132
+ var ssllService = new SSLLService ( "https://api.dev.ssllabs.com/api/fa78d5a4/" , mockedApiProvider . Object ) ;
133
+ Response = ssllService . Analyze ( TestHost , SSLLService . Publish . On , SSLLService . ClearCache . On ,
134
+ SSLLService . FromCache . Ignore , SSLLService . All . Done ) ;
135
+ }
136
+ }
137
+
111
138
public abstract class PositiveTests : GenericPositiveTests < Analyze >
112
139
{
113
140
public static string TestHost ;
114
141
115
142
[ TestMethod ]
116
143
public void then_the_host_property_should_match_the_requested_hostname ( )
117
144
{
118
- Response . host . Should ( ) . Be ( TestHost ) ;
145
+ Response . host . Should ( ) . Be ( TestHost . Substring ( 8 ) ) ;
119
146
}
120
147
121
148
[ TestMethod ]
@@ -133,5 +160,18 @@ public void then_the_port_should_be_that_of_a_ssl_connection()
133
160
134
161
public abstract class NegativeTests : GenericNegativeTests < Analyze >
135
162
{
163
+ public static string TestHost ;
164
+
165
+ [ TestMethod ]
166
+ public void then_an_error_occurred_should_be_marked ( )
167
+ {
168
+ Response . HasErrorOccurred . Should ( ) . BeTrue ( ) ;
169
+ }
170
+
171
+ [ TestMethod ]
172
+ public void then_a_error_message_should_be_returned ( )
173
+ {
174
+ Response . Errors . Count . Should ( ) . BeGreaterOrEqualTo ( 1 ) ;
175
+ }
136
176
}
137
177
}
0 commit comments