public void ReturnCorrectResult_IfNameMatch() { // Arrange var mockedCollection = new List <LakeModel>() { new LakeModel { Name = "First" }, new LakeModel { Name = "Second" } }; var model = new SearchModel() { Name = "not match" }; var mockedLakeService = new Mock <ILakeService>(); mockedLakeService.Setup(s => s.FindByLocation(It.IsAny <string>())).Returns(mockedCollection).Verifiable(); var controller = new SearchApiController(mockedLakeService.Object); // Act var result = controller.Lakes(model); var content = (result as OkNegotiatedContentResult <IEnumerable <LakeModel> >).Content; // Assert Assert.IsInstanceOf <OkNegotiatedContentResult <IEnumerable <LakeModel> > >(result); Assert.AreEqual(content, mockedCollection); mockedLakeService.Verify(s => s.FindByLocation(It.IsAny <string>()), Times.Once); }
public void ReturnNotFound_IfNameNotMatch() { // Arrange var model = new SearchModel() { Name = "not match" }; var mockedLakeService = new Mock <ILakeService>(); mockedLakeService.Setup(s => s.FindByLocation(It.IsAny <string>())).Verifiable(); var controller = new SearchApiController(mockedLakeService.Object); // Act var result = controller.Lakes(model); // Assert Assert.IsInstanceOf <NotFoundResult>(result); mockedLakeService.Verify(s => s.FindByLocation(It.IsAny <string>()), Times.Once); }