public void Initialize() { _mockHttpContext = new MockHttpContext(); var httpContextAccessorMock = new Mock <IHttpContextAccessor>(); httpContextAccessorMock .Setup(m => m.HttpContext) .Returns(_mockHttpContext); _service = new HttpContextService( new ClientIpResolver(httpContextAccessorMock.Object), httpContextAccessorMock.Object); }
public void Detect() { foreach (var accessor in Accessors) { var contextService = new HttpContextService(accessor); var userAgentService = new UserAgentService(contextService); var platformService = new PlatformService(userAgentService); var engineService = new EngineService(userAgentService, platformService); var browserService = new BrowserService(userAgentService, engineService); var deviceService = new DeviceService(userAgentService); _ = browserService.Name; _ = browserService.Version; _ = deviceService.Type; } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var agent = "useragent"; var context = new DefaultHttpContext(); context.Request.Headers["User-Agent"] = agent; var accessor = new HttpContextAccessor { HttpContext = context }; var contextService = new HttpContextService(accessor); var useragent = new UserAgentService(contextService); Console.WriteLine(useragent.UserAgent); }
public void Ctor_IServiceProvider_Success() { var agent = "Agent"; var context = new DefaultHttpContext(); context.Request.Headers["User-Agent"] = agent; var accessor = new HttpContextAccessor { HttpContext = context }; var contextService = new HttpContextService(accessor); var useragentService = new UserAgentService(contextService); Assert.NotNull(useragentService.UserAgent); Assert.Equal(agent, useragentService.UserAgent.ToString()); }
public _baseController(IServiceProvider serviceProvider) { _contextService = (HttpContextService)serviceProvider.GetService(typeof(HttpContextService)); }