Skip to content
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

Implemented string interpolation for increased code readability #113

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
22 changes: 11 additions & 11 deletions BrowserEfficiencyTest/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ private bool ProcessArgs(string[] args)
if (selectedWorkload == null)
{
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("The specified workload '{0}' was not found!", args[argNum]), false);
Logger.LogWriteLine($"The specified workload '{args[argNum]}' was not found!", false);
}
else
{
bool successfullyAddedScenarios = AddScenariosInWorkload(selectedWorkload);
if (!successfullyAddedScenarios)
{
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("Invalid scenario specified in workload '{0}'!", selectedWorkload.Name), false);
Logger.LogWriteLine($"Invalid scenario specified in workload '{selectedWorkload.Name}'!", false);
}
else
{
Expand Down Expand Up @@ -259,7 +259,7 @@ private bool ProcessArgs(string[] args)
else
{
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("The specified scenario '{0}' does not exist!", selectedScenario), false);
Logger.LogWriteLine($"The specified scenario '{selectedScenario}' does not exist!", false);
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ private bool ProcessArgs(string[] args)
if (!Directory.Exists(extensionsPath))
{
argumentsAreValid = false;
Logger.LogWriteLine("Invalid extensions path: " + extensionsPath, false);
Logger.LogWriteLine($"Invalid extensions path: {extensionsPath}", false);
}
else
{
Expand Down Expand Up @@ -350,7 +350,7 @@ private bool ProcessArgs(string[] args)
{
// The specified measureset is invalid.
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("The specified measureset '{0}' does not exist!", measureSet), false);
Logger.LogWriteLine($"The specified measureset '{measureSet}' does not exist!", false);
}
}

Expand Down Expand Up @@ -417,7 +417,7 @@ private bool ProcessArgs(string[] args)
if (!Directory.Exists(BrowserProfilePath))
{
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("The profile path: {0} does not exist!", BrowserProfilePath), false);
Logger.LogWriteLine($"The profile path: {BrowserProfilePath} does not exist!", false);
}
}
else
Expand All @@ -444,7 +444,7 @@ private bool ProcessArgs(string[] args)
if (!File.Exists(CredentialPath))
{
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("The credential file: {0} does not exist!", CredentialPath), false);
Logger.LogWriteLine($"The credential file: {CredentialPath} does not exist!", false);
}
}
else
Expand Down Expand Up @@ -589,7 +589,7 @@ private bool ProcessArgs(string[] args)
break;
default:
argumentsAreValid = false;
Logger.LogWriteLine(string.Format("Invalid argument encountered '{0}'", args[argNum]), false);
Logger.LogWriteLine($"Invalid argument encountered '{args[argNum]}'", false);
DisplayUsage();

break;
Expand Down Expand Up @@ -621,7 +621,7 @@ private bool ProcessArgs(string[] args)
}
}

Logger.LogWriteLine(string.Format("BrowserEfficiencyTest Version: {0}", BrowserEfficiencyTestVersion), false);
Logger.LogWriteLine($"BrowserEfficiencyTest Version: {BrowserEfficiencyTestVersion}", false);

if (args.Length == 0)
{
Expand Down Expand Up @@ -682,12 +682,12 @@ private void DisplayAvailableWorkloads()
Logger.LogWriteLine("Available workloads and scenarios:", false);
foreach (var workload in _workloads)
{
Logger.LogWriteLine(string.Format("Workload: {0}", workload.Name), false);
Logger.LogWriteLine($"Workload: {workload.Name}", false);
Logger.LogWriteLine(" Scenarios:", false);

foreach (var scenario in workload.Scenarios)
{
Logger.LogWriteLine(string.Format(" {0}", scenario.ScenarioName), false);
Logger.LogWriteLine($" {scenario.ScenarioName}", false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BrowserEfficiencyTest/CredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public UserInfo GetCredentials(string domain)
return item;
}
}
throw new Exception("No credentials matching domain '" + domain + "' were found in " + _credentialsPath);
throw new Exception($"No credentials matching domain '{domain}' were found in {_credentialsPath}");
}
}
}
4 changes: 2 additions & 2 deletions BrowserEfficiencyTest/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static class Logger
public static void SetupFileLogging(string path = null)
{
string _logPath = null;
string fileName = string.Format("BrowserEfficiencyTestLog" + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt");
string fileName = String.Format("BrowserEfficiencyTestLog_{0}.txt", DateTime.Now.ToString("yyyyMMdd_HHmmss"));

if (string.IsNullOrEmpty(path) )
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public static void LogWriteLine(string logString, bool includeDateTimeStamp = tr
if (includeDateTimeStamp)
{
// prefix log message with the current date-time stamp
dateTimeStamp = string.Format("[{0}] ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
dateTimeStamp = $"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] ";
}

string logEntry = dateTimeStamp + logString;
Expand Down
16 changes: 8 additions & 8 deletions BrowserEfficiencyTest/RemoteWebDriverExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void CreateNewTab(this RemoteWebDriver remoteWebDriver)
// sanity check to make sure we in fact did get a new tab opened.
if (endingTabCount != (originalTabCount + 1))
{
throw new Exception(string.Format("New tab was not created as expected! Expected {0} tabs but found {1} tabs.", (originalTabCount + 1), endingTabCount));
throw new Exception($"New tab was not created as expected! Expected {originalTabCount + 1} tabs but found {endingTabCount} tabs.");
}

// Go to that tab
Expand Down Expand Up @@ -280,7 +280,7 @@ public static void ClickElement(this RemoteWebDriver remoteWebDriver, IWebElemen
{
attempt++;

Logger.LogWriteLine("Failed attempt " + attempt + " to click element " + element.ToString());
Logger.LogWriteLine($"Failed attempt {attempt} to click element {element.ToString()}");

Thread.Sleep(1000);

Expand Down Expand Up @@ -353,7 +353,7 @@ public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clear
edgeOptions.AddAdditionalCapability("extensionPaths", extensionPaths);
foreach (var path in extensionPaths)
{
Logger.LogWriteLine("Sideloading extension(s) from " + path);
Logger.LogWriteLine($"Sideloading extension(s) from {path}");
}
}

Expand All @@ -372,7 +372,7 @@ public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clear
_port = edgeDriverService.Port;
_hostName = hostName;

Logger.LogWriteLine(string.Format(" Instantiating EdgeDriver object for local execution - Host: {0} Port: {1}", _hostName, _port));
Logger.LogWriteLine($" Instantiating EdgeDriver object for local execution - Host: {_hostName} Port: {_port}");
ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
driver = new EdgeDriver(edgeDriverService, edgeOptions);
}
Expand All @@ -388,7 +388,7 @@ public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clear
_hostName = hostName;
var remoteUri = new Uri("http://" + _hostName + ":" + _port + "/");

Logger.LogWriteLine(string.Format(" Instantiating RemoteWebDriver object for remote execution - Host: {0} Port: {1}", _hostName, _port));
Logger.LogWriteLine($" Instantiating RemoteWebDriver object for remote execution - Host: {_hostName} Port: {_port}");
ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
driver = new RemoteWebDriver(remoteUri, edgeOptions.ToCapabilities());
}
Expand All @@ -406,10 +406,10 @@ public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clear
}

_edgeBrowserBuildNumber = GetEdgeBuildNumber(driver);
Logger.LogWriteLine(string.Format(" Browser Version - MicrosoftEdge Build Version: {0}", _edgeBrowserBuildNumber));
Logger.LogWriteLine($" Browser Version - MicrosoftEdge Build Version: {_edgeBrowserBuildNumber}");

_edgeWebDriverBuildNumber = GetEdgeWebDriverVersion(driver);
Logger.LogWriteLine(string.Format(" WebDriver Server Version - MicrosoftWebDriver.exe File Version: {0}", _edgeWebDriverBuildNumber));
Logger.LogWriteLine($" WebDriver Server Version - MicrosoftWebDriver.exe File Version: {_edgeWebDriverBuildNumber}");

break;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ private static int GetEdgeBuildNumber(RemoteWebDriver remoteWebDriver)
}
else
{
Logger.LogWriteLine(string.Format(" Unable to extract Edge build version from {0}", edgeVersionToken));
Logger.LogWriteLine($" Unable to extract Edge build version from {edgeVersionToken}");
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions BrowserEfficiencyTest/ResponsivenessTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace BrowserEfficiencyTest
internal class ResponsivenessTimer
{
private List<List<String>> _results;
private string _currentSceanrio;
private string _currentScenario;
private int _iteration;
private string _browser;
private string _measureSet;
Expand Down Expand Up @@ -56,27 +56,27 @@ public void SetBrowser(string browser, Dictionary<string, string> extensionsName
{
foreach (var extension in extensionsNameAndVersion)
{
_browser = _browser + "|" + extension.Key + " " + extension.Value;
_browser = $"{_browser}|{extension.Key} {extension.Value}";
}
}
}

/// <summary>
/// Sets the measureSet, which will be included when a measurement is recorded later.
/// </summary>
/// <param name="measureSet"></param>
/// <param name="measureSet">The current measureset</param>
public void SetMeasureSet(string measureSet)
{
_measureSet = measureSet;
}

/// <summary>
/// Sets the sceanrio, which will be included when a measurement is recorded later.
/// Sets the scenario, which will be included when a measurement is recorded later.
/// </summary>
/// <param name="scenario">The current scenario</param>
public void SetScenario(string scenario)
{
_currentSceanrio = scenario;
_currentScenario = scenario;
}

/// <summary>
Expand Down Expand Up @@ -105,16 +105,16 @@ public List<string> GetResults()
List<string> results = new List<string>();
foreach (List<string> result in _results)
{
string resultString = "";
StringBuilder resultString = new StringBuilder();
foreach(string component in result)
{
if (resultString != "")
if (resultString.ToString() != "")
{
resultString += ",";
resultString.Append(",");
}
resultString += component;
resultString.Append(component);
}
results.Add(resultString);
results.Add(resultString.ToString());
}
return results;
}
Expand All @@ -134,7 +134,7 @@ public void ExtractPageLoadTime(string pageLoaded = null)
string measureName = "Page Load Time (ms)";
if (pageLoaded != null && pageLoaded != "")
{
measureName += ": " + pageLoaded;
measureName += $": {pageLoaded}";
}
MakeRecord(measureName, timeToLoad.ToString());
}
Expand All @@ -152,12 +152,12 @@ private void MakeRecord(string measure, string result)
DateTime now = DateTime.Now;
List<String> record = new List<String>();
record.Add("no_etl");
record.Add(_currentSceanrio);
record.Add(_currentScenario);
record.Add(_iteration.ToString());
record.Add(_browser);
record.Add(now.ToString("yyyyMMdd"));
record.Add(now.ToString("HHmmss"));
record.Add("responsiveness (" + _measureSet + ")");
record.Add($"responsiveness ({_measureSet})");
record.Add(measure);
record.Add(result);
_results.Add(record);
Expand Down
Loading