Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Allure.NUnit.Examples/allureConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"https://github.com/nunit/docs/issues?utf8=✓&q={issue}",
"https://example.org/{tms}",
"{link}"
]
],
"indentOutput": true
}
}
9 changes: 9 additions & 0 deletions Allure.Net.Commons.Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public void ShouldConfigureDefaultValues(string json)
Path.Combine(Environment.CurrentDirectory, AllureConstants.DEFAULT_RESULTS_FOLDER)
));
Assert.That(allureLifecycle.AllureConfiguration.Links, Is.Not.Null);
Assert.That(allureLifecycle.AllureConfiguration.UseLegacyIds, Is.False);
Assert.That(allureLifecycle.AllureConfiguration.IndentOutput, Is.False);
});
}

Expand Down Expand Up @@ -48,5 +50,12 @@ public void ShouldConfigureTitle()
var json = @"{""allure"":{""title"": ""hello Allure""}}";
Assert.That(new AllureLifecycle(JObject.Parse(json)).AllureConfiguration.Title, Is.EqualTo("hello Allure"));
}

[Test]
public void ShouldConfigureIndentation()
{
var json = @"{""allure"":{""indentOutput"": true}}";
Assert.That(new AllureLifecycle(JObject.Parse(json)).AllureConfiguration.IndentOutput, Is.True);
}
}
}
62 changes: 57 additions & 5 deletions Allure.Net.Commons.Tests/FileSystemResultsWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,38 @@
using System;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Linq;
using System.Text;

namespace Allure.Net.Commons.Tests
{
[TestFixture]
public class FileSystemResultsWriterTests
{
DirectoryInfo tmpDir;

[SetUp]
public void CreateTempDir()
{
this.tmpDir = Directory.CreateTempSubdirectory();
}

[TearDown]
public void DeleteTmpDir()
{
if (this.tmpDir.Exists)
{
try
{
this.tmpDir.Delete(true);
}
catch (Exception e)
{
TestContext.WriteLine(e.ToString());
}
}
}

[Test, Description("Should use temp path if no access to output directory")]
public void ShouldUseTempPathIfNoAccessToResultsDirectory()
{
Expand All @@ -25,14 +51,40 @@ public void ShouldUseTempPathIfNoAccessToResultsDirectory()
[Test, Description("Cleanup test")]
public void ShouldCleanupTempResultsFolder()
{
var resultsDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var json = $"{{\"allure\":{{\"directory\": {JsonConvert.ToString(resultsDirectory)}}}}}";
var json = $"{{\"allure\":{{\"directory\": {JsonConvert.ToString(this.tmpDir.FullName)}}}}}";
var config = AllureConfiguration.ReadFromJObject(JObject.Parse(json));
Directory.CreateDirectory(resultsDirectory);
File.WriteAllText(Path.Combine(resultsDirectory, Path.GetRandomFileName()), "");
File.WriteAllText(Path.Combine(this.tmpDir.FullName, Path.GetRandomFileName()), "");

new FileSystemResultsWriter(config).CleanUp();
Assert.That(Directory.GetFiles(resultsDirectory), Is.Empty);
Assert.That(this.tmpDir.EnumerateFiles(), Is.Empty);
}

[Test]
public void ShouldWriteCompressedJsonByDefault()
{
var config = new AllureConfiguration { Directory = this.tmpDir.FullName };
var writer = new FileSystemResultsWriter(config);
var testResult = new TestResult { name = "foo" };

writer.Write(testResult);

var resultFile = this.tmpDir.EnumerateFiles().Single();
var resultJson = File.ReadAllText(resultFile.FullName, Encoding.UTF8);
Assert.That(resultJson, Does.Not.Match(@"\s"));
}

[Test]
public void ShouldPrettyPrintJsonIfConfigured()
{
var config = new AllureConfiguration { Directory = this.tmpDir.FullName, IndentOutput = true };
var writer = new FileSystemResultsWriter(config);
var testResult = new TestResult { name = "foo" };

writer.Write(testResult);

var resultFile = this.tmpDir.EnumerateFiles().Single();
var resultJson = File.ReadAllText(resultFile.FullName, Encoding.UTF8);
Assert.That(resultJson, Does.Contain(" "));
}
}
}
7 changes: 4 additions & 3 deletions Allure.Net.Commons/Configuration/AllureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Allure.Net.Commons.Configuration
{
public class AllureConfiguration
{
private AllureConfiguration()
internal AllureConfiguration()
{
}

Expand All @@ -18,11 +18,12 @@ protected AllureConfiguration(string title, string directory, HashSet<string> li
Links = links ?? Links;
}

public string Title { get; }
public string Directory { get; } = AllureConstants.DEFAULT_RESULTS_FOLDER;
public string Title { get; init; }
public string Directory { get; init; } = AllureConstants.DEFAULT_RESULTS_FOLDER;
public HashSet<string> Links { get; } = new HashSet<string>();
public List<string> FailExceptions { get; set; }
public bool UseLegacyIds { get; set; } = false;
public bool IndentOutput { get; set; } = false;

public static AllureConfiguration ReadFromJObject(JObject jObject)
{
Expand Down
5 changes: 5 additions & 0 deletions Allure.Net.Commons/Schemas/allureConfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"type": "boolean",
"description": "Calculate fullNames, historyIds and uuids compatible with ones generated by the versions prior to 2.10.",
"default": false
},
"indentOutput": {
"type": "boolean",
"description": "If set to true, the output JSON files (*-result.json, *-container.json) will be indented to be more readable",
"default": false
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Allure.Net.Commons/Writer/FileSystemResultsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ internal FileSystemResultsWriter(AllureConfiguration configuration)
outputDirectory = GetResultsDirectory(configuration.Directory);

serializer.NullValueHandling = NullValueHandling.Ignore;
serializer.Formatting = Formatting.Indented;
if (configuration.IndentOutput)
{
serializer.Formatting = Formatting.Indented;
}

serializer.Converters.Add(
new StringEnumConverter(
new CamelCaseNamingStrategy()
Expand Down
1 change: 1 addition & 0 deletions Allure.Reqnroll.Tests.Samples/allureConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"https://example.org/{issue}",
"https://example.org/{tms}"
],
"indentOutput": true,
"gherkinPatterns": {
"stepArguments": {
"createFromDataTables": true,
Expand Down
6 changes: 6 additions & 0 deletions Allure.Reqnroll.Tests/Allure.Reqnroll.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
<ProjectReference Include="..\Allure.Reqnroll\Allure.Reqnroll.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="allureConfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Allure.Reqnroll.Tests/allureConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/2.12.1/Allure.Reqnroll/Schemas/allureConfig.schema.json",
"allure": {
"indentOutput": true
}
}
3 changes: 2 additions & 1 deletion Allure.SpecFlow.Tests.Samples/allureConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"links": [
"https://example.org/{issue}",
"https://example.org/{tms}"
]
],
"indentOutput": true
},
"specflow": {
"stepArguments": {
Expand Down
6 changes: 4 additions & 2 deletions Allure.SpecFlow.Tests/allureConfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/2.12.1/Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json",
"allure": {}
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/2.12.1/Allure.SpecFlow/Schemas/allureConfig.schema.json",
"allure": {
"indentOutput": true
}
}
5 changes: 3 additions & 2 deletions Allure.Xunit.Examples/allureConfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/2.12.1/Allure.XUnit/Schemas/allureConfig.schema.json",
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/2.12.1/Allure.Xunit/Schemas/allureConfig.schema.json",
"allure": {
"directory": "allure-results",
"links": [
"https://example.org/{issue}",
"https://example.org/{tms}"
],
"xunitRunnerReporter": "auto"
"indentOutput": true,
"xunitRunnerReporter": "none"
}
}
Loading