Project

Keep current project in tact. This is similar in practice as applying the strangler pattern. Doing so will keep the project as a point of reference. More importantly, it keeps the compiler happy and allows for porting each project independently. When selecting the project, always start with the core project (i.e. one with the least to no dependency).

Preserve project name and namespace. When creating the project, keep the project name and namespace the same. Do choose a new folder to create the project in. This could be as simple as naming the folder port. If you choose to create a Visual Studio solution folder, make sure it does not end up in the namespace.

Create an equivalent project under the .NET Core template. For a UnitTest project create the equivalent UnitTest Core project. Doing this step will create an empty project with a .NET Core template. Mainly the csproj XML structure. Keep the same UnitTest framework. A change here would exponentially increase refactoring efforts.

Wire up with DI

The following code is a snapshot for demonstration purpose. The goal is to demonstrate the ability to leverage the startup code to wire up all DI requirements.

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class ProductUnitTest
{
    IHost _host;

    // Setup
    public ProductUnitTest()
    {
        _host = Host.CreateDefaultBuilder()
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<MyProductProject.Startup>();
            })
            .ConfigureServices(services =>
            {
                // potentially an in-memory database
                services.AddScoped<DbContext>(); 
                services.AddScoped<ProductController>();
            }).Build();        
    }

    controller = _host.Services.GetService<ProductController>();
    [TestMethod]
    public void GetProduct_ShouldSucceed()
    {
        //Arrange
        var controller = _host.Services.GetService<ProductController>();
        var productRequest = "abc123";
        var expectedProductResponse = 
            new ProductResponse() { 
                Id = "abc123", 
                Title = "Product A" 
            };
        
        //Act
        var actualProductResponse = 
            (controller.Get(productRequest) as JsonResult)
            .Value as ProductResponse;

        //Assert
        Assert.IsTrue(actualProductResponse.Title == expectedProductResponse.Title);
    }
}

[ApiController]
[Route("api/[controller]")]
public class ProductController : ControllerBase
{
    public ProductController(DbContext db)
    {
        ...
    }

    [HttpGet]
    [Route("{id}")]
    public JsonResult Get(string id)
    {
        ...
    }
}