-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTests_RevitTask.cs
124 lines (113 loc) · 4.47 KB
/
Tests_RevitTask.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Autodesk.Revit.UI;
using NUnit.Framework;
using ricaun.Revit.UI.Tasks;
using System;
using System.Threading;
using System.Threading.Tasks;
[assembly: System.Reflection.AssemblyMetadata("ricaun.RevitTest.Application.Tasks.Name", "RevitTask")]
// [assembly: System.Reflection.AssemblyMetadata("ricaun.RevitTest.Application.Tasks.Timeout", "0.05")] // minutes (default 1 minute)
namespace RevitTest.Sample
{
public class Tests_RevitTask : RevitTaskBase
{
[Test]
public async Task TestPostableCommand_NewProject()
{
await RevitTask.Run((uiapp) =>
{
uiapp.DialogBoxShowing += DialogBoxShowingForceClose;
uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.NewProject));
});
await RevitTask.Run((uiapp) =>
{
uiapp.DialogBoxShowing -= DialogBoxShowingForceClose;
});
}
private void DialogBoxShowingForceClose(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e)
{
var uiapp = sender as UIApplication;
uiapp.DialogBoxShowing -= DialogBoxShowingForceClose;
Console.WriteLine($"DialogBoxShowing {e.DialogId}");
e.OverrideResult((int)TaskDialogResult.Close);
}
}
public class RevitTaskBase
{
protected IRevitTask RevitTask { get; private set; }
[OneTimeSetUp]
public void Initialize(Func<Func<UIApplication, object>, CancellationToken, Task<object>> revitTask)
{
RevitTask = new RevitTaskFuncService(revitTask);
}
public class RevitTaskFuncService : IRevitTask
{
private Func<Func<UIApplication, object>, CancellationToken, Task<object>> RevitTask;
public RevitTaskFuncService(Func<Func<UIApplication, object>, CancellationToken, Task<object>> revitTask)
{
RevitTask = revitTask;
}
public async Task<TResult> Run<TResult>(Func<UIApplication, TResult> function, CancellationToken cancellationToken)
{
var result = await RevitTask.Invoke((uiapp) => { return function(uiapp); }, cancellationToken);
if (result is TResult t)
return t;
return default;
}
}
}
public class Tests_RevitTask_Parameters
{
[Test]
public async Task RevitTaskNone0(Func<Action, Task> revitTask)
{
var result = false;
await revitTask.Invoke(() => { result = true; });
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskNone1(Func<Action<UIApplication>, Task> revitTask)
{
var result = false;
await revitTask.Invoke((uiapp) => { result = true; });
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskNone2(Func<Func<object>, Task<object>> revitTask)
{
var result = (bool)await revitTask.Invoke(() => { return true; });
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskNone3(Func<Func<UIApplication, object>, Task<object>> revitTask)
{
var result = (bool)await revitTask.Invoke((uiapp) => { return true; });
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskToken0(Func<Action, CancellationToken, Task> revitTask)
{
var result = false;
await revitTask.Invoke(() => { result = true; }, CancellationToken.None);
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskToken1(Func<Action<UIApplication>, CancellationToken, Task> revitTask)
{
var result = false;
await revitTask.Invoke((uiapp) => { result = true; }, CancellationToken.None);
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskToken2(Func<Func<object>, CancellationToken, Task<object>> revitTask)
{
var result = (bool)await revitTask.Invoke(() => { return true; }, CancellationToken.None);
Assert.IsTrue(result);
}
[Test]
public async Task RevitTaskToken3(Func<Func<UIApplication, object>, CancellationToken, Task<object>> revitTask)
{
var result = (bool)await revitTask.Invoke((uiapp) => { return true; }, CancellationToken.None);
Assert.IsTrue(result);
}
}
}