From 3c912fd07c0af91b774d6f8f7e1c6037a9f0061a Mon Sep 17 00:00:00 2001 From: Ilya Murzinov Date: Sat, 1 Nov 2014 22:20:16 +0400 Subject: [PATCH] refactoring --- NUnitAllureAdapter/AllureEventListener.cs | 45 +++++++++----------- NUnitAllureAdapter/NUnitAllureAdapter.csproj | 1 + NUnitAllureAdapter/config.xml | 1 + 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/NUnitAllureAdapter/AllureEventListener.cs b/NUnitAllureAdapter/AllureEventListener.cs index 0aebc5d..0dc802b 100644 --- a/NUnitAllureAdapter/AllureEventListener.cs +++ b/NUnitAllureAdapter/AllureEventListener.cs @@ -14,13 +14,16 @@ namespace NUnitAllureAdapter { - public class AllureEventListener : EventListener + public class AllureEventListener : EventListenerAdapter { private static readonly ILog Logger = LogManager.GetLogger(typeof (AllureEventListener)); private static readonly OrderedDictionary SuiteStorage = new OrderedDictionary(); + private static readonly bool WriteOutputToAttachmentFlag; + private static readonly bool TakeScreenShotOnFailedTestsFlag; + private readonly Allure _lifecycle = Allure.Lifecycle; private StringBuilder _log = new StringBuilder(); @@ -28,9 +31,6 @@ public class AllureEventListener : EventListener private StringBuilder _stdOut = new StringBuilder(); private StringBuilder _trace = new StringBuilder(); - private static readonly bool TakeScreenShotOnFailedTestsFlag; - private static readonly bool WriteOutputToAttachmentFlag; - static AllureEventListener() { try @@ -43,7 +43,7 @@ static AllureEventListener() XDocument.Load(path + "/config.xml") .Descendants() .First(x => x.Name.LocalName.Equals("results-path")) - .Value; + .Value + "/"; TakeScreenShotOnFailedTestsFlag = Convert.ToBoolean(XDocument.Load(path + "/config.xml") @@ -56,6 +56,12 @@ static AllureEventListener() .Descendants() .First(x => x.Name.LocalName.Equals("write-output-to-attachment")) .Value); + + Logger.Error("Initialization completed successfully.\n"); + Logger.Error( + String.Format( + "Results Path: {0};\n WriteOutputToAttachmentFlag: {1};\n TakeScreenShotOnFailedTestsFlag: {2}", + AllureConfig.ResultsPath, WriteOutputToAttachmentFlag, TakeScreenShotOnFailedTestsFlag)); } catch (Exception e) { @@ -63,7 +69,7 @@ static AllureEventListener() } } - public void RunStarted(string name, int testCount) + public override void RunStarted(string name, int testCount) { try { @@ -79,15 +85,7 @@ public void RunStarted(string name, int testCount) } } - public void RunFinished(TestResult result) - { - } - - public void RunFinished(Exception exception) - { - } - - public void TestStarted(TestName testName) + public override void TestStarted(TestName testName) { try { @@ -121,7 +119,7 @@ Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Co } } - public void TestFinished(TestResult result) + public override void TestFinished(TestResult result) { try { @@ -129,7 +127,7 @@ public void TestFinished(TestResult result) { if (TakeScreenShotOnFailedTestsFlag) { - TakeScreenshot(); + TakeScreenshot(); } _lifecycle.Fire(new TestCaseFailureEvent { @@ -141,7 +139,7 @@ public void TestFinished(TestResult result) { if (TakeScreenShotOnFailedTestsFlag) { - TakeScreenshot(); + TakeScreenshot(); } _lifecycle.Fire(new TestCaseFailureEvent { @@ -177,7 +175,7 @@ public void TestFinished(TestResult result) } } - public void SuiteStarted(TestName testName) + public override void SuiteStarted(TestName testName) { try { @@ -207,7 +205,7 @@ Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Co } } - public void SuiteFinished(TestResult result) + public override void SuiteFinished(TestResult result) { try { @@ -220,12 +218,7 @@ public void SuiteFinished(TestResult result) } } - public void UnhandledException(Exception exception) - { - Logger.Error(String.Format("UnhandledException"), exception); - } - - public void TestOutput(TestOutput testOutput) + public override void TestOutput(TestOutput testOutput) { switch (testOutput.Type) { diff --git a/NUnitAllureAdapter/NUnitAllureAdapter.csproj b/NUnitAllureAdapter/NUnitAllureAdapter.csproj index f7b59fe..93c10aa 100644 --- a/NUnitAllureAdapter/NUnitAllureAdapter.csproj +++ b/NUnitAllureAdapter/NUnitAllureAdapter.csproj @@ -55,6 +55,7 @@ + diff --git a/NUnitAllureAdapter/config.xml b/NUnitAllureAdapter/config.xml index db253b4..2c52e0f 100644 --- a/NUnitAllureAdapter/config.xml +++ b/NUnitAllureAdapter/config.xml @@ -1,6 +1,7 @@  + AllureResults true true