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);
        }