public void DebuggerAttributesValid <TKey, TElement>(System.Linq.IGrouping <TKey, TElement> grouping, string keyString) { Assert.Equal($"Key = {keyString}", DebuggerAttributes.ValidateDebuggerDisplayReferences(grouping)); object proxyObject = DebuggerAttributes.GetProxyObject(grouping); // Validate proxy fields Assert.Empty(DebuggerAttributes.GetDebuggerVisibleFields(proxyObject.GetType())); // Validate proxy properties IEnumerable <PropertyInfo> properties = DebuggerAttributes.GetDebuggerVisibleProperties(proxyObject.GetType()); Assert.Equal(2, properties.Count()); // Key TKey key = (TKey)properties.Single(property => property.Name == "Key").GetValue(proxyObject); Assert.Equal(grouping.Key, key); // Values PropertyInfo valuesProperty = properties.Single(property => property.Name == "Values"); Assert.Equal(DebuggerBrowsableState.RootHidden, DebuggerAttributes.GetDebuggerBrowsableState(valuesProperty)); TElement[] values = (TElement[])valuesProperty.GetValue(proxyObject); Assert.IsType <TElement[]>(values); // Arrays can be covariant / of assignment-compatible types Assert.Equal(grouping, values); Assert.Same(values, valuesProperty.GetValue(proxyObject)); // The result should be cached, as Grouping is immutable. }
private static void LogRedirectedUrls(DateTime logStamp, System.Linq.IGrouping <int, UrlTransformResult> initialRedirectSuccesses, int TotalRequests) { var log = CreateLog(logStamp, "Redirects"); log.WriteLine("Old Url, Target Url, Actual Url, Response Code, Redirect Same as Target"); List <UrlTransform> ThreeOOnes = initialRedirectSuccesses.Select(x => new UrlTransform { OldUrl = x.SourceUrls.OldUrl, NewUrl = x.SourceUrls.NewUrl }).ToList(); IEnumerable <UrlTransformResult> redirectResults = new List <UrlTransformResult>(); try { redirectResults = GetUrlResults(ThreeOOnes, true).OrderBy(x => (int)x.Response.Result.StatusCode); } catch (System.AggregateException AgEx) { RecurseInnerExceptions(AgEx); } if (redirectResults.Any()) { foreach (var result in redirectResults) { if (result.Response.IsCanceled || result.Response.IsFaulted) { log.WriteLine(String.Format("<<<<<<< ERROR {0} >>>>>>>", result.SourceUrls.OldUrl)); } else { bool NewUrlAndActualRedirectUrlMatch = (result.Response.Result.RequestMessage.RequestUri.LocalPath.ToLower() == result.SourceUrls.NewUrl.ToLower()); log.WriteLine(String.Format("{0},{1},{2},{3},{4}", result.SourceUrls.OldUrl, result.SourceUrls.NewUrl, result.Response.Result.RequestMessage.RequestUri.LocalPath, (int)result.Response.Result.StatusCode, NewUrlAndActualRedirectUrlMatch.ToString())); } } Console.WriteLine("Total Requests = " + TotalRequests.ToString()); var FailedRequests = redirectResults.GroupBy(x => (int)x.Response.Result.StatusCode).ToList(); Console.WriteLine("Request summary:"); foreach (var group in FailedRequests) { Console.WriteLine("\tResponse code: " + group.Key + " (" + group.Count().ToString() + ")"); } } LogFilePaths.Add(((FileStream)(log.BaseStream)).Name); log.Close(); }