mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Normalize string to fix test case on Unix (#1841)
This commit is contained in:
@@ -124,6 +124,7 @@ dotnet_diagnostic.IDE0011.severity = none
|
|||||||
dotnet_diagnostic.IDE0056.severity = none
|
dotnet_diagnostic.IDE0056.severity = none
|
||||||
dotnet_diagnostic.IDE0082.severity = none
|
dotnet_diagnostic.IDE0082.severity = none
|
||||||
dotnet_diagnostic.IDE0071.severity = none
|
dotnet_diagnostic.IDE0071.severity = none
|
||||||
|
dotnet_diagnostic.IDE0072.severity = suggestion # Add missing cases to switch statement; defaults to error, and doesn't consider discards to "handle" cases
|
||||||
dotnet_diagnostic.IDE0083.severity = none
|
dotnet_diagnostic.IDE0083.severity = none
|
||||||
dotnet_diagnostic.IDE0041.severity = none
|
dotnet_diagnostic.IDE0041.severity = none
|
||||||
dotnet_diagnostic.IDE0150.severity = none
|
dotnet_diagnostic.IDE0150.severity = none
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -10,6 +11,7 @@ using Microsoft.SqlServer.Dac.Projects;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlProjects;
|
using Microsoft.SqlTools.ServiceLayer.SqlProjects;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@@ -207,7 +209,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
|
|||||||
requestMock.AssertSuccess(nameof(service.HandleAddDacpacReferenceRequest));
|
requestMock.AssertSuccess(nameof(service.HandleAddDacpacReferenceRequest));
|
||||||
Assert.AreEqual(2, service.Projects[projectUri].DatabaseReferences.Count, "Database references after adding dacpac reference");
|
Assert.AreEqual(2, service.Projects[projectUri].DatabaseReferences.Count, "Database references after adding dacpac reference");
|
||||||
DacpacReference dacpacRef = (DacpacReference)service.Projects[projectUri].DatabaseReferences.First(x => x is DacpacReference);
|
DacpacReference dacpacRef = (DacpacReference)service.Projects[projectUri].DatabaseReferences.First(x => x is DacpacReference);
|
||||||
Assert.AreEqual(mockReferencePath, dacpacRef.DacpacPath, "Referenced dacpac");
|
Assert.AreEqual(FileUtils.NormalizePath(mockReferencePath, PlatformID.Win32NT), dacpacRef.DacpacPath, "Referenced dacpac");
|
||||||
Assert.AreEqual(databaseVar.Name, dacpacRef.DatabaseVariable);
|
Assert.AreEqual(databaseVar.Name, dacpacRef.DatabaseVariable);
|
||||||
Assert.AreEqual(serverVar.Name, dacpacRef.ServerVariable);
|
Assert.AreEqual(serverVar.Name, dacpacRef.ServerVariable);
|
||||||
Assert.IsFalse(dacpacRef.SuppressMissingDependencies, nameof(dacpacRef.SuppressMissingDependencies));
|
Assert.IsFalse(dacpacRef.SuppressMissingDependencies, nameof(dacpacRef.SuppressMissingDependencies));
|
||||||
|
|||||||
@@ -76,5 +76,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Normalizes Windows, Unix, and mixed paths to the same slash direction, specified by <paramref name="separatorType"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="separatorType">Win32NT for \, Unix for /</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string NormalizePath(string path, PlatformID separatorType)
|
||||||
|
{
|
||||||
|
return separatorType switch
|
||||||
|
{
|
||||||
|
PlatformID.Win32NT => path.Contains('/')
|
||||||
|
? String.Join('\\', path.Split('/', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
: path,
|
||||||
|
PlatformID.Unix => path.Contains('\\')
|
||||||
|
? String.Join('/', path.Split('\\', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
: path,
|
||||||
|
_ => throw new ArgumentException($"{nameof(separatorType)} must be either {PlatformID.Win32NT} or {PlatformID.Unix}, but {separatorType} was passed."),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user