-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
239 additions
and
7 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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Newtonsoft.Json.Linq; | ||
using Moq; | ||
using CKAN.NetKAN.Services; | ||
using CKAN.NetKAN.Model; | ||
using CKAN.NetKAN.Transformers; | ||
|
||
namespace Tests.NetKAN.Transformers | ||
{ | ||
[TestFixture] | ||
public sealed class AvcKrefTransformerTests | ||
{ | ||
[Test, | ||
TestCase( | ||
"https://mysite.org/AwesomeMod.version", | ||
"1.0.0", | ||
"1.4.1", | ||
"https://mysite.org/AwesomeMod.zip", | ||
@"{ | ||
""NAME"": ""AwesomeMod"", | ||
""URL"": ""https://mysite.org/AwesomeMod.version"", | ||
""DOWNLOAD"": ""https://mysite.org/AwesomeMod.zip"", | ||
""VERSION"": { | ||
""MAJOR"": 1, | ||
""MINOR"": 0, | ||
""PATCH"": 0 | ||
}, | ||
""KSP_VERSION"": { | ||
""MAJOR"": 1, | ||
""MINOR"": 4, | ||
""PATCH"": 1 | ||
} | ||
}" | ||
) | ||
] | ||
public void Transform_SimpleVersionFile_PropertiesSet(string remoteUrl, string version, string kspVersion, string download, string remoteAvc) | ||
{ | ||
// Arrange | ||
var mHttp = new Mock<IHttpService>(); | ||
mHttp.Setup(i => i.DownloadText(It.IsAny<Uri>())) | ||
.Returns(remoteAvc); | ||
|
||
// Act | ||
Metadata m = null; | ||
Assert.DoesNotThrow(() => m = TryKref(mHttp.Object, $"#/ckan/ksp-avc/{remoteUrl}")); | ||
|
||
// Assert | ||
var json = m.Json(); | ||
Assert.AreEqual((string)json["version"], version); | ||
Assert.AreEqual((string)json["ksp_version"], kspVersion); | ||
Assert.AreEqual((string)json["download"], download); | ||
} | ||
|
||
private Metadata TryKref(IHttpService http, string kref) | ||
{ | ||
// Arrange | ||
var json = new JObject(); | ||
json["spec_version"] = 1; | ||
json["identifier"] = "AwesomeMod"; | ||
if (kref != null) | ||
{ | ||
json["$kref"] = kref; | ||
} | ||
|
||
// Act | ||
var tran = new AvcKrefTransformer(http); | ||
return tran.Transform(new Metadata(json)); | ||
} | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using NUnit.Framework; | ||
using Newtonsoft.Json.Linq; | ||
using CKAN.NetKAN.Model; | ||
using CKAN.NetKAN.Validators; | ||
|
||
namespace Tests.NetKAN.Validators | ||
{ | ||
[TestFixture] | ||
public sealed class KrefValidatorTests | ||
{ | ||
[Test, | ||
TestCase(null), | ||
TestCase("#/ckan/curse/12345"), | ||
TestCase("#/ckan/github/AGoodModder/AGoodMod"), | ||
TestCase("#/ckan/http/https://mysite.org/AGoodMod.zip"), | ||
TestCase("#/ckan/ksp-avc/https://mysite.org/AGoodMod.version"), | ||
TestCase("#/ckan/netkan/https://mysite.org/AGoodMod.netkan"), | ||
TestCase("#/ckan/jenkins/https://mysite.org/AGoodMod/"), | ||
TestCase("#/ckan/spacedock/12345") | ||
] | ||
public void Validate_KnownKref_Valid(string kref) | ||
{ | ||
Assert.DoesNotThrow(() => TryKref(kref)); | ||
} | ||
|
||
[Test, | ||
TestCase("#/ckan/techman/iscool"), | ||
TestCase("#/ckan/spaceport/305") | ||
] | ||
public void Validate_TechManIsCool_Invalid(string kref) | ||
{ | ||
Assert.Throws<CKAN.Kraken>(() => TryKref(kref)); | ||
} | ||
|
||
private void TryKref(string kref) | ||
{ | ||
// Arrange | ||
var json = new JObject(); | ||
json["spec_version"] = 1; | ||
json["identifier"] = "AwesomeMod"; | ||
if (kref != null) | ||
{ | ||
json["$kref"] = kref; | ||
} | ||
|
||
// Act | ||
var val = new KrefValidator(); | ||
val.Validate(new Metadata(json)); | ||
} | ||
|
||
} | ||
} |
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