public void DeletePhone_NotExists() { Mock <IPhoneService> mockPhoneService = new Mock <IPhoneService>(); Phone phoneToDelete = null; mockPhoneService.Setup(service => service.GetPhone(1)).Returns(phoneToDelete); PhoneController controller = new PhoneController(mockPhoneService.Object); var result = controller.DeletePhone(1); Assert.AreEqual(typeof(NotFoundResult), result.GetType()); }
public void DeletePhone_Exists() { Mock <IPhoneService> mockPhoneService = new Mock <IPhoneService>(); Phone phoneToDelete = new Phone { ID = 1, FirstName = "xuxia", LastName = "yang", PhoneNumber = "4193771721" }; mockPhoneService.Setup(service => service.GetPhone(1)).Returns(phoneToDelete); PhoneController controller = new PhoneController(mockPhoneService.Object); var result = controller.DeletePhone(1) as OkNegotiatedContentResult <Phone>; mockPhoneService.Verify(service => service.DeletePhone(phoneToDelete), Times.Once()); Assert.AreEqual(phoneToDelete.FirstName, result.Content.FirstName); Assert.AreEqual(phoneToDelete.LastName, result.Content.LastName); Assert.AreEqual(phoneToDelete.PhoneNumber, result.Content.PhoneNumber); }