public void GetRepoByNameService_ReturnsRepo() { // Arrange var mockGitHubRepoRepository = new Mock<IGitHubRepoRepository>(); var mockUnitOfWork = new Mock<IUnitOfWork>(); // create a fake repo to return var owner = "fakeOwner"; var repoName = "fakeRepoName"; var fakeRepo = (GitHubRepo)MockHelper.GetRepoByName(owner, repoName); mockGitHubRepoRepository.Setup(s => s.GetRepoByName(owner, repoName)).Returns(fakeRepo); var svc = new GitHubRepoService(mockGitHubRepoRepository.Object, mockUnitOfWork.Object); // Act var result = svc.GetRepoByName(owner, repoName); // Assert Assert.AreEqual(result.Id , fakeRepo.Id); }
public void GetRepoByNameService_ifInvalidName_ReturnsNull() { // Arrange var mockGitHubRepoRepository = new Mock<IGitHubRepoRepository>(); var mockUnitOfWork = new Mock<IUnitOfWork>(); // create fake repo to return GitHubRepo fakeRepo = null; mockGitHubRepoRepository.Setup(s => s.GetRepoByName(null, null)).Returns(fakeRepo); var svc = new GitHubRepoService(mockGitHubRepoRepository.Object, mockUnitOfWork.Object); // Act var result = svc.GetRepoByName(null, null); // Assert Assert.IsNull(result); }
public void GetRepoByNameService_ReturnsException() { // Arrange var mockGitHubRepoRepository = new Mock<IGitHubRepoRepository>(); var mockUnitOfWork = new Mock<IUnitOfWork>(); mockGitHubRepoRepository.Setup(s => s.GetRepoByName(null, null)).Throws(new System.Exception("Fake exception")); var svc = new GitHubRepoService(mockGitHubRepoRepository.Object, mockUnitOfWork.Object); // Act var result = svc.GetRepoByName(null, null); // Assert // automatic }