corrige la création du lien
All checks were successful
Dotnet build and test / build (pull_request) Successful in 15m51s

This commit is contained in:
Paul Schneider 2026-09-18 12:13:00 +01:00
commit 9e8d00d78f
Signed by: notazof
GPG key ID: 1DD5D838E5343B06
2 changed files with 12 additions and 22 deletions

View file

@ -63,13 +63,17 @@ public class BlogAttachmentLinkTests
// carrying the file, then — because TryAppendAttachmentLinks // carrying the file, then — because TryAppendAttachmentLinks
// appended a link — a JSON one carrying the final article. // appended a link — a JSON one carrying the final article.
var linkPut = recorder.Calls.LastOrDefault( var linkPut = recorder.Calls.LastOrDefault(
c => c.method == HttpMethod.Put && c.body is BlogPostDto); c => c.method == HttpMethod.Put);
Assert.NotEqual(default, linkPut); 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"; 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. // 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 // Build a fresh BlogPostDto from the editor buffer on
// every Save — we no longer mutate SelectedPost in // 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) // (which was a no-op when SelectedPost was null)
// back onto the model and relied on a // back onto the model and relied on a
// [Required] violation to surface the missing // [Required] violation to surface the missing
@ -160,6 +160,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel
} }
else else
{ {
TryAppendAttachmentLinks(SelectedPost, attachments);
var update = new BlogPostDto var update = new BlogPostDto
{ {
Id = SelectedPost.Id, Id = SelectedPost.Id,
@ -170,24 +171,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel
DateCreated = SelectedPost.DateCreated, DateCreated = SelectedPost.DateCreated,
DateModified = DateTime.UtcNow, DateModified = DateTime.UtcNow,
}; };
await BlogClient!.UpdatePostAsync(SelectedPost.Id, update, attachments); 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é."); this.SetInfoStatus($"Billet {SelectedPost.Id} enregistré.");
DraftAttachments.Clear(); DraftAttachments.Clear();
} }
@ -374,6 +358,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel
public BlogsViewModel() public BlogsViewModel()
{ {
WindowTitle = "Blog";
SettingsModel = new Settings(); SettingsModel = new Settings();
Init(SettingsModel); Init(SettingsModel);
BlogClient = null; BlogClient = null;
@ -435,6 +420,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel
/// </summary> /// </summary>
public BlogsViewModel(BlogApiClient blogClient, Settings? settings = null, IServiceProvider? services = null) public BlogsViewModel(BlogApiClient blogClient, Settings? settings = null, IServiceProvider? services = null)
{ {
WindowTitle = "Blog";
SettingsModel = new Settings(); SettingsModel = new Settings();
BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient)); ; BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient)); ;
Services = services; Services = services;