Skip to content

Commit

Permalink
Add tests for skipping releases
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Feb 10, 2020
1 parent 58c84a1 commit 053c487
Showing 1 changed file with 89 additions and 16 deletions.
105 changes: 89 additions & 16 deletions Tests/NetKAN/Transformers/GithubTransformerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Moq;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using CKAN;
using CKAN.Versioning;
using CKAN.NetKAN.Model;
using CKAN.NetKAN.Sources.Github;
Expand All @@ -14,16 +13,12 @@ namespace Tests.NetKAN.Transformers
[TestFixture]
public sealed class GithubTransformerTests
{
private TransformOptions opts = new TransformOptions(1, null, null);
private readonly TransformOptions opts = new TransformOptions(1, null, null);

[Test]
public void CalculatesRepositoryUrlCorrectly()
private Mock<IGithubApi> apiMockUp;
[OneTimeSetUp]
public void setupApiMockup()
{
// Arrange
var json = new JObject();
json["spec_version"] = 1;
json["$kref"] = "#/ckan/github/ExampleAccount/ExampleProject";

var mApi = new Mock<IGithubApi>();
mApi.Setup(i => i.GetRepo(It.IsAny<GithubRef>()))
.Returns(new GithubRepo
Expand All @@ -40,14 +35,37 @@ public void CalculatesRepositoryUrlCorrectly()
));

mApi.Setup(i => i.GetAllReleases(It.IsAny<GithubRef>()))
.Returns(new GithubRelease[] { new GithubRelease(
"ExampleProject",
new ModuleVersion("1.0"),
new Uri("http://github.example/download"),
null
)});
.Returns(new GithubRelease[] {
new GithubRelease(
"ExampleProject",
new ModuleVersion("1.0"),
new Uri("http://github.example/download/1.0"),
null
),
new GithubRelease("ExampleProject",
new ModuleVersion("1.1"),
new Uri("http://github.example/download/1.1"),
null
),
new GithubRelease("ExampleProject",
new ModuleVersion("1.2"),
new Uri("http://github.example/download/1.2"),
null
),
});

var sut = new GithubTransformer(mApi.Object, false);
apiMockUp = mApi;
}

[Test]
public void CalculatesRepositoryUrlCorrectly()
{
// Arrange
var json = new JObject();
json["spec_version"] = 1;
json["$kref"] = "#/ckan/github/ExampleAccount/ExampleProject";

var sut = new GithubTransformer(apiMockUp.Object, false);

// Act
var result = sut.Transform(new Metadata(json), opts).First();
Expand Down Expand Up @@ -104,5 +122,60 @@ public void Transform_DownloadURLWithEncodedCharacter_DontDoubleEncode()
);
}

[Test]
public void Transform_MultipleReleases_TransformsAll()
{
// Arrange
var json = new JObject();
json["spec_version"] = 1;
json["$kref"] = "#/ckan/github/ExampleAccount/ExampleProject";

var sut = new GithubTransformer(apiMockUp.Object, false);

// Act
var results = sut.Transform(
new Metadata(json),
new TransformOptions(2, null, null)
);
var transformedJsons = results.Select(result => result.Json()).ToArray();

// Assert
Assert.AreEqual(
"http://github.example/download/1.0",
(string)transformedJsons[0]["download"]
);
Assert.AreEqual(
"http://github.example/download/1.1",
(string)transformedJsons[1]["download"]
);
}

[Test]
public void Transform_SkipReleases_SkipsCorrectly()
{
// Arrange
var json = new JObject();
json["spec_version"] = 1;
json["$kref"] = "#/ckan/github/ExampleAccount/ExampleProject";

var sut = new GithubTransformer(apiMockUp.Object, false);

// Act
var results = sut.Transform(
new Metadata(json),
new TransformOptions(3, 1, null)
).ToArray();
// var transformedJsons = results.Select(result => result.Json()).ToArray();

// Assert
Assert.AreEqual(
"1.1",
results[0].Version.ToString()
);
Assert.AreEqual(
"1.2",
results[1].Version.ToString()
);
}
}
}

0 comments on commit 053c487

Please sign in to comment.