Код: Выделить всё
[HttpGet]
public async Task DeviceType()
{
string deviceIp = HttpContext.GetServerVariable("REMOTE_ADDR");
var result = await DeviceService.GetTypeForAsync(deviceIp);
return Ok(result);
}
Код: Выделить всё
var actionContext = new Mock();
var httpContext = new Mock();
httpContext.Setup(x => x.GetServerVariable(It.IsAny())).Returns("192.168.1.1");
actionContext.Setup(x => x.HttpContext).Returns(httpContext.Object);
//...
var deviceController = new DeviceController();
deviceController.ControllerContext = new ControllerContext(actionContext.Object);
System.NotSupportedException: Неподдерживаемое выражение: x => x. GetServerVariable(It.IsAny())
Методы расширения (здесь: HttpContextServerVariableExtensions.GetServerVariable) не могут использоваться в выражениях настройки/проверки.
Вопрос в том, как издеваться над HttpContext.GetServerVariable("REMOTE_ADDR")?
Подробнее здесь: https://stackoverflow.com/questions/652 ... n-net-core