public void CanUpdateEnclosure(string title, string url, string mimetype, long size, bool addToFeed, bool showWithPost) { UnitTestHelper.SetupBlog(string.Empty); 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); Enclosures.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; Assert.IsTrue(Enclosures.Update(enc), "Should have updated the Enclosure"); Entry newEntry = ObjectProvider.Instance().GetEntry(entryId, true, false); UnitTestHelper.AssertEnclosures(enc, newEntry.Enclosure); }
public void Update_WithInvalidEnclosure_ThrowsArgumentException() { // arrange var enclosure = new Enclosure { EntryId = 0 }; // act, assert Assert.IsFalse(enclosure.IsValid); var exception = UnitTestHelper.AssertThrows <ArgumentException>(() => Enclosures.Update(enclosure)); Assert.AreEqual(enclosure.ValidationMessage, exception.Message); }
private void UpdatePost() { DateTime postDate = NullValue.NullDateTime; vCustomPostDate.IsValid = string.IsNullOrEmpty(txtPostDate.Text) || DateTime.TryParse(txtPostDate.Text, out postDate); EnableEnclosureValidation(EnclosureEnabled()); if (Page.IsValid) { string successMessage = Constants.RES_SUCCESSNEW; try { Entry entry; if (PostId == null) { ValidateEntryTypeIsNotNone(EntryType); entry = new Entry(EntryType); } else { entry = GetEntryForEditing(PostId.Value); if (entry.PostType != EntryType) { EntryType = entry.PostType; } } entry.Title = txbTitle.Text; entry.Body = richTextEditor.Xhtml; entry.Author = Config.CurrentBlog.Author; entry.Email = Config.CurrentBlog.Email; entry.BlogId = Config.CurrentBlog.Id; //Enclosure int enclosureId = 0; if (entry.Enclosure != null) { enclosureId = entry.Enclosure.Id; } if (EnclosureEnabled()) { if (entry.Enclosure == null) { entry.Enclosure = new Enclosure(); } Enclosure enc = entry.Enclosure; enc.Title = txbEnclosureTitle.Text; enc.Url = txbEnclosureUrl.Text; enc.MimeType = ddlMimeType.SelectedValue.Equals("other") ? txbEnclosureOtherMimetype.Text : ddlMimeType.SelectedValue; long size; Int64.TryParse(txbEnclosureSize.Text, out size); enc.Size = size; enc.AddToFeed = Boolean.Parse(ddlAddToFeed.SelectedValue); enc.ShowWithPost = Boolean.Parse(ddlDisplayOnPost.SelectedValue); } else { entry.Enclosure = null; } // Advanced options entry.IsActive = ckbPublished.Checked; entry.AllowComments = chkComments.Checked; entry.CommentingClosed = chkCommentsClosed.Checked; entry.DisplayOnHomePage = chkDisplayHomePage.Checked; entry.IncludeInMainSyndication = chkMainSyndication.Checked; entry.SyndicateDescriptionOnly = chkSyndicateDescriptionOnly.Checked; entry.IsAggregated = chkIsAggregated.Checked; entry.EntryName = txbEntryName.Text.NullIfEmpty(); entry.Description = txbExcerpt.Text.NullIfEmpty(); entry.Categories.Clear(); ReplaceSelectedCategoryNames(entry.Categories); if (!NullValue.IsNull(postDate)) { entry.DateSyndicated = postDate; } if (PostId != null) { successMessage = Constants.RES_SUCCESSEDIT; entry.DateModified = Config.CurrentBlog.TimeZone.Now; entry.Id = PostId.Value; var entryPublisher = SubtextContext.ServiceLocator.GetService <IEntryPublisher>(); entryPublisher.Publish(entry); if (entry.Enclosure == null && enclosureId != 0) { Enclosures.Delete(enclosureId); } else if (entry.Enclosure != null && entry.Enclosure.Id != 0) { Enclosures.Update(entry.Enclosure); } else if (entry.Enclosure != null && entry.Enclosure.Id == 0) { entry.Enclosure.EntryId = entry.Id; Enclosures.Create(entry.Enclosure); } UpdateCategories(); } else { var entryPublisher = SubtextContext.ServiceLocator.GetService <IEntryPublisher>(); _postId = entryPublisher.Publish(entry); NotificationServices.Run(entry, Blog, Url); if (entry.Enclosure != null) { entry.Enclosure.EntryId = PostId.Value; Enclosures.Create(entry.Enclosure); } UpdateCategories(); AddCommunityCredits(entry); } } catch (Exception ex) { Messages.ShowError(String.Format(Constants.RES_EXCEPTION, Constants.RES_FAILUREEDIT, ex.Message)); successMessage = string.Empty; } //Prepared success messages were reset in the catch block because of some error on posting the content if (!String.IsNullOrEmpty(successMessage)) { ReturnToOrigin(successMessage); } } }
public void Update_WithNullEnclosure_ThrowsArgumentNullException() { UnitTestHelper.AssertThrowsArgumentNullException(() => Enclosures.Update(null)); }