Example #1
0
        public void TestAddDocumentWorksOnExistingUser()
        {
            Mock <IUserRepository>       mockUserRepository       = new Mock <IUserRepository>();
            Mock <IDocumentRepository>   mockDocumentRepository   = new Mock <IDocumentRepository>();
            Mock <IStyleClassRepository> mockStyleClassRepository = new Mock <IStyleClassRepository>();
            IDocumentManagementService   documentLogic            = new DocumentManagementService()
            {
                UserRepository       = mockUserRepository.Object,
                DocumentRepository   = mockDocumentRepository.Object,
                StyleClassRepository = mockStyleClassRepository.Object
            };
            Document fakeDocument = new Document
            {
                Creator    = GetFakeUser(),
                StyleClass = new StyleClass()
            };
            string userMail = "*****@*****.**";

            mockUserRepository
            .Setup(wl => wl.Exists(userMail))
            .Returns(true);
            mockDocumentRepository
            .Setup(wl => wl.Add(fakeDocument));
            mockStyleClassRepository
            .Setup(wl => wl.Exists(fakeDocument.StyleClass.Name))
            .Returns(true);

            Document result = documentLogic.Add(userMail, fakeDocument);

            mockDocumentRepository.VerifyAll();
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Id);
            Assert.IsTrue(DateTime.Now > result.CreationDate);
        }
Example #2
0
        public void TestAddDocumentFailsOnMissingUser()
        {
            Mock <IUserRepository>     mockUserRepository     = new Mock <IUserRepository>();
            Mock <IDocumentRepository> mockDocumentRepository = new Mock <IDocumentRepository>();
            IDocumentManagementService documentLogic          = new DocumentManagementService()
            {
                UserRepository     = mockUserRepository.Object,
                DocumentRepository = mockDocumentRepository.Object
            };
            Document fakeDocument = new Document
            {
                Creator    = GetFakeUser(),
                StyleClass = new StyleClass()
            };
            string userMail = "*****@*****.**";

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

            Document result = documentLogic.Add(userMail, fakeDocument);

            mockDocumentRepository.VerifyAll();
        }