ASP.NET Testing Api controller: Uri(Request.GetEncodedUrl()…) returns null
问题 I am testing an ASP.NET Core Api post method, but I get a System.NullReferenceException causing my test to fail. The null exception appears when I try to return a Created()-ActionResult, like this: return Created(new Uri(Request.GetEncodedUrl() + "/" + personDto.Id), personDto); My personDto.Id nor the personDto is not null, but the result of the Uri() returns null. I have googled but not found a solution, but I believe I have to mock the Uri()-method in some way (I am new to testing and asp