|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 | 4 | using System.Collections.ObjectModel;
|
5 |
| -using System.Linq; |
6 | 5 | using Microsoft.AspNetCore.Builder;
|
7 | 6 | using Microsoft.AspNetCore.Http;
|
8 | 7 | using Microsoft.AspNetCore.Routing.Patterns;
|
@@ -58,6 +57,28 @@ public void CreatesShallowCopyOf_ListOfGroupedEndpoints()
|
58 | 57 | Assert.Equal(groupedEndpoints, resolvedGroupEndpoints);
|
59 | 58 | }
|
60 | 59 |
|
| 60 | + [Fact] |
| 61 | + public void RepeatedlyThrows_WhenChildDataSourcesThrow() |
| 62 | + { |
| 63 | + var ex = new Exception(); |
| 64 | + var compositeDataSource = new CompositeEndpointDataSource(new[] |
| 65 | + { |
| 66 | + new EndpointThrowingDataSource(ex), |
| 67 | + }); |
| 68 | + var groupContext = new RouteGroupContext |
| 69 | + { |
| 70 | + Prefix = RoutePatternFactory.Parse(""), |
| 71 | + Conventions = Array.Empty<Action<EndpointBuilder>>(), |
| 72 | + FinallyConventions = Array.Empty<Action<EndpointBuilder>>(), |
| 73 | + ApplicationServices = new ServiceCollection().BuildServiceProvider(), |
| 74 | + }; |
| 75 | + |
| 76 | + Assert.Same(ex, Assert.Throws<Exception>(() => compositeDataSource.Endpoints)); |
| 77 | + Assert.Same(ex, Assert.Throws<Exception>(() => compositeDataSource.Endpoints)); |
| 78 | + Assert.Same(ex, Assert.Throws<Exception>(() => compositeDataSource.GetGroupedEndpoints(groupContext))); |
| 79 | + Assert.Same(ex, Assert.Throws<Exception>(() => compositeDataSource.GetGroupedEndpoints(groupContext))); |
| 80 | + } |
| 81 | + |
61 | 82 | [Fact]
|
62 | 83 | public void Endpoints_ReturnsAllEndpoints_FromMultipleDataSources()
|
63 | 84 | {
|
@@ -502,4 +523,17 @@ public override IReadOnlyList<Endpoint> GetGroupedEndpoints(RouteGroupContext co
|
502 | 523 |
|
503 | 524 | public override IChangeToken GetChangeToken() => NullChangeToken.Singleton;
|
504 | 525 | }
|
| 526 | + |
| 527 | + private class EndpointThrowingDataSource : EndpointDataSource |
| 528 | + { |
| 529 | + private readonly Exception _ex; |
| 530 | + |
| 531 | + public EndpointThrowingDataSource(Exception ex) |
| 532 | + { |
| 533 | + _ex = ex; |
| 534 | + } |
| 535 | + |
| 536 | + public override IReadOnlyList<Endpoint> Endpoints => throw _ex; |
| 537 | + public override IChangeToken GetChangeToken() => NullChangeToken.Singleton; |
| 538 | + } |
505 | 539 | }
|
0 commit comments