-
-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathBootstrapBlazorRootRegisterServiceTest.cs
More file actions
65 lines (51 loc) · 2.78 KB
/
BootstrapBlazorRootRegisterServiceTest.cs
File metadata and controls
65 lines (51 loc) · 2.78 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
62
63
64
65
// 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 System.Runtime.CompilerServices;
namespace UnitTest.Services;
public class BootstrapBlazorRootRegisterServiceTest
{
[Fact]
public void Provider_Ok()
{
var service = new BootstrapBlazorRootRegisterService();
var exception = Assert.ThrowsAny<InvalidOperationException>(() => service.RemoveProvider(new object(), new BootstrapBlazorRootContent()));
Assert.Equal("There are no content providers with the given root ID 'System.Object'.", exception.Message);
var identifier = new object();
service.AddProvider(identifier, new BootstrapBlazorRootContent());
exception = Assert.ThrowsAny<InvalidOperationException>(() => service.RemoveProvider(identifier, new BootstrapBlazorRootContent()));
Assert.Equal("The provider was not found in the providers list of the given root ID 'System.Object'.", exception.Message);
}
[Fact]
public void Subscribe_Ok()
{
var service = new BootstrapBlazorRootRegisterService();
var identifier = new object();
service.Subscribe(identifier, new BootstrapBlazorRootOutlet());
service.Unsubscribe(new object());
}
[Fact]
public void NotifyContentProviderChanged_Ok()
{
var service = new BootstrapBlazorRootRegisterService();
var exception = Assert.ThrowsAny<InvalidOperationException>(() => service.NotifyContentProviderChanged(new object(), new BootstrapBlazorRootContent()));
Assert.Equal("There are no content providers with the given root ID 'System.Object'.", exception.Message);
var identifier = new object();
service.AddProvider(identifier, new BootstrapBlazorRootContent());
var providers = service.GetProviders(identifier);
providers.Clear();
service.NotifyContentProviderChanged(identifier, new BootstrapBlazorRootContent());
}
[Fact]
public void GetCurrentProviderContentOrDefault_Ok()
{
var service = new BootstrapBlazorRootRegisterService();
Assert.Null(GetCurrentProviderContentOrDefault(service, []));
var provider = new BootstrapBlazorRootContent();
service.AddProvider(new object(), provider);
Assert.Equal(provider, GetCurrentProviderContentOrDefault(service, [provider]));
}
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetCurrentProviderContentOrDefault")]
static extern BootstrapBlazorRootContent? GetCurrentProviderContentOrDefault(BootstrapBlazorRootRegisterService @this, List<BootstrapBlazorRootContent> providers);
}