-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring of RuntimeFramework and RuntimeFrameworkService #448
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
62f974e
Remove AvailableFrameworks from RuntimeFramework class and refactor
CharliePoole 0db7ddc
Add compatible implementation of FrameworkName
CharliePoole d5281c3
Add FrameworkName property to RuntimeFramework class
CharliePoole 50873d0
Code review changes
CharliePoole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
250 changes: 250 additions & 0 deletions
250
src/TestEngine/nunit.engine.core/Compatibility/FrameworkName.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,250 @@ | ||
// *********************************************************************** | ||
// Copyright (c) 2019 Charlie Poole | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// *********************************************************************** | ||
|
||
#if NET20 || NET35 | ||
using System.Diagnostics; | ||
using NUnit.Common; | ||
|
||
namespace System.Runtime.Versioning | ||
{ | ||
/// <summary> | ||
/// Compatible implementation of FrameworkName, based on the corefx implementation | ||
/// </summary> | ||
public sealed class FrameworkName : IEquatable<FrameworkName> | ||
{ | ||
private const string FRAMEWORK_NAME_INVALID = "Invalid FrameworkName"; | ||
private const string FRAMEWORK_NAME_VERSION_REQUIRED = "FramweworkName must include Version"; | ||
private const string FRAMEWORK_NAME_VERSION_INVALID = "The specified Version is invalid"; | ||
private const string FRAMEWORK_NAME_COMPONENT_COUNT = "FrameworkName must specify either two or three components"; | ||
|
||
private readonly string _identifier; | ||
private readonly Version _version = null; | ||
private readonly string _profile; | ||
private string _fullName; | ||
|
||
private const char COMPONENT_SEPARATOR = ','; | ||
private const char KEY_VALUE_SEPARATOR = '='; | ||
private const char VERSION_PREFIX = 'v'; | ||
private const string VERSION_KEY = "Version"; | ||
private const string PROFILE_KEY = "Profile"; | ||
|
||
private static readonly char[] COMPONENT_SPLIT_SEPARATOR = { COMPONENT_SEPARATOR }; | ||
|
||
public string Identifier | ||
{ | ||
get | ||
{ | ||
Debug.Assert(_identifier != null); | ||
return _identifier; | ||
} | ||
} | ||
|
||
public Version Version | ||
{ | ||
get | ||
{ | ||
Debug.Assert(_version != null); | ||
return _version; | ||
} | ||
} | ||
|
||
public string Profile | ||
{ | ||
get | ||
{ | ||
Debug.Assert(_profile != null); | ||
return _profile; | ||
} | ||
} | ||
|
||
public string FullName | ||
{ | ||
get | ||
{ | ||
if (_fullName == null) | ||
{ | ||
if (string.IsNullOrEmpty(Profile)) | ||
{ | ||
_fullName = | ||
Identifier + | ||
COMPONENT_SEPARATOR + VERSION_KEY + KEY_VALUE_SEPARATOR + VERSION_PREFIX + | ||
Version.ToString(); | ||
} | ||
else | ||
{ | ||
_fullName = | ||
Identifier + | ||
COMPONENT_SEPARATOR + VERSION_KEY + KEY_VALUE_SEPARATOR + VERSION_PREFIX + | ||
Version.ToString() + | ||
COMPONENT_SEPARATOR + PROFILE_KEY + KEY_VALUE_SEPARATOR + | ||
Profile; | ||
} | ||
} | ||
|
||
Debug.Assert(_fullName != null); | ||
return _fullName; | ||
} | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals(obj as FrameworkName); | ||
} | ||
|
||
public bool Equals(FrameworkName other) | ||
{ | ||
if (other is null) | ||
{ | ||
return false; | ||
} | ||
|
||
return Identifier == other.Identifier && | ||
Version == other.Version && | ||
Profile == other.Profile; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Identifier.GetHashCode() ^ Version.GetHashCode() ^ Profile.GetHashCode(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return FullName; | ||
} | ||
|
||
public FrameworkName(string identifier, Version version) | ||
: this(identifier, version, null) | ||
{ | ||
} | ||
|
||
public FrameworkName(string identifier, Version version, string profile=null) | ||
{ | ||
Guard.ArgumentNotNull(identifier, nameof(identifier)); | ||
Guard.ArgumentNotNull(version, nameof(version)); | ||
|
||
identifier = identifier.Trim(); | ||
Guard.ArgumentNotNullOrEmpty(identifier, nameof(identifier)); | ||
|
||
_identifier = identifier; | ||
_version = version; | ||
_profile = (profile == null) ? string.Empty : profile.Trim(); | ||
} | ||
|
||
// Parses strings in the following format: "<identifier>, Version=[v|V]<version>, Profile=<profile>" | ||
// - The identifier and version is required, profile is optional | ||
// - Only three components are allowed. | ||
// - The version string must be in the System.Version format; an optional "v" or "V" prefix is allowed | ||
public FrameworkName(string frameworkName) | ||
{ | ||
Guard.ArgumentNotNullOrEmpty(frameworkName, nameof(frameworkName)); | ||
|
||
string[] components = frameworkName.Split(COMPONENT_SPLIT_SEPARATOR); | ||
|
||
// Identifier and Version are required, Profile is optional. | ||
Guard.ArgumentValid(components.Length == 2 || components.Length == 3, | ||
FRAMEWORK_NAME_COMPONENT_COUNT, nameof(frameworkName)); | ||
|
||
// | ||
// 1) Parse the "Identifier", which must come first. Trim any whitespace | ||
// | ||
_identifier = components[0].Trim(); | ||
|
||
Guard.ArgumentValid(_identifier.Length > 0, FRAMEWORK_NAME_INVALID, nameof(frameworkName)); | ||
|
||
bool versionFound = false; | ||
_profile = string.Empty; | ||
|
||
// | ||
// The required "Version" and optional "Profile" component can be in any order | ||
// | ||
for (int i = 1; i < components.Length; i++) | ||
{ | ||
// Get the key/value pair separated by '=' | ||
string component = components[i]; | ||
int separatorIndex = component.IndexOf(KEY_VALUE_SEPARATOR); | ||
|
||
Guard.ArgumentValid(separatorIndex >= 0 && separatorIndex == component.LastIndexOf(KEY_VALUE_SEPARATOR), | ||
FRAMEWORK_NAME_INVALID, nameof(frameworkName)); | ||
|
||
// Get the key and value, trimming any whitespace | ||
string key = component.Substring(0, separatorIndex).Trim(); | ||
string value = component.Substring(separatorIndex + 1).Trim(); | ||
|
||
// | ||
// 2) Parse the required "Version" key value | ||
// | ||
if (key.Equals(VERSION_KEY, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
versionFound = true; | ||
|
||
// Allow the version to include a 'v' or 'V' prefix... | ||
if (value.Length > 0 && (value[0] == VERSION_PREFIX || value[0] == 'V')) | ||
value = value.Substring(1); | ||
|
||
try | ||
{ | ||
_version = new Version(value); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new ArgumentException(FRAMEWORK_NAME_VERSION_INVALID, nameof(frameworkName), e); | ||
} | ||
Comment on lines
+205
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use |
||
} | ||
// | ||
// 3) Parse the optional "Profile" key value | ||
// | ||
else if (key.Equals(PROFILE_KEY, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value.Length > 0) | ||
{ | ||
_profile = value.ToString(); | ||
} | ||
} | ||
else | ||
{ | ||
throw new ArgumentException(FRAMEWORK_NAME_INVALID, nameof(frameworkName)); | ||
} | ||
} | ||
|
||
if (!versionFound) | ||
throw new ArgumentException(FRAMEWORK_NAME_VERSION_REQUIRED, nameof(frameworkName)); | ||
} | ||
|
||
public static bool operator ==(FrameworkName left, FrameworkName right) | ||
{ | ||
if (left is null) | ||
{ | ||
return right is null; | ||
} | ||
|
||
return left.Equals(right); | ||
} | ||
|
||
public static bool operator !=(FrameworkName left, FrameworkName right) | ||
{ | ||
return !(left == right); | ||
} | ||
} | ||
} | ||
#endif |
106 changes: 0 additions & 106 deletions
106
src/TestEngine/nunit.engine.core/Internal/RuntimeFrameworks/DotNetFrameworkLocator.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing around
=
.