Skip to content

Commit

Permalink
Adding tests for SpecificVersion attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Jun 11, 2017
1 parent c2ac5f5 commit d7754c6
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 7 deletions.
11 changes: 9 additions & 2 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ let ``should read content none config``() =
let cfg = DependenciesFile.FromSource(noneContentConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]
Expand All @@ -232,13 +233,15 @@ let ``should read config with specific framework``() =
let cfg = DependenciesFile.FromSource(specificFrameworkConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]

let noTargetsImportConfig = """
import_targets false
copy_local false
specific_version false
source "http://www.nuget.org/api/v2" // first source
nuget "Microsoft.SqlServer.Types"
Expand All @@ -249,6 +252,7 @@ let ``should read no targets import config``() =
let cfg = DependenciesFile.FromSource(noTargetsImportConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]
Expand Down Expand Up @@ -786,11 +790,12 @@ let ``should read config with framework restriction``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual (makeOrList [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5)); FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] |> getExplicitRestriction)
p.Settings.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual None
p.Settings.SpecificVersion |> shouldEqual None

[<Test>]
let ``should read config with no targets import``() =
let config = """
nuget Foobar 1.2.3 alpha beta import_targets: false, copy_local: false
nuget Foobar 1.2.3 alpha beta import_targets: false, copy_local: false, specific_version: false
"""
let cfg = DependenciesFile.FromSource(config)

Expand All @@ -799,12 +804,13 @@ let ``should read config with no targets import``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual FrameworkRestriction.NoRestriction
p.Settings.ImportTargets |> shouldEqual (Some false)
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.SpecificVersion |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual None

[<Test>]
let ``should read config with content none``() =
let config = """
nuget Foobar 1.2.3 alpha beta content: none, copy_local: false
nuget Foobar 1.2.3 alpha beta content: none, copy_local: false, specific_version: true
"""
let cfg = DependenciesFile.FromSource(config)

Expand All @@ -813,6 +819,7 @@ let ``should read config with content none``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual FrameworkRestriction.NoRestriction
p.Settings.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.SpecificVersion |> shouldEqual (Some true)
p.Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit)

[<Test>]
Expand Down
17 changes: 15 additions & 2 deletions tests/Paket.Tests/DependenciesFile/SaveSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ let ``should serialize no local copy config``() =
cfg.ToString()
|> shouldEqual (normalizeLineEndings noLocalCopyConfig)

let noSpecificVersionConfig = """specific_version: false
source http://www.nuget.org/api/v2
nuget FAKE ~> 3.0"""


[<Test>]
let ``should serialize no specific version config``() =
let cfg = DependenciesFile.FromSource(noLocalCopyConfig)

cfg.ToString()
|> shouldEqual (normalizeLineEndings noLocalCopyConfig)

let simplestConfig = """nuget FAKE ~> 3.0"""

[<Test>]
Expand Down Expand Up @@ -236,8 +249,8 @@ let ``should serialize config with framework restrictions``() =
let withNoImportsRestrictions = """source https://www.nuget.org/api/v2
nuget FakeItEasy 1.24.0
nuget json-ld.net 1.0.3 copy_local: false, import_targets: false, framework: net35, net40
nuget Example3 !== 2.2.3 alpha beta import_targets: false
nuget json-ld.net 1.0.3 copy_local: false, import_targets: false, framework: net35, net40, specific_version: true
nuget Example3 !== 2.2.3 alpha beta import_targets: false, specific_version: false
nuget Example4 import_targets: false, content: none
nuget Example5 prerelease import_targets: false
Expand Down
236 changes: 236 additions & 0 deletions tests/Paket.Tests/InstallModel/Xml/ControlzEx.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
module Paket.InstallModel.Xml.ControlzEx

open FsUnit
open NUnit.Framework
open Paket
open Paket.Requirements
open Paket.Domain
open Paket.TestHelpers

let expectedWithoutSpecificVersion = """
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.0.3')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net40\ControlzEx.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net40\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net45\ControlzEx.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net462\ControlzEx.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net462\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>"""

let expectedWithSpecificVersionSetToTrue = """
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.0.3')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net40\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net40\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net45\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net462\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net462\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>"""

let expectedWithSpecificVersionSetToFalse = """
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.0.3')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net40\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net40\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net45\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7')">
<ItemGroup>
<Reference Include="ControlzEx">
<HintPath>..\..\..\ControlzEx\lib\net462\ControlzEx.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Windows.Interactivity">
<HintPath>..\..\..\ControlzEx\lib\net462\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>"""

[<Test>]
let ``should generate Xml without specific version for ControlzEx in CSharp project``() =
ensureDir()
let model =
InstallModel.CreateFromLibs(PackageName "ControlzEx", SemVer.Parse "3.0.1", FrameworkRestriction.NoRestriction,
[ @"..\ControlzEx\lib\net40\ControlzEx.dll"
@"..\ControlzEx\lib\net40\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net45\ControlzEx.dll"
@"..\ControlzEx\lib\net45\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net462\ControlzEx.dll"
@"..\ControlzEx\lib\net462\System.Windows.Interactivity.dll"]
|> Paket.InstallModel.ProcessingSpecs.fromLegacyList @"..\ControlzEx\",
[],
[],
Nuspec.All)

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyCsharpGuid.csprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,None,None,true,KnownTargetProfiles.AllProfiles,None)
let result =
ctx.ChooseNodes
|> (fun n -> n.Head.OuterXml)
|> normalizeXml
let expectedXml = normalizeXml expectedWithoutSpecificVersion
result |> shouldEqual expectedXml

[<Test>]
let ``should generate Xml with specific version set to true for ControlzEx in CSharp project``() =
ensureDir()
let model =
InstallModel.CreateFromLibs(PackageName "ControlzEx", SemVer.Parse "3.0.1", FrameworkRestriction.NoRestriction,
[ @"..\ControlzEx\lib\net40\ControlzEx.dll"
@"..\ControlzEx\lib\net40\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net45\ControlzEx.dll"
@"..\ControlzEx\lib\net45\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net462\ControlzEx.dll"
@"..\ControlzEx\lib\net462\System.Windows.Interactivity.dll"]
|> Paket.InstallModel.ProcessingSpecs.fromLegacyList @"..\ControlzEx\",
[],
[],
Nuspec.All)

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyCsharpGuid.csprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,None,Some true,true,KnownTargetProfiles.AllProfiles,None)
let result =
ctx.ChooseNodes
|> (fun n -> n.Head.OuterXml)
|> normalizeXml
let expectedXml = normalizeXml expectedWithSpecificVersionSetToTrue
result |> shouldEqual expectedXml

[<Test>]
let ``should generate Xml with specific version set to false for ControlzEx in CSharp project``() =
ensureDir()
let model =
InstallModel.CreateFromLibs(PackageName "ControlzEx", SemVer.Parse "3.0.1", FrameworkRestriction.NoRestriction,
[ @"..\ControlzEx\lib\net40\ControlzEx.dll"
@"..\ControlzEx\lib\net40\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net45\ControlzEx.dll"
@"..\ControlzEx\lib\net45\System.Windows.Interactivity.dll"
@"..\ControlzEx\lib\net462\ControlzEx.dll"
@"..\ControlzEx\lib\net462\System.Windows.Interactivity.dll"]
|> Paket.InstallModel.ProcessingSpecs.fromLegacyList @"..\ControlzEx\",
[],
[],
Nuspec.All)

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyCsharpGuid.csprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,None,Some false,true,KnownTargetProfiles.AllProfiles,None)
let result =
ctx.ChooseNodes
|> (fun n -> n.Head.OuterXml)
|> normalizeXml
let expectedXml = normalizeXml expectedWithSpecificVersionSetToFalse
result |> shouldEqual expectedXml
2 changes: 2 additions & 0 deletions tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let config1 = """
references strict
framework: >= net45
copy_local false
specific_version true
source "http://www.nuget.org/api/v2"
nuget "Castle.Windsor-log4net" "~> 3.2"
Expand All @@ -23,6 +24,7 @@ let graph1 =

let expected1 = """REFERENCES: STRICT
COPY-LOCAL: FALSE
SPECIFIC-VERSION: TRUE
RESTRICTION: >= net45
NUGET
remote: http://www.nuget.org/api/v2
Expand Down
24 changes: 24 additions & 0 deletions tests/Paket.Tests/Lockfile/GeneratorSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ let ``should generate lock file with no copy local for packages``() =
|> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options
|> shouldEqual (normalizeLineEndings expected)

let configWithSpecificVersion = """
source "http://www.nuget.org/api/v2"
nuget "Castle.Windsor-log4net" ~> 3.2 specific_version: false, import_targets: false, framework: net35
nuget "Rx-Main" "~> 2.0" framework: >= net40 """

[<Test>]
let ``should generate lock file with no specific version for packages``() =
let expected = """NUGET
remote: http://www.nuget.org/api/v2
Castle.Windsor (2.1) - specific_version: false, import_targets: false, restriction: == net35
Castle.Windsor-log4net (3.3) - specific_version: false, import_targets: false, restriction: == net35
Castle.Windsor (>= 2.0)
log4net (>= 1.0)
log (1.2) - specific_version: false, import_targets: false, restriction: == net35
log4net (1.1) - specific_version: false, import_targets: false, restriction: == net35
log (>= 1.0)
Rx-Core (2.1) - restriction: >= net40
Rx-Main (2.0) - restriction: >= net40
Rx-Core (>= 2.1)"""
let cfg = DependenciesFile.FromSource(configWithSpecificVersion)
ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail()
|> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options
|> shouldEqual (normalizeLineEndings expected)

let configWithDisabledContent = """
source "http://www.nuget.org/api/v2"
Expand Down
Loading

0 comments on commit d7754c6

Please sign in to comment.