-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace FineCodeCoverage.Impl | ||
{ | ||
internal class RunSettingsRetriever | ||
{ | ||
private object userSettings; | ||
|
||
public async Task<string> GetRunSettingsFileAsync(object userSettings, object testContainer) | ||
{ | ||
this.userSettings = userSettings; | ||
|
||
var runSettingsFile = GetDefaultRunSettingsFilePath(); | ||
var projectRunSettingsFile = await GetProjectRunSettingFileAsync(testContainer); | ||
|
||
if (!string.IsNullOrEmpty(projectRunSettingsFile)) | ||
{ | ||
return projectRunSettingsFile; | ||
} | ||
|
||
return runSettingsFile; | ||
} | ||
|
||
private string GetAndUpdateSolutionRunSettingsFilePath() | ||
{ | ||
return userSettings.GetType().GetMethod("GetAndUpdateSolutionRunSettingsFilePath", BindingFlags.Public | BindingFlags.Instance).Invoke(userSettings, new object[] { }) as string; | ||
} | ||
|
||
private string LastRunSettingsFilePath() | ||
{ | ||
return userSettings.GetType().GetProperty("LastRunSettingsFilePath", BindingFlags.Public | BindingFlags.Instance).GetValue(userSettings) as string; | ||
} | ||
|
||
private bool AutomaticallyDetectRunSettings() | ||
{ | ||
return (bool)userSettings.GetType().GetProperty("AutomaticallyDetectRunSettings", BindingFlags.Public | BindingFlags.Instance).GetValue(userSettings); | ||
} | ||
|
||
private string GetDefaultRunSettingsFilePath() | ||
{ | ||
string settingsFilePath = GetAndUpdateSolutionRunSettingsFilePath(); | ||
var lastRunSettingsFilePath = LastRunSettingsFilePath(); | ||
|
||
if (!string.IsNullOrEmpty(lastRunSettingsFilePath)) | ||
{ | ||
return lastRunSettingsFilePath; | ||
} | ||
|
||
if (!AutomaticallyDetectRunSettings() || string.IsNullOrEmpty(settingsFilePath)) | ||
{ | ||
return null; | ||
} | ||
|
||
return settingsFilePath; | ||
} | ||
|
||
private static async Task<string> GetProjectRunSettingFileAsync(object container) | ||
{ | ||
var projectDataProperty = container.GetType().GetProperty("ProjectData"); | ||
|
||
if (projectDataProperty != null) | ||
{ | ||
var projectData = projectDataProperty.GetValue(container); | ||
var projectRunSettingsFile = await (projectData.GetType().GetMethod("GetBuildPropertyAsync", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(projectData, new object[] { "RunSettingsFilePath", (string)null }) as Task<string>); | ||
return projectRunSettingsFile; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
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