ConfigStatus TryParseQueryString(string queryString, out IEnumerable <QueryParam> outParams) { if (string.IsNullOrEmpty(queryString)) { outParams = Enumerable.Empty <QueryParam>(); return(ConfigStatus.OkStatus()); } try { NameValueCollection nameValueCollection; try { // May throw an exception when maximum number of keys is exceeded. nameValueCollection = HttpUtility.ParseQueryString(queryString); } catch (Exception e) { throw new ApplicationException(e.Message); } var queryParams = new List <QueryParam>(); foreach (string key in nameValueCollection.AllKeys) { if (string.IsNullOrWhiteSpace(key)) { throw new ApplicationException("Parameter 'Key' can not be empty."); } queryParams.Add( new QueryParam() { Name = key, Value = nameValueCollection.Get(key) }); } LogQueryString(queryString, queryParams); outParams = queryParams; return(ConfigStatus.OkStatus()); } catch (ApplicationException e) { Trace.TraceWarning($"Error happened while parsing query string. {e.Message}"); outParams = null; return(ConfigStatus.WarningStatus(ErrorStrings.QueryParametersWrongFormat)); } }
public void CreateWarningStatusTest() { string message = "warning Message"; ConfigStatus status = ConfigStatus.WarningStatus(message); Assert.That(status.IsOk, Is.EqualTo(false)); Assert.That(status.IsWarningLevel, Is.EqualTo(true)); Assert.That(status.IsErrorLevel, Is.EqualTo(false)); Assert.That(status.AllMessages, Is.EqualTo(new [] { message })); Assert.That(status.ErrorMessages, Is.Empty); Assert.That(status.WarningMessages, Is.EqualTo(new[] { message })); Assert.That(status.WarningMessage, Is.EqualTo(message)); Assert.That(status.SeverityLevel, Is.EqualTo(ConfigStatus.ErrorLevel.Warning)); Assert.That(status.MessagesByErrorLevel(ConfigStatus.ErrorLevel.Ok), Is.Null); Assert.That(status.MessagesByErrorLevel(ConfigStatus.ErrorLevel.Warning), Is.EqualTo(new[] { message })); Assert.That(status.MessagesByErrorLevel(ConfigStatus.ErrorLevel.Error), Is.Empty); }
ConfigStatus StatusBySeverityLevel(ConfigStatus.ErrorLevel level, string message) { switch (level) { case ConfigStatus.ErrorLevel.Ok: return(ConfigStatus.OkStatus()); case ConfigStatus.ErrorLevel.Warning: return(ConfigStatus.WarningStatus(message)); case ConfigStatus.ErrorLevel.Error: return(ConfigStatus.ErrorStatus(message)); default: throw new ArgumentOutOfRangeException(nameof(level), level, "Unsupported error level value received."); } }