-
-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathBootstrapModuleComponentBaseTest.cs
More file actions
61 lines (49 loc) · 2.02 KB
/
BootstrapModuleComponentBaseTest.cs
File metadata and controls
61 lines (49 loc) · 2.02 KB
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
using Microsoft.JSInterop;
namespace UnitTest.Components;
public class BootstrapModuleComponentBaseTest : BootstrapBlazorTestBase
{
[Fact]
public void InvokeVoidAsync_Ok()
{
var cut = Context.RenderComponent<MockComponent>();
cut.InvokeAsync(() => cut.Instance.InvokeVoidAsyncTest());
Assert.True(cut.Instance.InvokeVoidRunner);
}
[Fact]
public async Task InvokeAsync_Ok()
{
var cut = Context.RenderComponent<MockObjectReferenceComponent>();
await cut.InvokeAsync(() => cut.Instance.InvokeAsyncTest());
Assert.True(cut.Instance.InvokeRunner);
}
[JSModuleAutoLoader("mock.js")]
class MockComponent : BootstrapModuleComponentBase
{
public bool InvokeVoidRunner { get; set; }
public async Task InvokeVoidAsyncTest()
{
await InvokeVoidAsync(Id);
await InvokeVoidAsync(Id, TimeSpan.FromMinutes(1));
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000);
await InvokeVoidAsync(Id, cancellationTokenSource.Token);
InvokeVoidRunner = true;
}
}
[JSModuleAutoLoader("mock.js", JSObjectReference = true, AutoInvokeDispose = true, AutoInvokeInit = true)]
class MockObjectReferenceComponent : Select<string>
{
public bool InvokeRunner { get; set; }
public async Task InvokeAsyncTest()
{
await InvokeAsync<string>(Id);
await InvokeAsync<string>(Id, TimeSpan.FromMinutes(1));
using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000);
await InvokeAsync<string>(Id, cancellationTokenSource.Token);
InvokeRunner = true;
}
}
}