public void CorrectRequestShouldReturnOKResult() { var httpReq = new HttpRequest("GET /Home/LivePage HTTP/1.1"); var controloller = new ApiController(httpReq); var result = controloller.ReturnMe("test").GetResponse(); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); }
public void GetDateWithCorsActionThrowsAnExceptionWhenGivenWrongRefererAsParameter() { const string Parameter = "somedomain"; var request = this.GetMockedRequestWithRefererHeader("otherdomain"); var actionResult = new ApiController(request); actionResult.GetDateWithCors(Parameter); }
public void GetDateWithCorsActionReturnsJsonContentType() { const string Parameter = "somedomain"; var request = this.GetMockedRequestWithRefererHeader("somedomain"); var actionResult = new ApiController(request); var contentType = actionResult.GetDateWithCors(Parameter).GetResponse().Headers["Content-Type"].First(); Assert.AreEqual("application/json", contentType); }
public void GetDateWithCorsActionThrowsAnExceptionWhenNotGivenReferer() { const string Parameter = "somedomain"; var request = new Mock<IHttpRequest>(); request.Setup(x => x.ProtocolVersion).Returns(new Version(1, 1)); var headers = new Dictionary<string, ICollection<string>>(); request.SetupGet(x => x.Headers).Returns(headers); var actionResult = new ApiController(request.Object); actionResult.GetDateWithCors(Parameter); }
public void GetDateWithCorsActionShouldReturnValidJson() { const string Parameter = "somedomain"; var request = this.GetMockedRequestWithRefererHeader("somedomain.com"); var expectedJson = string.Format( "{{\"date\":\"{0:yyyy-MM-dd}\",\"moreInfo\":\"Data available for somedomain\"}}", DateTime.Now); var actionResult = new ApiController(request); var responseBody = actionResult.GetDateWithCors(Parameter).GetResponse().Body; Assert.AreEqual(expectedJson, responseBody); }
public void EmptyReuqestShouldThrow() { var httpReq = new HttpRequest(string.Empty); var controloller = new ApiController(httpReq); var result = controloller.ReturnMe("test").GetResponse(); }
public void ReturnMeActionReturnsParameterInTheJsonObject() { const string Parameter = "someParam123"; var request = new Mock<IHttpRequest>(); request.Setup(x => x.ProtocolVersion).Returns(new Version(1, 1)); var actionResult = new ApiController(request.Object); var resultBody = actionResult.ReturnMe(Parameter).GetResponse().Body; Assert.AreEqual(string.Format("{{\"param\":\"{0}\"}}", Parameter), resultBody); }
public void ReturnMeActionReturnsJsonContentType() { const string Parameter = "someParam123"; var request = new Mock<IHttpRequest>(); request.Setup(x => x.ProtocolVersion).Returns(new Version(1, 1)); var actionResult = new ApiController(request.Object); var contentType = actionResult.ReturnMe(Parameter).GetResponse().Headers["Content-Type"].First(); Assert.AreEqual("application/json", contentType); }