mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Normalize string to fix test case on Unix (#1841)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,6 +11,7 @@ using Microsoft.SqlServer.Dac.Projects;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlProjects;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using NUnit.Framework;
|
||||
@@ -207,7 +209,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
|
||||
requestMock.AssertSuccess(nameof(service.HandleAddDacpacReferenceRequest));
|
||||
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);
|
||||
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(serverVar.Name, dacpacRef.ServerVariable);
|
||||
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