Example #1
0
        public void TestGetDocumentsByUserWorksOnExistingUser()
        {
            Mock <IUserRepository>     mockUserRepository     = new Mock <IUserRepository>();
            Mock <IDocumentRepository> mockDocumentRepository = new Mock <IDocumentRepository>();
            IDocumentManagementService documentLogic          = new DocumentManagementService()
            {
                UserRepository     = mockUserRepository.Object,
                DocumentRepository = mockDocumentRepository.Object
            };
            IEnumerable <Document> fakeDocuments = GetFakeDocuments();
            string userMail = "*****@*****.**";

            mockUserRepository
            .Setup(wl => wl.Exists(userMail))
            .Returns(true);
            mockDocumentRepository
            .Setup(wl => wl.GetAllByUser(userMail))
            .Returns(fakeDocuments);

            IEnumerable <Document> results = documentLogic.GetAllByUser(userMail);

            mockDocumentRepository.VerifyAll();
            Assert.IsNotNull(results);
            Assert.IsTrue(fakeDocuments.SequenceEqual(results));
        }
Example #2
0
        public void TestGetDocumentsByUserThrowsExceptionOnMissingUser()
        {
            Mock <IUserRepository>     mockUserRepository     = new Mock <IUserRepository>();
            Mock <IDocumentRepository> mockDocumentRepository = new Mock <IDocumentRepository>();
            IDocumentManagementService documentLogic          = new DocumentManagementService()
            {
                UserRepository     = mockUserRepository.Object,
                DocumentRepository = mockDocumentRepository.Object
            };
            IEnumerable <Document> fakeDocuments = GetFakeDocuments();
            string userMail = "*****@*****.**";

            mockUserRepository
            .Setup(wl => wl.Exists(userMail))
            .Returns(false);

            IEnumerable <Document> results = documentLogic.GetAllByUser(userMail);

            mockDocumentRepository.VerifyAll();
        }