public void GetAll_should_return_status_code_ok_and_platforms() { // Arrange var controller = new PlatformsController(_imagesServiceMock.Object) { Request = new HttpRequestMessage(HttpMethod.Get, ApiPlatforms) }; HttpContext.Current = new HttpContext( new HttpRequest("", ApiPlatforms, ""), new HttpResponse(new StringWriter())); controller.Request.SetConfiguration(new HttpConfiguration()); _imagesServiceMock.Setup(i => i .GetPlatformPhotos(It.IsAny <string>(), It.IsAny <string>())) .Returns(new List <ImageViewModel> { new ImageViewModel { Link = "Link", LinkResponsive = "LinkResponsive", Alt = "Alt" } }); _imagesServiceMock.Setup(i => i .FilterPlatformMainPhoto(It.IsAny <IEnumerable <ImageViewModel> >())) .Returns(new ImageViewModel { Link = "LinkMain", LinkResponsive = "LinkResponsiveMain", Alt = "AltMain" }); // Act var result = controller.GetAll(); var content = result.Content; // Assert Assert.IsNotNull(result); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.IsNotNull(content); _imagesServiceMock.Verify(i => i.GetPlatformPhotos(It.IsAny <string>(), It.IsAny <string>())); _imagesServiceMock.Verify(i => i.FilterPlatformMainPhoto(It.IsAny <IEnumerable <ImageViewModel> >())); }
public void GetAll_should_return_status_code_internal_server_error_on_exception() { // Arrange var controller = new PlatformsController(null) { Request = new HttpRequestMessage(HttpMethod.Get, ApiPlatforms) }; HttpContext.Current = new HttpContext( new HttpRequest("", ApiPlatforms, ""), new HttpResponse(new StringWriter())); controller.Request.SetConfiguration(new HttpConfiguration()); // Act var result = controller.GetAll(); var content = result.Content; // Assert Assert.IsNotNull(result); Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode); Assert.IsNotNull(content); }