-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from ejball/clone-settings
- Loading branch information
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/Facility.Core.UnitTests/Http/HttpClientServiceSettingsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections; | ||
using Facility.Core.Http; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Facility.Core.UnitTests.Http; | ||
|
||
public class HttpClientServiceSettingsTests | ||
{ | ||
[Test] | ||
public async Task CloneSettings() | ||
{ | ||
var original = new HttpClientServiceSettings | ||
{ | ||
BaseUri = new Uri("https://example.com"), | ||
HttpClient = new HttpClient(), | ||
ContentSerializer = HttpContentSerializer.Create(SystemTextJsonServiceSerializer.Instance), | ||
BytesSerializer = BytesHttpContentSerializer.Instance, | ||
TextSerializer = TextHttpContentSerializer.Instance, | ||
DisableChunkedTransfer = true, | ||
Aspects = Array.Empty<HttpClientServiceAspect>(), | ||
Synchronous = true, | ||
SkipRequestValidation = true, | ||
SkipResponseValidation = true, | ||
}; | ||
|
||
var clone = original.Clone(); | ||
|
||
foreach (var property in typeof(HttpClientServiceSettings).GetProperties()) | ||
{ | ||
var propertyType = property.PropertyType; | ||
|
||
var originalValue = property.GetValue(original); | ||
var nullOrDefault = propertyType.IsValueType && Nullable.GetUnderlyingType(propertyType) is null ? Activator.CreateInstance(propertyType) : null; | ||
originalValue.Should().NotBe(nullOrDefault, $"original {property.Name} should not be null/default."); | ||
|
||
var clonedValue = property.GetValue(clone); | ||
if (clonedValue is IEnumerable and not string) | ||
clonedValue.Should().BeEquivalentTo(originalValue, $"cloned {property.Name} should be equivalent to original."); | ||
else | ||
clonedValue.Should().Be(originalValue, $"cloned {property.Name} should be equal to original."); | ||
} | ||
} | ||
} |