//--------------------// #region Normalize /// <summary> /// Sets missing default values and handles legacy elements. /// </summary> /// <param name="feedUri">The feed the data was originally loaded from; can be <see langword="null"/>.</param> /// <remarks>This method should be called to prepare a <see cref="Feed"/> for solver processing. Do not call it if you plan on serializing the feed again since it may loose some of its structure.</remarks> public override void Normalize(FeedUri feedUri = null) { base.Normalize(feedUri); // Merge the version modifier into the normal version attribute if (!string.IsNullOrEmpty(VersionModifier)) { Version = new ImplementationVersion(Version + VersionModifier); VersionModifier = null; } // Default stability rating to testing if (Stability == Stability.Unset) { Stability = Stability.Testing; } // Make local paths absolute if (!string.IsNullOrEmpty(LocalPath)) { LocalPath = ModelUtils.GetAbsolutePath(LocalPath, feedUri); } else if (!string.IsNullOrEmpty(ID) && ID.StartsWith(".")) // Get local path from ID { LocalPath = ID = ModelUtils.GetAbsolutePath(ID, feedUri); } // Parse manifest digest from ID if missing if (!string.IsNullOrEmpty(ID)) { _manifestDigest.ParseID(ID); } }
public void TestGetAbsolutePath() { string absolutePath = WindowsUtils.IsWindows ? @"C:\local\subdir\file" : "/local/subdir/file"; string result = ModelUtils.GetAbsolutePath("subdir/file", new FeedUri(WindowsUtils.IsWindows ? @"C:\local\" : "/local/")); Assert.IsTrue(Path.IsPathRooted(result)); Assert.AreEqual(absolutePath, result); Assert.AreEqual(absolutePath, ModelUtils.GetAbsolutePath(absolutePath), "Should ignore source if path is already absolute."); }
public void TestGetAbsolutePath() { string absolutePath = WindowsUtils.IsWindows ? @"C:\local\subdir\file" : "/local/subdir/file"; string result = ModelUtils.GetAbsolutePath("subdir/file", new FeedUri(WindowsUtils.IsWindows ? @"C:\local\" : "/local/")); Path.IsPathRooted(result).Should().BeTrue(); result.Should().Be(absolutePath); ModelUtils.GetAbsolutePath(absolutePath) .Should().Be(absolutePath, because: "Should ignore source if path is already absolute."); }
/// <summary> /// Sets missing default values and handles legacy elements. /// </summary> /// <param name="feedUri">The feed the data was originally loaded from.</param> /// <remarks>This method should be called to prepare a <see cref="Feed"/> for solver processing. Do not call it if you plan on serializing the feed again since it may loose some of its structure.</remarks> public override void Normalize(FeedUri feedUri) { #region Sanity checks if (feedUri == null) { throw new ArgumentNullException(nameof(feedUri)); } #endregion base.Normalize(feedUri); // Merge the version modifier into the normal version attribute if (!string.IsNullOrEmpty(VersionModifier)) { Version = new ImplementationVersion(Version + VersionModifier); VersionModifier = null; } // Default stability rating to testing if (Stability == Stability.Unset) { Stability = Stability.Testing; } // Make local paths absolute try { if (!string.IsNullOrEmpty(LocalPath)) { LocalPath = ModelUtils.GetAbsolutePath(LocalPath, feedUri); } else if (!string.IsNullOrEmpty(ID) && ID.StartsWith(".")) // Get local path from ID { LocalPath = ID = ModelUtils.GetAbsolutePath(ID, feedUri); } } #region Error handling catch (UriFormatException ex) { Log.Error(ex); LocalPath = null; } #endregion // Parse manifest digest from ID if missing if (!string.IsNullOrEmpty(ID)) { _manifestDigest.ParseID(ID); } }
public void TestGetAbsolutePathException() { Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsolutePath("subdir/file")); Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsolutePath("subdir/file", new FeedUri("http://remote/"))); }