1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 4 using System; 5 using System.Collections.Generic; 6 using System.Text; 7 using Microsoft.Build.Framework; 8 using Microsoft.Build.Tasks; 9 using Microsoft.Build.Shared; 10 using Xunit; 11 12 namespace Microsoft.Build.UnitTests 13 { 14 sealed public class ComReference_Tests 15 { 16 private static Dictionary<string, string> s_existingFiles = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); 17 18 private static Dictionary<string, string> ExistingFilesDictionary 19 { 20 get 21 { 22 if (s_existingFiles.Count != 0) 23 return s_existingFiles; 24 25 s_existingFiles.Add(@"C:\test\typelib1.dll", string.Empty); 26 s_existingFiles.Add(@"C:\test\typelib2\2.dll", string.Empty); 27 s_existingFiles.Add(@"C:\test\typelib3.\3dll", string.Empty); 28 s_existingFiles.Add(@"C:\test\typelib4.dll", string.Empty); 29 s_existingFiles.Add(@"C:\test\typelib5.dll", string.Empty); 30 31 return s_existingFiles; 32 } 33 } 34 FileExistsMock(string filepath)35 private static bool FileExistsMock(string filepath) 36 { 37 return ExistingFilesDictionary.ContainsKey(filepath); 38 } 39 40 [Fact] TestStripTypeLibNumber()41 public void TestStripTypeLibNumber() 42 { 43 if (!NativeMethodsShared.IsWindows) 44 { 45 return; // "COM is only found on Windows" 46 } 47 48 Assert.Equal(@"C:\test\typelib1.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib1.dll", new FileExists(FileExistsMock))); 49 Assert.Equal(@"C:\test\typelib2\2.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib2\2.dll", new FileExists(FileExistsMock))); 50 Assert.Equal(@"C:\test\typelib3.\3dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib3.\3dll", new FileExists(FileExistsMock))); 51 Assert.Equal(@"C:\test\typelib4.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib4.dll\4", new FileExists(FileExistsMock))); 52 Assert.Equal(@"C:\test\typelib5.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib5.dll\555", new FileExists(FileExistsMock))); 53 Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib6.dll", new FileExists(FileExistsMock))); 54 Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib7.dll\7", new FileExists(FileExistsMock))); 55 } 56 } 57 } 58