From 0706a5b14481e2ec145d2ac4ef87a981f9d5eee8 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 30 Oct 2023 14:27:50 +0000 Subject: [PATCH] fix(umbraco): change made to keep checking through files found alongside umbraco folder this is because we may have had a web.config file found (that is not for umbraco) before a *.csproj file is later found that does include umbraco installed --- src/segments/umbraco.go | 16 +- src/segments/umbraco_test.go | 61 +- src/test/umbraco/ANonUmbracoProject.csproj | 861 +++++++++++++++++++++ 3 files changed, 927 insertions(+), 11 deletions(-) create mode 100644 src/test/umbraco/ANonUmbracoProject.csproj diff --git a/src/segments/umbraco.go b/src/segments/umbraco.go index 2abcd0dc..73189578 100644 --- a/src/segments/umbraco.go +++ b/src/segments/umbraco.go @@ -59,11 +59,23 @@ func (u *Umbraco) Enabled() bool { } if strings.EqualFold(file.Name(), "web.config") { - return u.TryFindLegacyUmbraco(filepath.Join(location, file.Name())) + if u.TryFindLegacyUmbraco(filepath.Join(location, file.Name())) { + return true + } + + // We may have found a web.config first before a *.csproj file + // So we need to keep checking to see if modern Umbraco is installed if we come across a *.csproj file + continue } if strings.EqualFold(filepath.Ext(file.Name()), ".csproj") { - return u.TryFindModernUmbraco(filepath.Join(location, file.Name())) + if u.TryFindModernUmbraco(filepath.Join(location, file.Name())) { + return true + } + + // We may have found a *.csproj first before a web.config file + // So we need to keep checking if legacy Umbraco is installed (as the *.csproj could be for a non-Umbraco project) + continue } } diff --git a/src/segments/umbraco_test.go b/src/segments/umbraco_test.go index bdbc3356..edc8b2c2 100644 --- a/src/segments/umbraco_test.go +++ b/src/segments/umbraco_test.go @@ -16,14 +16,15 @@ import ( func TestUmbracoSegment(t *testing.T) { cases := []struct { - Case string - ExpectedEnabled bool - ExpectedString string - Template string - HasUmbracoFolder bool - HasCsproj bool - HasWebConfig bool - UseLegacyWebConfig bool + Case string + ExpectedEnabled bool + ExpectedString string + Template string + HasUmbracoFolder bool + HasCsproj bool + HasWebConfig bool + UseLegacyWebConfig bool + HasCSProjWithoutUmbraco bool }{ { Case: "No Umbraco folder found", @@ -65,6 +66,36 @@ func TestUmbracoSegment(t *testing.T) { Template: "{{ .Version }}", ExpectedString: "12.1.2", }, + { + Case: "Umbraco Folder with a .csproj [without Umbraco] and a web.config", + HasUmbracoFolder: true, + HasCsproj: false, + HasWebConfig: true, + HasCSProjWithoutUmbraco: true, // This is a .csproj file without Umbraco installed - so we can test it doesn't return but carries on checking for more csproj or web.config files + ExpectedEnabled: true, // Segment should not be visible + Template: "{{ .Version }}", + ExpectedString: "8.18.9", + }, + { + Case: "Umbraco Folder with a .csproj [without Umbraco] and NO web.config", + HasUmbracoFolder: true, + HasCsproj: false, + HasWebConfig: false, + HasCSProjWithoutUmbraco: true, + ExpectedEnabled: false, + Template: "{{ .Version }}", + ExpectedString: "", + }, + { + Case: "Umbraco Folder with multiple .csproj's and NO web.config", + HasUmbracoFolder: true, + HasCsproj: true, + HasWebConfig: false, + HasCSProjWithoutUmbraco: true, + ExpectedEnabled: true, // Segment should be enabled and visible + Template: "{{ .Version }}", + ExpectedString: "12.1.2", + }, { Case: "Umbraco Folder and .csproj with custom template", HasUmbracoFolder: true, @@ -78,7 +109,7 @@ func TestUmbracoSegment(t *testing.T) { for _, tc := range cases { // Prepare/arrange the test env := new(mock.MockedEnvironment) - var sampleCSProj, sampleWebConfig string + var sampleCSProj, sampleWebConfig, sampleNonUmbracoCSProj string if tc.HasCsproj { content, _ := os.ReadFile("../test/umbraco/MyProject.csproj") @@ -95,10 +126,15 @@ func TestUmbracoSegment(t *testing.T) { content, _ := os.ReadFile(filePath) sampleWebConfig = string(content) } + if tc.HasCSProjWithoutUmbraco { + content, _ := os.ReadFile("../test/umbraco/ANonUmbracoProject.csproj") + sampleNonUmbracoCSProj = string(content) + } const umbracoProjectDirectory = "/workspace/MyProject" env.On("Pwd").Return(umbracoProjectDirectory) env.On("FileContent", filepath.Join(umbracoProjectDirectory, "MyProject.csproj")).Return(sampleCSProj) + env.On("FileContent", filepath.Join(umbracoProjectDirectory, "ANonUmbracoProject.csproj")).Return(sampleNonUmbracoCSProj) env.On("FileContent", filepath.Join(umbracoProjectDirectory, "web.config")).Return(sampleWebConfig) env.On("Debug", mock2.Anything) @@ -130,6 +166,13 @@ func TestUmbracoSegment(t *testing.T) { }) } + if tc.HasCSProjWithoutUmbraco { + dirEntries = append(dirEntries, &MockDirEntry{ + name: "ANonUmbracoProject.csproj", + isDir: false, + }) + } + env.On("LsDir", umbracoProjectDirectory).Return(dirEntries) // Setup the Umbraco segment with the mocked environment & properties diff --git a/src/test/umbraco/ANonUmbracoProject.csproj b/src/test/umbraco/ANonUmbracoProject.csproj new file mode 100644 index 00000000..a8f988bb --- /dev/null +++ b/src/test/umbraco/ANonUmbracoProject.csproj @@ -0,0 +1,861 @@ + + + + + + + + + Debug + AnyCPU + + + 2.0 + {EA5AED40-16B4-41F6-98BB-C4EE8F6B1893} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + MyOtherProject.Site + MyOtherProject.Site + v4.5.2 + true + 44333 + + + + + + + + + + + + 12.0 + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + MinimumRecommendedRules.ruleset + + + pdbonly + true + bin\ + TRACE + prompt + 4 + MinimumRecommendedRules.ruleset + + + + ..\packages\AngularGoogleMaps.2.0.1\lib\net45\AngularGoogleMaps.dll + True + + + ..\packages\Archetype.Binaries.1.13.1\lib\net40\Archetype.dll + True + + + ..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll + + + ..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\businesslogic.dll + + + ..\packages\ClientDependency.1.9.9\lib\net45\ClientDependency.Core.dll + + + ..\packages\ClientDependency-Mvc5.1.9.3\lib\net45\ClientDependency.Core.Mvc.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\cms.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\controls.dll + + + ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll + True + + + ..\packages\DiploTraceLogViewer.2.2.6\lib\net45\Diplo.TraceLogViewer.dll + True + + + ..\packages\Examine.0.1.90\lib\net45\Examine.dll + + + ..\packages\Foolproof.0.9.4518\lib\net45\FoolproofValidation.dll + + + ..\packages\HtmlAgilityPack.1.8.8\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + True + + + ..\packages\ImageProcessor.2.7.0.100\lib\net452\ImageProcessor.dll + + + ..\packages\ImageProcessor.Web.4.10.0.100\lib\net452\ImageProcessor.Web.dll + + + ..\packages\ImageResizer.3.4.3\lib\ImageResizer.dll + True + + + ..\packages\ImageResizer.Mvc.3.4.3\lib\ImageResizer.Mvc.dll + True + + + ..\packages\ImageResizer.Plugins.DiskCache.3.4.3\lib\ImageResizer.Plugins.DiskCache.dll + True + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\interfaces.dll + + + ..\packages\uSync.3.2.2.740\lib\net45\Jumoo.uSync.BackOffice.dll + True + + + ..\packages\uSync.Core.5.5.2.740\lib\net45\Jumoo.uSync.Core.dll + True + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\log4net.dll + + + ..\packages\Log4Net.Async.2.0.4\lib\net40\Log4Net.Async.dll + + + ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll + True + + + ..\packages\MailChimp.Net.V3.4.2.1\lib\net45\MailChimp.Net.dll + True + + + ..\packages\MailChimp.Net.V3.1.7.0.0\lib\net45\MailChimp.Net.V3.dll + True + + + ..\packages\Markdown.1.14.7\lib\net45\MarkdownSharp.dll + + + ..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.4.0\lib\net45\Microsoft.AI.Agent.Intercept.dll + + + ..\packages\Microsoft.ApplicationInsights.DependencyCollector.2.4.1\lib\net45\Microsoft.AI.DependencyCollector.dll + + + ..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.4.1\lib\net45\Microsoft.AI.PerfCounterCollector.dll + + + ..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.4.0\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll + + + ..\packages\Microsoft.ApplicationInsights.Web.2.4.1\lib\net45\Microsoft.AI.Web.dll + + + ..\packages\Microsoft.ApplicationInsights.WindowsServer.2.4.1\lib\net45\Microsoft.AI.WindowsServer.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\Microsoft.ApplicationBlocks.Data.dll + + + ..\packages\Microsoft.ApplicationInsights.2.4.0\lib\net45\Microsoft.ApplicationInsights.dll + + + ..\packages\Microsoft.ApplicationInsights.Log4NetAppender.2.4.1\lib\net45\Microsoft.ApplicationInsights.Log4NetAppender.dll + + + ..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll + + + ..\packages\Microsoft.AspNet.Identity.Owin.2.2.2\lib\net45\Microsoft.AspNet.Identity.Owin.dll + + + ..\packages\Microsoft.AspNet.SignalR.Core.2.4.1\lib\net45\Microsoft.AspNet.SignalR.Core.dll + + + ..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.0\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll + + + ..\packages\Microsoft.CodeAnalysis.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.dll + True + + + ..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.dll + True + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + + ..\packages\Microsoft.IO.RecyclableMemoryStream.1.2.2\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll + + + ..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll + + + ..\packages\Microsoft.Owin.Host.SystemWeb.4.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + + + ..\packages\Microsoft.Owin.Security.4.0.1\lib\net45\Microsoft.Owin.Security.dll + + + ..\packages\Microsoft.Owin.Security.Cookies.4.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll + + + ..\packages\Microsoft.Owin.Security.OAuth.4.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll + + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + True + + + ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll + True + + + ..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll + True + + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll + True + + + ..\packages\Ninject.Web.Common.3.2.0.0\lib\net45-full\Ninject.Web.Common.dll + True + + + ..\packages\Ninject.MVC3.3.2.1.0\lib\net45-full\Ninject.Web.Mvc.dll + True + + + ..\packages\Nustache.1.16.0.1\lib\net20\Nustache.Core.dll + True + + + ..\packages\Nustache.Mvc3.1.13.8.22\lib\net40\Nustache.Mvc3.dll + True + + + ..\packages\Our.Umbraco.Ditto.0.10.0\lib\net45\Our.Umbraco.Ditto.dll + True + + + ..\packages\Our.Umbraco.NestedContent.0.3.0\lib\net45\Our.Umbraco.NestedContent.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + ..\packages\RazorEngine.3.4.1\lib\net45\RazorEngine.dll + True + + + ..\packages\semver.1.1.2\lib\net451\Semver.dll + True + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\SQLCE4Umbraco.dll + + + ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + True + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\System.Data.SqlServerCe.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\System.Data.SqlServerCe.Entity.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.4.0\lib\net45\System.Diagnostics.DiagnosticSource.dll + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + ..\packages\System.Reflection.Metadata.1.0.21\lib\portable-net45+win8\System.Reflection.Metadata.dll + True + + + + ..\packages\System.Threading.Tasks.Dataflow.4.9.0\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + + + + + + + + + + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll + + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll + + + ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll + + + ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll + + + + + + + + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\TidyNet.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\umbraco.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\Umbraco.Core.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\umbraco.DataLayer.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\umbraco.editorControls.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\umbraco.MacroEngines.dll + + + ..\packages\Umbraco.ModelsBuilder.3.0.10\lib\Umbraco.ModelsBuilder.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\umbraco.providers.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\Umbraco.Web.UI.dll + + + ..\packages\UmbracoCms.Core.7.15.7\lib\net452\UmbracoExamine.dll + + + ..\packages\UrlRewritingNet.2.0.7\lib\UrlRewritingNet.UrlRewriter.dll + True + + + ..\packages\WebActivatorEx.2.0\lib\net40\WebActivatorEx.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + + + + + + Designer + + + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + + Designer + + + Web.config + + + + + Designer + + + + + 500.aspx + ASPXCodeBehind + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 12088 + / + https://localhost:44333/ + False + False + + + False + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + \ No newline at end of file