From 9e8d00d78fa53397618616263db89fcb2de7fe73 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 18 Sep 2026 12:13:00 +0100 Subject: [PATCH] =?UTF-8?q?corrige=20la=20cr=C3=A9ation=20du=20lien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PostIt.Tests/BlogAttachmentLinkTests.cs | 12 ++++++---- .../PostIt/ViewModels/Blogs/BlogsViewModel.cs | 22 ++++--------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/PostIt/PostIt.Tests/BlogAttachmentLinkTests.cs b/src/PostIt/PostIt.Tests/BlogAttachmentLinkTests.cs index 6572fdfbb..946d3d28e 100644 --- a/src/PostIt/PostIt.Tests/BlogAttachmentLinkTests.cs +++ b/src/PostIt/PostIt.Tests/BlogAttachmentLinkTests.cs @@ -63,13 +63,17 @@ public class BlogAttachmentLinkTests // carrying the file, then — because TryAppendAttachmentLinks // appended a link — a JSON one carrying the final article. var linkPut = recorder.Calls.LastOrDefault( - c => c.method == HttpMethod.Put && c.body is BlogPostDto); + c => c.method == HttpMethod.Put); Assert.NotEqual(default, linkPut); - var sent = Assert.IsType(linkPut.body); + var sent = Assert.IsType>(linkPut.body); + var multipartContent = Assert.IsType(sent()); var expectedUrl = $"{authority}/files/tester/blogs/42/note.txt"; - Assert.Contains($"- [note.txt]({expectedUrl})", sent.Article); + var sentStringContent = multipartContent.First() as StringContent ; + + var sentString = await sentStringContent.ReadAsStringAsync(TestContext.Current.CancellationToken); + Assert.Contains($"- [note.txt]({expectedUrl})", sentString); // The regression shape: a relative, authority-less link. - Assert.DoesNotContain("](/files/", sent.Article); + Assert.DoesNotContain("](/files/", sentString); } } diff --git a/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs b/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs index 78be2e789..f86e9a501 100644 --- a/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs @@ -116,7 +116,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel // Build a fresh BlogPostDto from the editor buffer on // every Save — we no longer mutate SelectedPost in - // place. The previous behaviour copied the buffer + // place. The previous behavior copied the buffer // (which was a no-op when SelectedPost was null) // back onto the model and relied on a // [Required] violation to surface the missing @@ -160,6 +160,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel } else { + TryAppendAttachmentLinks(SelectedPost, attachments); var update = new BlogPostDto { Id = SelectedPost.Id, @@ -170,24 +171,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel DateCreated = SelectedPost.DateCreated, DateModified = DateTime.UtcNow, }; - await BlogClient!.UpdatePostAsync(SelectedPost.Id, update, attachments); - - if (TryAppendAttachmentLinks(SelectedPost, attachments)) - { - var linkUpdate = new BlogPostDto - { - Id = SelectedPost.Id, - AuthorId = SelectedPost.AuthorId, - Photo = SelectedPost.Photo, - Title = DraftTitle, - Article = DraftArticle ?? string.Empty, - DateCreated = SelectedPost.DateCreated, - DateModified = DateTime.UtcNow, - }; - await BlogClient.UpdatePostAsync(SelectedPost.Id, linkUpdate); - } - this.SetInfoStatus($"Billet {SelectedPost.Id} enregistré."); DraftAttachments.Clear(); } @@ -374,6 +358,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel public BlogsViewModel() { + WindowTitle = "Blog"; SettingsModel = new Settings(); Init(SettingsModel); BlogClient = null; @@ -435,6 +420,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel /// public BlogsViewModel(BlogApiClient blogClient, Settings? settings = null, IServiceProvider? services = null) { + WindowTitle = "Blog"; SettingsModel = new Settings(); BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient)); ; Services = services;