This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for min runtime version at application start
- Loading branch information
Victor Hurdugaci
committed
Sep 11, 2015
1 parent
d689333
commit f228654
Showing
9 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
test/Microsoft.Dnx.Runtime.Tests/Host/MinRuntimeVersionFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.Versioning; | ||
using System.Text; | ||
using NuGet; | ||
using Xunit; | ||
|
||
namespace Microsoft.Dnx.Runtime.Tests.Host | ||
{ | ||
public class MinRuntimeVersionFacts | ||
{ | ||
private const string TooHighVersion = "100.0.0"; | ||
|
||
private static readonly FrameworkName Dnx451 = new FrameworkName(VersionUtility.DnxFrameworkIdentifier, new Version(4, 5, 1)); | ||
|
||
[Fact] | ||
public void LoadWithOldRuntime_Throws() | ||
{ | ||
var ahc = new ApplicationHostContext() | ||
{ | ||
RuntimeEnvironment = RuntimeEnvironmentHelper.RuntimeEnvironment, | ||
Project = CreateDummyProject(), | ||
TargetFramework = Dnx451, | ||
RuntimeIdentifiers = new[] { "win7-x64" }, | ||
SkipLockfileValidation = true, | ||
LockFile = CreateLockFile(TooHighVersion) | ||
}; | ||
|
||
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => ApplicationHostContext.GetRuntimeLibraries(ahc)); | ||
|
||
Assert.Contains(TooHighVersion, exception.Message); | ||
} | ||
|
||
[Fact] | ||
public void LoadWithNewerRuntime_NoThrow() | ||
{ | ||
var ahc = new ApplicationHostContext() | ||
{ | ||
RuntimeEnvironment = RuntimeEnvironmentHelper.RuntimeEnvironment, | ||
Project = CreateDummyProject(), | ||
TargetFramework = Dnx451, | ||
RuntimeIdentifiers = new[] { "win7-x64" }, | ||
SkipLockfileValidation = true, | ||
LockFile = CreateLockFile(RuntimeEnvironmentHelper.RuntimeEnvironment.RuntimeVersion) | ||
}; | ||
|
||
try | ||
{ | ||
ApplicationHostContext.GetRuntimeLibraries(ahc); | ||
} | ||
catch | ||
{ | ||
Assert.True(false, "No exception was expected"); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void DisableMinVersionCheck() | ||
{ | ||
var ahc = new ApplicationHostContext() | ||
{ | ||
RuntimeEnvironment = RuntimeEnvironmentHelper.RuntimeEnvironment, | ||
SkipRuntimeMinVersionCheck = true, | ||
Project = CreateDummyProject(), | ||
TargetFramework = Dnx451, | ||
RuntimeIdentifiers = new[] { "win7-x64" }, | ||
SkipLockfileValidation = true, | ||
LockFile = CreateLockFile(TooHighVersion) | ||
}; | ||
|
||
try | ||
{ | ||
ApplicationHostContext.GetRuntimeLibraries(ahc); | ||
} | ||
catch | ||
{ | ||
Assert.True(false, "No exception was expected"); | ||
} | ||
} | ||
|
||
private Project CreateDummyProject() | ||
{ | ||
const string DummyProject = @"{ ""frameworks"": { ""dnx451"": {} } }"; | ||
using (var strm = new MemoryStream(Encoding.UTF8.GetBytes(DummyProject))) | ||
{ | ||
return new ProjectReader().ReadProject(strm, "DummyProject", @"C:\DummyProject", new List<DiagnosticMessage>()); | ||
} | ||
} | ||
|
||
private LockFile CreateLockFile(string runtimeVersion) | ||
{ | ||
return new LockFile() | ||
{ | ||
Version = Constants.LockFileVersion, | ||
Targets = new List<LockFileTarget>() | ||
{ | ||
new LockFileTarget() | ||
{ | ||
TargetFramework = Dnx451, | ||
Libraries =new LockFileTargetLibrary[] | ||
{ | ||
new LockFileTargetLibrary() | ||
{ | ||
Name = "Microsoft.Dnx.Runtime.Abstractions", | ||
Version = new SemanticVersion(runtimeVersion) | ||
} | ||
} | ||
} | ||
}, | ||
PackageLibraries = new List<LockFilePackageLibrary>() | ||
{ | ||
new LockFilePackageLibrary() | ||
{ | ||
Name = "Microsoft.Dnx.Runtime.Abstractions", | ||
Version = new SemanticVersion(runtimeVersion) | ||
}, | ||
} | ||
}; | ||
} | ||
} | ||
} |