示例#1
0
        private bool IsValidParagraph(Guid paragraphId)
        {
            if (!ParagraphRepository.Exists(paragraphId))
            {
                throw new MissingDocumentException("The paragraph does not exist.");
            }

            return(true);
        }
        public void TestDocumentDeleteWithOneHeaderOneFooterOneParagraphFromDatabase()
        {
            User user4 = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "name4",
                LastName      = "lastname3",
                Email         = "email3",
                Administrator = true
            };

            UserRepository.Add(user4);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title",
                Creator          = user4,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = null
            };

            DocumentRepository.Add(document);

            Header header = new Header
            {
                Id                  = Guid.NewGuid(),
                Content             = null,
                DocumentThatBelongs = document,
                StyleClass          = null
            };

            HeaderRepository.Add(header);

            Footer footer = new Footer
            {
                Id                  = Guid.NewGuid(),
                Content             = null,
                DocumentThatBelongs = document,
                StyleClass          = null
            };

            FooterRepository.Add(footer);

            Paragraph paragraph1 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = null,
                DocumentThatBelongs = document,
                StyleClass          = null,
                Position            = 0
            };

            ParagraphRepository.Add(paragraph1);

            Paragraph paragraph2 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = null,
                DocumentThatBelongs = document,
                StyleClass          = null,
                Position            = 1
            };

            ParagraphRepository.Add(paragraph2);

            DocumentRepository.Delete(document.Id);
            UserRepository.Delete(user4.Email);

            bool headerExistsAfterDelete     = HeaderRepository.Exists(header.Id);
            bool paragraph1ExistsAfterDelete = ParagraphRepository.Exists(paragraph1.Id);
            bool paragraph2ExistsAfterDelete = ParagraphRepository.Exists(paragraph2.Id);
            bool footerExistsAfterDelete     = FooterRepository.Exists(footer.Id);

            Assert.IsFalse(headerExistsAfterDelete);
            Assert.IsFalse(paragraph1ExistsAfterDelete);
            Assert.IsFalse(paragraph2ExistsAfterDelete);
            Assert.IsFalse(footerExistsAfterDelete);
        }
        public void TestParagraphsDontExistsAfterDeleteDocumentFromDatabase()
        {
            User userP1 = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "nameP1",
                LastName      = "lastnameP1",
                Email         = "emailP1",
                Administrator = true
            };

            UserRepository.Add(userP1);

            StyleClass StyleClassP1 = new StyleClass
            {
                Name    = "StyleClassP1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP1);

            StyleClass StyleClassP2 = new StyleClass
            {
                Name    = "StyleClassP2",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP2);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title1",
                Creator          = userP1,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClassP1
            };

            DocumentRepository.Add(document);

            Content content = new Content
            {
                Id = Guid.NewGuid(),
            };

            ContentRepository.Add(content);

            Paragraph paragraph1 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP1,
                Position            = 0
            };

            ParagraphRepository.Add(paragraph1);

            Paragraph paragraph2 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP2,
                Position            = 1
            };

            ParagraphRepository.Add(paragraph2);

            bool existsBeforeDeleteDocument1 = ParagraphRepository.Exists(paragraph1.Id);
            bool existsBeforeDeleteDocument2 = ParagraphRepository.Exists(paragraph2.Id);

            DocumentRepository.Delete(document.Id);

            bool existsAfterDeleteDocument1  = ParagraphRepository.Exists(paragraph1.Id);
            bool existsAftereDeleteDocument2 = ParagraphRepository.Exists(paragraph2.Id);

            StyleClassRepository.Delete(StyleClassP1.Name);
            StyleClassRepository.Delete(StyleClassP2.Name);
            UserRepository.Delete(userP1.Email);
            ContentRepository.Delete(content);

            Assert.IsTrue(existsBeforeDeleteDocument1);
            Assert.IsTrue(existsBeforeDeleteDocument2);
            Assert.IsFalse(existsAfterDeleteDocument1);
            Assert.IsFalse(existsAftereDeleteDocument2);
        }