Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
#46 feature (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
unickq authored Jan 16, 2022
1 parent 9e8725c commit fb9c0d6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
35 changes: 35 additions & 0 deletions src/allure-nunit-tests/AllureDiffTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Allure.Commons;
using NUnit.Allure.Attributes;
using NUnit.Framework;
using NUnit.Allure.Core;

namespace allure_nunit_tests
{
[AllureSuite("Tests - ScreenDiff")]
public class AllureDiffTest : BaseTest
{
[Test]
[AllureName("Simple test with diff")]
public void DiffTest()
{
AddDiffs();
}

[Test]
[AllureName("Diff test with step")]
public void DiffStepsTest()
{
AddDiffs();
AllureLifecycle.Instance.WrapInStep(() =>
{
AllureLifecycle.Instance.WrapInStep(() => { AddDiffs(); }, "Step Inside");
AddDiffs();
}, "StepOutSide");
}

public static void AddDiffs()
{
AllureLifecycle.Instance.AddScreenDiff("logo.png", "logo.png", "logo.png");
}
}
}
2 changes: 1 addition & 1 deletion src/allure-nunit-tests/allure-nunit-tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>allure_nunit_tests</RootNamespace>
<IsPackable>false</IsPackable>
<OutputType>Library</OutputType>
Expand Down
14 changes: 14 additions & 0 deletions src/allure-nunit/Core/AllureExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using Allure.Commons;
using NUnit.Framework.Internal;
using System.Linq;

namespace NUnit.Allure.Core
{
Expand Down Expand Up @@ -110,5 +112,17 @@ public static T WrapInStep<T>(this AllureLifecycle lifecycle, Func<T> func, stri
throw;
}
}


/// <summary>
/// AllureNUnit AddScreenDiff wrapper method.
/// </summary>
public static void AddScreenDiff(this AllureLifecycle lifecycle, string expected, string actual, string diff)
{
var storageMain = lifecycle.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(lifecycle);
var storageInternal = storageMain.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(storageMain);
var keys = (storageInternal as System.Collections.Concurrent.ConcurrentDictionary<string, object>).Keys.ToList();
AllureLifecycle.Instance.AddScreenDiff(keys.Find(key => key.Contains("-tr-")), expected, actual, diff);
}
}
}
8 changes: 5 additions & 3 deletions src/allure-nunit/allure-nunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
<None Update="allureConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\logo.png" Pack="true" PackagePath="\"/>
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="\"/>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\logo.png" Pack="true" PackagePath="\">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>

0 comments on commit fb9c0d6

Please sign in to comment.