public void AvailableHttpContextIsReturned() { var httpContextAccessor = new DefaultHttpContextAccessor(); HttpContext.Current = new HttpContext( new HttpRequest(null, "http://nlog-project.org", ""), new HttpResponse(new StringWriter(new StringBuilder())) ); Assert.NotNull(httpContextAccessor.HttpContext); }
public void AvailableHttpContextIsReturned() { var httpContextAccessor = new DefaultHttpContextAccessor(); HttpContext.Current = new HttpContext( new HttpRequest(null, "http://nlog-project.org", ""), new HttpResponse(new StringWriter(new StringBuilder())) ); Assert.NotNull(httpContextAccessor.HttpContext); }
public void Should_Return_Correct_Current_HttpContext() { CreateHttpContext(); var webConfiguration = new Mock<IWebConfiguration>(); var accessor = new DefaultHttpContextAccessor(webConfiguration.Object); var current = accessor.GetCurrent(); Assert.IsNotNull(current); Assert.IsTrue(current.Items.Contains("TestKey")); Assert.AreEqual(current.Items["TestKey"], "TestValue"); RestoreContext(); }
public void Should_Return_Correct_Current_HttpContext() { CreateHttpContext(); var webConfiguration = new Mock <IWebConfiguration>(); var accessor = new DefaultHttpContextAccessor(webConfiguration.Object); var current = accessor.GetCurrent(); Assert.IsNotNull(current); Assert.IsTrue(current.Items.Contains("TestKey")); Assert.AreEqual(current.Items["TestKey"], "TestValue"); RestoreContext(); }
public void Should_Map_Local_Path_WithoutContext_Correctly() { currentContext = HttpContext.Current; HttpContext.Current = null; var webConfiguration = new Mock<IWebConfiguration>(); var accessor = new DefaultHttpContextAccessor(webConfiguration.Object); var path = accessor.MapPath("test\\test1"); Assert.IsNotNull(path); Assert.IsTrue(path.EndsWith("test\\test1")); Assert.IsTrue(path.StartsWith(AppDomain.CurrentDomain.BaseDirectory)); RestoreContext(); }
public void Should_Map_Local_Path_WithoutContext_Correctly() { currentContext = HttpContext.Current; HttpContext.Current = null; var webConfiguration = new Mock <IWebConfiguration>(); var accessor = new DefaultHttpContextAccessor(webConfiguration.Object); var path = accessor.MapPath("test\\test1"); Assert.IsNotNull(path); Assert.IsTrue(path.EndsWith("test\\test1")); Assert.IsTrue(Path.IsPathRooted(AppDomain.CurrentDomain.BaseDirectory), "\"{0}\" should start with \"{1}\".", path, AppDomain.CurrentDomain.BaseDirectory); RestoreContext(); }
public void UnavailableHttpContextReturnsNull() { var httpContextAccessor = new DefaultHttpContextAccessor(); Assert.Null(httpContextAccessor.HttpContext); }
/// <summary> /// Initializes the <see cref="AspNetLayoutRendererBase"/>. /// </summary> protected AspNetLayoutRendererBase() { #if !DNX HttpContextAccessor = new DefaultHttpContextAccessor(); #endif }
/// <summary> /// Initializes the <see cref="AspNetLayoutRendererBase"/>. /// </summary> protected AspNetLayoutRendererBase() { #if !ASP_NET_CORE HttpContextAccessor = new DefaultHttpContextAccessor(); #endif }
/// <summary> /// Initializes the <see cref="AspNetLayoutRendererBase"/>. /// </summary> protected AspNetLayoutRendererBase() { #if !NETSTANDARD_1plus HttpContextAccessor = new DefaultHttpContextAccessor(); #endif }
public void UnavailableHttpContextReturnsNull() { var httpContextAccessor = new DefaultHttpContextAccessor(); Assert.Null(httpContextAccessor.HttpContext); }