Logging test objects were copy-pasta from logging repo, removing and using official version
This commit is contained in:
parent
81a17300b2
commit
be7984eebc
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||
using Microsoft.AspNet.Http;
|
||||
#if ASPNET50
|
||||
using Microsoft.AspNet.Routing.Logging;
|
||||
using Microsoft.AspNet.Testing.Logging;
|
||||
using Moq;
|
||||
#endif
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class BeginScopeContext
|
||||
{
|
||||
public object Scope { get; set; }
|
||||
|
||||
public string LoggerName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class TestLogger : ILogger
|
||||
{
|
||||
private object _scope;
|
||||
private TestSink _sink;
|
||||
private string _name;
|
||||
private bool _enabled;
|
||||
|
||||
public TestLogger(string name, TestSink sink, bool enabled)
|
||||
{
|
||||
_sink = sink;
|
||||
_name = name;
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public IDisposable BeginScope(object state)
|
||||
{
|
||||
_scope = state;
|
||||
|
||||
_sink.Begin(new BeginScopeContext()
|
||||
{
|
||||
LoggerName = _name,
|
||||
Scope = state,
|
||||
});
|
||||
|
||||
return NullDisposable.Instance;
|
||||
}
|
||||
|
||||
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
|
||||
{
|
||||
_sink.Write(new WriteContext()
|
||||
{
|
||||
LogLevel = logLevel,
|
||||
EventId = eventId,
|
||||
State = state,
|
||||
Exception = exception,
|
||||
Formatter = formatter,
|
||||
LoggerName = _name,
|
||||
Scope = _scope
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class TestLoggerFactory : ILoggerFactory
|
||||
{
|
||||
private TestSink _sink;
|
||||
private bool _enabled;
|
||||
|
||||
public LogLevel MinimumLevel { get; set; }
|
||||
|
||||
public TestLoggerFactory(TestSink sink, bool enabled)
|
||||
{
|
||||
_sink = sink;
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
public ILogger Create(string name)
|
||||
{
|
||||
return new TestLogger(name, _sink, _enabled);
|
||||
}
|
||||
|
||||
public void AddProvider(ILoggerProvider provider)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. 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.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class TestSink
|
||||
{
|
||||
public TestSink(
|
||||
Func<WriteContext, bool> writeEnabled = null,
|
||||
Func<BeginScopeContext, bool> beginEnabled = null)
|
||||
{
|
||||
WriteEnabled = writeEnabled;
|
||||
BeginEnabled = beginEnabled;
|
||||
|
||||
Scopes = new List<BeginScopeContext>();
|
||||
Writes = new List<WriteContext>();
|
||||
}
|
||||
|
||||
public Func<WriteContext, bool> WriteEnabled { get; set; }
|
||||
|
||||
public Func<BeginScopeContext, bool> BeginEnabled { get; set; }
|
||||
|
||||
public List<BeginScopeContext> Scopes { get; set; }
|
||||
|
||||
public List<WriteContext> Writes { get; set; }
|
||||
|
||||
public void Write(WriteContext context)
|
||||
{
|
||||
if (WriteEnabled == null || WriteEnabled(context))
|
||||
{
|
||||
Writes.Add(context);
|
||||
}
|
||||
}
|
||||
|
||||
public void Begin(BeginScopeContext context)
|
||||
{
|
||||
if (BeginEnabled == null || BeginEnabled(context))
|
||||
{
|
||||
Scopes.Add(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool EnableWithTypeName<T>(WriteContext context)
|
||||
{
|
||||
return context.LoggerName.Equals(typeof(T).FullName);
|
||||
}
|
||||
|
||||
public static bool EnableWithTypeName<T>(BeginScopeContext context)
|
||||
{
|
||||
return context.LoggerName.Equals(typeof(T).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing.Logging;
|
||||
using Microsoft.AspNet.Routing.Template;
|
||||
using Microsoft.AspNet.Testing.Logging;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using Moq;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.AspNet.Routing.Logging;
|
||||
using Microsoft.AspNet.Testing.Logging;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Routing.Constraints;
|
||||
using Microsoft.AspNet.Routing.Logging;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Microsoft.AspNet.Testing.Logging;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Moq;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
"Microsoft.AspNet.Http.Core": "1.0.0-*",
|
||||
"Microsoft.AspNet.Routing": "1.0.0-*",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.AspNet.Testing.Logging": "1.0.0-*",
|
||||
"xunit.runner.kre": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"aspnetcore50": {},
|
||||
"aspnetcore50": { },
|
||||
"aspnet50": {
|
||||
"dependencies": {
|
||||
"Moq": "4.2.1312.1622"
|
||||
|
|
@ -19,4 +20,4 @@
|
|||
"commands": {
|
||||
"test": "xunit.runner.kre"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue