-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestScaffoldAttribute.cs
59 lines (48 loc) · 1.97 KB
/
TestScaffoldAttribute.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
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ExecContext=DSM.Engine.ExecutionContext;
using DSM.Common.Model.States;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
namespace DSM.Tests
{
public delegate (ExecContext, CancellationTokenSource)
ScaffoldFactoryDelegate(IStateMachineMetadata metadata, Func<string, IStateMachineMetadata> lookup, ILogger logger);
[AttributeUsage(AttributeTargets.Method)]
public class TestScaffoldAttribute : Attribute, ITestDataSource
{
public static TimeSpan ExecutionTimeout => Debugger.IsAttached ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(1);
public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
yield return new object[]
{
(ScaffoldFactoryDelegate) ((machine, lookup, logger) =>
{
var cts = new CancellationTokenSource();
var context = new ExecContext(machine, cts.Token, lookup, null, logger);
return (context, cts);
}),
"Lite"
};
//yield return new object[]
//{
// (ScaffoldFactoryDelegate) ((machine, logger) =>
// {
// var cts = new CancellationTokenSource();
// var emulator = new LocalOrchestrationService();
// var storage = new Durable.InMemoryOrchestrationStorage();
// var context = new Durable.ExecutionContext(machine, emulator, storage, cts.Token, ExecutionTimeout, logger);
// return (context, cts);
// }),
// "Durable"
//};
}
public string GetDisplayName(MethodInfo methodInfo, object[] data)
{
return $"{methodInfo.Name}-{data[1]}";
}
}
}