Skip to content

Commit 9c457fb

Browse files
committed
Adding negative test to analyze tests
1 parent f240157 commit 9c457fb

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

SSLLWrapper.Tests/AnalyzeTests.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentAssertions;
1+
using System;
2+
using FluentAssertions;
23
using Microsoft.VisualStudio.TestTools.UnitTesting;
34
using Moq;
45
using SSLLWrapper;
@@ -84,14 +85,14 @@ public static void Setup(TestContext testContext)
8485
TestHost = "https://www.ashleypoole.co.uk";
8586
var webResponseModel = new WebResponseModel()
8687
{
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,\"" +
8889
"status\":\"IN_PROGRESS\",\"startTime\":1422479488403,\"engineVersion\":\"1.12.8\",\"criteriaVersion\":\"2009i\"" +
8990
",\"endpoints\":[{\"ipAddress\":\"104.28.6.2\",\"statusMessage\":\"In progress\",\"statusDetails\":\"TESTING_HTTPS\"" +
9091
",\"statusDetailsMessage\":\"Sending one complete HTTPS request\",\"progress\":-1,\"eta\":-1,\"delegation\":3}," +
9192
"{\"ipAddress\":\"104.28.7.2\",\"statusMessage\":\"Pending\",\"progress\":-1,\"eta\":-1,\"delegation\":3}]}",
9293
StatusCode = 200,
9394
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")
9596
};
9697

9798
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
@@ -108,14 +109,40 @@ public void then_the_scan_results_should_be_public()
108109
}
109110
}
110111

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+
111138
public abstract class PositiveTests : GenericPositiveTests<Analyze>
112139
{
113140
public static string TestHost;
114141

115142
[TestMethod]
116143
public void then_the_host_property_should_match_the_requested_hostname()
117144
{
118-
Response.host.Should().Be(TestHost);
145+
Response.host.Should().Be(TestHost.Substring(8));
119146
}
120147

121148
[TestMethod]
@@ -133,5 +160,18 @@ public void then_the_port_should_be_that_of_a_ssl_connection()
133160

134161
public abstract class NegativeTests : GenericNegativeTests<Analyze>
135162
{
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+
}
136176
}
137177
}

0 commit comments

Comments
 (0)