forked from bagetter/BaGetter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests * add JsonConverter * include PR bagetter#91 * include PR # 85 * add test for tags
- Loading branch information
1 parent
828e794
commit 78ef62c
Showing
9 changed files
with
329 additions
and
17 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
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
150 changes: 150 additions & 0 deletions
150
tests/BaGetter.Protocol.Tests/Models/PackageMetadataTests.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,150 @@ | ||
using System.Text.Json; | ||
using BaGetter.Protocol.Internal; | ||
using BaGetter.Protocol.Models; | ||
using Xunit; | ||
|
||
namespace BaGetter.Protocol.Tests.Models; | ||
|
||
public class PackageMetadataTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions; | ||
|
||
public PackageMetadataTests() | ||
{ | ||
_serializerOptions = new JsonSerializerOptions(); | ||
_serializerOptions.Converters.Add(new StringOrStringArrayJsonConverter()); | ||
} | ||
|
||
[Fact] | ||
public void Tags_EmptyArray_ShouldDeserialize() | ||
{ | ||
// Arrange | ||
var stringToDeserialize = """ | ||
{ | ||
"@id": "https://nuget.pkg.github.com/FakeOrga/fakepkg/1.5.1.json", | ||
"authors": "Someone", | ||
"copyright": "", | ||
"dependencyGroups": [ ], | ||
"description": "Package Description", | ||
"iconUrl": "", | ||
"id": "fakepkg", | ||
"isPrerelease": false, | ||
"language": "", | ||
"licenseUrl": "", | ||
"packageContent": "https://nuget.pkg.github.com/FakeOrga/download/fakepkg/1.5.1/fakepkg.1.5.1.nupkg", | ||
"projectUrl": "", | ||
"requireLicenseAcceptance": false, | ||
"summary": "", | ||
"tags": [ ], | ||
"version": "1.5.1" | ||
} | ||
"""; | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<PackageMetadata>(stringToDeserialize, _serializerOptions); | ||
|
||
// Assert | ||
Assert.NotNull(result.Tags); | ||
Assert.Empty(result.Tags); | ||
} | ||
|
||
[Fact] | ||
public void Tags_EmptyString_ShouldDeserialize() | ||
{ | ||
// Arrange | ||
var stringToDeserialize = """ | ||
{ | ||
"@id": "https://nuget.pkg.github.com/FakeOrga/fakepkg/1.5.1.json", | ||
"authors": "Someone", | ||
"copyright": "", | ||
"dependencyGroups": [ ], | ||
"description": "Package Description", | ||
"iconUrl": "", | ||
"id": "fakepkg", | ||
"isPrerelease": false, | ||
"language": "", | ||
"licenseUrl": "", | ||
"packageContent": "https://nuget.pkg.github.com/FakeOrga/download/fakepkg/1.5.1/fakepkg.1.5.1.nupkg", | ||
"projectUrl": "", | ||
"requireLicenseAcceptance": false, | ||
"summary": "", | ||
"tags": "", | ||
"version": "1.5.1" | ||
} | ||
"""; | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<PackageMetadata>(stringToDeserialize, _serializerOptions); | ||
|
||
// Assert | ||
Assert.NotNull(result.Tags); | ||
Assert.Single(result.Tags); | ||
} | ||
|
||
[Fact] | ||
public void Tags_SingleEntry_ShouldDeserializeSingleTag() | ||
{ | ||
// Arrange | ||
var stringToDeserialize = """ | ||
{ | ||
"@id": "https://nuget.pkg.github.com/FakeOrga/fakepkg/1.5.1.json", | ||
"authors": "Someone", | ||
"copyright": "", | ||
"dependencyGroups": [ ], | ||
"description": "Package Description", | ||
"iconUrl": "", | ||
"id": "fakepkg", | ||
"isPrerelease": false, | ||
"language": "", | ||
"licenseUrl": "", | ||
"packageContent": "https://nuget.pkg.github.com/FakeOrga/download/fakepkg/1.5.1/fakepkg.1.5.1.nupkg", | ||
"projectUrl": "", | ||
"requireLicenseAcceptance": false, | ||
"summary": "", | ||
"tags": "tag1", | ||
"version": "1.5.1" | ||
} | ||
"""; | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<PackageMetadata>(stringToDeserialize, _serializerOptions); | ||
|
||
// Assert | ||
Assert.NotNull(result.Tags); | ||
Assert.Single(result.Tags); | ||
} | ||
|
||
[Fact] | ||
public void Tags_HasMultipleEntries_ShouldDeserializeMultipleTags() | ||
{ | ||
// Arrange | ||
var stringToDeserialize = """ | ||
{ | ||
"@id": "https://nuget.pkg.github.com/FakeOrga/fakepkg/1.5.1.json", | ||
"authors": "Someone", | ||
"copyright": "", | ||
"dependencyGroups": [ ], | ||
"description": "Package Description", | ||
"iconUrl": "", | ||
"id": "fakepkg", | ||
"isPrerelease": false, | ||
"language": "", | ||
"licenseUrl": "", | ||
"packageContent": "https://nuget.pkg.github.com/FakeOrga/download/fakepkg/1.5.1/fakepkg.1.5.1.nupkg", | ||
"projectUrl": "", | ||
"requireLicenseAcceptance": false, | ||
"summary": "", | ||
"tags": ["tag1", "tag2"], | ||
"version": "1.5.1" | ||
} | ||
"""; | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<PackageMetadata>(stringToDeserialize, _serializerOptions); | ||
|
||
// Assert | ||
Assert.NotNull(result.Tags); | ||
Assert.Equal(2, result.Tags.Count); | ||
} | ||
|
||
} |
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
Oops, something went wrong.