This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent NullReferenceException when disposing Context.Scope (#782).
- Loading branch information
Cesar Blum Silveira
committed
Jun 9, 2016
1 parent
525b925
commit 0f79bff
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/Microsoft.AspNetCore.Hosting.Tests/HostingApplicationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting.Internal; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.ObjectPool; | ||
using Microsoft.Extensions.Options; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Hosting.Tests | ||
{ | ||
public class HostingApplicationTests | ||
{ | ||
[Fact] | ||
public void DisposeContextDoesNotThrowWhenContextScopeIsNull() | ||
{ | ||
// Arrange | ||
var httpContextFactory = new HttpContextFactory(new DefaultObjectPoolProvider(), Options.Create(new FormOptions()), new HttpContextAccessor()); | ||
var hostingApplication = new HostingApplication(ctx => Task.FromResult(0), new NullScopeLogger(), new NoopDiagnosticSource(), httpContextFactory); | ||
var context = hostingApplication.CreateContext(new FeatureCollection()); | ||
|
||
// Act/Assert | ||
hostingApplication.DisposeContext(context, null); | ||
} | ||
|
||
private class NullScopeLogger : ILogger | ||
{ | ||
public IDisposable BeginScope<TState>(TState state) => null; | ||
|
||
public bool IsEnabled(LogLevel logLevel) => true; | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
} | ||
} | ||
|
||
private class NoopDiagnosticSource : DiagnosticSource | ||
{ | ||
public override bool IsEnabled(string name) => true; | ||
|
||
public override void Write(string name, object value) | ||
{ | ||
} | ||
} | ||
} | ||
} |