public void TestPostImageReturns200_WhenTheImageIsInTheDatabase()
        {
            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(true));
            this.businessValidation.Setup(validation => validation.IsValidModifyNews(this.mockNewsRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>())).Returns(Task.FromResult(true));
            this.businessValidation.Setup(validation => validation.IsValidGetImageNews(this.mockImageRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(false));

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

            var newsImageController = new NewsImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

            Image        image  = Image.FromFile("goten.png");
            MemoryStream stream = new MemoryStream();

            image.Save(stream, image.RawFormat);
            stream.Position = 0;

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

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, guid.ToString()));
            request.Content          = new ByteArrayContent(stream.GetBuffer());

            newsImageController.ConfigureForTesting(request, "PostImage", new HttpRoute(GOUriBuilder.NewsImageTemplate));
            newsImageController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null);

            HttpResponseMessage response = newsImageController.Post(City, Date, guid.ToString()).Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        private void AssertGetFails(HttpStatusCode resultCode)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, Id.ToString()));

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

            var newsImageController = new NewsImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

            newsImageController.ConfigureForTesting(request, "GetImage", new HttpRoute(GOUriBuilder.NewsImageTemplate));

            HttpResponseMessage response = newsImageController.Get(City, Date, Id.ToString()).Result;

            Assert.AreEqual(resultCode, response.StatusCode);
            this.mockImageRepository.Verify(storage => storage.GetNewsImage(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>()), Times.Never());
        }
        private void AssertPostFails(HttpStatusCode resultCode)
        {
            var newsImageController = new NewsImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

            var request = new HttpRequestMessage(HttpMethod.Post, GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, Id.ToString()));

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, Id.ToString()));
            request.Content          = new ByteArrayContent(new byte[0]);

            newsImageController.ConfigureForTesting(request, "PostImage", new HttpRoute(GOUriBuilder.NewsImageTemplate));
            newsImageController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null);

            HttpResponseMessage response = newsImageController.Post(City, Date, Id.ToString()).Result;

            Assert.AreEqual(resultCode, response.StatusCode);
            this.mockImageRepository.Verify(storage => storage.CreateNewsImage(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <Image>()), Times.Never());
        }
        public void TestGetImageReturns200_WhenTheThumbnailIsInTheDatabase()
        {
            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(true));
            this.businessValidation.Setup(validation => validation.IsValidGetImageNews(this.mockImageRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true));

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

            var newsImageController = new NewsImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object);

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

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

            newsImageController.ConfigureForTesting(request, "GetImage", new HttpRoute(GOUriBuilder.NewsImageTemplate));

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

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(new MediaTypeHeaderValue("image/png"), response.Content.Headers.ContentType);
        }