public void NullTargetPlatformIdentifier()
        {
            GetInstalledSDKLocations t = new GetInstalledSDKLocations();

            t.TargetPlatformIdentifier = null;
            t.TargetPlatformVersion    = "1.0";
            t.Execute();
        }
 public void NullTargetPlatformIdentifier()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         GetInstalledSDKLocations t = new GetInstalledSDKLocations();
         t.TargetPlatformIdentifier = null;
         t.TargetPlatformVersion    = "1.0";
         t.Execute();
     }
                                           );
 }
        public void NoSDKsFound()
        {
            MockEngine engine          = new MockEngine();
            GetInstalledSDKLocations t = new GetInstalledSDKLocations();

            t.TargetPlatformIdentifier = "Hello";
            t.TargetPlatformVersion    = "1.0";
            t.BuildEngine = engine;
            bool success = t.Execute();

            Assert.True(success);

            Assert.Equal(1, engine.Warnings);
            engine.AssertLogContains("MSB3785");
        }
        public void EmptyTargetPlatformIdentifier()
        {
            MockEngine engine          = new MockEngine();
            GetInstalledSDKLocations t = new GetInstalledSDKLocations();

            t.TargetPlatformIdentifier = String.Empty;
            t.TargetPlatformVersion    = "1.0";
            t.BuildEngine = engine;
            bool success = t.Execute();

            Assert.False(success);

            Assert.Equal(1, engine.Errors);
            engine.AssertLogContains("MSB3784");
        }
        public void BadTargetPlatformVersion()
        {
            MockEngine engine          = new MockEngine();
            GetInstalledSDKLocations t = new GetInstalledSDKLocations();

            t.TargetPlatformIdentifier = "Hello";
            t.TargetPlatformVersion    = "CAT";
            t.BuildEngine = engine;
            bool success = t.Execute();

            Assert.False(success);


            Assert.Equal(1, engine.Errors);
            engine.AssertLogContains("MSB3786");
        }
        public void GetGoodSDKs()
        {
            try
            {
                Environment.SetEnvironmentVariable("MSBUILDSDKREFERENCEDIRECTORY", s_fakeSDKStructureRoot + ";" + s_fakeSDKStructureRoot2);
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", "true");
                MockEngine engine          = new MockEngine();
                GetInstalledSDKLocations t = new GetInstalledSDKLocations();
                t.TargetPlatformIdentifier = "Windows";
                t.TargetPlatformVersion    = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue).ToString();
                t.SDKRegistryRoot          = "Somewhere";
                t.SDKRegistryRoot          = "Hello;Jello";
                t.BuildEngine = engine;
                bool success = t.Execute();
                Assert.IsTrue(success);

                ITaskItem[] installedSDKs = t.InstalledSDKs;
                Assert.IsTrue(installedSDKs.Length == 6);

                Dictionary <string, string> extensionSDKs = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (ITaskItem item in installedSDKs)
                {
                    extensionSDKs.Add(item.GetMetadata("SDKName"), item.ItemSpec);
                }

                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=1.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=1.0"].Equals(Path.Combine(s_fakeSDKStructureRoot, "Windows\\v1.0\\ExtensionSDKs\\MyAssembly\\1.0\\"), StringComparison.OrdinalIgnoreCase));
                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=2.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=2.0"].Equals(Path.Combine(s_fakeSDKStructureRoot, "Windows\\1.0\\ExtensionSDKs\\MyAssembly\\2.0\\"), StringComparison.OrdinalIgnoreCase));
                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=3.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=3.0"].Equals(Path.Combine(s_fakeSDKStructureRoot, "Windows\\2.0\\ExtensionSDKs\\MyAssembly\\3.0\\"), StringComparison.OrdinalIgnoreCase));

                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=4.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=4.0"].Equals(Path.Combine(s_fakeSDKStructureRoot2, "Windows\\v1.0\\ExtensionSDKs\\MyAssembly\\4.0\\"), StringComparison.OrdinalIgnoreCase));
                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=5.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=5.0"].Equals(Path.Combine(s_fakeSDKStructureRoot2, "Windows\\1.0\\ExtensionSDKs\\MyAssembly\\5.0\\"), StringComparison.OrdinalIgnoreCase));
                Assert.IsTrue(extensionSDKs.ContainsKey("MyAssembly, Version=6.0"));
                Assert.IsTrue(extensionSDKs["MyAssembly, Version=6.0"].Equals(Path.Combine(s_fakeSDKStructureRoot2, "Windows\\2.0\\ExtensionSDKs\\MyAssembly\\6.0\\"), StringComparison.OrdinalIgnoreCase));
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDSDKREFERENCEDIRECTORY", null);
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", null);
            }
        }
        public void GetSDKVersions()
        {
            try
            {
                Environment.SetEnvironmentVariable("MSBUILDSDKREFERENCEDIRECTORY", _fakeSDKStructureRoot + ";" + _fakeSDKStructureRoot2);
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", "true");
                MockEngine engine          = new MockEngine();
                GetInstalledSDKLocations t = new GetInstalledSDKLocations();
                t.TargetPlatformIdentifier = "Windows";
                t.TargetPlatformVersion    = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue).ToString();
                t.SDKRegistryRoot          = "Somewhere";
                t.SDKRegistryRoot          = "Hello;Jello";
                t.BuildEngine = engine;
                bool success = t.Execute();
                Assert.True(success);

                ITaskItem[] installedSDKs = t.InstalledSDKs;
                Assert.Equal(6, installedSDKs.Length);

                Dictionary <string, string> sdksAndVersions = new Dictionary <string, string>();

                foreach (ITaskItem item in installedSDKs)
                {
                    sdksAndVersions.Add(item.GetMetadata("SDKName"), item.GetMetadata("PlatformVersion"));
                }

                Assert.Equal("1.0", sdksAndVersions["MyAssembly, Version=1.0"]);
                Assert.Equal("1.0", sdksAndVersions["MyAssembly, Version=2.0"]);
                Assert.Equal("2.0", sdksAndVersions["MyAssembly, Version=3.0"]);
                Assert.Equal("1.0", sdksAndVersions["MyAssembly, Version=4.0"]);
                Assert.Equal("1.0", sdksAndVersions["MyAssembly, Version=5.0"]);
                Assert.Equal("2.0", sdksAndVersions["MyAssembly, Version=6.0"]);

                Assert.False(sdksAndVersions.ContainsValue("3.0"));
                Assert.False(sdksAndVersions.ContainsValue("4.0"));
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDSDKREFERENCEDIRECTORY", null);
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", null);
            }
        }
        public void GetGoodSDKs2()
        {
            try
            {
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", "true");

                MockEngine engine          = new MockEngine();
                GetInstalledSDKLocations t = new GetInstalledSDKLocations();
                t.TargetPlatformIdentifier = "Windows";
                t.TargetPlatformVersion    = new Version(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue).ToString();
                t.BuildEngine       = engine;
                t.SDKRegistryRoot   = String.Empty;
                t.SDKDirectoryRoots = new string[] { _fakeSDKStructureRoot, _fakeSDKStructureRoot2 };
                bool success = t.Execute();
                Assert.True(success);

                ITaskItem[] installedSDKs = t.InstalledSDKs;
                Assert.Equal(6, installedSDKs.Length);

                Dictionary <string, string> extensionSDKs = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (ITaskItem item in installedSDKs)
                {
                    extensionSDKs.Add(item.GetMetadata("SDKName"), item.ItemSpec);
                }

                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=1.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot, "Windows", "v1.0", "ExtensionSDKs", "MyAssembly", "1.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=1.0"]);
                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=2.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot, "Windows", "1.0", "ExtensionSDKs", "MyAssembly", "2.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=2.0"]);
                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=3.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot, "Windows", "2.0", "ExtensionSDKs", "MyAssembly", "3.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=3.0"]);

                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=4.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot2, "Windows", "v1.0", "ExtensionSDKs", "MyAssembly", "4.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=4.0"]);
                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=5.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot2, "Windows", "1.0", "ExtensionSDKs", "MyAssembly", "5.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=5.0"]);
                Assert.True(extensionSDKs.ContainsKey("MyAssembly, Version=6.0"));
                Assert.Equal(
                    Path.Combine(
                        new[] { _fakeSDKStructureRoot2, "Windows", "2.0", "ExtensionSDKs", "MyAssembly", "6.0" })
                    + Path.DirectorySeparatorChar,
                    extensionSDKs["MyAssembly, Version=6.0"]);
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", null);
            }
        }