Skip to content

Commit

Permalink
Remove Set* API for labels (extracted to set-label-api)
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie committed Nov 17, 2023
1 parent e410451 commit 33138b2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand All @@ -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" }
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand All @@ -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" }
);
}
}
93 changes: 7 additions & 86 deletions Allure.Net.Commons/AllureApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

/// <summary>
/// Adds a label to the current test result. Removes all previously added
/// labels with the same name.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="name">The name of the label.</param>
/// <param name="value">The value of the label.</param>
public static void SetLabel(string name, string value) =>
SetLabel(new() { name = name, value = value });

/// <summary>
/// Adds a label to the current test result.
/// </summary>
Expand All @@ -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));

/// <summary>
/// Adds a label to the current test result. Removes all previously added
/// labels with the same name.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="label">The new label of the test.</param>
public static void SetLabel(Label label) =>
CurrentLifecycle.UpdateTestCase(tr =>
{
tr.labels.RemoveAll(lr => lr.name == label.name);
tr.labels.Add(label);
});

/// <summary>
/// Sets the current test's severity.
/// </summary>
Expand Down Expand Up @@ -169,17 +146,6 @@ public static void AddParentSuite(string additionalParentSuite) =>
Label.ParentSuite(additionalParentSuite)
);

/// <summary>
/// Sets the parent suite of the current test. Existing parent suites
/// will be removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newParentSuite">The new parent suite.</param>
public static void SetParentSuite(string newParentSuite) =>
SetLabel(
Label.ParentSuite(newParentSuite)
);

/// <summary>
/// Adds an additional suite to the current test.
/// </summary>
Expand All @@ -190,17 +156,6 @@ public static void AddSuite(string additionalSuite) =>
Label.Suite(additionalSuite)
);

/// <summary>
/// Sets the suite of the current test. Existing suites will be
/// removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newSuite">The new suite.</param>
public static void SetSuite(string newSuite) =>
SetLabel(
Label.Suite(newSuite)
);

/// <summary>
/// Adds an additional sub-suite to the current test.
/// </summary>
Expand All @@ -211,17 +166,6 @@ public static void AddSubSuite(string additionalSubSuite) =>
Label.SubSuite(additionalSubSuite)
);

/// <summary>
/// Sets the sub-suite of the current test. Existing sub-suites will be
/// removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newSubSuite">The new sub-suite.</param>
public static void SetSubSuite(string newSubSuite) =>
SetLabel(
Label.SubSuite(newSubSuite)
);

#endregion

#region BDD-labels
Expand All @@ -236,16 +180,6 @@ public static void AddEpic(string additionalEpic) =>
Label.Epic(additionalEpic)
);

/// <summary>
/// Sets the epic of the current test. Existing epics will be removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newEpic">The new epic.</param>
public static void SetEpic(string newEpic) =>
SetLabel(
Label.Epic(newEpic)
);

/// <summary>
/// Adds an additional feature to the current test.
/// </summary>
Expand All @@ -256,16 +190,6 @@ public static void AddFeature(string additionalFeature) =>
Label.Feature(additionalFeature)
);

/// <summary>
/// Sets the feature of the current test. Existing features will be removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newFeature">The new feature.</param>
public static void SetFeature(string newFeature) =>
SetLabel(
Label.Feature(newFeature)
);

/// <summary>
/// Adds an additional story to the current test.
/// </summary>
Expand All @@ -276,16 +200,6 @@ public static void AddStory(string additionalStory) =>
Label.Story(additionalStory)
);

/// <summary>
/// Sets the story of the current test. Existing stories will be removed.
/// </summary>
/// <remarks>Requires the test context to be active.</remarks>
/// <param name="newStory">The new story.</param>
public static void SetStory(string newStory) =>
SetLabel(
Label.Story(newStory)
);

#endregion

#region Links
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 33138b2

Please sign in to comment.