public void TestGetByDocumentFailsOnMissingHeader() { Mock <IHeaderRepository> mockHeaderRepository = new Mock <IHeaderRepository>(); Mock <IDocumentRepository> mockDocumentRepository = new Mock <IDocumentRepository>(); IHeaderManagementService headerLogic = new HeaderManagementService { HeaderRepository = mockHeaderRepository.Object, DocumentRepository = mockDocumentRepository.Object }; Document fakeDocument = GetFakeDocument(); Header fakeHeader = GetFakeHeaderForDocument(fakeDocument); mockDocumentRepository .Setup(wl => wl.Exists(fakeDocument.Id)) .Returns(true); mockHeaderRepository .Setup(wl => wl.ExistsForDocument(fakeDocument.Id)) .Returns(false); Header result = headerLogic.GetByDocument(fakeDocument.Id); mockDocumentRepository.VerifyAll(); mockHeaderRepository.VerifyAll(); }
public void TestGetByDocumentReturnsHeaderOnExistingHeaderAndDocument() { Mock <IHeaderRepository> mockHeaderRepository = new Mock <IHeaderRepository>(); Mock <IDocumentRepository> mockDocumentRepository = new Mock <IDocumentRepository>(); IHeaderManagementService headerLogic = new HeaderManagementService { HeaderRepository = mockHeaderRepository.Object, DocumentRepository = mockDocumentRepository.Object }; Document fakeDocument = GetFakeDocument(); Header fakeHeader = GetFakeHeaderForDocument(fakeDocument); mockDocumentRepository .Setup(wl => wl.Exists(fakeDocument.Id)) .Returns(true); mockHeaderRepository .Setup(wl => wl.ExistsForDocument(fakeDocument.Id)) .Returns(true); mockHeaderRepository .Setup(wl => wl.GetByDocument(fakeDocument.Id)) .Returns(fakeHeader); Header result = headerLogic.GetByDocument(fakeDocument.Id); mockDocumentRepository.VerifyAll(); mockHeaderRepository.VerifyAll(); Assert.IsNotNull(result); Assert.AreEqual(result, fakeHeader); }