Relocate test project: test/yavscTests -> src/Yavsc.Org.Tests
Move the integration test project from the top-level test/ directory into src/ alongside the projects it tests. Rename the project (and folder) to Yavsc.Org.Tests to match .NET conventions and reflect that it tests the Org runtime primarily. Path changes: - test/yavscTests/yavscTests.csproj -> src/Yavsc.Org.Tests/Yavsc.Org.Tests.csproj - All .cs / .json / .resx files moved to their new location - PostItViewModelTests moved out to the dedicated src/PostIt.Tests project (it was unrelated to Org testing) Build adjustments: - <ProjectReference> paths shortened (..\..\src\X -> ..\X) - PostIt project reference removed (covered by its own test project) - <OutputType>exe added (required by xunit.v3) - xunit.v3.common and xunit.v3.extensibility.core added to package versions Solution + sln: - yavsc.sln Project Name updated to 'Yavsc.Org.Tests' and path updated - GUID preserved so existing build configs stay valid Static web assets: - The CopyStaticWebAssetsManifest target was hard-coding the destination filename to 'testhost.staticwebassets.endpoints.json', which worked when the assembly was named 'yavscTests'. Now that the assembly name is 'Yavsc.Org.Tests', ASP.NET Core's MapStaticAssets() looks for 'Yavsc.Org.Tests.staticwebassets.endpoints.json' (entry-assembly-based resolution). Use $(MSBuildProjectName) so the copy target stays correct under any future rename.
This commit is contained in:
parent
ad19ccbcfa
commit
22b397ce7e
18 changed files with 16 additions and 22 deletions
79
src/PostIt.Tests/PostItViewModelTests.cs
Normal file
79
src/PostIt.Tests/PostItViewModelTests.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using PostIt.Models;
|
||||
using PostIt.Services;
|
||||
using PostIt.ViewModels;
|
||||
using Xunit;
|
||||
|
||||
namespace PostIt;
|
||||
|
||||
public class PostItViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void SearchCommand_filters_posts_by_title_article_or_author()
|
||||
{
|
||||
var viewModel = new MainPageViewModel();
|
||||
|
||||
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.SearchText = "search";
|
||||
viewModel.SearchCommand.Execute(null);
|
||||
|
||||
Assert.Single(viewModel.FilteredPosts);
|
||||
Assert.Equal(3, viewModel.FilteredPosts[0].Id);
|
||||
|
||||
viewModel.SearchText = "bob";
|
||||
viewModel.SearchCommand.Execute(null);
|
||||
|
||||
Assert.Single(viewModel.FilteredPosts);
|
||||
Assert.Equal(2, viewModel.FilteredPosts[0].Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BlogApiClient_GetPostsAsync_returns_posts_from_api()
|
||||
{
|
||||
var expected = new List<BlogPost>
|
||||
{
|
||||
new() { Id = 1, Title = "Hello" },
|
||||
new() { Id = 2, Title = "World" }
|
||||
};
|
||||
|
||||
var handler = new FakeHttpMessageHandler(HttpStatusCode.OK, JsonSerializer.Serialize(expected));
|
||||
using var client = new HttpClient(handler)
|
||||
{
|
||||
BaseAddress = new System.Uri("http://localhost/")
|
||||
};
|
||||
|
||||
using var apiClient = new BlogApiClient(client);
|
||||
var posts = await apiClient.GetPostsAsync();
|
||||
|
||||
Assert.Equal(2, posts.Count);
|
||||
Assert.Equal("Hello", posts[0].Title);
|
||||
}
|
||||
|
||||
private sealed class FakeHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
private readonly HttpResponseMessage _response;
|
||||
|
||||
public FakeHttpMessageHandler(HttpStatusCode statusCode, string content)
|
||||
{
|
||||
_response = new HttpResponseMessage(statusCode)
|
||||
{
|
||||
Content = new StringContent(content, Encoding.UTF8, "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(_response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue