|
1 | 1 | module Tests.IntegrationTests |
2 | 2 |
|
3 | | -open Tests.Setup |
4 | | -open Moq |
5 | | -open Microsoft.Build.Framework |
6 | | -open Ionide.KeepAChangelog.Tasks |
7 | | -open Shouldly |
| 3 | +open System.IO |
| 4 | +open System.Runtime.CompilerServices |
| 5 | +open System.Threading.Tasks |
| 6 | +open Microsoft.VisualStudio.TestTools.UnitTesting |
| 7 | +open BlackFox.CommandLine |
| 8 | +open Faqt |
| 9 | +open SimpleExec |
| 10 | +open Workspace |
8 | 11 |
|
9 | | -// [<Test>] |
10 | | -// let ``works for 'ci' type with default config`` () = |
11 | | -// let buildEngine = Mock<IBuildEngine>() |
12 | | -// let errors = ResizeArray<BuildErrorEventArgs>() |
13 | 12 |
|
14 | | -// buildEngine |
15 | | -// .Setup(fun x -> x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())) |
16 | | -// .Callback(fun args -> errors.Add(args)) |
17 | | -// |> ignore |
| 13 | +module Utils = |
| 14 | + let packAndGetPackageProperties projectName = |
| 15 | + let packageCache = VirtualWorkspace.``test-package-cache``.``.`` |
| 16 | + if Directory.Exists packageCache then |
| 17 | + Directory.Delete(packageCache, true) |
| 18 | + Directory.CreateDirectory packageCache |> ignore |
| 19 | + Command.Run( |
| 20 | + "dotnet", |
| 21 | + CmdLine.empty |
| 22 | + |> CmdLine.appendPrefix "restore" projectName |
| 23 | + |> CmdLine.appendPrefix "--packages" VirtualWorkspace.``test-package-cache``.``.`` |
| 24 | + |> CmdLine.toString, |
| 25 | + workingDirectory = Workspace.fixtures.``.`` |
| 26 | + ) |
| 27 | + Command.ReadAsync( |
| 28 | + "dotnet", |
| 29 | + CmdLine.empty |
| 30 | + |> CmdLine.appendPrefix "pack" projectName |
| 31 | + |> CmdLine.appendPrefix "-c" "Release" |
| 32 | + |> CmdLine.append "--no-restore" |
| 33 | + |> CmdLine.appendRaw "--getProperty:Version" |
| 34 | + |> CmdLine.appendRaw "--getProperty:PackageVersion" |
| 35 | + |> CmdLine.appendRaw "--getProperty:PackageReleaseNotes" |
| 36 | + |> CmdLine.toString, |
| 37 | + workingDirectory = Workspace.fixtures.``.`` |
| 38 | + ) |
18 | 39 |
|
19 | | -// let item = Mock<ITaskItem>() |
20 | | -// item.Setup(fun x -> x.GetMetadata("MaximeTest")).Returns("test") |> ignore |
| 40 | +type StringHelper = |
| 41 | + [<Extension>] |
| 42 | + static member ReplaceEscapedNewLines (s: string) = |
| 43 | + s.ReplaceLineEndings().Replace("\\r\\n","\\n") |
21 | 44 |
|
22 | | -// let myTask = ParseChangelog(ChangelogFile = "MyChangelog.md") |
23 | | -// myTask.BuildEngine <- buildEngine.Object |
| 45 | +[<TestClass>] |
| 46 | +type IntegrationTests() = |
24 | 47 |
|
25 | | -// let success = myTask.Execute() |
| 48 | + member val testPackageVersion = null with get, set |
26 | 49 |
|
27 | | -// success.ShouldBeTrue() |
| 50 | + member this.AddPackageReference(projectName: string) = |
| 51 | + let suffix = projectName.Replace(".fsproj", "") |
| 52 | + |
| 53 | + this.testPackageVersion <- $"0.0.1-test-{suffix}" |
| 54 | + |
| 55 | + |
| 56 | + // Create a package to be used in the tests |
| 57 | + // I didn't find a way to test the MSBuild tasks execution using MSBuild only |
| 58 | + // So each fsproj, will use a package reference to the package created here |
| 59 | + Command.Run( |
| 60 | + "dotnet", |
| 61 | + CmdLine.empty |
| 62 | + |> CmdLine.appendPrefix "pack" "src" |
| 63 | + |> CmdLine.appendPrefix "-c" "Release" |
| 64 | + |> CmdLine.appendPrefix "-o" VirtualWorkspace.``test-nupkgs``.``.`` |
| 65 | + |> CmdLine.appendRaw $"-p:PackageVersion=%s{this.testPackageVersion}" |
| 66 | + |> CmdLine.toString, |
| 67 | + workingDirectory = Workspace.``..``.``.`` |
| 68 | + ) |
| 69 | + |
| 70 | + Command.Run( |
| 71 | + "dotnet", |
| 72 | + CmdLine.empty |
| 73 | + |> CmdLine.appendPrefix "add" projectName |
| 74 | + |> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks" |
| 75 | + // |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.`` |
| 76 | + |> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]" |
| 77 | + |> CmdLine.toString, |
| 78 | + workingDirectory = Workspace.fixtures.``.`` |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | + [<TestMethod>] |
| 83 | + member this.``works for absolute path with keep a changelog``() : Task = |
| 84 | + task { |
| 85 | + let projectName = "WorksForAbsolutePathWithKeepAChangelog.fsproj" |
| 86 | + |
| 87 | + this.AddPackageReference projectName |
| 88 | + |
| 89 | + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName |
| 90 | + |
| 91 | + stdout |
| 92 | + .ReplaceEscapedNewLines() |
| 93 | + .Should() |
| 94 | + .Be( |
| 95 | + """{ |
| 96 | + "Properties": { |
| 97 | + "Version": "0.1.0", |
| 98 | + "PackageVersion": "0.1.0", |
| 99 | + "PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" |
| 100 | + } |
| 101 | +} |
| 102 | +""" |
| 103 | + ) |
| 104 | + |> ignore |
| 105 | + } |
| 106 | + |
| 107 | + [<TestMethod>] |
| 108 | + member this.``works for relative path with keep a changelog``() : Task = |
| 109 | + task { |
| 110 | + let projectName = "WorksForRelativePathWithKeepAChangelog.fsproj" |
| 111 | + |
| 112 | + this.AddPackageReference projectName |
| 113 | + |
| 114 | + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName |
| 115 | + |
| 116 | + stdout |
| 117 | + .ReplaceEscapedNewLines() |
| 118 | + .Should() |
| 119 | + .Be( |
| 120 | + """{ |
| 121 | + "Properties": { |
| 122 | + "Version": "0.1.0", |
| 123 | + "PackageVersion": "0.1.0", |
| 124 | + "PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" |
| 125 | + } |
| 126 | +} |
| 127 | +""" |
| 128 | + ) |
| 129 | + |> ignore |
| 130 | + } |
| 131 | + |
| 132 | + [<TestMethod>] |
| 133 | + member this.``fails if no changelog is specified``() : Task = |
| 134 | + task { |
| 135 | + let projectName = "FailIfChangelogNotSpecified.fsproj" |
| 136 | + |
| 137 | + this.AddPackageReference projectName |
| 138 | + |
| 139 | + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName |
| 140 | + |
| 141 | + stdout |
| 142 | + .ReplaceEscapedNewLines() |
| 143 | + .Should() |
| 144 | + .Be( |
| 145 | + """{ |
| 146 | + "Properties": { |
| 147 | + "Version": "1.0.0", |
| 148 | + "PackageVersion": "1.0.0", |
| 149 | + "PackageReleaseNotes": "" |
| 150 | + } |
| 151 | +} |
| 152 | +""" |
| 153 | + ) |
| 154 | + |> ignore |
| 155 | + } |
| 156 | + |
| 157 | + [<TestMethod>] |
| 158 | + member this.``fails if changelog specified doesn't exist``() : Task = |
| 159 | + task { |
| 160 | + let projectName = "FailIfChangelogDoesNotExist.fsproj" |
| 161 | + |
| 162 | + this.AddPackageReference projectName |
| 163 | + |
| 164 | + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName |
| 165 | + |
| 166 | + stdout |
| 167 | + .ReplaceEscapedNewLines() |
| 168 | + .Should() |
| 169 | + .Be( |
| 170 | + """{ |
| 171 | + "Properties": { |
| 172 | + "Version": "1.0.0", |
| 173 | + "PackageVersion": "1.0.0", |
| 174 | + "PackageReleaseNotes": "" |
| 175 | + } |
| 176 | +} |
| 177 | +""" |
| 178 | + ) |
| 179 | + |> ignore |
| 180 | + } |
0 commit comments