using System.Net;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Routing;

namespace Sentinel.UnitTests.Helpers;

public class FakeController : ControllerBase
{
    public static FakeController CreateFakeController()
    {
        byte[] ipAddress = { 143, 24, 20, 36 };
        return CreateFakeController(ipAddress);
    }

    public static FakeController CreateFakeController(byte[] ipAddress)
    {
        var fakeController = new FakeController();

        HttpContext fakeHttpContext = new DefaultHttpContext();

        fakeHttpContext.Connection.RemoteIpAddress = new IPAddress(ipAddress);
        var routeData = new RouteData();
        var controllerActionDescriptor = new ControllerActionDescriptor();
        var fakeActionContext = new ActionContext(fakeHttpContext, routeData, controllerActionDescriptor);
        fakeController.ControllerContext = new ControllerContext(fakeActionContext);

        return fakeController;
    }
}