|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Concurrent;
|
6 | 6 | using System.Collections.Generic;
|
| 7 | +using System.Linq; |
7 | 8 | using System.Net;
|
8 | 9 | using System.Net.Http;
|
9 | 10 | using System.Threading;
|
@@ -392,39 +393,37 @@ public void AddHttpClient_AddSameTypedClientTwice_WithSameName_WithAddTypedClien
|
392 | 393 | }
|
393 | 394 |
|
394 | 395 | [Fact]
|
395 |
| - public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_ThrowsError() |
| 396 | + public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_IsAllowed() |
396 | 397 | {
|
397 | 398 | // Arrange
|
398 | 399 | var serviceCollection = new ServiceCollection();
|
399 |
| - serviceCollection.AddHttpClient<TestTypedClient>(); |
| 400 | + serviceCollection.AddHttpClient<TestTypedClient>("Test1"); |
| 401 | + serviceCollection.AddHttpClient<TestTypedClient>("Test2"); |
| 402 | + |
| 403 | + var services = serviceCollection.BuildServiceProvider(); |
400 | 404 |
|
401 | 405 | // Act
|
402 |
| - var ex = Assert.Throws<InvalidOperationException>(() => serviceCollection.AddHttpClient<TestTypedClient>("Test")); |
| 406 | + var clients = services.GetRequiredService<IEnumerable<TestTypedClient>>(); |
403 | 407 |
|
404 | 408 | // Assert
|
405 |
| - Assert.Equal( |
406 |
| - "The HttpClient factory already has a registered client with the type 'Microsoft.Extensions.Http.TestTypedClient'. " + |
407 |
| - "Client types must be unique. " + |
408 |
| - "Consider using inheritance to create multiple unique types with the same API surface.", |
409 |
| - ex.Message); |
| 409 | + Assert.Equal(2, clients.Count()); |
410 | 410 | }
|
411 | 411 |
|
412 | 412 | [Fact]
|
413 |
| - public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_WithAddTypedClient_ThrowsError() |
| 413 | + public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_WithAddTypedClient_IsAllowed() |
414 | 414 | {
|
415 | 415 | // Arrange
|
416 | 416 | var serviceCollection = new ServiceCollection();
|
417 | 417 | serviceCollection.AddHttpClient<TestTypedClient>();
|
| 418 | + serviceCollection.AddHttpClient("Test").AddTypedClient<TestTypedClient>(); |
| 419 | + |
| 420 | + var services = serviceCollection.BuildServiceProvider(); |
418 | 421 |
|
419 | 422 | // Act
|
420 |
| - var ex = Assert.Throws<InvalidOperationException>(() => serviceCollection.AddHttpClient("Test").AddTypedClient<TestTypedClient>()); |
| 423 | + var clients = services.GetRequiredService<IEnumerable<TestTypedClient>>(); |
421 | 424 |
|
422 | 425 | // Assert
|
423 |
| - Assert.Equal( |
424 |
| - "The HttpClient factory already has a registered client with the type 'Microsoft.Extensions.Http.TestTypedClient'. " + |
425 |
| - "Client types must be unique. " + |
426 |
| - "Consider using inheritance to create multiple unique types with the same API surface.", |
427 |
| - ex.Message); |
| 426 | + Assert.Equal(2, clients.Count()); |
428 | 427 | }
|
429 | 428 |
|
430 | 429 | [Fact]
|
|
0 commit comments