public void Cannot_Retrieve_TextImage_Data_For_Invalid_ID() { // Arrange - create a TextTemplate with image data TextTemplate textTemplate = new TextTemplate { Id = 1, Name = "TextTemplate1", Image = new byte[] { } }; // Arrange - create the mock repository Mock<IRepository<TextTemplate>> mock = new Mock<IRepository<TextTemplate>>(); mock.Setup(m => m.Get(1)).Returns(textTemplate); // Arrange - create the controller TextTemplateController target = new TextTemplateController(mock.Object); // Act - call the Image method HttpResponseMessage result = target.Image(100); // Assert Assert.IsInstanceOfType(result, typeof(HttpResponseMessage)); Assert.AreEqual(result.StatusCode, HttpStatusCode.BadRequest); }
public void Can_Retrieve_Text_Image_Data() { // Arrange - create a TextTemplate with image data TextTemplate textTemplate = new TextTemplate { Id = 1, Name = "TextTemplate1", Image = new byte[] { } }; // Arrange - create the mock repository Mock<IRepository<TextTemplate>> mock = new Mock<IRepository<TextTemplate>>(); mock.Setup(m => m.Get(1)).Returns(textTemplate); // Arrange - create the controller TextTemplateController target = new TextTemplateController(mock.Object); // Act - call the Image method HttpResponseMessage result = target.Image(1); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(HttpResponseMessage)); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual(result.Content.Headers.ContentType.MediaType, "image/png"); }