コード例 #1
0
        public void Equals_Version(string x, string y, bool expected)
        {
            var versionX = DotNetCoreVersion.Parse(x);
            var versionY = DotNetCoreVersion.Parse(y);

            Assert.AreEqual(expected, versionX.Equals(versionY));
        }
コード例 #2
0
        public void GetVersionId(string version, long expected)
        {
            var dotNetCoreVersion = DotNetCoreVersion.Parse(version);
            var versionId         = DotNetCoreSystemInformation.GenerateVersionId(dotNetCoreVersion);

            Assert.That(versionId, Is.EqualTo(expected));
        }
コード例 #3
0
        public void TryParse_InvalidVersion()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse("INVALID", out version);

            Assert.IsFalse(result);
        }
コード例 #4
0
        public async Task WhenGlobalJsonAndVersionNotMatches(string requestedVersion, string expectedVersion, bool isSupported)
        {
            var resolver = CreateResolver(DotNetCoreRuntime.FileName, mockSdkVersions: true);
            var versionThatDoesNotExists = DotNetCoreVersion.Parse(requestedVersion);
            DotNetCoreVersion versionThatShouldReturn;
            string            expectedResult = string.Empty;

            if (!string.IsNullOrEmpty(expectedVersion))
            {
                versionThatShouldReturn = DotNetCoreVersion.Parse(expectedVersion);
                expectedResult          = Path.Combine(resolver.SdkRootPath, versionThatShouldReturn.OriginalString, "Sdks");
            }

            using (var solution = await GetSolution()) {
                var workingDirectory = Path.GetDirectoryName(solution.FileName);
                var globalJsonPath   = CreateGlobalJson(workingDirectory, versionThatDoesNotExists.OriginalString);

                resolver.GlobalJsonPath = globalJsonPath;
                resolver.ResolveSDK(workingDirectory);

                Assert.That(resolver.IsUnsupportedSdkVersion, Is.EqualTo(!isSupported));
                if (isSupported)
                {
                    Assert.That(resolver.MSBuildSDKsPath, Is.EqualTo(expectedResult));
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Only .NET Core SDKs 2.1/2.2/3.0 are supported.
        /// </summary>
        string GetDotNetCoreSdkTemplatesDirectory(string tag)
        {
            DotNetCoreVersion dotNetCoreSdk = null;

            foreach (var sdk in SupportedSDK)
            {
                if (tag.StartsWith($"DotNetCoreSdk.{sdk}", StringComparison.OrdinalIgnoreCase))
                {
                    dotNetCoreSdk = GetDotNetCoreSdkVersion(DotNetCoreVersion.Parse(sdk));
                    break;
                }
            }

            if (dotNetCoreSdk == null)
            {
                return(null);
            }

            string templatesDirectory = Path.Combine(
                DotNetCoreSdk.SdkRootPath,
                dotNetCoreSdk.OriginalString,
                "Templates"
                );

            if (DirectoryExists(templatesDirectory))
            {
                return(templatesDirectory);
            }

            return(string.Empty);
        }
コード例 #6
0
        public void TryParse_NullVersion()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse(null, out version);

            Assert.IsFalse(result);
        }
コード例 #7
0
        public void TryParse_VersionIsEmptyString()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse(string.Empty, out version);

            Assert.IsFalse(result);
        }
コード例 #8
0
        public void LessThanOrEqualOperator_Version(string x, string y, bool expected)
        {
            var versionX = DotNetCoreVersion.Parse(x);
            var versionY = DotNetCoreVersion.Parse(y);

            Assert.AreEqual(expected, versionX <= versionY);
        }
コード例 #9
0
        /// <summary>
        /// Only .NET Core SDKs 2.1 is supported.
        /// </summary>
        string GetDotNetCoreSdkTemplatesDirectory(string tag)
        {
            DotNetCoreVersion dotNetCoreSdk21 = GetDotNetCoreSdk21Version();

            if (dotNetCoreSdk21 == null)
            {
                return(null);
            }

            if (!tag.StartsWith("DotNetCoreSdk.2.1", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            string templatesDirectory = Path.Combine(
                DotNetCoreSdk.SdkRootPath,
                dotNetCoreSdk21.OriginalString,
                "Templates"
                );

            if (DirectoryExists(templatesDirectory))
            {
                return(templatesDirectory);
            }

            return(string.Empty);
        }
コード例 #10
0
        public void CompareTo_PrereleaseVersions()
        {
            var versionX = DotNetCoreVersion.Parse("1.0.2");
            var versionY = DotNetCoreVersion.Parse("1.0.2-preview1-002912-00");

            Assert.IsTrue(versionX.CompareTo(versionX) == 0);
            Assert.IsTrue(versionY.CompareTo(versionY) == 0);
            Assert.IsTrue(versionX.CompareTo(versionY) > 0);
            Assert.IsTrue(versionY.CompareTo(versionX) < 0);
        }
コード例 #11
0
        public void CompareTo_StableVersion()
        {
            var versionX = DotNetCoreVersion.Parse("1.0.2");
            var versionY = DotNetCoreVersion.Parse("1.2.3");

            Assert.IsTrue(versionX.CompareTo(versionX) == 0);
            Assert.IsTrue(versionY.CompareTo(versionY) == 0);
            Assert.IsTrue(versionX.CompareTo(versionY) < 0);
            Assert.IsTrue(versionY.CompareTo(versionX) > 0);
        }
コード例 #12
0
        public void NetStandard_IsVersionOrHigher(string version, params string [] versionsToCheck)
        {
            var frameworkVersion = DotNetCoreVersion.Parse(version);

            foreach (var v in versionsToCheck)
            {
                var framework = CreateTargetFramework(".NETStandard", v);
                Assert.True(framework.IsNetStandardOrHigher(frameworkVersion));
            }
        }
コード例 #13
0
        public void CheckSupportedSdkVersion(string version, bool isSupported)
        {
            if (!DotNetCoreVersion.TryParse(version, out var dotnetCoreVersion))
            {
                Assert.Inconclusive("Unable to parse {0}", version);
            }

            var result = DotNetCoreVersion.IsSdkSupported(dotnetCoreVersion);

            Assert.True(result == isSupported);
        }
コード例 #14
0
        public void Parse_StableVersion()
        {
            var version = DotNetCoreVersion.Parse("1.2.3");

            Assert.AreEqual(1, version.Major);
            Assert.AreEqual(2, version.Minor);
            Assert.AreEqual(3, version.Patch);
            Assert.AreEqual("1.2.3", version.Version.ToString());
            Assert.IsFalse(version.IsPrerelease);
            Assert.AreEqual("1.2.3", version.OriginalString);
            Assert.AreEqual("1.2.3", version.ToString());
        }
コード例 #15
0
        DotNetCoreVersion GetDotNetCoreSdkVersion(DotNetCoreVersion version)
        {
            //special case 2.1
            if (version.Major == 2 && version.Minor == 1)
            {
                return(DotNetCoreSdk.Versions
                       .FirstOrDefault(v => v.Major == version.Major && v.Minor == version.Minor && v.Patch >= 300));
            }

            return(DotNetCoreSdk.Versions
                   .FirstOrDefault(v => v.Major == version.Major && v.Minor == version.Minor));
        }
コード例 #16
0
        public void Operators_NullVersions()
        {
            DotNetCoreVersion nullVersionX = null;
            DotNetCoreVersion nullVersionY = null;
            var nonNullVersion             = DotNetCoreVersion.Parse("1.0");

            Assert.IsTrue(nullVersionX == nullVersionY);
            Assert.IsTrue(nullVersionX < nonNullVersion);
            Assert.IsFalse(nullVersionX > nonNullVersion);
            Assert.IsFalse(nonNullVersion < nullVersionY);
            Assert.IsTrue(nonNullVersion > nullVersionY);
        }
コード例 #17
0
        public void Parse_PrereleaseVersion()
        {
            var version = DotNetCoreVersion.Parse("2.0.0-preview2-002093-00");

            Assert.AreEqual(2, version.Major);
            Assert.AreEqual(0, version.Minor);
            Assert.AreEqual(0, version.Patch);
            Assert.AreEqual("2.0.0", version.Version.ToString());
            Assert.IsTrue(version.IsPrerelease);
            Assert.AreEqual("2.0.0-preview2-002093-00", version.OriginalString);
            Assert.AreEqual("2.0.0-preview2-002093-00", version.ToString());
        }
コード例 #18
0
        /// <summary>
        /// Only .NET Core SDKs 2.1/2.2/3.0 are supported.
        /// </summary>
        string GetDotNetCoreSdkTemplatesDirectory(string tag)
        {
            DotNetCoreVersion dotNetCoreSdk = null;

            foreach (var sdk in SupportedSDK)
            {
                if (tag.StartsWith($"DotNetCoreSdk.{sdk}", StringComparison.OrdinalIgnoreCase))
                {
                    dotNetCoreSdk = GetDotNetCoreSdkVersion(DotNetCoreVersion.Parse(sdk));
                    break;
                }
            }

            if (dotNetCoreSdk == null)
            {
                return(null);
            }

            string templatesDirectory = Path.Combine(
                DotNetCoreSdk.SdkRootPath,
                dotNetCoreSdk.OriginalString,
                "Templates"
                );

            if (!DirectoryExists(templatesDirectory))
            {
                // .NET Core 3.0 Preview 8 and higher place templates in the root dir
                // and versioned by runtime, not SDK
                var baseTemplatesDir = Path.Combine(Directory.GetParent(DotNetCoreSdk.SdkRootPath).FullName, "templates");
                if (DirectoryExists(baseTemplatesDir))
                {
                    var availableTemplates = new Dictionary <DotNetCoreVersion, string> ();
                    foreach (var dir in EnumerateDirectories(baseTemplatesDir))
                    {
                        if (DotNetCoreVersion.TryParse(Path.GetFileName(dir), out var version))
                        {
                            availableTemplates [version] = dir;
                        }
                    }

                    templatesDirectory = availableTemplates.Keys
                                         .Where(v => v.Major < dotNetCoreSdk.Major || (v.Major == dotNetCoreSdk.Major && v.Minor <= dotNetCoreSdk.Minor))
                                         .OrderByDescending(v => v)
                                         .Select(v => availableTemplates [v])
                                         .FirstOrDefault();
                }
            }

            return(DirectoryExists(templatesDirectory) ? templatesDirectory : string.Empty);
        }
コード例 #19
0
        public async Task WhenGlobalJsonAndVersionNotMatches_AndVersionIs21OrBefore_ThenItReturnsIsNotSupported()
        {
            var resolver = CreateResolver(DotNetCoreRuntime.FileName, mockSdkVersions: true);
            var versionThatDoesNotExists = DotNetCoreVersion.Parse("2.1.503");

            using (var solution = await GetSolution()) {
                var workingDirectory = Path.GetDirectoryName(solution.FileName);
                var globalJsonPath   = CreateGlobalJson(workingDirectory, versionThatDoesNotExists.OriginalString);

                resolver.GlobalJsonPath = globalJsonPath;
                resolver.ResolveSDK(workingDirectory);

                Assert.True(resolver.IsUnsupportedSdkVersion);
            }
        }
コード例 #20
0
        public async Task WhenGlobalJsonAndVersionMatches_ThenItReturnsThatVersion()
        {
            var resolver        = CreateResolver(DotNetCoreRuntime.FileName, mockSdkVersions: true);
            var expectedVersion = DotNetCoreVersion.Parse("2.1.500");
            var expectedResult  = Path.Combine(resolver.SdkRootPath, expectedVersion.OriginalString, "Sdks");

            using (var solution = await GetSolution()) {
                var workingDirectory = Path.GetDirectoryName(solution.FileName);
                var globalJsonPath   = CreateGlobalJson(workingDirectory, expectedVersion.OriginalString);

                resolver.GlobalJsonPath = globalJsonPath;
                resolver.ResolveSDK(workingDirectory);

                Assert.That(resolver.MSBuildSDKsPath, Is.EqualTo(expectedResult));
            }
        }
コード例 #21
0
        public async Task WhenGlobalJsonAndVersionNotMatches_AndVersionIs21OrBefore_ThenItReturnsLatestPatchVersion()
        {
            var resolver = CreateResolver(DotNetCoreRuntime.FileName, mockSdkVersions: true);
            var versionThatDoesNotExists = DotNetCoreVersion.Parse("2.1.310");
            var versionThatShouldReturn  = DotNetCoreVersion.Parse("2.1.399");
            var expectedResult           = Path.Combine(resolver.SdkRootPath, versionThatShouldReturn.OriginalString, "Sdks");

            using (var solution = await GetSolution()) {
                var workingDirectory = Path.GetDirectoryName(solution.FileName);
                var globalJsonPath   = CreateGlobalJson(workingDirectory, versionThatDoesNotExists.OriginalString);

                resolver.GlobalJsonPath = globalJsonPath;
                resolver.ResolveSDK(workingDirectory);

                Assert.That(resolver.MSBuildSDKsPath, Is.EqualTo(expectedResult));
            }
        }
コード例 #22
0
        [TestCase(".NETCoreApp", "2.1", new [] { "2.1.400" }, false, true)]                 // v2.1.400 will support .NET Core  2.1
        public void IsSupportedTargetFramework(
            string frameworkIdentifier,
            string frameworkVersion,
            string[] installedSdkVersions,
            bool msbuildSdksInstalled,             // True if Mono has the .NET Core sdks.
            bool expected)
        {
            string framework = $"{frameworkIdentifier},Version=v{frameworkVersion}";
            var    targetFrameworkMoniker = TargetFrameworkMoniker.Parse(framework);
            var    versions = installedSdkVersions.Select(version => DotNetCoreVersion.Parse(version))
                              .OrderByDescending(version => version)
                              .ToArray();

            bool actual = DotNetCoreSdk.IsSupported(targetFrameworkMoniker, versions, msbuildSdksInstalled);

            Assert.AreEqual(expected, actual);
        }
コード例 #23
0
        public async Task WhenGlobalJsonIsInParentWorkDirAndVersionMatches_ThenItReturnsThatVersion()
        {
            var resolver        = CreateResolver(DotNetCoreRuntime.FileName, mockSdkVersions: true);
            var expectedVersion = DotNetCoreVersion.Parse("2.1.500");
            var expectedResult  = Path.Combine(resolver.SdkRootPath, expectedVersion.OriginalString, "Sdks");

            using (var solution = await GetSolution()) {
                var workingDirectory       = Path.GetDirectoryName(solution.FileName);
                var workingParentDirectory = new DirectoryInfo(workingDirectory).Parent;
                var globalJsonPath         = CreateGlobalJson(workingParentDirectory.FullName, expectedVersion.OriginalString);

                //in this test we force ResolveSDK to look up global.json in parent's directories
                resolver.ResolveSDK(workingDirectory, forceLookUpGlobalJson: true);

                Assert.That(globalJsonPath, Is.EqualTo(resolver.GlobalJsonPath));
                Assert.That(resolver.MSBuildSDKsPath, Is.EqualTo(expectedResult));
            }
        }
コード例 #24
0
        public void SortingPrereleaseVersions()
        {
            var version100           = DotNetCoreVersion.Parse("1.0.0");
            var version102           = DotNetCoreVersion.Parse("1.0.2");
            var version102preview1_1 = DotNetCoreVersion.Parse("1.0.2-preview1-002912-00");
            var version102preview1_2 = DotNetCoreVersion.Parse("1.0.2-preview1-003912-00");
            var version102preview2_1 = DotNetCoreVersion.Parse("1.0.2-preview2-001112-00");
            var version200preview2_1 = DotNetCoreVersion.Parse("2.0.0-preview2-002093-00");
            var version200preview2_2 = DotNetCoreVersion.Parse("2.0.0-preview2-002094-00");
            var version200           = DotNetCoreVersion.Parse("2.0.0");
            var version201           = DotNetCoreVersion.Parse("2.0.1");

            var expected = new [] {
                version100,
                version102preview1_1,
                version102preview1_2,
                version102preview2_1,
                version102,
                version200preview2_2,
                version200,
                version201
            };

            var unsorted = new [] {
                version200,
                version102,
                version102preview1_2,
                version201,
                version102preview2_1,
                version100,
                version102preview1_1,
                version200preview2_2,
            };

            var sorted = unsorted.OrderBy(v => v).ToArray();

            Assert.AreEqual(expected, sorted);
        }
コード例 #25
0
 /// <summary>
 /// This checks for .NET Core SDK 2.1 to be installed. Note that the
 /// .NET Core SDK versions is confusing. Here we want the .NET Core 2.1
 /// SDK that supports .NET Core App 2.1. Not the .NET Core 2.1 SDK that
 /// supports .NET Core App 2.0 only.
 /// </summary>
 static bool IsNetCoreSdk21(DotNetCoreVersion version)
 {
     return(version.Major == 2 && version.Minor == 1 && version.Patch >= 300);
 }
コード例 #26
0
 /// <summary>
 /// This checks for .NET Core SDK 2.1 or higher to be installed. Note that the
 /// .NET Core SDK versions is confusing. Here we want at least the .NET Core 2.1
 /// SDK that supports .NET Core App 2.1. Not the .NET Core 2.1 SDK that
 /// supports .NET Core App 2.0 only.
 /// </summary>
 static bool IsNetCoreSdk21OrHigher(DotNetCoreVersion version) => version >= MinimumCoreSDK;
コード例 #27
0
        /// <summary>
        /// Set default parameter values if no wizard will be displayed.
        /// </summary>
        void ConfigureDefaultParameters()
        {
            if (IsSupportedParameter("NetStandard"))
            {
                var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetStandardTargetFrameworks().FirstOrDefault();

                var parameter = highestFramework.GetParameterName();
                if (!string.IsNullOrEmpty(parameter))
                {
                    Parameters [parameter] = "true";
                }
            }
            else
            {
                if (!SupportsNetCore1x())
                {
                    var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworks().FirstOrDefault();
                    if (highestFramework != null && highestFramework.IsNetCoreAppOrHigher(DotNetCoreVersion.Parse("2.0")))
                    {
                        var parameter = highestFramework.GetParameterName();
                        if (!string.IsNullOrEmpty(parameter))
                        {
                            Parameters [parameter] = "true";
                        }
                    }
                    else
                    {
                        Parameters [defaultParameterNetCore20] = "true";
                    }
                }
                else
                {
                    var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworks().FirstOrDefault();
                    if (highestFramework != null)
                    {
                        var parameter = highestFramework.GetParameterName();
                        if (!string.IsNullOrEmpty(parameter))
                        {
                            Parameters [parameter] = "true";
                        }
                    }
                    else
                    {
                        Parameters [defaultParameterNetCore1x] = "true";
                    }
                }
                ConfigureDefaultNetCoreAppFramework();
            }
        }
コード例 #28
0
 public void Parse_InvalidVersion()
 {
     Assert.Throws <FormatException> (() => {
         DotNetCoreVersion.Parse("invalid");
     });
 }
コード例 #29
0
 public void Parse_NullVersion()
 {
     Assert.Throws <ArgumentException> (() => {
         DotNetCoreVersion.Parse(null);
     });
 }
コード例 #30
0
 public void Parse_VersionIsEmptyString()
 {
     Assert.Throws <ArgumentException> (() => {
         DotNetCoreVersion.Parse(null);
     });
 }