32 lines
1011 B
C#
32 lines
1011 B
C#
using Bunit;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using RichardSzalay.MockHttp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Koogle.Tests.Common
|
|
{
|
|
public static class MockHttpClientBunitHelpers
|
|
{
|
|
public static MockHttpMessageHandler AddMockHttpClient(this TestServiceProvider services)
|
|
{
|
|
var mockHttpHandler = new MockHttpMessageHandler();
|
|
var httpClient = mockHttpHandler.ToHttpClient();
|
|
httpClient.BaseAddress = new Uri("http://localhost");
|
|
services.AddSingleton<HttpClient>(httpClient);
|
|
|
|
var context = new DefaultHttpContext();
|
|
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
|
|
|
httpContextAccessor.Setup(_ => _.HttpContext).Returns(context);
|
|
|
|
services.AddSingleton(httpContextAccessor.Object);
|
|
|
|
return mockHttpHandler;
|
|
}
|
|
}
|
|
} |