Beispiel #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));
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public void GetVersionId(string version, long expected)
        {
            var dotNetCoreVersion = DotNetCoreVersion.Parse(version);
            var versionId         = DotNetCoreSystemInformation.GenerateVersionId(dotNetCoreVersion);

            Assert.That(versionId, Is.EqualTo(expected));
        }
Beispiel #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));
                }
            }
        }
Beispiel #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);
        }
Beispiel #6
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));
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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());
        }
Beispiel #11
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());
        }
Beispiel #12
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);
        }
Beispiel #13
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);
            }
        }
Beispiel #14
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));
            }
        }
Beispiel #15
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));
            }
        }
        [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);
        }
Beispiel #17
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));
            }
        }
Beispiel #18
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);
        }
Beispiel #19
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();
            }
        }
Beispiel #20
0
 public void Parse_VersionIsEmptyString()
 {
     Assert.Throws <ArgumentException> (() => {
         DotNetCoreVersion.Parse(null);
     });
 }
Beispiel #21
0
 public void Parse_NullVersion()
 {
     Assert.Throws <ArgumentException> (() => {
         DotNetCoreVersion.Parse(null);
     });
 }
Beispiel #22
0
 public void Parse_InvalidVersion()
 {
     Assert.Throws <FormatException> (() => {
         DotNetCoreVersion.Parse("invalid");
     });
 }
Beispiel #23
0
        public void ParseRevisionNumber(string version, long expected)
        {
            var dotNetCoreVersion = DotNetCoreVersion.Parse(version);

            Assert.That(dotNetCoreVersion.Revision, Is.EqualTo(expected));
        }
Beispiel #24
0
 /// <summary>
 /// Some templates (Blazor, Worker) are only available on 3.0.
 /// </summary>
 /// <param name="targetFrameworks"></param>
 static void RemoveUnsupportedNetCoreApp2xTargetFrameworks(List <TargetFramework> targetFrameworks)
 {
     targetFrameworks.RemoveAll(framework => !framework.IsNetCoreAppOrHigher(DotNetCoreVersion.Parse("3.0")));
 }
Beispiel #25
0
        public void Equals_NullVersion()
        {
            var x = DotNetCoreVersion.Parse("1.0");

            Assert.IsFalse(x.Equals(null));
        }