corrige la création du lien

This commit is contained in:
Paul Schneider 2026-09-18 12:13:00 +01:00
commit 64df506f3d
2 changed files with 12 additions and 22 deletions

View file

@ -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<BlogPostDto>(linkPut.body);
var sent = Assert.IsType<System.Func<HttpContent>>(linkPut.body);
var multipartContent = Assert.IsType<MultipartFormDataContent>(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);
}
}

View file

@ -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
/// </summary>
public BlogsViewModel(BlogApiClient blogClient, Settings? settings = null, IServiceProvider? services = null)
{
WindowTitle = "Blog";
SettingsModel = new Settings();
BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient)); ;
Services = services;