Пример #1
0
        public static Har FixAutoGeneratedReferences(this Har har)
        {
            var pageIds = har.Log.Pages.Select(p => p.Id);

            foreach (var entry in har.Log.Entries)
            {
                entry.PageRef = pageIds.ElementAt(_random.Next(pageIds.Count()));
            }
            return(har);
        }
Пример #2
0
        /// <summary>
        /// Serialize the HTTP archive object.
        /// </summary>
        /// <param name="har">The HTTP archive object.</param>
        /// <returns>The HTTP archive string.</returns>
        /// <exception cref="InvalidOperationException">If the page ids contain duplicates or unknown page ids are referenced from an entry.</exception>
        public static string Serialize(Har har)
        {
            if (har == null)
            {
                throw new ArgumentNullException(nameof(har));
            }

            var countPages = har.Log.Pages.Count();
            var pageIds    = har.Log.Pages.Select(p => p.Id).Distinct();

            if (countPages > pageIds.Count())
            {
                throw new InvalidOperationException(Resources.PageIdsNotUnique);
            }
            if (har.Log.Entries.Any(e => !pageIds.Contains(e.PageRef)))
            {
                throw new InvalidOperationException(Resources.EntryPageRefNotFound);
            }

            return(JsonConvert.SerializeObject(har, SerializerSettings));
        }