예제 #1
0
        public void TestGetThumbnailImageReturns400_WhenInputValidationFails()
        {
            Guid guid = Guid.NewGuid();

            this.inputValidation.Setup(validation => validation.ValidateNewsParameters(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Throws(new InputValidationException(HttpStatusCode.BadRequest, string.Empty));

            var newsThumbnailController = new NewsThumbnailImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

            var request = new HttpRequestMessage(HttpMethod.Get, GOUriBuilder.BuildAbsoluteNewsThumbnailImageUri(Scheme, Host, Port, City, Date, guid.ToString()));

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsThumbnailImageUri(Scheme, Host, Port, City, Date, guid.ToString()));

            newsThumbnailController.ConfigureForTesting(request, "GetThumbnail", new HttpRoute(GOUriBuilder.NewsImageThumbnailTemplate));

            HttpResponseMessage response = newsThumbnailController.Get(City, Date, guid.ToString()).Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #2
0
        public void TestGetThumbnailImageReturns404_WhenTheNewsIsNotTheDatabase()
        {
            Guid guid = Guid.NewGuid();

            this.businessValidation.Setup(validation => validation.IsValidGetNews(this.mockNewsRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(false));
            this.businessValidation.Setup(validation => validation.IsValidGetImageNews(this.mockImageRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true));
            this.businessValidation.Setup(validation => validation.IsValidGetThumbnailImageNews(this.mockImageRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true));

            this.mockImageRepository.Setup(storage => storage.GetNewsThumbnailImage(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(Image.FromFile("goten.png")));

            var newsThumbnailController = new NewsThumbnailImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

            var request = new HttpRequestMessage(HttpMethod.Get, GOUriBuilder.BuildAbsoluteNewsThumbnailImageUri(Scheme, Host, Port, City, Date, guid.ToString()));

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsThumbnailImageUri(Scheme, Host, Port, City, Date, guid.ToString()));

            newsThumbnailController.ConfigureForTesting(request, "GetThumbnail", new HttpRoute(GOUriBuilder.NewsImageThumbnailTemplate));

            HttpResponseMessage response = newsThumbnailController.Get(City, Date, guid.ToString()).Result;

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }