From f28a7047d2800026c2f8e4ab41e97c16a44a0c04 Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:05:49 +0200 Subject: [PATCH 01/11] Added ConsoleLogger, Ilogger interface and static factory. --- src/coverlet.core/Logging/ConsoleLogger.cs | 20 ++++++++++++++++++++ src/coverlet.core/Logging/ILogger.cs | 7 +++++++ src/coverlet.core/Logging/LoggerFactory.cs | 10 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/coverlet.core/Logging/ConsoleLogger.cs create mode 100644 src/coverlet.core/Logging/ILogger.cs create mode 100644 src/coverlet.core/Logging/LoggerFactory.cs diff --git a/src/coverlet.core/Logging/ConsoleLogger.cs b/src/coverlet.core/Logging/ConsoleLogger.cs new file mode 100644 index 000000000..86539a76f --- /dev/null +++ b/src/coverlet.core/Logging/ConsoleLogger.cs @@ -0,0 +1,20 @@ +using System; + +namespace Coverlet.Core.Logging +{ + public class ConsoleLogger : ILogger + { + private ConsoleLogger() + { + } + + public static ILogger Instance { get; } = new ConsoleLogger(); + + public void Log(string s) + { + if (s == null) + return; + Console.WriteLine(s); + } + } +} \ No newline at end of file diff --git a/src/coverlet.core/Logging/ILogger.cs b/src/coverlet.core/Logging/ILogger.cs new file mode 100644 index 000000000..a630a6cc0 --- /dev/null +++ b/src/coverlet.core/Logging/ILogger.cs @@ -0,0 +1,7 @@ +namespace Coverlet.Core.Logging +{ + public interface ILogger + { + void Log(string s); + } +} \ No newline at end of file diff --git a/src/coverlet.core/Logging/LoggerFactory.cs b/src/coverlet.core/Logging/LoggerFactory.cs new file mode 100644 index 000000000..6ff45f35e --- /dev/null +++ b/src/coverlet.core/Logging/LoggerFactory.cs @@ -0,0 +1,10 @@ +namespace Coverlet.Core.Logging +{ + public static class LoggerFactory + { + public static ILogger GetLogger() + { + return ConsoleLogger.Instance; + } + } +} \ No newline at end of file From e7a716a7188495f1413a6077957e9e7a12e789bc Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:42:15 +0200 Subject: [PATCH 02/11] Replace with method group. --- src/coverlet.core/Coverage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index 1d065334c..5d8806697 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -30,7 +30,7 @@ public void PrepareModules() { string[] modules = InstrumentationHelper.GetCoverableModules(_module); string[] excludedFiles = InstrumentationHelper.GetExcludedFiles(_rules); - _filters = _filters?.Where(f => InstrumentationHelper.IsValidFilterExpression(f)).ToArray(); + _filters = _filters?.Where(InstrumentationHelper.IsValidFilterExpression).ToArray(); foreach (var module in modules) { From 2a96a27f64b86c12a77f6e506aba3d120c11994b Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:43:37 +0200 Subject: [PATCH 03/11] Updated ILogger interface (renamed method argument name). --- src/coverlet.core/Logging/ConsoleLogger.cs | 7 ++++--- src/coverlet.core/Logging/ILogger.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coverlet.core/Logging/ConsoleLogger.cs b/src/coverlet.core/Logging/ConsoleLogger.cs index 86539a76f..0edfcf77a 100644 --- a/src/coverlet.core/Logging/ConsoleLogger.cs +++ b/src/coverlet.core/Logging/ConsoleLogger.cs @@ -10,11 +10,12 @@ private ConsoleLogger() public static ILogger Instance { get; } = new ConsoleLogger(); - public void Log(string s) + public void Log(string text) { - if (s == null) + if (text == null) return; - Console.WriteLine(s); + + Console.WriteLine(text); } } } \ No newline at end of file diff --git a/src/coverlet.core/Logging/ILogger.cs b/src/coverlet.core/Logging/ILogger.cs index a630a6cc0..157d36f89 100644 --- a/src/coverlet.core/Logging/ILogger.cs +++ b/src/coverlet.core/Logging/ILogger.cs @@ -2,6 +2,6 @@ { public interface ILogger { - void Log(string s); + void Log(string text); } } \ No newline at end of file From 0888e0d7bb3ca48c14dcd0d8ddcd264ddb223e63 Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:45:17 +0200 Subject: [PATCH 04/11] Added interface IInstrumenter and added this interface to Instrumenter class. --- src/coverlet.core/Instrumentation/Instrumenter.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index dfc853204..829db5abc 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -14,7 +14,14 @@ namespace Coverlet.Core.Instrumentation { - internal class Instrumenter + internal interface IInstrumenter + { + bool CanInstrument(); + + InstrumenterResult Instrument(); + } + + internal class Instrumenter : IInstrumenter { private readonly string _module; private readonly string _identifier; From 3cd15cecea760cc7fa93cb18178879fc468e19e9 Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:48:28 +0200 Subject: [PATCH 05/11] Added static InstrumenterFactory to return the original Instrumenter (without decorating the instance with a logger or something like that). The creation of Instrumenter in Coverage class is done using the static Instrumenter factory. Still no functionality has changed --- src/coverlet.core/Coverage.cs | 2 +- src/coverlet.core/Instrumentation/Instrumenter.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index 5d8806697..51d9f6f27 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -37,7 +37,7 @@ public void PrepareModules() if (InstrumentationHelper.IsModuleExcluded(module, _filters)) continue; - var instrumenter = new Instrumenter(module, _identifier, _filters, excludedFiles); + var instrumenter = InstrumenterFactory.Create(module, _identifier, _filters, excludedFiles); if (instrumenter.CanInstrument()) { InstrumentationHelper.BackupOriginalModule(module, _identifier); diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 829db5abc..bcf6ecc18 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -21,6 +21,17 @@ internal interface IInstrumenter InstrumenterResult Instrument(); } + internal static class InstrumenterFactory + { + + public static IInstrumenter Create(string module, string identifier, string[] filters, string[] excludedFiles) + { + IInstrumenter result = new Instrumenter(module, identifier, filters, excludedFiles); + + return result; + } + } + internal class Instrumenter : IInstrumenter { private readonly string _module; From 2010ed942504b01211e73fc20eab1ed87ac5095b Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:49:33 +0200 Subject: [PATCH 06/11] Added Instrumenter decorator to log any call to the Instrument method of the instrumenter --- .../Decorators/InstrumenterLoggerDecorator.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/coverlet.core/Logging/Decorators/InstrumenterLoggerDecorator.cs diff --git a/src/coverlet.core/Logging/Decorators/InstrumenterLoggerDecorator.cs b/src/coverlet.core/Logging/Decorators/InstrumenterLoggerDecorator.cs new file mode 100644 index 000000000..13152ed5b --- /dev/null +++ b/src/coverlet.core/Logging/Decorators/InstrumenterLoggerDecorator.cs @@ -0,0 +1,29 @@ +using Coverlet.Core.Instrumentation; +using Coverlet.Core.Logging; + +namespace coverlet.core.Logging.Decorators +{ + internal class InstrumenterLoggerDecorator : IInstrumenter + { + private readonly IInstrumenter _decoratee; + private readonly ILogger _logger; + + public InstrumenterLoggerDecorator(IInstrumenter decoratee, ILogger logger) + { + _decoratee = decoratee; + _logger = logger; + } + + public bool CanInstrument() + { + return _decoratee.CanInstrument(); + } + + public InstrumenterResult Instrument() + { + var result = _decoratee.Instrument(); + _logger.Log($"Module {result.Module} was instrumented."); + return result; + } + } +} \ No newline at end of file From 6f2fc30a012e6be44d923aaf9439f416b12c2ce8 Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 21:51:28 +0200 Subject: [PATCH 07/11] Extended the InstrumenterFactory to decorate the real instance with all registered decorators. Added EnableLogging method that registers the logging decorator to the InstrumenterFactory --- src/coverlet.core/Instrumentation/Instrumenter.cs | 13 +++++++++++++ src/coverlet.core/Logging/EnableLogging.cs | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/coverlet.core/Logging/EnableLogging.cs diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index bcf6ecc18..4cf08ea47 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -23,13 +23,26 @@ internal interface IInstrumenter internal static class InstrumenterFactory { + private static readonly List> DecoratorFunctions = new List>(); public static IInstrumenter Create(string module, string identifier, string[] filters, string[] excludedFiles) { IInstrumenter result = new Instrumenter(module, identifier, filters, excludedFiles); + // Decorate the real Instrumenter instance + foreach (var decoratorFunc in DecoratorFunctions) + result = decoratorFunc.Invoke(result); + return result; } + + public static void RegisterDecorator(Func decoratingFunc) + { + if (decoratingFunc == null) + throw new ArgumentNullException(nameof(decoratingFunc)); + + DecoratorFunctions.Add(decoratingFunc); + } } internal class Instrumenter : IInstrumenter diff --git a/src/coverlet.core/Logging/EnableLogging.cs b/src/coverlet.core/Logging/EnableLogging.cs new file mode 100644 index 000000000..eaeec671a --- /dev/null +++ b/src/coverlet.core/Logging/EnableLogging.cs @@ -0,0 +1,14 @@ +using coverlet.core.Logging.Decorators; +using Coverlet.Core.Instrumentation; +using Coverlet.Core.Logging; + +namespace coverlet.core.Logging +{ + public static class EnableLogging + { + public static void Execute() + { + InstrumenterFactory.RegisterDecorator(instrumenter => new InstrumenterLoggerDecorator(instrumenter, LoggerFactory.GetLogger())); + } + } +} \ No newline at end of file From 80aef4b6ee7537cbc95990a072aa30ef24343f1d Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 22:12:01 +0200 Subject: [PATCH 08/11] Add Verbose option to Instrumentation Task and enable logging when verbositiy is true. --- src/coverlet.core/Logging/EnableLogging.cs | 1 + src/coverlet.msbuild.tasks/InstrumentationTask.cs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coverlet.core/Logging/EnableLogging.cs b/src/coverlet.core/Logging/EnableLogging.cs index eaeec671a..2f2c13703 100644 --- a/src/coverlet.core/Logging/EnableLogging.cs +++ b/src/coverlet.core/Logging/EnableLogging.cs @@ -8,6 +8,7 @@ public static class EnableLogging { public static void Execute() { + LoggerFactory.GetLogger().Log("Logging enabled."); InstrumenterFactory.RegisterDecorator(instrumenter => new InstrumenterLoggerDecorator(instrumenter, LoggerFactory.GetLogger())); } } diff --git a/src/coverlet.msbuild.tasks/InstrumentationTask.cs b/src/coverlet.msbuild.tasks/InstrumentationTask.cs index 12c641ce0..2ebe92675 100644 --- a/src/coverlet.msbuild.tasks/InstrumentationTask.cs +++ b/src/coverlet.msbuild.tasks/InstrumentationTask.cs @@ -1,4 +1,5 @@ using System; +using coverlet.core.Logging; using Coverlet.Core; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -23,7 +24,7 @@ public string Path get { return _path; } set { _path = value; } } - + public string Exclude { get { return _exclude; } @@ -36,6 +37,8 @@ public string ExcludeByFile set { _excludeByFile = value; } } + public bool Verbose { get; set; } + public override bool Execute() { try @@ -43,6 +46,9 @@ public override bool Execute() var rules = _excludeByFile?.Split(','); var filters = _exclude?.Split(','); + if (Verbose) + EnableLogging.Execute(); + _coverage = new Coverage(_path, Guid.NewGuid().ToString(), filters, rules); _coverage.PrepareModules(); } From b4e66f7adc6970a08ea1e0351f9a634364c2ee3a Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Mon, 21 May 2018 22:13:33 +0200 Subject: [PATCH 09/11] Moved interface and class to seperate files. --- .../Instrumentation/IInstrumenter.cs | 9 +++++ .../Instrumentation/Instrumenter.cs | 36 ++----------------- .../Instrumentation/InstrumenterFactory.cs | 29 +++++++++++++++ 3 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 src/coverlet.core/Instrumentation/IInstrumenter.cs create mode 100644 src/coverlet.core/Instrumentation/InstrumenterFactory.cs diff --git a/src/coverlet.core/Instrumentation/IInstrumenter.cs b/src/coverlet.core/Instrumentation/IInstrumenter.cs new file mode 100644 index 000000000..f5d65ebe3 --- /dev/null +++ b/src/coverlet.core/Instrumentation/IInstrumenter.cs @@ -0,0 +1,9 @@ +namespace Coverlet.Core.Instrumentation +{ + internal interface IInstrumenter + { + bool CanInstrument(); + + InstrumenterResult Instrument(); + } +} \ No newline at end of file diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 4cf08ea47..39bccf30d 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -14,37 +13,6 @@ namespace Coverlet.Core.Instrumentation { - internal interface IInstrumenter - { - bool CanInstrument(); - - InstrumenterResult Instrument(); - } - - internal static class InstrumenterFactory - { - private static readonly List> DecoratorFunctions = new List>(); - - public static IInstrumenter Create(string module, string identifier, string[] filters, string[] excludedFiles) - { - IInstrumenter result = new Instrumenter(module, identifier, filters, excludedFiles); - - // Decorate the real Instrumenter instance - foreach (var decoratorFunc in DecoratorFunctions) - result = decoratorFunc.Invoke(result); - - return result; - } - - public static void RegisterDecorator(Func decoratingFunc) - { - if (decoratingFunc == null) - throw new ArgumentNullException(nameof(decoratingFunc)); - - DecoratorFunctions.Add(decoratingFunc); - } - } - internal class Instrumenter : IInstrumenter { private readonly string _module; @@ -147,7 +115,7 @@ private void InstrumentIL(MethodDefinition method) var instruction = processor.Body.Instructions[index]; var sequencePoint = method.DebugInformation.GetSequencePoint(instruction); var targetedBranchPoints = branchPoints.Where(p => p.EndOffset == instruction.Offset); - + if (sequencePoint != null && !sequencePoint.IsHidden) { var target = AddInstrumentationCode(method, processor, instruction, sequencePoint); @@ -170,7 +138,7 @@ private void InstrumentIL(MethodDefinition method) */ if (_branchTarget.StartLine == -1 || _branchTarget.Document == null) continue; - + var target = AddInstrumentationCode(method, processor, instruction, _branchTarget); foreach (var _instruction in processor.Body.Instructions) ReplaceInstructionTarget(_instruction, instruction, target); diff --git a/src/coverlet.core/Instrumentation/InstrumenterFactory.cs b/src/coverlet.core/Instrumentation/InstrumenterFactory.cs new file mode 100644 index 000000000..77aa3f315 --- /dev/null +++ b/src/coverlet.core/Instrumentation/InstrumenterFactory.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace Coverlet.Core.Instrumentation +{ + internal static class InstrumenterFactory + { + private static readonly List> DecoratorFunctions = new List>(); + + public static IInstrumenter Create(string module, string identifier, string[] filters, string[] excludedFiles) + { + IInstrumenter result = new Instrumenter(module, identifier, filters, excludedFiles); + + // Decorate the real Instrumenter instance + foreach (var decoratorFunc in DecoratorFunctions) + result = decoratorFunc.Invoke(result); + + return result; + } + + public static void RegisterDecorator(Func decoratingFunc) + { + if (decoratingFunc == null) + throw new ArgumentNullException(nameof(decoratingFunc)); + + DecoratorFunctions.Add(decoratingFunc); + } + } +} \ No newline at end of file From a004a03f134b67087ff8a58f4357a4cdf56292bd Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Tue, 22 May 2018 20:41:26 +0200 Subject: [PATCH 10/11] Added some tests --- .../Logging/ConsoleLoggerTests.cs | 45 +++++++ .../InstrumenterLoggerDecoratorTests.cs | 113 ++++++++++++++++++ .../Logging/LoggerFactoryTests.cs | 20 ++++ 3 files changed, 178 insertions(+) create mode 100644 test/coverlet.core.tests/Logging/ConsoleLoggerTests.cs create mode 100644 test/coverlet.core.tests/Logging/Decorators/InstrumenterLoggerDecoratorTests.cs create mode 100644 test/coverlet.core.tests/Logging/LoggerFactoryTests.cs diff --git a/test/coverlet.core.tests/Logging/ConsoleLoggerTests.cs b/test/coverlet.core.tests/Logging/ConsoleLoggerTests.cs new file mode 100644 index 000000000..01a5e2100 --- /dev/null +++ b/test/coverlet.core.tests/Logging/ConsoleLoggerTests.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using Coverlet.Core.Logging; +using Xunit; + +namespace Coverlet.Core.Tests.Logging +{ + public class ConsoleLoggerTests + { + private readonly TextWriter _textWriter; + + public ConsoleLoggerTests() + { + _textWriter = new StringWriter(); + Console.SetOut(_textWriter); + } + + [Fact] + public void TestConsoleLoggerLogShouldWriteMessageToConsole() + { + // arrange + const string message = "this is a test message"; + + // act + ConsoleLogger.Instance.Log(message); + + // assert + _textWriter.Flush(); + Assert.Equal($"{message}{Environment.NewLine}" , _textWriter.ToString()); + } + + [Fact] + public void TestConsoleLoggerLogShouldWriteNothingWhenMessageIsNull() + { + // arrange + + // act + ConsoleLogger.Instance.Log(null); + + // assert + _textWriter.Flush(); + Assert.Empty(_textWriter.ToString()); + } + } +} \ No newline at end of file diff --git a/test/coverlet.core.tests/Logging/Decorators/InstrumenterLoggerDecoratorTests.cs b/test/coverlet.core.tests/Logging/Decorators/InstrumenterLoggerDecoratorTests.cs new file mode 100644 index 000000000..6b6c4b600 --- /dev/null +++ b/test/coverlet.core.tests/Logging/Decorators/InstrumenterLoggerDecoratorTests.cs @@ -0,0 +1,113 @@ +using System; +using System.Text; +using coverlet.core.Logging.Decorators; +using Coverlet.Core.Instrumentation; +using Coverlet.Core.Logging; +using Xunit; + +namespace Coverlet.Core.Tests.Logging.Decorators +{ + public class InstrumenterLoggerDecoratorTests + { + private readonly FakeInstumenter _decoratee; + private readonly FakeLogger _logger; + private readonly InstrumenterLoggerDecorator _sut; + + public InstrumenterLoggerDecoratorTests() + { + _decoratee = new FakeInstumenter(); + _logger = new FakeLogger(); + _sut = new InstrumenterLoggerDecorator(_decoratee, _logger); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void TestCanInstrumentIsForwardedToDecoratee(bool setupCanInstrument) + { + // arrange + var canInstrumentCalled = false; + _decoratee.SetCanInstrument(() => + { + canInstrumentCalled = true; + return setupCanInstrument; + }); + + // act + var result = _sut.CanInstrument(); + + // assert + Assert.True(canInstrumentCalled); + Assert.Equal(setupCanInstrument, result); + } + + + [Fact] + public void TestInstrumentIsForwardedToDecorateeAndLoggedInLogger() + { + // arrange + var setupResult = new InstrumenterResult { Module = "m0dule"}; + var instrumentCalled = false; + _decoratee.SetInstrument(() => + { + instrumentCalled = true; + return setupResult; + }); + + // act + var result = _sut.Instrument(); + + // assert + Assert.True(instrumentCalled); + Assert.Equal(setupResult, result); + Assert.Equal($"Module {result.Module} was instrumented.{Environment.NewLine}", _logger.ToString()); + } + } + + public class FakeLogger : ILogger + { + private readonly StringBuilder _sb; + + public FakeLogger() + { + _sb = new StringBuilder(); + } + + public void Log(string text) + { + _sb.AppendLine(text); + } + + public override string ToString() + { + return _sb.ToString(); + } + } + + internal class FakeInstumenter : IInstrumenter + { + private Func _canInstrument = () => throw new NotImplementedException(); + private Func _instrumenterResult = () => throw new NotImplementedException(); + + public void SetCanInstrument(Func func) + { + _canInstrument = func ?? throw new ArgumentNullException(nameof(func)); + } + + public bool CanInstrument() + { + return _canInstrument.Invoke(); + } + + public void SetInstrument(Func instrumenterResult) + { + _instrumenterResult = instrumenterResult ?? throw new ArgumentNullException(nameof(instrumenterResult)); + } + + public InstrumenterResult Instrument() + { + return _instrumenterResult.Invoke(); + } + + } +} \ No newline at end of file diff --git a/test/coverlet.core.tests/Logging/LoggerFactoryTests.cs b/test/coverlet.core.tests/Logging/LoggerFactoryTests.cs new file mode 100644 index 000000000..7068b246f --- /dev/null +++ b/test/coverlet.core.tests/Logging/LoggerFactoryTests.cs @@ -0,0 +1,20 @@ +using Coverlet.Core.Logging; +using Xunit; + +namespace Coverlet.Core.Tests.Logging +{ + public class LoggerFactoryTests + { + [Fact] + public void TestGetLoggerReturnsConsoleLoggerInstance() + { + // arrange + + // act + var result = LoggerFactory.GetLogger(); + + // assert + Assert.Equal(ConsoleLogger.Instance, result); + } + } +} \ No newline at end of file From b221bd5e945c2ef4008dc872244503f696a2ec7f Mon Sep 17 00:00:00 2001 From: Coen Munckhof Date: Tue, 22 May 2018 20:56:23 +0200 Subject: [PATCH 11/11] Added extra test --- .../Logging/EnableLoggingTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/coverlet.core.tests/Logging/EnableLoggingTests.cs diff --git a/test/coverlet.core.tests/Logging/EnableLoggingTests.cs b/test/coverlet.core.tests/Logging/EnableLoggingTests.cs new file mode 100644 index 000000000..0b4b676f5 --- /dev/null +++ b/test/coverlet.core.tests/Logging/EnableLoggingTests.cs @@ -0,0 +1,34 @@ +using coverlet.core.Logging; +using coverlet.core.Logging.Decorators; +using Coverlet.Core.Instrumentation; +using Xunit; + +namespace Coverlet.Core.Tests.Logging +{ + public class EnableLoggingTests + { + const string Module = "MOD"; + const string Identifier = "123"; + private string[] _filters; + private string[] _excludedFiles; + + [Fact] + public void TestExecuteShouldRegisterDecoraterToFactory() + { + // arrange + _filters = new string[0]; + _excludedFiles = new string[0]; + + // assume + var before = InstrumenterFactory.Create(Module, Identifier, _filters, _excludedFiles); + Assert.IsNotType(before); + + // act + EnableLogging.Execute(); + + // assert + var after = InstrumenterFactory.Create(Module, Identifier, _filters, _excludedFiles); + Assert.IsType(after); + } + } +} \ No newline at end of file