Skip to content

Commit

Permalink
Fixed setComponentsNeverOverwrite and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Kroenert authored and Florian Kroenert committed May 26, 2015
1 parent ce7cd1d commit bd3f8db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
8 changes: 1 addition & 7 deletions src/app/FakeLib/WiXHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,7 @@ let rec wixComponentRefs (directoryInfo : DirectoryInfo) =
/// Take a component string and set "neverOverwrite" Tag
/// This is useful for config files, since they are not replaced on upgrade like that
let setComponentsNeverOverwrite (components : string) =
let lines = split '\n' components

// Filter for lines which have a name tag matching the given regex, pick the first and return its ID
lines
|> Seq.filter(fun line -> Regex.IsMatch(line, "<Component"))
|> Seq.map(fun f -> f.Replace("/>", "NeverOverwrite=\"yes\" />"))
|> toLines
components.Replace("<Component", "<Component NeverOverwrite=\"yes\"")

open System

Expand Down
23 changes: 20 additions & 3 deletions src/test/Test.Fake.Deploy.Web/WixHelperTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Fake
open Xunit

[<Fact>]
let ``should find correct id`` () =
let ``should find correct file id`` () =
let wixDirString = "<Component Id=\"comp\" Guid=\"1290b30b-4242-4ed5-99z0-52e3ad1337e6\">
<File Id=\"fi_2\" Name=\"Castle.Core.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Core.dll\" />
<File Id=\"fi_3\" Name=\"Castle.Windsor.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Windsor.dll\" />
Expand All @@ -18,14 +18,31 @@ let ``should find correct id`` () =
let executableId = getFileIdFromWiXString wixDirString "\S*.exe"
Assert.Equal<string>("fi_5", executableId)

[<Fact>]
let ``should find correct component id`` () =
let wixDirString = "<Component Id=\"comp\" Guid=\"1290b30b-4242-4ed5-99z0-52e3ad1337e6\">
<File Id=\"fi_2\" Name=\"Castle.Core.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Core.dll\" />
<File Id=\"fi_3\" Name=\"Castle.Windsor.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Windsor.dll\" />
</Component>
<Component Id=\"comp2\" Guid=\"1337b30b-4242-4ed5-99z0-52e3ad1337e6\">
<File Id=\"fi_4\" Name=\"FAKE.Test.Abstractions.dll\" Source=\"C:\Git\Test\Publish\wixHelper\FAKE.Test.Abstractions.dll\" />
<File Id=\"fi_5\" Name=\"FAKE.Test.SomeProject.exe\" Source=\"C:\Git\Test\Publish\wixHelper\FAKE.Test.SomeProject.exe\" />
<File Id=\"fi_6\" Name=\"FAKE.Test.SomeProject.exe.config\" Source=\"C:\Git\Test\Publish\wixHelper\FAKE.Test.SomeProject.exe.config\" />
<File Id=\"fi_7\" Name=\"Magnum.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Magnum.dll\" />
<File Id=\"fi_8\" Name=\"MassTransit.dll\" Source=\"C:\Git\Test\Publish\wixHelper\MassTransit.dll\" />
</Component>"
let componentIds = getComponentIdsFromWiXString wixDirString
Assert.Equal<string>("<ComponentRef Id=\"comp\" /><ComponentRef Id=\"comp2\" />", componentIds)


[<Fact>]
let ``should set components never overwrite true if desired`` () =
let componentDefault = "<Component Id=\"comp\" Guid=\"1290b30b-4242-4ed5-99z0-52e3ad1337e6\">
<File Id=\"fi_2\" Name=\"Castle.Core.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Core.dll\" />
</Component>"
let componentExpected = "<Component NeverOverwrite=\"yes\" Id=\"comp\" Guid=\"1290b30b-4242-4ed5-99z0-52e3ad1337e6\">
<File Id=\"fi_2\" Name=\"Castle.Core.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Core.dll\" />
</Component>"
<File Id=\"fi_2\" Name=\"Castle.Core.dll\" Source=\"C:\Git\Test\Publish\wixHelper\Castle.Core.dll\" />
</Component>"
let actualComponent = setComponentsNeverOverwrite componentDefault
Assert.Equal<string>(componentExpected, actualComponent)

Expand Down

0 comments on commit bd3f8db

Please sign in to comment.