Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Dec 15, 2025

Phase 2: Add .NET Core 6.0 Web API with Read-Only Endpoints

Summary

This PR implements Phase 2 of the .NET Framework to .NET Core migration by creating a new .NET Core 6.0 Web API project that runs alongside the existing .NET Framework MVC application, sharing the same SQL Server database.

Three new projects are added:

SampleWebApp.Core - Class library containing entities, DTOs, and MediatR handlers for read-only queries. Handlers use AutoMapper to map entities to DTOs and include related data via EF Core's .Include().

SampleWebApp.Api - Web API project with three controllers exposing read-only endpoints:

  • GET /api/blogs and GET /api/blogs/{id}
  • GET /api/tags and GET /api/tags/{id}
  • GET /api/posts?blogId={blogId} and GET /api/posts/{id}

SampleWebApp.Api.Tests - Test project with 42 unit and integration tests using xUnit, FluentAssertions, and EF Core InMemory provider.

The API includes Swagger UI for testing endpoints in development mode.

Updates Since Last Revision

Added comprehensive test suite (SampleWebApp.Api.Tests):

  • Unit tests for all 6 MediatR handlers (Blogs, Tags, Posts)
  • Integration tests for all 3 API controllers
  • Test fixtures using EF Core InMemory database with seeded test data
  • All 42 tests pass locally

Review & Testing Checklist for Human

  • Database schema compatibility: The EF Core DbContext defines a many-to-many relationship between Post and Tag using implicit join table conventions. Verify this matches the existing database's join table structure (table name, column names).
  • Test against actual database: The unit tests use in-memory database which may behave differently than SQL Server. Run the API locally against the real SampleWebAppDb and verify all endpoints return correct data.
  • Entity property alignment: Compare the new entity classes in SampleWebApp.Core/Entities/ against the existing DataLayer/DataClasses/Concrete/ to ensure all properties and constraints match.
  • Connection string: The default connection string uses LocalDB (Server=(localdb)\\mssqllocaldb). Update for your environment if needed.

Recommended test plan:

  1. Run dotnet test SampleWebApp.Api.Tests to verify all 42 tests pass
  2. Ensure the existing MVC app's database has seed data
  3. Run dotnet run --project SampleWebApp.Api
  4. Navigate to /swagger and test each endpoint
  5. Compare API responses against the existing MVC app's data to verify consistency

Notes

The handlers inject DbContext (abstract base class) rather than the concrete SampleWebAppDbContext. This is registered in DI via AddScoped<DbContext>(provider => provider.GetRequiredService<SampleWebAppDbContext>()).

The test project uses EF Core InMemory provider which does not enforce referential integrity the same way SQL Server does. Integration tests verify API behavior but do not guarantee database compatibility.

Link to Devin run: https://app.devin.ai/sessions/d522c71ef39e4168b74915566b62b279
Requested by: Abhay Aggarwal (@abhay-codeium)

… Tags, and Posts

Phase 2 of the .NET Framework to .NET Core migration:

- Create SampleWebApp.Core class library with:
  - Entity classes (Blog, Post, Tag)
  - DTOs (BlogDto, TagDto, SimplePostDto, DetailPostDto)
  - MediatR handlers for read-only queries
  - AutoMapper mapping profile

- Create SampleWebApp.Api Web API project with:
  - DbContext configured for SQL Server (same database as existing app)
  - BlogsController with GET /api/blogs and GET /api/blogs/{id}
  - TagsController with GET /api/tags and GET /api/tags/{id}
  - PostsController with GET /api/posts?blogId={blogId} and GET /api/posts/{id}
  - Swagger/OpenAPI documentation
  - MediatR and AutoMapper integration

Co-Authored-By: Abhay Aggarwal <abhay.aggarwal@codeium.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Add SampleWebApp.Api.Tests project with xUnit, FluentAssertions, Moq
- Add TestDbContextFixture for in-memory database testing
- Add AutoMapperFixture for mapping configuration
- Add unit tests for Blog handlers (GetBlogsHandler, GetBlogByIdHandler)
- Add unit tests for Tag handlers (GetTagsHandler, GetTagByIdHandler)
- Add unit tests for Post handlers (GetPostsHandler, GetPostByIdHandler)
- Add integration tests for BlogsController, TagsController, PostsController
- Add CustomWebApplicationFactory for integration testing with in-memory database
- Update Program.cs with partial class for test accessibility

All 42 tests pass successfully.

Co-Authored-By: Abhay Aggarwal <abhay.aggarwal@codeium.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant