-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
366 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
171 changes: 170 additions & 1 deletion
171
src/DisposeableFixer/DisposeableFixer/DisposeableFixer.Test/Dummy.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 |
---|---|---|
@@ -1 +1,170 @@ | ||
| ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace UsingAspDotNetILoggerFactory | ||
{ | ||
public class SomeClass | ||
{ | ||
public SomeClass() | ||
{ | ||
var factory = new LoggerFactory(); | ||
var provider = new LoggerProvider(); | ||
factory.AddConsole(); | ||
|
||
factory.AddProvider(provider); | ||
|
||
provider.Dispose(); | ||
|
||
} | ||
|
||
private class LoggerFactory : ILoggerFactory | ||
{ | ||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void AddProvider(ILoggerProvider provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
private class LoggerProvider : ILoggerProvider | ||
{ | ||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public interface IConsoleLoggerSettings { | ||
bool IncludeScopes { get; } | ||
//IChangeToken ChangeToken { get; } | ||
bool TryGetSwitch(string name, out LogLevel level); | ||
IConsoleLoggerSettings Reload(); | ||
} | ||
public interface ILoggingBuilder { | ||
//IServiceCollection Services { get; } | ||
} | ||
public class ConsoleLoggerOptions { | ||
public bool IncludeScopes { get; set; } = false; | ||
} | ||
public static class ConsoleLoggerExtensions { | ||
public static ILoggingBuilder AddConsole(this ILoggingBuilder builder) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static ILoggingBuilder AddConsole(this ILoggingBuilder builder, Action<ConsoleLoggerOptions> configure) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static ILoggerFactory AddConsole(this ILoggerFactory factory) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, LogLevel minLevel) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
LogLevel minLevel, | ||
bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
Func<string, LogLevel, bool> filter) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
Func<string, LogLevel, bool> filter, | ||
bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
IConsoleLoggerSettings settings) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, IConfiguration configuration) { | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public interface IConfiguration { | ||
string this[string key] { get; set; } | ||
//IConfigurationSection GetSection(string key); | ||
|
||
//IEnumerable<IConfigurationSection> GetChildren(); | ||
|
||
//IChangeToken GetReloadToken(); | ||
} | ||
namespace Microsoft.Extensions.Logging { | ||
public interface ILogger { | ||
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, | ||
Func<TState, Exception, string> formatter); | ||
|
||
bool IsEnabled(LogLevel logLevel); | ||
IDisposable BeginScope<TState>(TState state); | ||
} | ||
|
||
public enum LogLevel { | ||
Trace = 0, | ||
Debug = 1, | ||
Information = 2, | ||
Warning = 3, | ||
Error = 4, | ||
Critical = 5, | ||
None = 6 | ||
} | ||
|
||
public struct EventId { | ||
public EventId(int id, string name = null) { | ||
Id = id; | ||
Name = name; | ||
} | ||
|
||
public int Id { get; } | ||
|
||
public string Name { get; } | ||
|
||
public static implicit operator EventId(int i) { | ||
return new EventId(i); | ||
} | ||
|
||
public override string ToString() { | ||
if (Name != null) { | ||
return Name; | ||
} | ||
return Id.ToString(); | ||
} | ||
} | ||
|
||
public interface ILoggerProvider : IDisposable { | ||
ILogger CreateLogger(string categoryName); | ||
} | ||
|
||
public interface ILoggerFactory : IDisposable { | ||
ILogger CreateLogger(string categoryName); | ||
void AddProvider(ILoggerProvider provider); | ||
} | ||
} |
195 changes: 195 additions & 0 deletions
195
...sposeableFixer/DisposeableFixer.Test/IssueTests/If_Analyser_runs_on_code_from_issue_38.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,195 @@ | ||
using FluentAssertions; | ||
using Microsoft.CodeAnalysis; | ||
using NUnit.Framework; | ||
|
||
namespace DisposableFixer.Test.IssueTests | ||
{ | ||
[TestFixture] | ||
internal class If_Analyser_runs_on_code_from_issue_38 : IssueSpec | ||
{ | ||
private const string Code = @" | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
namespace UsingAspDotNetILoggerFactory | ||
{ | ||
public class SomeClass | ||
{ | ||
public SomeClass() | ||
{ | ||
var factory = new LoggerFactory(); | ||
var provider = new LoggerProvider(); | ||
factory.AddConsole(); | ||
factory.AddProvider(provider); | ||
provider.Dispose(); | ||
} | ||
private class LoggerFactory : ILoggerFactory | ||
{ | ||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public void AddProvider(ILoggerProvider provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
private class LoggerProvider : ILoggerProvider | ||
{ | ||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} | ||
public interface IConsoleLoggerSettings { | ||
bool IncludeScopes { get; } | ||
//IChangeToken ChangeToken { get; } | ||
bool TryGetSwitch(string name, out LogLevel level); | ||
IConsoleLoggerSettings Reload(); | ||
} | ||
public interface ILoggingBuilder { | ||
//IServiceCollection Services { get; } | ||
} | ||
public class ConsoleLoggerOptions { | ||
public bool IncludeScopes { get; set; } = false; | ||
} | ||
public static class ConsoleLoggerExtensions { | ||
public static ILoggingBuilder AddConsole(this ILoggingBuilder builder) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggingBuilder AddConsole(this ILoggingBuilder builder, Action<ConsoleLoggerOptions> configure) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole(this ILoggerFactory factory) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, LogLevel minLevel) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
LogLevel minLevel, | ||
bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
Func<string, LogLevel, bool> filter) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
Func<string, LogLevel, bool> filter, | ||
bool includeScopes) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole( | ||
this ILoggerFactory factory, | ||
IConsoleLoggerSettings settings) { | ||
throw new NotImplementedException(); | ||
} | ||
public static ILoggerFactory AddConsole(this ILoggerFactory factory, IConfiguration configuration) { | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
public interface IConfiguration { | ||
string this[string key] { get; set; } | ||
//IConfigurationSection GetSection(string key); | ||
//IEnumerable<IConfigurationSection> GetChildren(); | ||
//IChangeToken GetReloadToken(); | ||
} | ||
namespace Microsoft.Extensions.Logging { | ||
public interface ILogger { | ||
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, | ||
Func<TState, Exception, string> formatter); | ||
bool IsEnabled(LogLevel logLevel); | ||
IDisposable BeginScope<TState>(TState state); | ||
} | ||
public enum LogLevel { | ||
Trace = 0, | ||
Debug = 1, | ||
Information = 2, | ||
Warning = 3, | ||
Error = 4, | ||
Critical = 5, | ||
None = 6 | ||
} | ||
public struct EventId { | ||
public EventId(int id, string name = null) { | ||
Id = id; | ||
Name = name; | ||
} | ||
public int Id { get; } | ||
public string Name { get; } | ||
public static implicit operator EventId(int i) { | ||
return new EventId(i); | ||
} | ||
public override string ToString() { | ||
if (Name != null) { | ||
return Name; | ||
} | ||
return Id.ToString(); | ||
} | ||
} | ||
public interface ILoggerProvider : IDisposable { | ||
ILogger CreateLogger(string categoryName); | ||
} | ||
public interface ILoggerFactory : IDisposable { | ||
ILogger CreateLogger(string categoryName); | ||
void AddProvider(ILoggerProvider provider); | ||
} | ||
}"; | ||
|
||
private Diagnostic[] _diagnostics; | ||
|
||
protected override void BecauseOf() | ||
{ | ||
_diagnostics = MyHelper.RunAnalyser(Code, Sut); | ||
} | ||
|
||
[Test] | ||
public void Then_there_should_be_no_Diagnostics() | ||
{ | ||
_diagnostics.Length.Should().Be(0); | ||
} | ||
} | ||
} |