Пример #1
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."
                        );
        }
Пример #2
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"
                        );
        }