public void TestCreateResult() { const string resultProjectId = "result-project-id"; AspNetVersion resultVersion = AspNetVersion.AspNetCore11; const FrameworkType resultFrameworkType = FrameworkType.NetCore; _targetSdkVersions.Add("2.0.0"); _targetSdkVersions.Add("1.0.0"); var objectUnderTest = new AspNetCoreTemplateChooserViewModel(_closeWindowMock.Object) { SelectedFramework = resultFrameworkType, SelectedVersion = resultVersion, GcpProjectId = resultProjectId, IsWebApi = true }; objectUnderTest.OkCommand.Execute(null); Assert.IsNotNull(objectUnderTest.Result); Assert.AreEqual(resultProjectId, objectUnderTest.Result.GcpProjectId); Assert.AreEqual(resultFrameworkType, objectUnderTest.Result.SelectedFramework); Assert.AreEqual(resultVersion, objectUnderTest.Result.SelectedVersion); Assert.AreEqual(AppType.WebApi, objectUnderTest.Result.AppType); }
public void TestGetAvailableAspNetCoreVersions_ForVS2017NetCore20() { PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2017Version); _toolsPathProviderMock.Setup(p => p.GetNetCoreSdkVersions()).Returns(new[] { "2.0.35" }); IList <AspNetVersion> results = AspNetVersion.GetAvailableAspNetCoreVersions(FrameworkType.NetCore); CollectionAssert.AreEqual(new[] { AspNetVersion.AspNetCore20 }, results.ToList()); }
/// <summary> /// Updates site /// </summary> /// <param name="siteId"></param> /// <param name="contentPath"></param> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="host"></param> /// <param name="aspNet">ASP.NET version</param> internal static void UpdateSite(string siteId, string contentPath, string ip, string port, string host, AspNetVersion aspNet) { ManagementObject objSite = wmi.GetObject(String.Format("IIsWebServerSetting='{0}'", siteId)); ManagementObject objVirtDir = wmi.GetObject( String.Format("IIsWebVirtualDirSetting='{0}'", GetVirtualDirectoryPath(siteId, ""))); // check if we need to add a server binding string existSiteId = GetSiteIdByBinding(ip, port, host); if (existSiteId == null) { // binding doesn't exist // add the binding to the web site ManagementBaseObject[] objProbBindings = (ManagementBaseObject[])objSite.Properties["ServerBindings"].Value; ManagementClass clsBinding = wmi.GetClass("ServerBinding"); ManagementObject[] newBindings = new ManagementObject[objProbBindings.Length + 1]; // copy existing bindings for (int i = 0; i < objProbBindings.Length; i++) { newBindings[i] = clsBinding.CreateInstance(); newBindings[i]["Hostname"] = (string)objProbBindings[i].Properties["Hostname"].Value; newBindings[i]["IP"] = (string)objProbBindings[i].Properties["IP"].Value; newBindings[i]["Port"] = (string)objProbBindings[i].Properties["Port"].Value; } //create new binding newBindings[objProbBindings.Length] = clsBinding.CreateInstance(); newBindings[objProbBindings.Length]["Hostname"] = host; newBindings[objProbBindings.Length]["IP"] = ip; newBindings[objProbBindings.Length]["Port"] = port; objSite.Properties["ServerBindings"].Value = newBindings; } objSite.Put(); // set path if (!String.IsNullOrEmpty(contentPath)) { // set content path objVirtDir.Properties["Path"].Value = contentPath; // set correct default documents SetVirtualDirectoryDefaultDocs(objVirtDir); } // set ASP.NET SetVirtualDirectoryAspNetMappings(objVirtDir, aspNet); // save object objVirtDir.Put(); }
public void TestGetAvailableAspNetCoreVersions_ForVS2017NetCoreAll() { PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2017Version); _toolsPathProviderMock.Setup(p => p.GetNetCoreSdkVersions()).Returns( new[] { AspNetVersion.s_firstSdkVersionWith11Runtime.ToString(), AspNetVersion.s_firstSdkVersionWith21Runtime.ToString() }); IList <AspNetVersion> results = AspNetVersion.GetAvailableAspNetCoreVersions(FrameworkType.NetCore); CollectionAssert.AreEqual( new[] { AspNetVersion.AspNetCore10, AspNetVersion.AspNetCore11, AspNetVersion.AspNetCore20, AspNetVersion.AspNetCore21 }, results.ToList()); }
private static void SetVirtualDirectoryAspNetMappings(ManagementBaseObject obj, AspNetVersion aspNet) { if (aspNet != AspNetVersion.Unknown) { // configure ASP.NET // remove existing mappings List<string> aspNetMaps = new List<string>(); aspNetMaps.AddRange(aspNet20Maps); List<ManagementBaseObject> scriptMaps = new List<ManagementBaseObject>(); ManagementBaseObject[] objScriptMaps = ((ManagementBaseObject[])obj.Properties["ScriptMaps"].Value); // get/filter existing maps foreach (ManagementBaseObject objScriptMap in objScriptMaps) { string ext = (string)objScriptMap.Properties["Extensions"].Value; if (!aspNetMaps.Contains(ext)) scriptMaps.Add(objScriptMap); } // add script maps string[] aspNetExtensions = aspNet11Maps; string aspNetVersionName = AspNet11; if (aspNet == AspNetVersion.AspNet20) { aspNetExtensions = aspNet20Maps; aspNetVersionName = AspNet20; } // add required script maps RegistryKey netFramework = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\.NetFramework", false); string installRoot = netFramework.GetValue("InstallRoot").ToString(); string processorPath = Path.Combine(installRoot, aspNetVersionName + "\\aspnet_isapi.dll"); // correct mappings for IIS 32-bit mode if (Utils.IsWin64() && Utils.IIS32Enabled()) processorPath = processorPath.Replace("Framework64", "Framework"); foreach (string extension in aspNetExtensions) { ManagementClass clsScriptMap = wmi.GetClass("ScriptMap"); ManagementObject objScriptMap = clsScriptMap.CreateInstance(); objScriptMap.Properties["Extensions"].Value = extension; int flags = 5; if (extension == ".soap" || extension == ".rem" || extension == ".vsdisco" || extension == ".axd" || extension == ".aspx" || extension == ".asmx" || extension == ".ashx") flags = 1; objScriptMap.Properties["Flags"].Value = flags; objScriptMap.Properties["IncludedVerbs"].Value = "GET,HEAD,POST,DEBUG"; objScriptMap.Properties["ScriptProcessor"].Value = processorPath; objScriptMap.Put(); scriptMaps.Add(objScriptMap); } // set script maps obj.Properties["ScriptMaps"].Value = scriptMaps.ToArray(); } }
/// <summary> /// Updates site /// </summary> /// <param name="siteId"></param> /// <param name="contentPath"></param> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="host"></param> /// <param name="aspNet">ASP.NET version</param> internal static void UpdateSite(string siteId, string contentPath, string ip, string port, string host, AspNetVersion aspNet) { ManagementObject objSite = wmi.GetObject(String.Format("IIsWebServerSetting='{0}'", siteId)); ManagementObject objVirtDir = wmi.GetObject( String.Format("IIsWebVirtualDirSetting='{0}'", GetVirtualDirectoryPath(siteId, ""))); // check if we need to add a server binding string existSiteId = GetSiteIdByBinding(ip, port, host); if(existSiteId == null) { // binding doesn't exist // add the binding to the web site ManagementBaseObject[] objProbBindings = (ManagementBaseObject[])objSite.Properties["ServerBindings"].Value; ManagementClass clsBinding = wmi.GetClass("ServerBinding"); ManagementObject[] newBindings = new ManagementObject[objProbBindings.Length+1]; // copy existing bindings for(int i = 0; i < objProbBindings.Length; i++) { newBindings[i] = clsBinding.CreateInstance(); newBindings[i]["Hostname"] = (string)objProbBindings[i].Properties["Hostname"].Value; newBindings[i]["IP"] = (string)objProbBindings[i].Properties["IP"].Value; newBindings[i]["Port"] = (string)objProbBindings[i].Properties["Port"].Value; } //create new binding newBindings[objProbBindings.Length] = clsBinding.CreateInstance(); newBindings[objProbBindings.Length]["Hostname"] = host; newBindings[objProbBindings.Length]["IP"] = ip; newBindings[objProbBindings.Length]["Port"] = port; objSite.Properties["ServerBindings"].Value = newBindings; } objSite.Put(); // set path if (!String.IsNullOrEmpty(contentPath)) { // set content path objVirtDir.Properties["Path"].Value = contentPath; // set correct default documents SetVirtualDirectoryDefaultDocs(objVirtDir); } // set ASP.NET SetVirtualDirectoryAspNetMappings(objVirtDir, aspNet); // save object objVirtDir.Put(); }
private static void SetVirtualDirectoryAspNetMappings(ManagementBaseObject obj, AspNetVersion aspNet) { if (aspNet != AspNetVersion.Unknown) { // configure ASP.NET // remove existing mappings List <string> aspNetMaps = new List <string>(); aspNetMaps.AddRange(aspNet20Maps); List <ManagementBaseObject> scriptMaps = new List <ManagementBaseObject>(); ManagementBaseObject[] objScriptMaps = ((ManagementBaseObject[])obj.Properties["ScriptMaps"].Value); // get/filter existing maps foreach (ManagementBaseObject objScriptMap in objScriptMaps) { string ext = (string)objScriptMap.Properties["Extensions"].Value; if (!aspNetMaps.Contains(ext)) { scriptMaps.Add(objScriptMap); } } // add script maps string[] aspNetExtensions = aspNet11Maps; string aspNetVersionName = AspNet11; if (aspNet == AspNetVersion.AspNet20) { aspNetExtensions = aspNet20Maps; aspNetVersionName = AspNet20; } // add required script maps RegistryKey netFramework = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\.NetFramework", false); string installRoot = netFramework.GetValue("InstallRoot").ToString(); string processorPath = Path.Combine(installRoot, aspNetVersionName + "\\aspnet_isapi.dll"); // correct mappings for IIS 32-bit mode if (Utils.IsWin64() && Utils.IIS32Enabled()) { processorPath = processorPath.Replace("Framework64", "Framework"); } foreach (string extension in aspNetExtensions) { ManagementClass clsScriptMap = wmi.GetClass("ScriptMap"); ManagementObject objScriptMap = clsScriptMap.CreateInstance(); objScriptMap.Properties["Extensions"].Value = extension; int flags = 5; if (extension == ".soap" || extension == ".rem" || extension == ".vsdisco" || extension == ".axd" || extension == ".aspx" || extension == ".asmx" || extension == ".ashx") { flags = 1; } objScriptMap.Properties["Flags"].Value = flags; objScriptMap.Properties["IncludedVerbs"].Value = "GET,HEAD,POST,DEBUG"; objScriptMap.Properties["ScriptProcessor"].Value = processorPath; objScriptMap.Put(); scriptMaps.Add(objScriptMap); } // set script maps obj.Properties["ScriptMaps"].Value = scriptMaps.ToArray(); } }