Beispiel #1
0
        public void CompareToWorksCorrectly(KspVersion v1, KspVersion v2, int comparison)
        {
            // Act
            var genericCompareTo           = v1.CompareTo(v2);
            var nonGenericCompareTo        = v1.CompareTo((object)v2);
            var lessThanOperator           = v1 < v2;
            var lessThanOrEqualOperator    = v1 <= v2;
            var greaterThanOperator        = v1 > v2;
            var greaterThanOrEqualOperator = v1 >= v2;

            var reverseGenericCompareTo           = v2.CompareTo(v1);
            var reverseNonGenericCompareTo        = v2.CompareTo((object)v1);
            var reverseLessThanOperator           = v2 < v1;
            var reverseLessThanOrEqualOperator    = v2 <= v1;
            var reverseGreaterThanOperator        = v2 > v1;
            var reverseGreaterThanOrEqualOperator = v2 >= v1;

            // Assert
            Assert.AreEqual(Math.Sign(comparison), Math.Sign(genericCompareTo));
            Assert.AreEqual(Math.Sign(comparison), Math.Sign(nonGenericCompareTo));
            Assert.AreEqual(comparison < 0, lessThanOperator);
            Assert.AreEqual(comparison <= 0, lessThanOrEqualOperator);
            Assert.AreEqual(comparison > 0, greaterThanOperator);
            Assert.AreEqual(comparison >= 0, greaterThanOrEqualOperator);
            Assert.AreEqual(-Math.Sign(comparison), Math.Sign(reverseGenericCompareTo));
            Assert.AreEqual(-Math.Sign(comparison), Math.Sign(reverseNonGenericCompareTo));
            Assert.AreEqual(comparison > 0, reverseLessThanOperator);
            Assert.AreEqual(comparison >= 0, reverseLessThanOrEqualOperator);
            Assert.AreEqual(comparison < 0, reverseGreaterThanOperator);
            Assert.AreEqual(comparison <= 0, reverseGreaterThanOrEqualOperator);
        }
Beispiel #2
0
 /// <summary>
 /// Find the minimum and maximum mod versions and compatible game versions
 /// for a list of modules (presumably different versions of the same mod).
 /// </summary>
 /// <param name="modVersions">The modules to inspect</param>
 /// <param name="minMod">Return parameter for the lowest  mod  version</param>
 /// <param name="maxMod">Return parameter for the highest mod  version</param>
 /// <param name="minKsp">Return parameter for the lowest  game version</param>
 /// <param name="maxKsp">Return parameter for the highest game version</param>
 public static void GetMinMaxVersions(IEnumerable <CkanModule> modVersions,
                                      out ModuleVersion minMod, out ModuleVersion maxMod,
                                      out KspVersion minKsp, out KspVersion maxKsp)
 {
     minMod = maxMod = null;
     minKsp = maxKsp = null;
     foreach (CkanModule rel in modVersions.Where(v => v != null))
     {
         if (minMod == null || minMod > rel.version)
         {
             minMod = rel.version;
         }
         if (maxMod == null || maxMod < rel.version)
         {
             maxMod = rel.version;
         }
         KspVersion relMin = rel.EarliestCompatibleKSP();
         KspVersion relMax = rel.LatestCompatibleKSP();
         if (minKsp == null || !minKsp.IsAny && (minKsp > relMin || relMin.IsAny))
         {
             minKsp = relMin;
         }
         if (maxKsp == null || !maxKsp.IsAny && (maxKsp < relMax || relMax.IsAny))
         {
             maxKsp = relMax;
         }
     }
 }
Beispiel #3
0
        public void GetsInternalAvcCorrectly()
        {
            //Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "DogeCoinFlag";
            json["version"]      = "1.0.0";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";

            var sut = new ModuleService();

            // Act
            var result = sut.GetInternalAvc(CkanModule.FromJson(json.ToString()), TestData.DogeCoinFlagAvcZip());

            // Assert
            Assert.That(result, Is.Not.Null,
                        "ModuleService should get an internal AVC file."
                        );
            Assert.That(result.version, Is.EqualTo(new Version("1.1.0.0")),
                        "ModuleService should get correct version from the internal AVC file."
                        );
            Assert.That(result.ksp_version, Is.EqualTo(KspVersion.Parse("0.24.2")),
                        "ModuleService should get correct ksp_version from the internal AVC file."
                        );
            Assert.That(result.ksp_version_min, Is.EqualTo(KspVersion.Parse("0.24.0")),
                        "ModuleService should get correct ksp_version_min from the internal AVC file."
                        );
            Assert.That(result.ksp_version_max, Is.EqualTo(KspVersion.Parse("0.24.2")),
                        "ModuleService should get correct ksp_version_max from  the internal AVC file."
                        );
        }
Beispiel #4
0
        public void CompareToThrowsOnNullParameters()
        {
            // Act
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            // ReSharper disable UnusedVariable
            TestDelegate actGenericCompareTo                 = () => new KspVersion().CompareTo(null);
            TestDelegate actNonGenericCompareTo              = () => new KspVersion().CompareTo((object)null);
            TestDelegate lessThanOperatorNullLeft            = () => { var _ = null < new KspVersion(); };
            TestDelegate lessThanOperatorNullRight           = () => { var _ = new KspVersion() < null; };
            TestDelegate lessThanOrEqualOperatorNullLeft     = () => { var _ = null <= new KspVersion(); };
            TestDelegate lessThanOrEqualOperatorNullRight    = () => { var _ = new KspVersion() <= null; };
            TestDelegate greaterThanOperatorNullLeft         = () => { var _ = null > new KspVersion(); };
            TestDelegate greaterThanOperatorNullRight        = () => { var _ = new KspVersion() > null; };
            TestDelegate greaterThanOrEqualOperatorNullLeft  = () => { var _ = null >= new KspVersion(); };
            TestDelegate greaterThanOrEqualOperatorNullRight = () => { var _ = new KspVersion() >= null; };

            // ReSharper restore UnusedVariable
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed

            // Assert
            Assert.That(actGenericCompareTo, Throws.Exception);
            Assert.That(actNonGenericCompareTo, Throws.Exception);
            Assert.That(lessThanOperatorNullLeft, Throws.Exception);
            Assert.That(lessThanOperatorNullRight, Throws.Exception);
            Assert.That(lessThanOrEqualOperatorNullLeft, Throws.Exception);
            Assert.That(lessThanOrEqualOperatorNullRight, Throws.Exception);
            Assert.That(greaterThanOperatorNullLeft, Throws.Exception);
            Assert.That(greaterThanOperatorNullRight, Throws.Exception);
            Assert.That(greaterThanOrEqualOperatorNullLeft, Throws.Exception);
            Assert.That(greaterThanOrEqualOperatorNullRight, Throws.Exception);
        }
        public bool TryGetVersion(string directory, out KspVersion result)
        {
            var buildIdPath = Path.Combine(directory, "buildID.txt");

            if (File.Exists(buildIdPath))
            {
                var match = File
                            .ReadAllLines(buildIdPath)
                            .Select(i => BuildIdPattern.Match(i))
                            .FirstOrDefault(i => i.Success);

                if (match != null)
                {
                    var version = _kspBuildMap[match.Groups["buildid"].Value];

                    if (version != null)
                    {
                        result = version;
                        return(true);
                    }
                }
            }

            result = default(KspVersion);
            return(false);
        }
Beispiel #6
0
        public bool Compatible(KspVersion gameVersion, CkanModule module)
        {
            // If it's strictly compatible, then it's compatible.
            if (strict.Compatible(gameVersion, module))
            {
                return(true);
            }

            // If we're in strict mode, and it's not strictly compatible, then it's
            // not compatible.
            if (module.ksp_version_strict)
            {
                return(false);
            }

            // Otherwise, check if it's "generally recognise as safe".

            // If we're running KSP 1.0.4, then allow the mod to run if we would have
            // considered it compatible under 1.0.3 (as 1.0.4 was "just a hotfix").
            if (gameVersion.Equals(KspVersion.Parse("1.0.4")))
            {
                return(strict.Compatible(v103, module));
            }

            return(false);
        }
 private void AddVersionToListButton_Click(object sender, EventArgs e)
 {
     if (AddVersionToListTextBox.Text.Length == 0)
     {
         return;
     }
     if (AddVersionToListTextBox.Text.ToLower() == "any")
     {
         MessageBox.Show(
             Properties.Resources.CompatibleKspVersionsDialogInvalidFormat,
             Properties.Resources.CompatibleKspVersionsDialogErrorTitle,
             MessageBoxButtons.OK,
             MessageBoxIcon.Error
             );
         return;
     }
     try
     {
         var version = KspVersion.Parse(AddVersionToListTextBox.Text);
         SelectedVersionsCheckedListBox.Items.Insert(0, version);
     }
     catch (FormatException)
     {
         MessageBox.Show(
             Properties.Resources.CompatibleKspVersionsDialogInvalidFormat,
             Properties.Resources.CompatibleKspVersionsDialogErrorTitle,
             MessageBoxButtons.OK,
             MessageBoxIcon.Error
             );
     }
 }
Beispiel #8
0
        /// <summary>
        /// Returns true if our mod is compatible with the KSP version specified.
        /// </summary>
        public bool IsCompatibleKSP(KspVersion version)
        {
            log.DebugFormat("Testing if {0} is compatible with KSP {1}", this, version);


            return(_comparator.Compatible(version, this));
        }
Beispiel #9
0
        public CkanModule GeneratorRandomModule(
            KspVersion ksp_version = null,
            List <RelationshipDescriptor> conflicts = null,
            List <RelationshipDescriptor> depends   = null,
            List <RelationshipDescriptor> sugests   = null,
            List <String> provides = null,
            string identifier      = null,
            Version version        = null)
        {
            var mod = new CkanModule
            {
                name         = Generator.Next().ToString(CultureInfo.InvariantCulture),
                @abstract    = Generator.Next().ToString(CultureInfo.InvariantCulture),
                identifier   = identifier ?? Generator.Next().ToString(CultureInfo.InvariantCulture),
                spec_version = new Version(1.ToString(CultureInfo.InvariantCulture)),
                ksp_version  = ksp_version ?? KspVersion.Parse("0." + Generator.Next()),
                version      = version ?? new Version(Generator.Next().ToString(CultureInfo.InvariantCulture))
            };

            mod.ksp_version_max = mod.ksp_version_min = null;
            mod.conflicts       = conflicts;
            mod.depends         = depends;
            mod.suggests        = sugests;
            mod.provides        = provides;
            return(mod);
        }
Beispiel #10
0
        public void FakeInstance_ValidArgumentsWithDLCs_ManagerHasValidInstance()
        {
            string     name      = "testname";
            KspVersion mhVersion = KspVersion.Parse("1.1.0");
            KspVersion bgVersion = KspVersion.Parse("1.0.0");
            string     tempdir   = TestData.NewTempDir();
            KspVersion version   = KspVersion.Parse("1.7.1");

            Dictionary <CKAN.DLC.IDlcDetector, KspVersion> dlcs = new Dictionary <CKAN.DLC.IDlcDetector, KspVersion>()
            {
                { new CKAN.DLC.MakingHistoryDlcDetector(), mhVersion },
                { new CKAN.DLC.BreakingGroundDlcDetector(), bgVersion }
            };

            manager.FakeInstance(name, tempdir, version, dlcs);
            CKAN.KSP newKSP = new CKAN.KSP(tempdir, name, new NullUser());
            CKAN.DLC.MakingHistoryDlcDetector  mhDetector = new CKAN.DLC.MakingHistoryDlcDetector();
            CKAN.DLC.BreakingGroundDlcDetector bgDetector = new CKAN.DLC.BreakingGroundDlcDetector();

            Assert.IsTrue(manager.HasInstance(name));
            Assert.IsTrue(mhDetector.IsInstalled(newKSP, out string _, out UnmanagedModuleVersion detectedMhVersion));
            Assert.IsTrue(bgDetector.IsInstalled(newKSP, out string _, out UnmanagedModuleVersion detectedBgVersion));
            Assert.IsTrue(detectedMhVersion == new UnmanagedModuleVersion(mhVersion.ToString()));
            Assert.IsTrue(detectedBgVersion == new UnmanagedModuleVersion(bgVersion.ToString()));

            // Tidy up.
            CKAN.RegistryManager.Instance(newKSP).ReleaseLock();
            System.IO.Directory.Delete(tempdir, true);
        }
Beispiel #11
0
        public void CompatibleModules_PastAndFutureCompatibility_ReturnsCurrentOnly()
        {
            // Arrange
            CkanModule modFor161 = CkanModule.FromJson(@"{
                ""identifier"":  ""TypicalMod"",
                ""version"":     ""0.9.0"",
                ""download"":    ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
                ""ksp_version"": ""1.6.1""
            }");
            CkanModule modFor173 = CkanModule.FromJson(@"{
                ""identifier"":  ""TypicalMod"",
                ""version"":     ""1.0.0"",
                ""download"":    ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
                ""ksp_version"": ""1.7.3""
            }");
            CkanModule modFor181 = CkanModule.FromJson(@"{
                ""identifier"":  ""TypicalMod"",
                ""version"":     ""1.1.0"",
                ""download"":    ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
                ""ksp_version"": ""1.8.1""
            }");

            registry.AddAvailable(modFor161);
            registry.AddAvailable(modFor173);
            registry.AddAvailable(modFor181);

            // Act
            KspVersionCriteria v173   = new KspVersionCriteria(KspVersion.Parse("1.7.3"));
            List <CkanModule>  compat = registry.CompatibleModules(v173).ToList();

            // Assert
            Assert.IsFalse(compat.Contains(modFor161));
            Assert.IsTrue(compat.Contains(modFor173));
            Assert.IsFalse(compat.Contains(modFor181));
        }
Beispiel #12
0
 public KspVersion Version()
 {
     if (version == null)
     {
         version = DetectVersion(GameDir());
     }
     return(version);
 }
Beispiel #13
0
        public void ToVersionRangeWorksCorrectly(KspVersion version, KspVersionRange expectedRange)
        {
            // Act
            var result = version.ToVersionRange();

            // Assert
            Assert.AreEqual(expectedRange, result);
        }
Beispiel #14
0
        public void ReadJsonWorksCorrectly(string json, KspVersion expected)
        {
            // Act
            var result = JsonConvert.DeserializeObject <TestPoco>(json);

            // Assert
            Assert.That(result.KspVersion, Is.EqualTo(expected));
        }
Beispiel #15
0
        /// <summary>
        /// Initialize the popup
        /// </summary>
        public CompatibleVersionDialog() : base()
        {
            int l = GetLeft(),
                r = GetRight();
            int t = GetTop(),
                b = GetBottom();

            choices = new ConsoleListBox <KspVersion>(
                l + 2, t + 2, r - 2, b - 4,
                options,
                new List <ConsoleListBoxColumn <KspVersion> >()
            {
                new ConsoleListBoxColumn <KspVersion>()
                {
                    Header   = "Predefined Version",
                    Width    = r - l - 5,
                    Renderer = v => v.ToString(),
                    Comparer = (v1, v2) => v1.CompareTo(v2)
                }
            },
                0, 0, ListSortDirection.Descending
                );
            AddObject(choices);
            choices.AddTip("Enter", "Select version");
            choices.AddBinding(Keys.Enter, (object sender) => {
                choice = choices.Selection;
                return(false);
            });

            manualEntry = new ConsoleField(
                l + 2, b - 2, r - 2
                )
            {
                GhostText = () => "<Enter a version>"
            };
            AddObject(manualEntry);
            manualEntry.AddTip("Enter", "Accept value", () => KspVersion.TryParse(manualEntry.Value, out choice));
            manualEntry.AddBinding(Keys.Enter, (object sender) => {
                if (KspVersion.TryParse(manualEntry.Value, out choice))
                {
                    // Good value, done running
                    return(false);
                }
                else
                {
                    // Not valid, so they can't even see the key binding
                    return(true);
                }
            });

            AddTip("Esc", "Cancel");
            AddBinding(Keys.Escape, (object sender) => {
                choice = null;
                return(false);
            });

            CenterHeader = () => "Select Compatible Version";
        }
Beispiel #16
0
        public void MissingPatch_VersionOnlyHasMajorMinor()
        {
            var    converter = new JsonAvcToKspVersion();
            string json      = @"{""MAJOR"":1, ""MINOR"":5}";
            var    reader    = new JsonTextReader(new StringReader(json));
            var    result    = (KspVersion)converter.ReadJson(reader, null, null, null);

            Assert.That(result, Is.EqualTo(KspVersion.Parse("1.5")));
        }
Beispiel #17
0
 /// <summary>
 /// Attempts to convert the module_names to ckan modules via  CkanModule.FromIDandVersion and then calls RelationshipResolver.ctor(IEnumerable{CkanModule}, Registry, KSPVersion)"/>
 /// </summary>
 /// <param name="module_names"></param>
 /// <param name="options"></param>
 /// <param name="registry"></param>
 /// <param name="kspversion"></param>
 public RelationshipResolver(IEnumerable <string> module_names, RelationshipResolverOptions options, IRegistryQuerier registry,
                             KspVersion kspversion) :
     this(module_names.Select(name => CkanModule.FromIDandVersion(registry, name, kspversion)).ToList(),
          options,
          registry,
          kspversion)
 {
     // Does nothing, just calls the other overloaded constructor
 }
Beispiel #18
0
        public void ParseWorksCorrectly(string s, KspVersion version)
        {
            // Act
            var result = KspVersion.Parse(s);

            // Assert
            Assert.AreEqual(version, result);
            Assert.AreEqual(s, result.ToString());
        }
Beispiel #19
0
        public void ParseThrowsExceptionOnInvalidParameter(string s)
        {
            // Act
            // ReSharper disable once ObjectCreationAsStatement
            TestDelegate act = () => KspVersion.Parse(s);

            // Assert
            Assert.That(act, Throws.Exception);
        }
Beispiel #20
0
        public void TryParseReturnsFalseOnInvalidParameter(string s)
        {
            // Act
            KspVersion result;
            var        success = KspVersion.TryParse(s, out result);

            // Assert
            Assert.IsFalse(success);
        }
Beispiel #21
0
 /// <summary>
 /// <see cref = "IRegistryQuerier.LatestAvailableWithProvides" />
 /// </summary>
 public List <CkanModule> LatestAvailableWithProvides(string module, KspVersion ksp_version, RelationshipDescriptor relationship_descriptor = null)
 {
     // This public interface calculates a cache of modules which
     // are compatible with the current version of KSP, and then
     // calls the private version below for heavy lifting.
     return(LatestAvailableWithProvides(module, ksp_version,
                                        available_modules.Values.Select(pair => pair.Latest(ksp_version)).Where(mod => mod != null).ToArray(),
                                        relationship_descriptor));
 }
Beispiel #22
0
        public void UpdateRegistryZip()
        {
            CKAN.Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());

            // Test we've got an expected module.
            CkanModule far = registry.LatestAvailable("FerramAerospaceResearch", KspVersion.Parse("0.25.0"));

            Assert.AreEqual("v0.14.3.2", far.version.ToString());
        }
Beispiel #23
0
        public void TestStrictGameComparator(String modVersion, String gameVersion, bool expectedResult)
        {
            var comparator = new CKAN.StrictGameComparator();

            // We're going to tweak compatibly of the mod
            gameMod.ksp_version = KspVersion.Parse(modVersion);

            // Now test!
            Assert.AreEqual(expectedResult, comparator.Compatible(new KspVersionCriteria(KspVersion.Parse(gameVersion)), gameMod));
        }
Beispiel #24
0
        public KspVersion this[string buildId]
        {
            get
            {
                EnsureBuildMap();

                string version;
                return(_jBuilds.Builds.TryGetValue(buildId, out version) ? KspVersion.Parse(version) : null);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Create a new fake KSP instance
        /// </summary>
        /// <param name="new_name">The name for the new instance.</param>
        /// <param name="new_path">The loaction of the new instance.</param>
        /// <param name="version">The version of the new instance. Should have a build number.</param>
        /// <param name="dlcVersion">The version of the DLC. Null if DLC should be faked.</param>
        public void FakeInstance(string new_name, string new_path, KspVersion version, string dlcVersion = null)
        {
            if (!version.InBuildMap())
            {
                throw new IncorrectKSPVersionKraken(String.Format("The specified KSP version is not a known version: {0}", version.ToString()));
            }
            if (Directory.Exists(new_path) && (Directory.GetFiles(new_path).Length != 0 || Directory.GetDirectories(new_path).Length != 0))
            {
                throw new BadInstallLocationKraken("The specified folder already exists and is not empty.");
            }

            try
            {
                log.DebugFormat("Creating folder structure and text files at {0} for KSP version {1}", Path.GetFullPath(new_path), version.ToString());

                // Create a KSP root directory, containing a GameData folder, a buildID.txt/buildID64.txt and a readme.txt
                Directory.CreateDirectory(new_path);
                Directory.CreateDirectory(Path.Combine(new_path, "GameData"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships", "VAB"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships", "SPH"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships", "@thumbs"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships", "@thumbs", "VAB"));
                Directory.CreateDirectory(Path.Combine(new_path, "Ships", "@thumbs", "SPH"));

                // Don't write the buildID.txts if we have no build, otherwise it would be -1.
                if (version.IsBuildDefined)
                {
                    File.WriteAllText(Path.Combine(new_path, "buildID.txt"), String.Format("build id = {0}", version.Build));
                    File.WriteAllText(Path.Combine(new_path, "buildID64.txt"), String.Format("build id = {0}", version.Build));
                }

                // Create the readme.txt WITHOUT build number.
                File.WriteAllText(Path.Combine(new_path, "readme.txt"), String.Format("Version {0}", new KspVersion(version.Major, version.Minor, version.Patch).ToString()));

                // If a installed DLC should be simulated, we create the needed folder structure and the readme.txt
                if (!String.IsNullOrEmpty(dlcVersion) && version.CompareTo(new KspVersion(1, 4, 0)) >= 0)
                {
                    Directory.CreateDirectory(Path.Combine(new_path, "GameData", "SquadExpansion", "MakingHistory"));
                    File.WriteAllText(
                        Path.Combine(new_path, "GameData", "SquadExpansion", "MakingHistory", "readme.txt"),
                        String.Format("Version {0}", dlcVersion));
                }

                // Add the new instance to the registry
                KSP new_instance = new KSP(new_path, new_name, User);
                AddInstance(new_instance);
            }
            // Thrown by AddInstance() if created instance is not valid.
            // Thrown f.e. if a write operation didn't complete for unknown reasons.
            catch (NotKSPDirKraken kraken)
            {
                throw kraken;
            }
        }
Beispiel #26
0
        /// <summary>
        /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy.
        /// </summary>
        /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param>
        /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param>
        /// <returns></returns>
        public CkanModule Latest(KspVersion ksp_version = null, RelationshipDescriptor relationship = null)
        {
            var        available_versions = new List <Version>(module_version.Keys);
            CkanModule module;

            log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count);
            log.DebugFormat("Choosing between {0} available versions", available_versions.Count);

            // Uh oh, nothing available. Maybe this existed once, but not any longer.
            if (available_versions.Count == 0)
            {
                return(null);
            }

            // No restrictions? Great, we can just pick the first one!
            if (ksp_version == null && relationship == null)
            {
                module = module_version[available_versions.First()];

                log.DebugFormat("No KSP version restriction, {0} is most recent", module);
                return(module);
            }

            // If there's no relationship to satisfy, we can just pick the first that is
            // compatible with our version of KSP.
            if (relationship == null)
            {
                // Time to check if there's anything that we can satisfy.
                var version =
                    available_versions.FirstOrDefault(v => module_version[v].IsCompatibleKSP(ksp_version));
                if (version != null)
                {
                    return(module_version[version]);
                }

                log.DebugFormat("No version of {0} is compatible with KSP {1}",
                                module_version[available_versions[0]].identifier, ksp_version);

                return(null);
            }

            // If we're here, then we have a relationship to satisfy, so things get more complex.
            if (ksp_version == null)
            {
                var version = available_versions.FirstOrDefault(relationship.version_within_bounds);
                return(version == null ? null : module_version[version]);
            }
            else
            {
                var version = available_versions.FirstOrDefault(v =>
                                                                relationship.version_within_bounds(v) &&
                                                                module_version[v].IsCompatibleKSP(ksp_version));
                return(version == null ? null : module_version[version]);
            }
        }
Beispiel #27
0
        public void VersionSpan_FiniteRange_CorrectString()
        {
            // Arrange
            KspVersion min = new KspVersion(1, 0, 0);
            KspVersion max = new KspVersion(1, 1, 1);
            // Act
            string s = KspVersionRange.VersionSpan(min, max);

            // Assert
            Assert.AreEqual("KSP 1.0.0 - 1.1.1", s);
        }
Beispiel #28
0
        public void VersionSpan_MaxOnly_CorrectString()
        {
            // Arrange
            KspVersion min = KspVersion.Any;
            KspVersion max = new KspVersion(1, 0, 0);
            // Act
            string s = KspVersionRange.VersionSpan(min, max);

            // Assert
            Assert.AreEqual("KSP 1.0.0 and earlier", s);
        }
Beispiel #29
0
        public void VersionSpan_OneOnly_CorrectString()
        {
            // Arrange
            KspVersion min = new KspVersion(1, 0, 0);
            KspVersion max = new KspVersion(1, 0, 0);
            // Act
            string s = KspVersionRange.VersionSpan(min, max);

            // Assert
            Assert.AreEqual("KSP 1.0.0", s);
        }
Beispiel #30
0
        public void VersionSpan_AllVersions_CorrectString()
        {
            // Arrange
            KspVersion min = KspVersion.Any;
            KspVersion max = KspVersion.Any;
            // Act
            string s = KspVersionRange.VersionSpan(min, max);

            // Assert
            Assert.AreEqual("KSP all versions", s);
        }