public void Transform_SkipReleases_SkipsCorrectly()
        {
            // Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["$kref"]        = "#/ckan/github/ExampleAccount/ExampleProject";
            json["identifier"]   = "ExampleProject5";

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

            // Act
            var results = sut.Transform(
                new Metadata(json),
                new TransformOptions(2, 1, null, false, null)
                ).ToArray();

            // Assert
            Assert.AreEqual(
                "1.1",
                results[0].Version.ToString()
                );
            Assert.AreEqual(
                "1.2",
                results[1].Version.ToString()
                );
        }
Ejemplo n.º 2
0
        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"]
                );
        }
Ejemplo n.º 3
0
        public void CalculatesRepositoryUrlCorrectly()
        {
            // Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["$kref"]        = "#/ckan/github/ExampleAccount/ExampleProject";

            var mApi = new Mock <IGithubApi>();

            mApi.Setup(i => i.GetLatestRelease(It.IsAny <GithubRef>()))
            .Returns(new GithubRelease(
                         new Version("1.0"),
                         new Uri("http://github.example/download"),
                         0,
                         "ExampleProject"
                         ));

            var sut = new GithubTransformer(mApi.Object, matchPreleases: false);

            // Act
            var result          = sut.Transform(new Metadata(json));
            var transformedJson = result.Json();

            // Assert
            Assert.AreEqual(
                "https://github.com/ExampleAccount/ExampleProject",
                (string)transformedJson["resources"]["repository"]
                );
        }
        public void Transform_DownloadURLWithEncodedCharacter_DontDoubleEncode()
        {
            // Arrange
            JObject json = new JObject();

            json["spec_version"] = 1;
            json["$kref"]        = "#/ckan/github/jrodrigv/DestructionEffects";
            json["identifier"]   = "ExampleProject2";

            var mApi = new Mock <IGithubApi>();

            mApi.Setup(i => i.GetRepo(It.IsAny <GithubRef>()))
            .Returns(new GithubRepo()
            {
                HtmlUrl = "https://github.com/jrodrigv/DestructionEffects"
            });

            mApi.Setup(i => i.GetLatestRelease(It.IsAny <GithubRef>()))
            .Returns(new GithubRelease(
                         "DestructionEffects",
                         new ModuleVersion("v1.8,0"),
                         new List <GithubReleaseAsset>
            {
                new GithubReleaseAsset(
                    "DestructionEffects.1.8.0_0412018.zip",
                    new Uri("https://github.com/jrodrigv/DestructionEffects/releases/download/v1.8%2C0/DestructionEffects.1.8.0_0412018.zip"),
                    null
                    )
            }
                         ));

            mApi.Setup(i => i.GetAllReleases(It.IsAny <GithubRef>()))
            .Returns(new GithubRelease[] { new GithubRelease(
                                               "DestructionEffects",
                                               new ModuleVersion("v1.8,0"),
                                               new List <GithubReleaseAsset>
                {
                    new GithubReleaseAsset(
                        "DestructionEffects.1.8.0_0412018.zip",
                        new Uri("https://github.com/jrodrigv/DestructionEffects/releases/download/v1.8%2C0/DestructionEffects.1.8.0_0412018.zip"),
                        null
                        )
                }
                                               ) });

            ITransformer sut = new GithubTransformer(mApi.Object, false);

            // Act
            Metadata result          = sut.Transform(new Metadata(json), opts).First();
            JObject  transformedJson = result.Json();

            // Assert
            Assert.AreEqual(
                "https://github.com/jrodrigv/DestructionEffects/releases/download/v1.8%2C0/DestructionEffects.1.8.0_0412018.zip",
                (string)transformedJson["download"]
                );
        }
Ejemplo n.º 5
0
        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();
            var transformedJson = result.Json();

            // Assert
            Assert.AreEqual(
                "https://github.com/ExampleAccount/ExampleProject",
                (string)transformedJson["resources"]["repository"]
                );
        }
        public void Transform_MultipleAssets_TransformsAll()
        {
            // Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["$kref"]        = "#/ckan/github/ExampleAccount/ExampleProject/version_from_asset/^.+_(?<version>.+)\\.zip$";
            json["identifier"]   = "ExampleProject4";

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

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

            // Assert
            Assert.AreEqual(
                "http://github.example/download/1.2/ExampleProject_1.2-1.8.1.zip",
                (string)transformedJsons[0]["download"]
                );
            Assert.AreEqual(
                "http://github.example/download/1.2/ExampleProject_1.2-1.9.1.zip",
                (string)transformedJsons[1]["download"]
                );

            Assert.AreEqual(
                "1.2-1.8.1",
                (string)transformedJsons[0]["version"]
                );
            Assert.AreEqual(
                "1.2-1.9.1",
                (string)transformedJsons[1]["version"]
                );
        }