Пример #1
0
        public void Transform_TrustVersionFileTrue_OverridesExistingInfo()
        {
            // Arrange
            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new AvcVersion()
            {
                version = new ModuleVersion("1.2.3")
            });

            ITransformer sut = new AvcTransformer(mHttp.Object, mModuleService.Object);

            JObject json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";
            json["version"]      = "9001";
            json["x_netkan_trust_version_file"] = true;

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

            // Assert
            Assert.That((string)transformedJson["version"], Is.EqualTo("1.2.3"),
                        "AvcTransformer should override an existing version when x_netkan_trust_version_file is true."
                        );
        }
Пример #2
0
        public void DoesNotOverrideExistingVersionInfo()
        {
            // Arrange
            var avcVersion = new AvcVersion {
                version = new ModuleVersion("1.2.3")
            };

            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(avcVersion);

            var sut = new AvcTransformer(mHttp.Object, mModuleService.Object);

            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";
            json["version"]      = "9001";

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

            // Assert
            Assert.That((string)transformedJson["version"], Is.EqualTo("9001"),
                        "AvcTransformer should not override an existing version."
                        );
        }
Пример #3
0
        public void OverridesExistingVersionInfo(string propertyName)
        {
            // Arrange
            var avcVersion = new AvcVersion();

            switch (propertyName)
            {
            case "version":
                avcVersion.version = new Version("1.2.3");
                break;

            case "ksp_version":
                avcVersion.ksp_version = new KSPVersion("1.2.3");
                break;

            case "ksp_version_min":
                avcVersion.ksp_version_min = new KSPVersion("1.2.3");
                break;

            case "ksp_version_max":
                avcVersion.ksp_version_max = new KSPVersion("1.2.3");
                break;
            }

            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(avcVersion);

            var sut = new AvcTransformer(mHttp.Object, mModuleService.Object);

            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";
            json[propertyName]   = "9001";

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

            // Assert
            Assert.That((string)transformedJson[propertyName], Is.EqualTo("1.2.3"),
                        string.Format("AvcTransformer should override an existing {0}.", propertyName)
                        );
        }
Пример #4
0
        public void PreferentiallyAddsRangedKspVersionInfo()
        {
            // Arrange
            var avcVersion = new AvcVersion
            {
                ksp_version     = KspVersion.Parse("1.0.4"),
                ksp_version_min = KspVersion.Parse("0.90"),
                ksp_version_max = KspVersion.Parse("1.0.3")
            };

            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(avcVersion);

            var sut = new AvcTransformer(mHttp.Object, mModuleService.Object);

            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";

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

            // Assert
            Assert.That((string)transformedJson["ksp_version_min"], Is.EqualTo("0.90"),
                        "AvcTransformer should add the KSP min version specified in the AVC version file."
                        );
            Assert.That((string)transformedJson["ksp_version_max"], Is.EqualTo("1.0.3"),
                        "AvcTransformer should add the KSP min version specified in the AVC version file."
                        );
            Assert.That(transformedJson["ksp_version"], Is.Null,
                        "AvcTransformer should not add a KSP version if min or max versions are specified."
                        );
        }
Пример #5
0
        public void AddsMissingVersionInfo()
        {
            // Arrange
            var avcVersion = new AvcVersion
            {
                version     = new ModuleVersion("1.0.0"),
                ksp_version = GameVersion.Parse("1.0.4")
            };

            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(avcVersion);

            var sut = new AvcTransformer(mHttp.Object, mModuleService.Object, null);

            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";

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

            // Assert
            Assert.That((string)transformedJson["version"], Is.EqualTo("1.0.0"),
                        "AvcTransformer should add the version specified in the AVC version file."
                        );
            Assert.That((string)transformedJson["ksp_version"], Is.EqualTo("1.0.4"),
                        "AvcTransformer should add the game version specified in the AVC version file."
                        );
        }
Пример #6
0
        public void CorrectlyCalculatesKspVersionInfo(
            string existingKsp, string existingKspMin, string existingKspMax,
            string avcKsp, string avcKspMin, string avcKspMax,
            string expectedKsp, string expectedKspMin, string expectedKspMax
            )
        {
            // Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AwesomeMod";
            json["$vref"]        = "#/ckan/ksp-avc";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";

            if (!string.IsNullOrWhiteSpace(existingKsp))
            {
                json["ksp_version"] = existingKsp;
            }

            if (!string.IsNullOrWhiteSpace(existingKspMin))
            {
                json["ksp_version_min"] = existingKspMin;
            }

            if (!string.IsNullOrWhiteSpace(existingKspMax))
            {
                json["ksp_version_max"] = existingKspMax;
            }

            var avcVersion = new AvcVersion();

            if (!string.IsNullOrWhiteSpace(avcKsp))
            {
                avcVersion.ksp_version = KspVersion.Parse(avcKsp);
            }

            if (!string.IsNullOrWhiteSpace(avcKspMin))
            {
                avcVersion.ksp_version_min = KspVersion.Parse(avcKspMin);
            }

            if (!string.IsNullOrWhiteSpace(avcKspMax))
            {
                avcVersion.ksp_version_max = KspVersion.Parse(avcKspMax);
            }

            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.GetInternalAvc(It.IsAny <CkanModule>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(avcVersion);

            var sut = new AvcTransformer(mHttp.Object, mModuleService.Object);

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

            // Assert
            Assert.That((string)transformedJson["ksp_version"], Is.EqualTo(expectedKsp),
                        "AvcTransformer should calculate ksp_version correctly"
                        );

            Assert.That((string)transformedJson["ksp_version_min"], Is.EqualTo(expectedKspMin),
                        "AvcTransformer should calculate ksp_version_min correctly"
                        );

            Assert.That((string)transformedJson["ksp_version_max"], Is.EqualTo(expectedKspMax),
                        "AvcTransformer should calculate ksp_version_max correctly"
                        );
        }