public void ContentItemController_Get_BadRequest_Test() { // Arrange Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Find(It.IsAny<long>(), It.IsAny<int>())).Throws(new Exception()); ContentItemController target = new ContentItemController(mock.Object); // Act IHttpActionResult result = target.Get(-1); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is BadRequestErrorMessageResult); }
public void ContentItemController_Get_Test() { // Arrange Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Find(It.IsAny<long>(), It.IsAny<int>())).Returns(new ContentItem() { Children = new ContentItem[2] }); ContentItemController target = new ContentItemController(mock.Object); // Act IHttpActionResult result = target.Get(1); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is OkNegotiatedContentResult<ContentItem>); Assert.AreEqual(2, (result as OkNegotiatedContentResult<ContentItem>).Content.Children.Length); mock.Verify(verify => verify.Find(It.IsAny<long>(), It.IsAny<int>()), Times.Once); }