|
| 1 | +using System.Linq; |
| 2 | +using ICSharpCode.CodeConverter.Shared; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace ICSharpCode.CodeConverter.Tests.LanguageAgnostic |
| 6 | +{ |
| 7 | + public class SolutionFileTextEditorTests |
| 8 | + { |
| 9 | + [Fact] |
| 10 | + public void WhenInSolutionBaseDirThenUpdated() |
| 11 | + { |
| 12 | + AssertProjectReplacement(SolutionProjectReferenceLine("VbLibrary", @"VbLibrary.vbproj"), |
| 13 | + UpdatedSolutionProjectReferenceLine("VbLibrary", @"VbLibrary.csproj"), |
| 14 | + (FilePath: @"C:\MySolution\VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\")); |
| 15 | + } |
| 16 | + [Fact] |
| 17 | + public void WhenInProjectFolderThenUpdated() |
| 18 | + { |
| 19 | + AssertProjectReplacement(SolutionProjectReferenceLine("VbLibrary", @"VbLibrary\VbLibrary.vbproj"), |
| 20 | + UpdatedSolutionProjectReferenceLine("VbLibrary", @"VbLibrary\VbLibrary.csproj"), |
| 21 | + (FilePath: @"C:\MySolution\VbLibrary\VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\VbLibrary\")); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void GivenDifferentLibraryThenNotUpdated() |
| 26 | + { |
| 27 | + string unaffectedProject = SolutionProjectReferenceLine("Prefix.VbLibrary", @"Prefix.VbLibrary\Prefix.VbLibrary.vbproj"); |
| 28 | + AssertProjectReplacement(unaffectedProject, unaffectedProject, (FilePath: @"C:\MySolution\VbLibrary\VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\VbLibrary\")); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void GivenDifferentLibraryThenNotUpdated2() |
| 33 | + { |
| 34 | + string unaffectedProject = SolutionProjectReferenceLine("VbLibrary", @"VbLibrary\VbLibrary.vbproj"); |
| 35 | + AssertProjectReplacement(unaffectedProject, unaffectedProject, (FilePath: @"C:\MySolution\Prefix.VbLibrary\Prefix.VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\Prefix.VbLibrary\")); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void GivenDifferentLibraryWhenInSolutionBaseDirThenNotUpdated() |
| 40 | + { |
| 41 | + string unaffectedProject = SolutionProjectReferenceLine("Prefix.VbLibrary", @"Prefix.VbLibrary.vbproj"); |
| 42 | + AssertProjectReplacement(unaffectedProject, unaffectedProject, (FilePath: @"C:\MySolution\VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\")); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void GivenDifferentLibraryWhenInSolutionBaseDirThenNotUpdated2() |
| 47 | + { |
| 48 | + string unaffectedProject = SolutionProjectReferenceLine("VbLibrary", @"VbLibrary.vbproj"); |
| 49 | + AssertProjectReplacement(unaffectedProject, unaffectedProject, (FilePath: @"C:\MySolution\Prefix.VbLibrary.vbproj", DirectoryPath: @"C:\MySolution\")); |
| 50 | + } |
| 51 | + |
| 52 | + private static string SolutionProjectReferenceLine(string projectName, string projRelativePath) => |
| 53 | + $@"Project(""{{F184B08F-C81C-45F6-A57F-5ABD9991F28F}}"") = ""{projectName}"", ""{projRelativePath}"", ""{{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}}"""; |
| 54 | + |
| 55 | + private static string UpdatedSolutionProjectReferenceLine(string projectName, string projRelativePath) => |
| 56 | + $@"Project(""{{F184B08F-C81C-45F6-A57F-5ABD9991F28F}}"") = ""{projectName}"", ""{projRelativePath}"", ""{{7D8F03A6-764F-00F9-1BBA-8A41CF27F0CA}}"""; |
| 57 | + |
| 58 | + private static void AssertProjectReplacement(string originalText, string expectedOutput, params (string FilePath, string DirectoryPath)[] projects) |
| 59 | + { |
| 60 | + var replacements = SolutionFileTextEditor.GetProjectReferenceReplacements(projects, originalText).ToList(); |
| 61 | + var actualOutput = TextReplacementConverter.Replace(originalText, replacements); |
| 62 | + Assert.Equal(Utils.HomogenizeEol(expectedOutput), Utils.HomogenizeEol(actualOutput)); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments