public void UpdateExistingBreedOkTest() { //Arrange var fakeBreed = GetAFakeBreed(); var expectedResult = true; var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.Update(It.IsAny <Guid>(), It.IsAny <Breed>())) .Returns(true); var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Put(new Guid(), fakeBreed); var createdResult = obtainedResult as CreatedAtRouteNegotiatedContentResult <Breed>; //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsNotNull(createdResult); Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.AreEqual(expectedResult, createdResult.RouteValues["updated"]); Assert.AreEqual(fakeBreed, createdResult.Content); }
public void UpdateBreedWithNullIdErrorTest() { //Arrange Breed fakeBreed = null; var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.Update(new Guid(), It.IsAny <Breed>())) .Throws(new ArgumentNullException()); var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Put(new Guid(), fakeBreed); //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsInstanceOfType(obtainedResult, typeof(BadRequestErrorMessageResult)); }