/// <summary>
        /// Creates a new implementation version from a a string.
        /// </summary>
        /// <param name="value">The string containing the version information.</param>
        /// <exception cref="FormatException"><paramref name="value"/> is not a valid version string.</exception>
        public ImplementationVersion(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new FormatException(Resources.MustStartWithDottedList);
            }

            if (ModelUtils.ContainsTemplateVariables(value))
            {
                _verbatimString = value;
                AdditionalParts = new VersionPart[0];
                return;
            }

            var parts = value.Split('-');

            // Ensure the first part is a dotted list
            if (!VersionDottedList.IsValid(parts[0]))
            {
                throw new FormatException(Resources.MustStartWithDottedList);
            }
            FirstPart = new VersionDottedList(parts[0]);

            // Iterate through all additional parts
            var additionalParts = new VersionPart[parts.Length - 1];

            for (int i = 1; i < parts.Length; i++)
            {
                additionalParts[i - 1] = new VersionPart(parts[i]);
            }
            AdditionalParts = additionalParts;
        }
Exemple #2
0
 public void TestContainsTemplateVariables()
 {
     ModelUtils.ContainsTemplateVariables("").Should().BeFalse();
     ModelUtils.ContainsTemplateVariables("x").Should().BeFalse();
     ModelUtils.ContainsTemplateVariables("}{").Should().BeFalse();
     ModelUtils.ContainsTemplateVariables("{}").Should().BeTrue();
     ModelUtils.ContainsTemplateVariables("{var}").Should().BeTrue();
     ModelUtils.ContainsTemplateVariables("x{var}x").Should().BeTrue();
 }
Exemple #3
0
        public void TestGetAbsoluteHref()
        {
            var absoluteHref = WindowsUtils.IsWindows ? new Uri("file:///C:/local/subdir/file") : new Uri("file:///local/subdir/file");

            var result = ModelUtils.GetAbsoluteHref(new Uri("subdir/file", UriKind.Relative), new FeedUri(WindowsUtils.IsWindows ? @"C:\local\feed.xml" : "/local/feed.xml"));

            result.IsAbsoluteUri.Should().BeTrue();
            result.Should().Be(absoluteHref);

            ModelUtils.GetAbsoluteHref(absoluteHref)
            .Should().Be(absoluteHref, because: "Should ignore source if href is already absolute.");
        }
Exemple #4
0
        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.");
        }
Exemple #5
0
 public void TestGetAbsoluteHrefException()
 {
     Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsoluteHref(new Uri("subdir/file", UriKind.Relative)));
     Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsoluteHref(new Uri("subdir/file", UriKind.Relative), new FeedUri("http://remote/")));
 }
Exemple #6
0
 public void TestGetAbsolutePathException()
 {
     Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsolutePath("subdir/file"));
     Assert.Throws <UriFormatException>(() => ModelUtils.GetAbsolutePath("subdir/file", new FeedUri("http://remote/")));
 }