Update() public method

public Update ( Enclosure enclosure ) : bool
enclosure Subtext.Framework.Components.Enclosure
return bool
コード例 #1
0
        public void CanUpdateEnclosure(string title, string url, string mimetype, long size, bool addToFeed,
                                       bool showWithPost)
        {
            // Arrange
            UnitTestHelper.SetupBlog(string.Empty);
            var repository = new DatabaseObjectProvider();
            Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Simone Chiaretta", "Post for testing Enclosures",
                                                                       "Listen to my great podcast");
            int entryId = UnitTestHelper.Create(e);
            Enclosure enc = UnitTestHelper.BuildEnclosure(title, url, mimetype, entryId, size, addToFeed, showWithPost);

            repository.Create(enc);

            string randomStr = UnitTestHelper.GenerateUniqueString().Left(20);
            enc.Url = url + randomStr;

            if (!string.IsNullOrEmpty(title))
            {
                enc.Title = title + randomStr;
            }

            enc.MimeType = mimetype + randomStr;

            int randomSize = new Random().Next(10, 100);
            enc.Size = size + randomSize;

            // Act
            repository.Update(enc);

            // Assert
            Entry newEntry = repository.GetEntry(entryId, true, false);
            UnitTestHelper.AssertEnclosures(enc, newEntry.Enclosure);
        }
コード例 #2
0
        public void Update_WithInvalidEnclosure_ThrowsArgumentException()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 0 };
            var repository = new DatabaseObjectProvider();

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            var exception = UnitTestHelper.AssertThrows<ArgumentException>(() => repository.Update(enclosure));
            Assert.AreEqual(enclosure.ValidationMessage, exception.Message);
        }
コード例 #3
0
        public void CanRemoveHttpEquivAndAddName()
        {
            var blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            MetaTag tag = UnitTestHelper.BuildMetaTag("Still nothing to see here.", null, "expires", blog.Id, null, DateTime.UtcNow);
            repository.Create(tag);

            tag.HttpEquiv = null;
            tag.Name = "author";
            tag.Content = "Steve-o-rino!";

            repository.Update(tag);

            ValidateMetaTags(tag, repository.GetMetaTagsForBlog(blog, 0, 100)[0]);
        }
コード例 #4
0
        public void CanRemoveNameAndAddHttpEquiv()
        {
            var blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            MetaTag tag = UnitTestHelper.BuildMetaTag("Nothing to see here.", "description", null, blog.Id, null,
                                                      DateTime.UtcNow);
            repository.Create(tag);

            tag.HttpEquiv = "cache-control";
            tag.Name = null;
            tag.Content = "no-cache";

            repository.Update(tag);

            ValidateMetaTags(tag, repository.GetMetaTagsForBlog(blog, 0, 100)[0]);
        }
コード例 #5
0
ファイル: ImageTests.cs プロジェクト: rsaladrigas/Subtext
 public void UpdateThrowsArgumentNullExceptionForNullImage()
 {
     var repository = new DatabaseObjectProvider();
     UnitTestHelper.AssertThrowsArgumentNullException(() => repository.Update(null, new byte[0]));
 }
コード例 #6
0
ファイル: ImageTests.cs プロジェクト: rsaladrigas/Subtext
 public void UpdateImageThrowsArgumentNullException()
 {
     var repository = new DatabaseObjectProvider();
     UnitTestHelper.AssertThrowsArgumentNullException(() => repository.Update((Image)null));
 }
コード例 #7
0
ファイル: ImageTests.cs プロジェクト: rsaladrigas/Subtext
        public void CanUpdate()
        {
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();

            Image image = CreateImageInstance();
            Assert.GreaterEqualThan(Config.CurrentBlog.Id, 0);
            Assert.AreEqual(Config.CurrentBlog.Id, image.BlogId);
            int imageId = repository.Insert(image, singlePixelBytes);

            Image saved = repository.GetImage(imageId, true /* activeOnly */);
            Assert.AreEqual(Config.CurrentBlog.Id, saved.BlogId, "The blog id for the image does not match!");
            saved.LocalDirectoryPath = Path.GetFullPath(TestDirectory);
            Assert.AreEqual("Test Image", saved.Title);

            saved.Title = "A Better Title";
            repository.Update(saved, singlePixelBytes);

            Image loaded = repository.GetImage(imageId, true /* activeOnly */);
            Assert.AreEqual(Config.CurrentBlog.Id, loaded.BlogId, "The blog id for the image does not match!");
            loaded.LocalDirectoryPath = Path.GetFullPath(TestDirectory);

            Assert.AreEqual("A Better Title", loaded.Title, "The title was not updated");
        }
コード例 #8
0
ファイル: FeedbackTests.cs プロジェクト: rsaladrigas/Subtext
        static FeedbackItem CreateAndUpdateFeedbackWithExactStatus(Entry entry, FeedbackType type,
                                                                   FeedbackStatusFlag status)
        {
            var repository = new DatabaseObjectProvider();
            var feedback = new FeedbackItem(type);
            feedback.Title = UnitTestHelper.GenerateUniqueString();
            feedback.Body = UnitTestHelper.GenerateUniqueString();
            feedback.EntryId = entry.Id;
            feedback.Author = "TestAuthor";

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Cache).Returns(new TestCache());
            subtextContext.SetupBlog(Config.CurrentBlog);
            subtextContext.SetupRepository(repository);
            subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable());
            subtextContext.Setup(c => c.HttpContext).Returns(new HttpContextWrapper(HttpContext.Current));

            var service = new CommentService(subtextContext.Object, null);
            int id = service.Create(feedback, true/*runFilters*/);

            feedback = repository.Get(id);
            feedback.Status = status;
            repository.Update(feedback);

            return repository.Get(id);
        }
コード例 #9
0
ファイル: FeedbackTests.cs プロジェクト: rsaladrigas/Subtext
        public void OnlyApprovedItemsContributeToEntryFeedbackCount()
        {
            Entry entry = SetupBlogForCommentsAndCreateEntry();
            var repository = new DatabaseObjectProvider();
            int entryId = entry.Id;

            CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved);
            entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false);
            Assert.AreEqual(1, entry.FeedBackCount, "Expected one approved feedback entry.");

            FeedbackItem comment = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment,
                                                                          FeedbackStatusFlag.FlaggedAsSpam);
            entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false);
            Assert.AreEqual(1, entry.FeedBackCount, "Expected one approved feedback entry.");

            comment.Approved = true;
            repository.Update(comment);
            entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false);
            Assert.AreEqual(2, entry.FeedBackCount,
                            "After approving the second comment, expected two approved feedback entry.");

            comment.Approved = false;
            repository.Update(comment);
            entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false);
            Assert.AreEqual(1, entry.FeedBackCount,
                            "After un-approving the second comment, expected one approved feedback entry.");

            repository.Delete(comment);
            entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false);
            Assert.AreEqual(1, entry.FeedBackCount,
                            "After un-approving the second comment, expected one approved feedback entry.");
        }
コード例 #10
0
        public void CanUpdateMetaTag(string content, string name, string httpequiv)
        {
            var blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            MetaTag tag = UnitTestHelper.BuildMetaTag(content, name, httpequiv, blog.Id, null, DateTime.UtcNow);
            repository.Create(tag);

            string randomStr = UnitTestHelper.GenerateUniqueString().Left(20);
            tag.Content = content + randomStr;

            if (!string.IsNullOrEmpty(name))
            {
                tag.Name = name + randomStr;
            }

            if (!string.IsNullOrEmpty(httpequiv))
            {
                tag.HttpEquiv = httpequiv + randomStr;
            }

            Assert.IsTrue(repository.Update(tag));

            MetaTag updTag = repository.GetMetaTagsForBlog(blog, 0, 100)[0];

            ValidateMetaTags(tag, updTag);
        }
コード例 #11
0
 public void Update_WithNullMetaTag_ThrowsArgumentNullException()
 {
     var repository = new DatabaseObjectProvider();
     UnitTestHelper.AssertThrowsArgumentNullException(() => repository.Update((MetaTag)null));
 }
コード例 #12
0
        public void Update_WithInvalidMetaTag_ThrowsArgumentException()
        {
            // arrange
            var metaTag = new MetaTag(null);
            var repository = new DatabaseObjectProvider();

            // act, assert
            Assert.IsFalse(metaTag.IsValid);
            UnitTestHelper.AssertThrows<ArgumentException>(() => repository.Update(metaTag));
        }