Skip to content

Commit

Permalink
Added tests to verify #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
BADF00D committed Sep 28, 2017
1 parent 1869408 commit 817a6ed
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_26.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_27.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_33.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_38.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_41.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_50.cs" />
<Compile Include="IssueTests\If_Analyser_runs_on_code_from_issue_58.cs" />
Expand Down
171 changes: 170 additions & 1 deletion src/DisposeableFixer/DisposeableFixer/DisposeableFixer.Test/Dummy.cs
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);
}
}
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);
}
}
}

0 comments on commit 817a6ed

Please sign in to comment.