forked from allure-framework/allure-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllureStepBase.cs
72 lines (66 loc) · 2.1 KB
/
AllureStepBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Allure.Net.Commons;
#if NETCOREAPP3_0_OR_GREATER
using System.Runtime.CompilerServices;
#endif
namespace Allure.Xunit
{
public abstract class AllureStepBase<T> : IDisposable where T : AllureStepBase<T>
{
protected AllureStepBase(string uuid)
{
UUID = uuid;
}
private string UUID { get; }
public void Dispose()
{
#if NETCOREAPP3_0_OR_GREATER
var failed = Marshal.GetExceptionPointers() != IntPtr.Zero;
#else
var failed = Marshal.GetExceptionCode() != 0;
#endif
if (failed)
{
if (this is AllureBefore || this is AllureAfter)
{
Steps.StopFixtureSuppressTestCase(result => result.status = Status.failed);
}
else
{
Steps.FailStep(UUID);
}
}
else
{
if (this is AllureBefore || this is AllureAfter)
{
Steps.StopFixtureSuppressTestCase(result => result.status = Status.passed);
}
else
{
Steps.PassStep(UUID);
}
}
}
[Obsolete("For named parameters use NameAttribute; For skipped parameters use SkipAttribute")]
public T SetParameter(string name, object value)
{
AllureLifecycle.Instance.UpdateStep(UUID,
result =>
{
result.parameters ??= new List<Parameter>();
result.parameters.Add(new Parameter { name = name, value = value?.ToString() });
});
return (T) this;
}
#if NETCOREAPP3_0_OR_GREATER
[Obsolete("For named parameters use NameAttribute; For skipped parameters use SkipAttribute")]
public T SetParameter(object value, [CallerArgumentExpression("value")] string name = null)
{
return SetParameter(name, value);
}
#endif
}
}