Ejemplo n.º 1
0
        public void TryGetNuGetVersionNoVersionSpecified()
        {
            MockSdkResolverContext context = new MockSdkResolverContext("foo.proj")
            {
                State = new Dictionary <string, string>()
            };

            VerifyTryGetNuGetVersionForSdk(
                version: null,
                expectedVersion: null,
                context: context);
        }
Ejemplo n.º 2
0
        public void EmptyGlobalJson()
        {
            using (TestEnvironment testEnvironment = TestEnvironment.Create())
            {
                TransientTestFolder folder = testEnvironment.CreateFolder();

                File.WriteAllText(Path.Combine(folder.FolderPath, GlobalJsonReader.GlobalJsonFileName), " { } ");

                MockSdkResolverContext context = new MockSdkResolverContext(Path.Combine(folder.FolderPath, "foo.proj"));

                GlobalJsonReader.GetMSBuildSdkVersions(context).ShouldBeNull();
            }
        }
Ejemplo n.º 3
0
        public void TryGetNuGetVersionForSdkInvalidVersionInGlobalJson()
        {
            MockSdkResolverContext context = new MockSdkResolverContext("foo.proj")
            {
                State = new Dictionary <string, string>
                {
                    { "foo", "abc" }
                }
            };

            VerifyTryGetNuGetVersionForSdk(
                version: "abc",
                expectedVersion: null,
                context: context);
        }
Ejemplo n.º 4
0
        public void TryGetNuGetVersionForSdkGetsVersionFromState()
        {
            MockSdkResolverContext context = new MockSdkResolverContext("foo.proj")
            {
                State = new Dictionary <string, string>
                {
                    { "foo", "1.2.3" }
                }
            };

            VerifyTryGetNuGetVersionForSdk(
                version: null,
                expectedVersion: NuGetVersion.Parse("1.2.3"),
                context: context);
        }
Ejemplo n.º 5
0
        public void SdkVersionsAreSuccessfullyLoaded()
        {
            Dictionary <string, string> expectedVersions = new Dictionary <string, string>
            {
                { "foo", "1.0.0" },
                { "bar", "2.0.0" }
            };

            using (TestEnvironment testEnvironment = TestEnvironment.Create())
            {
                TransientTestProjectWithFiles projectWithFiles = testEnvironment.CreateTestProjectWithFiles("", relativePathFromRootToProject: @"a\b\c");

                WriteGlobalJson(projectWithFiles.TestRoot, expectedVersions);

                MockSdkResolverContext context = new MockSdkResolverContext(projectWithFiles.ProjectFile);

                GlobalJsonReader.GetMSBuildSdkVersions(context).ShouldBe(expectedVersions);
            }
        }
Ejemplo n.º 6
0
        public void TryGetNuGetVersionForSdkGetsVersionFromGlobalJson()
        {
            Dictionary <string, string> expectedVersions = new Dictionary <string, string>
            {
                { "foo", "5.11.77" },
                { "bar", "2.0.0" }
            };

            using (TestEnvironment testEnvironment = TestEnvironment.Create())
            {
                TransientTestProjectWithFiles projectWithFiles = testEnvironment.CreateTestProjectWithFiles("", relativePathFromRootToProject: @"a\b\c");

                GlobalJsonReader_Tests.WriteGlobalJson(projectWithFiles.TestRoot, expectedVersions);

                MockSdkResolverContext context = new MockSdkResolverContext(projectWithFiles.ProjectFile);

                VerifyTryGetNuGetVersionForSdk(
                    version: null,
                    expectedVersion: NuGetVersion.Parse(expectedVersions["foo"]),
                    context: context);
            }
        }
Ejemplo n.º 7
0
        private void TryGetNuGetVersionNullVersionShouldNotLoadNuGetAssemblies()
        {
            // Keep a list of assemblies loaded before attempting to parse
            Assembly[] assembliesLoadedBeforeParsingVersion = AppDomain.CurrentDomain.GetAssemblies();

            MockSdkResolverContext context = new MockSdkResolverContext("foo.proj");

            object parsedVersion;

            // Since we pass a null version, we expect no NuGet assemblies to be loaded
            NuGetSdkResolver.TryGetNuGetVersionForSdk(
                id: "foo",
                version: null,
                context: context,
                parsedVersion: out parsedVersion);

            foreach (string newlyLoadedAssembly in AppDomain.CurrentDomain.GetAssemblies()
                     .Except(assembliesLoadedBeforeParsingVersion)
                     .Select(i => i.ManifestModule.Name))
            {
                NuGetSdkResolverBase.NuGetAssemblies.ShouldNotContain(newlyLoadedAssembly);
            }
        }
Ejemplo n.º 8
0
        public void InvalidJsonLogsMessage()
        {
            Dictionary <string, string> expectedVersions = new Dictionary <string, string>
            {
                { "foo", "1.0.0" },
                { "bar", "2.0.0" }
            };

            using (TestEnvironment testEnvironment = TestEnvironment.Create())
            {
                TransientTestProjectWithFiles projectWithFiles = testEnvironment.CreateTestProjectWithFiles("");

                string globalJsonPath = WriteGlobalJson(projectWithFiles.TestRoot, expectedVersions, additionalcontent: ", abc");

                MockSdkResolverContext context = new MockSdkResolverContext(projectWithFiles.ProjectFile);

                GlobalJsonReader.GetMSBuildSdkVersions(context).ShouldBeNull();

                context.MockSdkLogger.LoggedMessages
                .ShouldHaveSingleItem()
                .Key
                .ShouldBe($"Failed to parse \"{globalJsonPath}\". Invalid JavaScript property identifier character: }}. Path \'msbuild-sdks\', line 6, position 5.");
            }
        }