private void AssertDeleteFails(HttpStatusCode resultCode) { var newsImageController = new NewsImageController(this.mockNewsRepository.Object, this.mockImageRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Delete, GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, Id.ToString())); request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsImageUri(Scheme, Host, Port, City, Date, Id.ToString())); newsImageController.ConfigureForTesting(request, "DeleteImage", new HttpRoute(GOUriBuilder.NewsImageTemplate)); newsImageController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = newsImageController.Delete(City, Date, Id.ToString()).Result; Assert.AreEqual(resultCode, response.StatusCode); this.mockImageRepository.Verify(storage => storage.DeleteNewsImage(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>()), Times.Never()); }
public void TestDeleteImageReturns200_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.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(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.Delete, 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, "DeleteImage", new HttpRoute(GOUriBuilder.NewsImageTemplate)); newsImageController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = newsImageController.Delete(City, Date, guid.ToString()).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }