Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Updated all string for Utilities #684

Merged
merged 5 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Framework/Utilities/Helper/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static void Validate(ConfigSection configSection, ConfigValidation config
{
if (!configSectionPassed.ContainsKey(requiredField))
{
exceptions.Add("Key missing " + requiredField);
exceptions.Add($"Key missing {requiredField}");
}
}

Expand Down Expand Up @@ -489,7 +489,7 @@ private static IEnumerable<KeyValuePair<string, string>> GetXml()

if (attributes.Any(x => x.Name.LocalName.Equals("key")) && attributes.Any(y => y.Name.LocalName.Equals("value")))
{
keys.Add(node.Name.LocalName + ":" + config.Attribute("key").Value, config.Attribute("value").Value);
keys.Add($"{node.Name.LocalName}:{config.Attribute("key").Value}", config.Attribute("value").Value);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions Framework/Utilities/Helper/GenericWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void WaitFor(Func<bool> waitForTrue)
{
if (!Wait(waitForTrue, retryTimeFromConfig, timeoutFromConfig, true))
{
throw new TimeoutException(StringProcessor.SafeFormatter("Timed out waiting for '{0}' to return true", waitForTrue.Method.Name));
throw new TimeoutException(StringProcessor.SafeFormatter($"Timed out waiting for '{waitForTrue.Method.Name}' to return true"));
}
}

Expand All @@ -71,7 +71,7 @@ public static void WaitFor<T>(Func<T, bool> waitForTrue, T arg)
{
if (!Wait(waitForTrue, retryTimeFromConfig, timeoutFromConfig, true, arg))
{
throw new TimeoutException(StringProcessor.SafeFormatter("Timed out waiting for '{0}' to return true", waitForTrue.Method.Name));
throw new TimeoutException(StringProcessor.SafeFormatter($"Timed out waiting for '{waitForTrue.Method.Name}' to return true"));
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public static void WaitForMatch<T>(Func<T> waitForTrue, T comparativeValue)

if (!paramsAreEqual)
{
throw new TimeoutException("Timed out waiting for " + waitForTrue.Method.Name + " to return expected value of " + typeof(T) + ": " + comparativeValue);
throw new TimeoutException($"Timed out waiting for {waitForTrue.Method.Name} to return expected value of {typeof(T)}: {comparativeValue}");
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ public static void WaitForMatch<T>(Func<T> waitForTrue, TimeSpan retryTime, Time

if (!paramsAreEqual)
{
throw new TimeoutException("Timed out waiting for " + waitForTrue.Method.Name + " to return expected value of " + typeof(T) + ": " + comparativeValue);
throw new TimeoutException($"Timed out waiting for {waitForTrue.Method.Name} to return expected value of {typeof(T)}: {comparativeValue}");
}
}

Expand Down Expand Up @@ -366,7 +366,7 @@ public static T Wait<T>(Func<T> waitFor, TimeSpan retryTime, TimeSpan timeout)
}
while ((DateTime.Now - start) < timeout);

throw new TimeoutException("Timed out waiting for " + waitFor.Method.Name + " to return", exception);
throw new TimeoutException($"Timed out waiting for {waitFor.Method.Name} to return", exception);
}

/// <summary>
Expand Down Expand Up @@ -401,7 +401,7 @@ public static T Wait<T, U>(Func<U, T> waitFor, TimeSpan retryTime, TimeSpan time
}
while ((DateTime.Now - start) < timeout);

throw new TimeoutException("Timed out waiting for " + waitFor.Method.Name + " to return", exception);
throw new TimeoutException($"Timed out waiting for {waitFor.Method.Name} to return", exception);
}

/// <summary>
Expand Down Expand Up @@ -449,7 +449,7 @@ public static T WaitForAnyAction<T>(string actionName, TimeSpan waitTime, TimeSp
}
while (DateTime.Now < maxWait);

throw new TimeoutException("Timed out waiting for " + actionName + " to return. Exception log: " + sb.ToString());
throw new TimeoutException($"Timed out waiting for {actionName} to return. Exception log: {sb.ToString()}");
}

/// <summary>
Expand Down Expand Up @@ -671,7 +671,7 @@ public static T WaitUntilTimeout<T>(Func<T> waitFor, TimeSpan retryTime, TimeSpa
}
}

throw new TimeoutException("Timed out waiting for " + waitFor.Method.Name + " to return", exception);
throw new TimeoutException($"Timed out waiting for {waitFor.Method.Name} to return", exception);
}

/// <summary>
Expand Down Expand Up @@ -713,7 +713,7 @@ public static T WaitUntilTimeout<T, U>(Func<U, T> waitFor, TimeSpan retryTime, T
}
}

throw new TimeoutException("Timed out waiting for " + waitFor.Method.Name + " to return", exception);
throw new TimeoutException($"Timed out waiting for {waitFor.Method.Name} to return", exception);
}

/// <summary>
Expand Down
13 changes: 4 additions & 9 deletions Framework/Utilities/Helper/ListProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static string CreateCommaDelimitedString(List<string> stringList, bool so
}
else
{
commaDelimitedString.Append(StringProcessor.SafeFormatter(", {0}", text));
commaDelimitedString.Append(StringProcessor.SafeFormatter($", {text}"));
}
}

Expand All @@ -61,12 +61,7 @@ public static bool ListOfStringsComparer(List<string> expectedList, List<string>
{
results.Append(
StringProcessor.SafeFormatter(
"The following lists are not the same size: Expected {0} [{1}] {2} and got {3} [{4}]",
Environment.NewLine,
CreateCommaDelimitedString(expectedList),
Environment.NewLine,
Environment.NewLine,
CreateCommaDelimitedString(actualList)));
$"The following lists are not the same size: Expected {Environment.NewLine} [{CreateCommaDelimitedString(expectedList)}] {Environment.NewLine} and got {Environment.NewLine} [{CreateCommaDelimitedString(actualList)}]"));
}

// Clone the first list
Expand All @@ -83,7 +78,7 @@ public static bool ListOfStringsComparer(List<string> expectedList, List<string>
{
if (!clonedList.Contains(expectedValue))
{
results.Append(StringProcessor.SafeFormatter("[{0}] was not found in the list but was expected{1}", expectedValue, Environment.NewLine));
results.Append(StringProcessor.SafeFormatter($"[{expectedValue}] was not found in the list but was expected{Environment.NewLine}"));
}
else
{
Expand All @@ -93,7 +88,7 @@ public static bool ListOfStringsComparer(List<string> expectedList, List<string>
}
else if (clonedList[i] == null || !clonedList[i].Equals(expectedValue))
{
results.Append(StringProcessor.SafeFormatter("Expected [{0}] but found [{1}]{2}", expectedValue, clonedList[i], Environment.NewLine));
results.Append(StringProcessor.SafeFormatter($"Expected [{expectedValue}] but found [{clonedList[i]}]{Environment.NewLine}"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Framework/Utilities/Logging/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void SetColorWriteAndRestore(MessageType type, bool line, string message
}
catch (Exception e)
{
Console.WriteLine(StringProcessor.SafeFormatter("Failed to write to the console because: {0}", e.Message));
Console.WriteLine(StringProcessor.SafeFormatter($"Failed to write to the console because: {e.Message}"));
}

// Cleanup after yourself
Expand Down
6 changes: 3 additions & 3 deletions Framework/Utilities/Logging/FileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public override void LogMessage(MessageType messageType, string message, params
using (StreamWriter writer = new StreamWriter(this.FilePath, true))
{
string date = DateTime.UtcNow.ToString(Logger.DEFAULTDATEFORMAT, CultureInfo.InvariantCulture);
writer.WriteLine(StringProcessor.SafeFormatter("{0}{1}", Environment.NewLine, date));
writer.Write(StringProcessor.SafeFormatter("{0}:\t", messageType.ToString()));
writer.WriteLine(StringProcessor.SafeFormatter($"{Environment.NewLine}{date}"));
writer.Write(StringProcessor.SafeFormatter($"{messageType.ToString()}:\t"));

writer.WriteLine(StringProcessor.SafeFormatter(message, args));
}
Expand All @@ -127,7 +127,7 @@ public override void LogMessage(MessageType messageType, string message, params
{
// Failed to write to the event log, write error to the console instead
ConsoleLogger console = new ConsoleLogger();
console.LogMessage(MessageType.ERROR, StringProcessor.SafeFormatter("Failed to write to event log because: {0}", e.Message));
console.LogMessage(MessageType.ERROR, StringProcessor.SafeFormatter($"Failed to write to event log because: {e.Message}"));
console.LogMessage(messageType, message, args);
}
}
Expand Down
8 changes: 2 additions & 6 deletions Framework/Utilities/Logging/HtmlFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,14 @@ public override void LogMessage(MessageType messageType, string message, params
using (StreamWriter writer = new StreamWriter(this.FilePath, true))
{
writer.Write(StringProcessor.SafeFormatter(
"<div class='collapse col-12 show' data-logtype='{0}'><div class='card'><div class='card-body {1}'><h5 class='card-title mb-1'>{0}</h5><h6 class='card-subtitle mb-1'>{2}</h6><p class='card-text'>{3}</p></div></div></div>",
messageType.ToString(),
GetTextWithColorFlag(messageType),
date,
HttpUtility.HtmlEncode(StringProcessor.SafeFormatter(message, args))));
$"<div class='collapse col-12 show' data-logtype='{messageType.ToString()}'><div class='card'><div class='card-body {GetTextWithColorFlag(messageType)}'><h5 class='card-title mb-1'>{messageType.ToString()}</h5><h6 class='card-subtitle mb-1'>{date}</h6><p class='card-text'>{HttpUtility.HtmlEncode(StringProcessor.SafeFormatter(message, args))}</p></div></div></div>"));
}
}
catch (Exception e)
{
// Failed to write to the event log, write error to the console instead
ConsoleLogger console = new ConsoleLogger();
console.LogMessage(MessageType.ERROR, StringProcessor.SafeFormatter("Failed to write to event log because: {0}", e.Message));
console.LogMessage(MessageType.ERROR, StringProcessor.SafeFormatter($"Failed to write to event log because: {e.Message}"));
console.LogMessage(messageType, message, args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/Utilities/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected bool ShouldMessageBeLogged(MessageType messageType)
/// <returns>The unknown message type message</returns>
protected string UnknownMessageTypeMessage(MessageType type)
{
return StringProcessor.SafeFormatter("Unknown MessageType: {0}{1}{2}{3}", Enum.GetName(typeof(MessageType), type), Environment.NewLine, "Message will be displayed with the MessageType of: ", Enum.GetName(typeof(MessageType), MessageType.GENERIC));
return StringProcessor.SafeFormatter($"Unknown MessageType: {Enum.GetName(typeof(MessageType), type)}{Environment.NewLine}Message will be displayed with the MessageType of: {Enum.GetName(typeof(MessageType), MessageType.GENERIC)}");
}
}
}
6 changes: 3 additions & 3 deletions Framework/Utilities/Logging/LoggingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static LoggingEnabled GetLoggingEnabledSetting()
case "NO":
return LoggingEnabled.NO;
default:
throw new ArgumentException(StringProcessor.SafeFormatter("Log value '{0}' is not a valid option", Config.GetGeneralValue("Log", "NO")));
throw new ArgumentException(StringProcessor.SafeFormatter($"Log value '{Config.GetGeneralValue("Log", "NO")}' is not a valid option"));
}
}

Expand Down Expand Up @@ -63,7 +63,7 @@ public static MessageType GetLoggingLevelSetting()
case "SUSPENDED":
return MessageType.SUSPENDED; // All logging is suspended
default:
throw new ArgumentException(StringProcessor.SafeFormatter("Logging level value '{0}' is not a valid option", Config.GetGeneralValue("LogLevel")));
throw new ArgumentException(StringProcessor.SafeFormatter($"Logging level value '{Config.GetGeneralValue("LogLevel")}' is not a valid option"));
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public static Logger GetLogger(string fileName)
case "HTM":
return new HtmlFileLogger(logDirectory, fileName, GetLoggingLevelSetting());
default:
throw new ArgumentException(StringProcessor.SafeFormatter("Log type '{0}' is not a valid option", Config.GetGeneralValue("LogType", "CONSOLE")));
throw new ArgumentException(StringProcessor.SafeFormatter($"Log type '{Config.GetGeneralValue("LogType", "CONSOLE")}' is not a valid option"));
}
}

Expand Down
14 changes: 7 additions & 7 deletions Framework/Utilities/Performance/PerfTimerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void StartTimer(string contextName, string timerName)
{
if (this.openTimerList.ContainsKey(timerName))
{
throw new ArgumentException("Timer already Started: " + timerName);
throw new ArgumentException($"Timer already Started: {timerName}");
}
else
{
this.Log.LogMessage(MessageType.INFORMATION, "Starting response timer: {0}", timerName);
this.Log.LogMessage(MessageType.INFORMATION, $"Starting response timer: {timerName}");
PerfTimer timer = new PerfTimer();
timer.TimerName = timerName;
timer.TimerContext = contextName;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void StopTimer(string timerName)
}
else
{
this.Log.LogMessage(MessageType.INFORMATION, "Stopping response time test: {0}", timerName);
this.Log.LogMessage(MessageType.INFORMATION, $"Stopping response time test: {timerName}");
this.openTimerList[timerName].EndTime = et;
this.openTimerList[timerName].Duration = this.openTimerList[timerName].EndTime - this.openTimerList[timerName].StartTime;
this.Timerlist.Add(this.openTimerList[timerName]);
Expand All @@ -161,16 +161,16 @@ public void Write(Logger log)
// If filename doesn't exist, we haven't created the file yet
if (this.FileName == null)
{
this.FileName = "PerformanceTimerResults" + "-" + this.TestName + "-" + DateTime.UtcNow.ToString("O").Replace(':', '-') + ".xml";
this.FileName = $"PerformanceTimerResults-{this.TestName}-{DateTime.UtcNow.ToString("O").Replace(':', '-')}.xml";
}

log.LogMessage(MessageType.INFORMATION, "filename: " + LoggingConfig.GetLogDirectory() + Path.DirectorySeparatorChar + this.FileName);
log.LogMessage(MessageType.INFORMATION, $"filename: {LoggingConfig.GetLogDirectory()}{Path.DirectorySeparatorChar}{this.FileName}");

XmlWriterSettings settings = new XmlWriterSettings();
settings.WriteEndDocumentOnClose = true;
settings.Indent = true;

XmlWriter writer = XmlWriter.Create(string.Format("{0}{2}{1}", LoggingConfig.GetLogDirectory(), this.FileName, Path.DirectorySeparatorChar), settings);
XmlWriter writer = XmlWriter.Create($"{LoggingConfig.GetLogDirectory()}{Path.DirectorySeparatorChar}{this.FileName}", settings);

XmlSerializer x = new XmlSerializer(this.GetType());
x.Serialize(writer, this);
Expand All @@ -180,7 +180,7 @@ public void Write(Logger log)
}
catch (Exception e)
{
log.LogMessage(MessageType.ERROR, "Could not save response time file. Error was: {0}", e.Message);
log.LogMessage(MessageType.ERROR, $"Could not save response time file. Error was: {e.Message}");
}
}
}
Expand Down