Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.4.7-beta04</Version>
<Version>9.4.7</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 7 additions & 10 deletions src/BootstrapBlazor/Services/BootstrapBlazorRootRegisterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
private readonly Dictionary<object, List<BootstrapBlazorRootContent>> _providersByIdentifier = [];

/// <summary>
/// add provider
/// Add provider
/// </summary>
/// <param name="identifier"></param>
/// <param name="provider"></param>
Expand All @@ -30,7 +30,7 @@
}

/// <summary>
/// remove provider
/// Remove provider
/// </summary>
/// <param name="identifier"></param>
/// <param name="provider"></param>
Expand Down Expand Up @@ -58,7 +58,7 @@
}

/// <summary>
/// get all providers by identifier
/// Get all providers by identifier
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
Expand All @@ -69,30 +69,27 @@
}

/// <summary>
/// subscribe
/// Subscribe
/// </summary>
/// <param name="identifier"></param>
/// <param name="subscriber"></param>
public void Subscribe(object identifier, BootstrapBlazorRootOutlet subscriber)
{
if (_subscribersByIdentifier.ContainsKey(identifier))
{
throw new InvalidOperationException($"There is already a subscriber to the content with the given root ID '{identifier}'.");
return;

Check warning on line 80 in src/BootstrapBlazor/Services/BootstrapBlazorRootRegisterService.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Services/BootstrapBlazorRootRegisterService.cs#L80

Added line #L80 was not covered by tests
}

_subscribersByIdentifier.Add(identifier, subscriber);
}

/// <summary>
/// 取消订阅
/// Unsubscribe
/// </summary>
/// <param name="identifier"></param>
public void Unsubscribe(object identifier)
{
if (!_subscribersByIdentifier.Remove(identifier))
{
throw new InvalidOperationException($"The subscriber with the given root ID '{identifier}' is already unsubscribed.");
}
_subscribersByIdentifier.Remove(identifier);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public void Subscribe_Ok()
var service = new BootstrapBlazorRootRegisterService();
var identifier = new object();
service.Subscribe(identifier, new BootstrapBlazorRootOutlet());
var exception = Assert.ThrowsAny<InvalidOperationException>(() => service.Subscribe(identifier, new BootstrapBlazorRootOutlet()));
Assert.Equal("There is already a subscriber to the content with the given root ID 'System.Object'.", exception.Message);

exception = Assert.ThrowsAny<InvalidOperationException>(() => service.Unsubscribe(new object()));
Assert.Equal("The subscriber with the given root ID 'System.Object' is already unsubscribed.", exception.Message);
service.Unsubscribe(new object());
}

[Fact]
Expand Down