From dce78756bc5b1e1e313cd27f9eee361106218467 Mon Sep 17 00:00:00 2001 From: Anshoo Arora Date: Tue, 28 Mar 2017 15:20:10 -0400 Subject: [PATCH] closes #18 - provide ability to remove a test --- ExtentReports/ExtentReports/ExtentReports.cs | 9 +++++++ .../ExtentReports/Model/AbstractStructure.cs | 5 ++++ ExtentReports/ExtentReports/Model/Report.cs | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/ExtentReports/ExtentReports/ExtentReports.cs b/ExtentReports/ExtentReports/ExtentReports.cs index 3ac9150..6a6a70f 100644 --- a/ExtentReports/ExtentReports/ExtentReports.cs +++ b/ExtentReports/ExtentReports/ExtentReports.cs @@ -121,6 +121,15 @@ public ExtentTest CreateTest(GherkinKeyword gherkinKeyword, string name, string return extentTest; } + /// + /// Allows removing a test from the list + /// + /// An ExtentTest object + public void RemoveTest(ExtentTest test) + { + base.RemoveTest(test.GetModel()); + } + /// /// Writes test information from the started reporters to their output view /// diff --git a/ExtentReports/ExtentReports/Model/AbstractStructure.cs b/ExtentReports/ExtentReports/Model/AbstractStructure.cs index c95767b..7544c1c 100644 --- a/ExtentReports/ExtentReports/Model/AbstractStructure.cs +++ b/ExtentReports/ExtentReports/Model/AbstractStructure.cs @@ -26,6 +26,11 @@ public void Add(T t) _list.Add(t); } + public void Remove(T t) + { + _list.Remove(t); + } + public T Get(int index) { return _list[index]; diff --git a/ExtentReports/ExtentReports/Model/Report.cs b/ExtentReports/ExtentReports/Model/Report.cs index d54e8b7..b74af69 100644 --- a/ExtentReports/ExtentReports/Model/Report.cs +++ b/ExtentReports/ExtentReports/Model/Report.cs @@ -62,6 +62,31 @@ protected void CreateTest(Test test) _reporterCollection.ForEach(x => x.OnTestStarted(test)); } + [MethodImpl(MethodImplOptions.Synchronized)] + protected void RemoveTest(Test test) + { + foreach (var t in _testCollection) + { + if (t.TestId == test.TestId) + { + _testCollection.Remove(t); + return; + } + + if (t.HasChildren()) + { + foreach (var n in t.NodeContext().GetAllItems()) + { + if (n.TestId == test.TestId) + { + t.NodeContext().Remove(n); + return; + } + } + } + } + } + [MethodImpl(MethodImplOptions.Synchronized)] internal void AddNode(Test node) {