Skip to content

Commit

Permalink
Merge pull request #1 from allure-framework/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
unickq authored May 8, 2020
2 parents a2adf28 + 5b513d8 commit 6eb8f86
Show file tree
Hide file tree
Showing 67 changed files with 755 additions and 1,463 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,6 @@ __pycache__/
*.pyc

*.feature.cs

.DS_Store
*mono_crash*
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Allure.Commons.NetCore.Nuget.Tests</AssemblyName>
<RootNamespace>Allure.Commons.NetCore.Nuget.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Allure.Commons" Version="2.4.2.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Allure.Commons" Version="3.0.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions Allure.Commons.Tests/Allure.Commons.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 7 additions & 8 deletions Allure.Commons/Allure.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<AssemblyVersion>2.4.2.4</AssemblyVersion>
<FileVersion>2.4.2.4</FileVersion>
<Version>2.4.2.4</Version>
<Version>3.0.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Alexander Bakanov</Authors>
<Company />
<Product />
<Description>.net implementation of Allure java-commons</Description>
<PackageProjectUrl>https://github.com/allure-framework/allure-csharp/wiki/Allure.Commons</PackageProjectUrl>
<PackageTags>allure</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/allure-framework/allure-csharp/master/img/allure-net.png</PackageIconUrl>
<PackageIcon>allure-net.png</PackageIcon>
<SignAssembly>False</SignAssembly>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<PackageReleaseNotes></PackageReleaseNotes>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Include="./../img/allure-net.png" Pack="true" PackagePath="\" />
<Content Include="allureConfig.Template.json" Pack="true" />
<PackageReference Include="MimeTypesMap" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="MimeTypesMap" Version="1.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions Allure.Commons/AllureConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ public sealed class AllureConstants
public static string TEST_RESULT_CONTAINER_FILE_SUFFIX = "-container.json";
public static string TEST_RUN_FILE_SUFFIX = "-testrun.json";
public static string ATTACHMENT_FILE_SUFFIX = "-attachment";



}
}
}
79 changes: 45 additions & 34 deletions Allure.Commons/AllureLifecycle.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
using Allure.Commons.Configuration;
using System;
using System.IO;
using Allure.Commons.Configuration;
using Allure.Commons.Helpers;
using Allure.Commons.Storage;
using Allure.Commons.Writer;
using HeyRed.Mime;
using System;
using System.IO;

namespace Allure.Commons
{
public class AllureLifecycle
{
private static readonly object lockobj = new object();
private AllureStorage storage;
private IAllureResultsWriter writer;
private static AllureLifecycle instance;
private readonly AllureStorage storage;
private readonly IAllureResultsWriter writer;

public AllureLifecycle(string jsonConfigurationFile = null)
{
if (jsonConfigurationFile != null)
JsonConfiguration = File.ReadAllText(jsonConfigurationFile);
else
JsonConfiguration = File.ReadAllText(GetDefaultJsonConfiguration());

AllureConfiguration = AllureConfiguration.ReadFromJson(JsonConfiguration);
writer = new FileSystemResultsWriter(AllureConfiguration);
storage = new AllureStorage();
}

public string JsonConfiguration { get; private set; } = string.Empty;
public AllureConfiguration AllureConfiguration { get; private set; }
public string JsonConfiguration { get; } = string.Empty;
public AllureConfiguration AllureConfiguration { get; }

public string ResultsDirectory => writer.ToString();

public static AllureLifecycle Instance
{
get
{
if (instance == null)
{
lock (lockobj)
{
instance = instance ?? new AllureLifecycle();
}
}

return instance;
}
}

public AllureLifecycle(string jsonConfigurationFile = null)
{
if (jsonConfigurationFile != null)
JsonConfiguration = File.ReadAllText(jsonConfigurationFile);
else
JsonConfiguration = File.ReadAllText(GetDefaultJsonConfiguration());

AllureConfiguration = AllureConfiguration.ReadFromJson(JsonConfiguration);
writer = new FileSystemResultsWriter(AllureConfiguration);
storage = new AllureStorage();

}

#region TestContainer

public virtual AllureLifecycle StartTestContainer(TestResultContainer container)
{
container.start = DateTimeOffset.Now.ToUnixTimeMilliseconds();
Expand Down Expand Up @@ -80,9 +79,11 @@ public virtual AllureLifecycle WriteTestContainer(string uuid)
writer.Write(storage.Remove<TestResultContainer>(uuid));
return this;
}

#endregion

#region Fixture

public virtual AllureLifecycle StartBeforeFixture(string parentUuid, string uuid, FixtureResult result)
{
UpdateTestContainer(parentUuid, container => container.befores.Add(result));
Expand All @@ -102,6 +103,7 @@ public virtual AllureLifecycle UpdateFixture(Action<FixtureResult> update)
UpdateFixture(storage.GetRootStep(), update);
return this;
}

public virtual AllureLifecycle UpdateFixture(string uuid, Action<FixtureResult> update)
{
update.Invoke(storage.Get<FixtureResult>(uuid));
Expand All @@ -113,6 +115,7 @@ public virtual AllureLifecycle StopFixture(Action<FixtureResult> beforeStop)
UpdateFixture(beforeStop);
return StopFixture(storage.GetRootStep());
}

public virtual AllureLifecycle StopFixture(string uuid)
{
var fixture = storage.Remove<FixtureResult>(uuid);
Expand All @@ -121,6 +124,7 @@ public virtual AllureLifecycle StopFixture(string uuid)
fixture.stop = DateTimeOffset.Now.ToUnixTimeMilliseconds();
return this;
}

#endregion

#region TestCase
Expand Down Expand Up @@ -176,6 +180,7 @@ public virtual AllureLifecycle WriteTestCase(string uuid)
#endregion

#region Step

public virtual AllureLifecycle StartStep(string uuid, StepResult result)
{
StartStep(storage.GetCurrentStep(), uuid, result);
Expand All @@ -202,6 +207,7 @@ public virtual AllureLifecycle UpdateStep(string uuid, Action<StepResult> update
update.Invoke(storage.Get<StepResult>(uuid));
return this;
}

public virtual AllureLifecycle StopStep(Action<StepResult> beforeStop)
{
UpdateStep(beforeStop);
Expand Down Expand Up @@ -232,10 +238,12 @@ public virtual AllureLifecycle AddAttachment(string name, string type, string pa
var fileExtension = new FileInfo(path).Extension;
return AddAttachment(name, type, File.ReadAllBytes(path), fileExtension);
}
public virtual AllureLifecycle AddAttachment(string name, string type, byte[] content, string fileExtension = "")

public virtual AllureLifecycle AddAttachment(string name, string type, byte[] content,
string fileExtension = "")
{
var source = $"{Guid.NewGuid().ToString("N")}{AllureConstants.ATTACHMENT_FILE_SUFFIX}{fileExtension}";
var attachment = new Attachment()
var attachment = new Attachment
{
name = name,
type = type,
Expand All @@ -256,18 +264,19 @@ public virtual AllureLifecycle AddAttachment(string path, string name = null)
#endregion

#region Extensions

public virtual void CleanupResultDirectory()
{
writer.CleanUp();
}

public virtual AllureLifecycle AddScreenDiff(string testCaseUuid, string expectedPng, string actualPng, string diffPng)
public virtual AllureLifecycle AddScreenDiff(string testCaseUuid, string expectedPng, string actualPng,
string diffPng)
{

AddAttachment(expectedPng, "expected")
.AddAttachment(actualPng, "actual")
.AddAttachment(diffPng, "diff")
.UpdateTestCase(testCaseUuid, x => x.labels.Add(Label.TestType("screenshotDiff")));
.AddAttachment(actualPng, "actual")
.AddAttachment(diffPng, "diff")
.UpdateTestCase(testCaseUuid, x => x.labels.Add(Label.TestType("screenshotDiff")));

return this;
}
Expand All @@ -276,12 +285,14 @@ public virtual AllureLifecycle AddScreenDiff(string testCaseUuid, string expecte


#region Privates

private string GetDefaultJsonConfiguration()
{
var envConfig = Environment.GetEnvironmentVariable(AllureConstants.ALLURE_CONFIG_ENV_VARIABLE);

if (envConfig != null && !File.Exists(envConfig))
throw new FileNotFoundException($"Couldn't find '{envConfig}' specified in {AllureConstants.ALLURE_CONFIG_ENV_VARIABLE} environment variable");
throw new FileNotFoundException(
$"Couldn't find '{envConfig}' specified in {AllureConstants.ALLURE_CONFIG_ENV_VARIABLE} environment variable");

if (File.Exists(envConfig))
return envConfig;
Expand All @@ -290,11 +301,12 @@ private string GetDefaultJsonConfiguration()
var binaryConfig = Path.Combine(binaryFolder, AllureConstants.CONFIG_FILENAME);

if (!File.Exists(binaryConfig))
throw new FileNotFoundException($"Couldn't find Allure configuration file. Please either specify full path to {AllureConstants.CONFIG_FILENAME} in the {AllureConstants.ALLURE_CONFIG_ENV_VARIABLE} environment variable or place {AllureConstants.CONFIG_FILENAME} to the '{binaryFolder}' folder");
throw new FileNotFoundException(
$"Couldn't find Allure configuration file. Please either specify full path to {AllureConstants.CONFIG_FILENAME} in the {AllureConstants.ALLURE_CONFIG_ENV_VARIABLE} environment variable or place {AllureConstants.CONFIG_FILENAME} to the '{binaryFolder}' folder");

return binaryConfig;

}

private void StartFixture(string uuid, FixtureResult fixtureResult)
{
storage.Put(uuid, fixtureResult);
Expand All @@ -305,6 +317,5 @@ private void StartFixture(string uuid, FixtureResult fixtureResult)
}

#endregion

}
}
}
18 changes: 10 additions & 8 deletions Allure.Commons/Configuration/AllureConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace Allure.Commons.Configuration
{
public class AllureConfiguration
{
public string Title { get; }
public string Directory { get; } = "allure-results";
public HashSet<string> Links { get; } = new HashSet<string>();

private AllureConfiguration() { }
private AllureConfiguration()
{
}

[JsonConstructor]
protected AllureConfiguration(string title, string directory, HashSet<string> links)
Expand All @@ -20,6 +18,10 @@ protected AllureConfiguration(string title, string directory, HashSet<string> li
Links = links ?? Links;
}

public string Title { get; }
public string Directory { get; } = "allure-results";
public HashSet<string> Links { get; } = new HashSet<string>();

public static AllureConfiguration ReadFromJson(string json)
{
var config = new AllureConfiguration();
Expand All @@ -32,4 +34,4 @@ public static AllureConfiguration ReadFromJson(string json)
return config;
}
}
}
}
8 changes: 5 additions & 3 deletions Allure.Commons/Helpers/LinkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ public static void UpdateLinks(IEnumerable<Link> links, HashSet<string> patterns
.GroupBy(l => l.type))
{
var typePattern = $"{{{linkTypeGroup.Key}}}";
var linkPattern = patterns.FirstOrDefault(x => x.IndexOf(typePattern, StringComparison.CurrentCultureIgnoreCase) >= 0);
var linkPattern = patterns.FirstOrDefault(x =>
x.IndexOf(typePattern, StringComparison.CurrentCultureIgnoreCase) >= 0);
if (linkPattern != null)
{
var linkArray = linkTypeGroup.ToArray();
for (var i = 0; i < linkArray.Length; i++)
{
var replacedLink = Regex.Replace(linkPattern, typePattern, linkArray[i].url ?? string.Empty, RegexOptions.IgnoreCase);
var replacedLink = Regex.Replace(linkPattern, typePattern, linkArray[i].url ?? string.Empty,
RegexOptions.IgnoreCase);
linkArray[i].url = Uri.EscapeUriString(replacedLink);
}
}
}
}
}
}
}
Loading

0 comments on commit 6eb8f86

Please sign in to comment.