public void TestGeneralFrameworkMonikerGood()
 {
     string targetFrameworkMoniker = ".NetFramework, Version=v4.5";
     MockEngine engine = new MockEngine();
     GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
     getReferencePaths.BuildEngine = engine;
     getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
     getReferencePaths.Execute();
     string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
     Assert.Equal(ToolLocationHelper.GetPathToReferenceAssemblies(new FrameworkNameVersioning(targetFrameworkMoniker)).Count, returnedPaths.Length);
     Assert.Equal(0, engine.Errors); // "Expected the log to contain no errors"
 }
        public void TestGeneralFrameworkMonikerGoodWithRoot()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithRoot");
            string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\");
            string redistListDirectory = Path.Combine(framework41Directory, "RedistList");
            string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml");
            try
            {
                Directory.CreateDirectory(framework41Directory);
                Directory.CreateDirectory(redistListDirectory);

                string redistListContents =
                        "<FileList Redist='Microsoft-Windows-CLRCoreComp' Name='.NET Framework 4.1'>" +
                            "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
                             "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
                        "</FileList >";

                File.WriteAllText(redistListFile, redistListContents);

                string targetFrameworkMoniker = "MyFramework, Version=v4.1";
                MockEngine engine = new MockEngine();
                GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
                getReferencePaths.BuildEngine = engine;
                getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
                getReferencePaths.RootPath = tempDirectory;
                getReferencePaths.Execute();
                string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
                string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
                Assert.Equal(1, returnedPaths.Length);
                Assert.True(returnedPaths[0].Equals(framework41Directory, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(0, engine.Log.Length); // "Expected the log to contain nothing"
                Assert.True(displayName.Equals(".NET Framework 4.1", StringComparison.OrdinalIgnoreCase));
            }
            finally
            {
                if (Directory.Exists(framework41Directory))
                {
                    Directory.Delete(framework41Directory, true);
                }
            }
        }
        public void TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath");
            string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\");
            string redistListDirectory = Path.Combine(framework41Directory, "RedistList");
            string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml");
            try
            {
                Directory.CreateDirectory(framework41Directory);
                Directory.CreateDirectory(redistListDirectory);

                string redistListContents =
                        "<FileList Redist='Microsoft-Windows-CLRCoreComp' IncludeFramework='v4.*' Name='Chained oh noes'>" +
                            "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
                             "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
                        "</FileList >";

                File.WriteAllText(redistListFile, redistListContents);

                string targetFrameworkMoniker = "MyFramework, Version=v4.1";
                MockEngine engine = new MockEngine();
                GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
                getReferencePaths.BuildEngine = engine;
                getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
                getReferencePaths.RootPath = tempDirectory;
                getReferencePaths.Execute();
                string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
                Assert.Equal(0, returnedPaths.Length);
                string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
                Assert.Null(displayName);
                FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
                engine.AssertLogContains("MSB3643");
            }
            finally
            {
                if (Directory.Exists(framework41Directory))
                {
                    Directory.Delete(framework41Directory, true);
                }
            }
        }
 public void TestGeneralFrameworkMonikerNonExistent()
 {
     MockEngine engine = new MockEngine();
     GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
     getReferencePaths.BuildEngine = engine;
     // Make a framework which does not exist, intentional mispelling of framework
     getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0";
     getReferencePaths.Execute();
     string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
     Assert.Equal(0, returnedPaths.Length);
     string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
     Assert.Null(displayName);
     FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
     string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString());
     engine.AssertLogContains(message);
 }
 public void TestGeneralFrameworkMonikerNull()
 {
     MockEngine engine = new MockEngine();
     GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
     getReferencePaths.BuildEngine = engine;
     getReferencePaths.TargetFrameworkMoniker = null;
     getReferencePaths.Execute();
     string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
     Assert.Null(getReferencePaths.TargetFrameworkMonikerDisplayName);
     Assert.Equal(0, returnedPaths.Length);
     Assert.Equal(1, engine.Errors);
 }
 public void TestGeneralFrameworkMonikerNonExistentOverrideError()
 {
     MockEngine engine = new MockEngine();
     GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
     getReferencePaths.BuildEngine = engine;
     // Make a framework which does not exist, intentional misspelling of framework
     getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0";
     
     try
     {
         Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", "1");
         bool success = getReferencePaths.Execute();
         Assert.True(success);
     }
     finally
     {
         Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", null);
     }
     
     string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
     Assert.Equal(0, returnedPaths.Length);
     string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
     Assert.Null(displayName);
     FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
     string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString());
     engine.AssertLogContains("WARNING MSB3644: " + message);
 }