示例#1
0
        public void testUpdate()
        {
            // Arrange
            int count = repo.All().Count();

            repo.Add(entity);
            this.repo.SaveChanges();

            Assert.Null(repo.GetByName(n + "alala"));


            Assert.AreEqual(count + 1, repo.All().Count());
            entity.Name += "alala";


            // Act
            repo.Update(entity);
            repo.SaveChanges();

            // Assert

            Assert.NotNull(repo.GetByName(n + "alala"));
            this.repo.HardDelete(entity);
            this.repo.SaveChanges();
        }
示例#2
0
 public void Update(Guid textId, Text newTextData)
 {
     if (TextRepository.Exists(textId))
     {
         Text textToUpdate = TextRepository.GetById(textId);
         if (textToUpdate.Position != newTextData.Position)
         {
             IEnumerable <Text> textsInContent = TextRepository.GetByContent(textToUpdate.ContentThatBelongs);
             int newPosition = newTextData.Position;
             int maxPosition = textsInContent.Count() - 1;
             if (newPosition > maxPosition || newPosition < 0)
             {
                 throw new InvalidPositionException("This position is not valid for the content in question.");
             }
             else
             {
                 Text swappedText = textsInContent.First(p => p.Position == newPosition);
                 swappedText.Position = textToUpdate.Position;
                 TextRepository.Update(swappedText);
                 textToUpdate.Position = newPosition;
             }
         }
         if (newTextData.StyleClass != null && !StyleClassRepository.Exists(newTextData.StyleClass.Name))
         {
             newTextData.StyleClass = null;
         }
         textToUpdate.StyleClass  = newTextData.StyleClass;
         textToUpdate.TextContent = newTextData.TextContent;
         TextRepository.Update(textToUpdate);
     }
     else
     {
         throw new MissingParagraphException("This paragraph is not in the database.");
     }
 }
示例#3
0
 public void Delete(Guid textId)
 {
     if (TextRepository.Exists(textId))
     {
         Text textToDelete = TextRepository.GetById(textId);
         IEnumerable <Text> textsInContent = TextRepository.GetByContent(textToDelete.ContentThatBelongs);
         foreach (Text textInContent in textsInContent)
         {
             if (textInContent.Position > textToDelete.Position)
             {
                 textInContent.Position--;
                 TextRepository.Update(textInContent);
             }
         }
         TextRepository.Delete(textId);
     }
     else
     {
         throw new MissingTextException("This text is not in the database");
     }
 }