public void CanDeleteEnclosure() { Blog blog = UnitTestHelper.CreateBlogAndSetupContext(); Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Simone Chiaretta", "Post for testing Enclosures", "Listen to my great podcast"); int entryId = UnitTestHelper.Create(e); Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryId, 12345678, true, true); Enclosures.Create(enc); Entry newEntry = ObjectProvider.Instance().GetEntry(entryId, true, false); Assert.IsNotNull(newEntry.Enclosure, "Did not create enclosure."); Enclosures.Delete(enc.Id); Entry newEntry1 = ObjectProvider.Instance().GetEntry(entryId, true, false); Assert.IsNull(newEntry1.Enclosure, "Did not delete enclosure."); }
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); } } }