refactor(model): rename Yavsc.Blogspot.BlogPost to BlogPostDto
When commit 0e95e283 moved BlogPost from PostIt.Models to
Yavsc.Blogspot, it created an unfortunate collision with the
server-side EF entity Yavsc.Models.Blog.BlogPost. The two
classes have nothing in common beyond the name; the DTO is
the wire shape PostIt exchanges with the Blogs API, the EF
entity is the persistence model. Server code that imports both
namespaces (BlogSpotService.cs, etc.) ended up with 'BlogPost
is an ambiguous reference between X and Y' errors.
Renaming the client DTO to BlogPostDto (matching the
naming convention of the other DTOs in Yavsc.Api.Client.Dtos
— CircleDto, CircleAuthorizationDto, UserSearchResultDto)
disambiguates without renaming the EF entity on the server.
The namespace stays Yavsc.Blogspot; only the class name
changes. All call sites (client code, tests, XAML DataTemplates,
XML doc comments) are updated mechanically.
This commit is contained in:
parent
0e7576857d
commit
1b289c1387
12 changed files with 43 additions and 43 deletions
|
|
@ -97,7 +97,7 @@ public class BearerScopeTests
|
|||
// CapturingHttpHandler is the assertion point. It
|
||||
// records the first request's Authorization header and
|
||||
// returns 200 with an empty array (BlogApiClient
|
||||
// deserialises to List<BlogPost>).
|
||||
// deserialises to List<BlogPostDto>).
|
||||
var captured = new CapturingHttpHandler();
|
||||
var client = new YavscApiClient(
|
||||
settings,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ internal sealed class CallRecorder
|
|||
|
||||
/// <summary>Test fake that records every CallAsync invocation
|
||||
/// and answers them with a canned sequence: the first call gets
|
||||
/// a server-issued BlogPost (Id=42), the second call gets a
|
||||
/// a server-issued BlogPostDto (Id=42), the second call gets a
|
||||
/// single-element list containing that post. Used by the ViewModel
|
||||
/// tests and the headless UI test to capture exactly what the
|
||||
/// Save button posts to the server.</summary>
|
||||
|
|
@ -44,20 +44,20 @@ internal sealed class RecordingYavscApiClient : YavscApiClient
|
|||
public override Task<T> CallAsync<T>(HttpMethod method, string path, object? body = null, CancellationToken ct = default)
|
||||
{
|
||||
_recorder.Calls.Add((method, path, body));
|
||||
// BlogPost? boxes to BlogPost at runtime, so we test the
|
||||
// non-nullable type — typeof(BlogPost?) is a C# error
|
||||
// BlogPostDto? boxes to BlogPostDto at runtime, so we test the
|
||||
// non-nullable type — typeof(BlogPostDto?) is a C# error
|
||||
// (CS8639: "typeof cannot be used on a nullable reference
|
||||
// type").
|
||||
if (typeof(T) == typeof(BlogPost))
|
||||
return Task.FromResult((T)(object)new BlogPost
|
||||
if (typeof(T) == typeof(BlogPostDto))
|
||||
return Task.FromResult((T)(object)new BlogPostDto
|
||||
{
|
||||
Id = 42,
|
||||
Title = "Mon premier billet",
|
||||
AuthorId = "tester",
|
||||
Article = "Contenu du billet de test.",
|
||||
});
|
||||
if (typeof(T) == typeof(List<BlogPost>))
|
||||
return Task.FromResult((T)(object)new List<BlogPost>
|
||||
if (typeof(T) == typeof(List<BlogPostDto>))
|
||||
return Task.FromResult((T)(object)new List<BlogPostDto>
|
||||
{
|
||||
new() { Id = 42, Title = "Mon premier billet" }
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace PostIt.Tests;
|
|||
/// in which a brand-new post can be created), the binding has
|
||||
/// no target and the user's keystrokes are silently dropped.
|
||||
/// Clicking "Save" then routes to the VM branch
|
||||
/// <c>if (SelectedPost is null) { new BlogPost { Title = string.Empty, ... } }</c>
|
||||
/// <c>if (SelectedPost is null) { new BlogPostDto { Title = string.Empty, ... } }</c>
|
||||
/// which the controller rejects with 400 "The Title field is
|
||||
/// required." This test fails on that branch today and will
|
||||
/// pass once the VM owns a dedicated <c>Title</c>/<c>Article</c>
|
||||
|
|
@ -77,14 +77,14 @@ public class MainPageSaveTests
|
|||
// we inspect the recorder.
|
||||
await Task.Delay(200);
|
||||
|
||||
// Assert: the first POST to "blog" carried a BlogPost
|
||||
// Assert: the first POST to "blog" carried a BlogPostDto
|
||||
// whose Title is exactly what the user typed. The bug
|
||||
// fails this assertion with Title == string.Empty.
|
||||
Assert.NotEmpty(recorder.Calls);
|
||||
var (method, path, body) = recorder.FirstCall;
|
||||
Assert.Equal(HttpMethod.Post, method);
|
||||
Assert.Equal("blog", path);
|
||||
var sent = Assert.IsType<BlogPost>(body);
|
||||
var sent = Assert.IsType<BlogPostDto>(body);
|
||||
Assert.Equal(typed, sent.Title);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ public class PostItViewModelTests
|
|||
var blog = new BlogApiClient(fakeApi, "http://localhost/");
|
||||
var viewModel = new MainPageViewModel(blog);
|
||||
|
||||
viewModel.Posts.Add(new BlogPost { Id = 1, Title = "First post", Article = "Hello world", AuthorId = "alice" });
|
||||
viewModel.Posts.Add(new BlogPost { Id = 2, Title = "Second post", Article = "Nothing here", AuthorId = "bob" });
|
||||
viewModel.Posts.Add(new BlogPost { Id = 3, Title = "Third post", Article = "Search me", AuthorId = "carol" });
|
||||
viewModel.Posts.Add(new BlogPostDto { Id = 1, Title = "First post", Article = "Hello world", AuthorId = "alice" });
|
||||
viewModel.Posts.Add(new BlogPostDto { Id = 2, Title = "Second post", Article = "Nothing here", AuthorId = "bob" });
|
||||
viewModel.Posts.Add(new BlogPostDto { Id = 3, Title = "Third post", Article = "Search me", AuthorId = "carol" });
|
||||
|
||||
viewModel.SearchText = "search";
|
||||
viewModel.SearchCommand.Execute(null);
|
||||
|
|
@ -41,7 +41,7 @@ public class PostItViewModelTests
|
|||
// The new BlogApiClient delegates transport to YavscApiClient.
|
||||
// We feed it a fake YavscApiClient that returns the expected
|
||||
// list straight from CallAsync.
|
||||
var expected = new List<BlogPost>
|
||||
var expected = new List<BlogPostDto>
|
||||
{
|
||||
new() { Id = 1, Title = "Hello" },
|
||||
new() { Id = 2, Title = "World" }
|
||||
|
|
@ -77,8 +77,8 @@ public class PostItViewModelTests
|
|||
/// <summary>Test fake that hands back a canned list of posts from any CallAsync.</summary>
|
||||
private sealed class StubYavscApiClient : YavscApiClient
|
||||
{
|
||||
private readonly List<BlogPost> _posts;
|
||||
public StubYavscApiClient(List<BlogPost> posts)
|
||||
private readonly List<BlogPostDto> _posts;
|
||||
public StubYavscApiClient(List<BlogPostDto> posts)
|
||||
: base(
|
||||
new Settings
|
||||
{
|
||||
|
|
@ -98,7 +98,7 @@ public class PostItViewModelTests
|
|||
{
|
||||
// The canned fake only knows about a list of posts; the
|
||||
// BlogApiClient test asserts on that list directly.
|
||||
if (typeof(T) == typeof(List<BlogPost>))
|
||||
if (typeof(T) == typeof(List<BlogPostDto>))
|
||||
return Task.FromResult((T)(object)_posts);
|
||||
return Task.FromResult(default(T)!);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue