From 33138b2f353a4d612fdcfc188c86b77cb5d9cc4a Mon Sep 17 00:00:00 2001
From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com>
Date: Fri, 17 Nov 2023 19:59:41 +0700
Subject: [PATCH] Remove Set* API for labels (extracted to set-label-api)
---
.../AllureFacadeTests/BddTests.cs | 75 ---------------
.../AllureFacadeTests/MetadataTests.cs | 34 -------
.../AllureFacadeTests/SuiteTests.cs | 75 ---------------
Allure.Net.Commons/AllureApi.cs | 93 ++-----------------
4 files changed, 7 insertions(+), 270 deletions(-)
diff --git a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/BddTests.cs b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/BddTests.cs
index 91571121..622edd02 100644
--- a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/BddTests.cs
+++ b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/BddTests.cs
@@ -30,31 +30,6 @@ public void AddEpicAppendsLabel()
);
}
- [Test]
- public void EpicCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetEpic("My Epic");
-
- this.AssertLabels(
- new Label() { name = "epic", value = "My Epic" }
- );
- }
-
- [Test]
- public void SetEpicOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddEpic("My Epic 1");
-
- AllureApi.SetEpic("My Epic 2");
-
- this.AssertLabels(
- new Label() { name = "epic", value = "My Epic 2" }
- );
- }
-
[Test]
public void FeatureCanBeAdded()
{
@@ -81,31 +56,6 @@ public void AddFeatureAppendsLabel()
);
}
- [Test]
- public void FeatureCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetFeature("My Feature");
-
- this.AssertLabels(
- new Label() { name = "feature", value = "My Feature" }
- );
- }
-
- [Test]
- public void SetFeatureOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddFeature("My Feature 1");
-
- AllureApi.SetFeature("My Feature 2");
-
- this.AssertLabels(
- new Label() { name = "feature", value = "My Feature 2" }
- );
- }
-
[Test]
public void StoryCanBeAdded()
{
@@ -131,29 +81,4 @@ public void AddStoryAppendsLabel()
new Label() { name = "story", value = "My Story 2" }
);
}
-
- [Test]
- public void StoryCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetStory("My Story");
-
- this.AssertLabels(
- new Label() { name = "story", value = "My Story" }
- );
- }
-
- [Test]
- public void SetStoryOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddStory("My Story 1");
-
- AllureApi.SetStory("My Story 2");
-
- this.AssertLabels(
- new Label() { name = "story", value = "My Story 2" }
- );
- }
}
diff --git a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/MetadataTests.cs b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/MetadataTests.cs
index bca7f57d..d739db00 100644
--- a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/MetadataTests.cs
+++ b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/MetadataTests.cs
@@ -87,23 +87,6 @@ public void NewLabelCanBeAddedByNameValue()
);
}
- [Test]
- public void LabelsOverwriteByNameValue()
- {
- var testResult = new TestResult() { uuid = "uuid" };
- testResult.labels.Add(new() { name = "l1", value = "v1" });
- testResult.labels.Add(new() { name = "l2", value = "v2" });
- testResult.labels.Add(new() { name = "l2", value = "v3" });
- this.lifecycle.StartTestCase(testResult);
-
- AllureApi.SetLabel("l2", "v4");
-
- this.AssertLabels(
- new() { name = "l1", value = "v1" },
- new() { name = "l2", value = "v4" }
- );
- }
-
[Test]
public void NewLabelCanBeAdded()
{
@@ -116,23 +99,6 @@ public void NewLabelCanBeAdded()
);
}
- [Test]
- public void LabelsOverwrite()
- {
- var testResult = new TestResult() { uuid = "uuid" };
- testResult.labels.Add(new() { name = "l1", value = "v1" });
- testResult.labels.Add(new() { name = "l2", value = "v2" });
- testResult.labels.Add(new() { name = "l2", value = "v3" });
- this.lifecycle.StartTestCase(testResult);
-
- AllureApi.SetLabel(new() { name = "l2", value = "v4" });
-
- this.AssertLabels(
- new() { name = "l1", value = "v1" },
- new() { name = "l2", value = "v4" }
- );
- }
-
[Test]
public void SeverityAdded()
{
diff --git a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/SuiteTests.cs b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/SuiteTests.cs
index ad809845..8b887a9e 100644
--- a/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/SuiteTests.cs
+++ b/Allure.Net.Commons.Tests/UserAPITests/AllureFacadeTests/SuiteTests.cs
@@ -29,31 +29,6 @@ public void AddParentSuiteAppendsLabel()
);
}
- [Test]
- public void ParentSuiteCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetParentSuite("My Parent Suite");
-
- this.AssertLabels(
- new Label() { name = "parentSuite", value = "My Parent Suite" }
- );
- }
-
- [Test]
- public void SetParentSuiteOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddParentSuite("My Parent Suite 1");
-
- AllureApi.SetParentSuite("My Parent Suite 2");
-
- this.AssertLabels(
- new Label() { name = "parentSuite", value = "My Parent Suite 2" }
- );
- }
-
[Test]
public void SuiteCanBeAdded()
{
@@ -80,31 +55,6 @@ public void AddSuiteAppendsLabel()
);
}
- [Test]
- public void SuiteCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetSuite("My Suite");
-
- this.AssertLabels(
- new Label() { name = "suite", value = "My Suite" }
- );
- }
-
- [Test]
- public void SetSuiteOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddSuite("My Suite 1");
-
- AllureApi.SetSuite("My Suite 2");
-
- this.AssertLabels(
- new Label() { name = "suite", value = "My Suite 2" }
- );
- }
-
[Test]
public void SubSuiteCanBeAdded()
{
@@ -130,29 +80,4 @@ public void AddSubSuiteAppendsLabel()
new Label() { name = "subSuite", value = "My Sub-suite 2" }
);
}
-
- [Test]
- public void SubSuiteCanBeSet()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
-
- AllureApi.SetSubSuite("My Sub-suite");
-
- this.AssertLabels(
- new Label() { name = "subSuite", value = "My Sub-suite" }
- );
- }
-
- [Test]
- public void SetSubSuiteOverwritesLabel()
- {
- this.lifecycle.StartTestCase(new() { uuid = "uuid" });
- AllureApi.AddSubSuite("My Sub-suite 1");
-
- AllureApi.SetSubSuite("My Sub-suite 2");
-
- this.AssertLabels(
- new Label() { name = "subSuite", value = "My Sub-suite 2" }
- );
- }
}
diff --git a/Allure.Net.Commons/AllureApi.cs b/Allure.Net.Commons/AllureApi.cs
index b52deb27..e86e11af 100644
--- a/Allure.Net.Commons/AllureApi.cs
+++ b/Allure.Net.Commons/AllureApi.cs
@@ -85,16 +85,6 @@ public static void AddLabels(params Label[] labels) =>
public static void AddLabel(string name, string value) =>
AddLabel(new() { name = name, value = value });
- ///
- /// Adds a label to the current test result. Removes all previously added
- /// labels with the same name.
- ///
- /// Requires the test context to be active.
- /// The name of the label.
- /// The value of the label.
- public static void SetLabel(string name, string value) =>
- SetLabel(new() { name = name, value = value });
-
///
/// Adds a label to the current test result.
///
@@ -103,19 +93,6 @@ public static void SetLabel(string name, string value) =>
public static void AddLabel(Label newLabel) =>
CurrentLifecycle.UpdateTestCase(tr => tr.labels.Add(newLabel));
- ///
- /// Adds a label to the current test result. Removes all previously added
- /// labels with the same name.
- ///
- /// Requires the test context to be active.
- /// The new label of the test.
- public static void SetLabel(Label label) =>
- CurrentLifecycle.UpdateTestCase(tr =>
- {
- tr.labels.RemoveAll(lr => lr.name == label.name);
- tr.labels.Add(label);
- });
-
///
/// Sets the current test's severity.
///
@@ -169,17 +146,6 @@ public static void AddParentSuite(string additionalParentSuite) =>
Label.ParentSuite(additionalParentSuite)
);
- ///
- /// Sets the parent suite of the current test. Existing parent suites
- /// will be removed.
- ///
- /// Requires the test context to be active.
- /// The new parent suite.
- public static void SetParentSuite(string newParentSuite) =>
- SetLabel(
- Label.ParentSuite(newParentSuite)
- );
-
///
/// Adds an additional suite to the current test.
///
@@ -190,17 +156,6 @@ public static void AddSuite(string additionalSuite) =>
Label.Suite(additionalSuite)
);
- ///
- /// Sets the suite of the current test. Existing suites will be
- /// removed.
- ///
- /// Requires the test context to be active.
- /// The new suite.
- public static void SetSuite(string newSuite) =>
- SetLabel(
- Label.Suite(newSuite)
- );
-
///
/// Adds an additional sub-suite to the current test.
///
@@ -211,17 +166,6 @@ public static void AddSubSuite(string additionalSubSuite) =>
Label.SubSuite(additionalSubSuite)
);
- ///
- /// Sets the sub-suite of the current test. Existing sub-suites will be
- /// removed.
- ///
- /// Requires the test context to be active.
- /// The new sub-suite.
- public static void SetSubSuite(string newSubSuite) =>
- SetLabel(
- Label.SubSuite(newSubSuite)
- );
-
#endregion
#region BDD-labels
@@ -236,16 +180,6 @@ public static void AddEpic(string additionalEpic) =>
Label.Epic(additionalEpic)
);
- ///
- /// Sets the epic of the current test. Existing epics will be removed.
- ///
- /// Requires the test context to be active.
- /// The new epic.
- public static void SetEpic(string newEpic) =>
- SetLabel(
- Label.Epic(newEpic)
- );
-
///
/// Adds an additional feature to the current test.
///
@@ -256,16 +190,6 @@ public static void AddFeature(string additionalFeature) =>
Label.Feature(additionalFeature)
);
- ///
- /// Sets the feature of the current test. Existing features will be removed.
- ///
- /// Requires the test context to be active.
- /// The new feature.
- public static void SetFeature(string newFeature) =>
- SetLabel(
- Label.Feature(newFeature)
- );
-
///
/// Adds an additional story to the current test.
///
@@ -276,16 +200,6 @@ public static void AddStory(string additionalStory) =>
Label.Story(additionalStory)
);
- ///
- /// Sets the story of the current test. Existing stories will be removed.
- ///
- /// Requires the test context to be active.
- /// The new story.
- public static void SetStory(string newStory) =>
- SetLabel(
- Label.Story(newStory)
- );
-
#endregion
#region Links
@@ -652,6 +566,13 @@ public static void AddTestParameter(Parameter parameter) =>
#endregion
+ static void SetLabel(Label label) =>
+ CurrentLifecycle.UpdateTestCase(tr =>
+ {
+ tr.labels.RemoveAll(lr => lr.name == label.name);
+ tr.labels.Add(label);
+ });
+
static string FormatParameterValue(object? value) =>
FormatFunctions.Format(value, CurrentLifecycle.TypeFormatters);