public async Task GetPetReturnsAPet() { var repoMock = new Mock <IPetRepository>(); var logger = new Mock <ILogger>(); logger.Setup(x => x.Path).Returns("sample"); repoMock.Setup(x => x.GetPet(1)).Returns(new FakeModelRepo().GetPet(1)); var controller = new PetController(repoMock.Object, logger.Object); dynamic result = await controller.GetPet(1) as OkObjectResult; dynamic notFound = await controller.GetPet(3) as NotFoundObjectResult; if (result != null) { Assert.Equal <int>(1, result.Value.Id); } if (notFound != null) { Assert.Equal("Sorry, there is no Pet with this ID", notFound.Value); } }
public void Get() { // Arrange var mockProvider = new MockProvider(); var mockService = new Mock <IPetOwnerService>(); mockService.Setup(p => p.GetPetDetailsByGenderGroup(PetType.Cat)).Returns(mockProvider.GetMockPetGroup()); PetController controller = new PetController(mockService.Object); // Act var result = controller.GetPet(); // Assert Assert.IsNotNull(result); }