public void RomInfoEnumerable_BogusDataData_ValuesAreRetained(RomInfoIndex romInfoIndex) { var badStringBytes = new byte[255]; for (var i = 0; i < 255; ++i) { badStringBytes[i] = (byte)(255 - i); } var badString = System.Text.Encoding.UTF8.GetString(badStringBytes, 0, badStringBytes.Length); var testValues = Enumerable.Repeat(badString, (int)RomInfoIndex.NumEntries).ToArray(); var expectedResult = System.Text.RegularExpressions.Regex.Replace(badString, @"\s+", " ").Trim(); Assert.Equal(expectedResult, testValues.GetRomInfoString(romInfoIndex)); }
/// <summary> /// Gets a specific value from an enumerable of strings. /// </summary> /// <param name="results">The results from which to extract a result.</param> /// <param name="index">The desired result to extract.</param> /// <returns>Desired value extracted from the enumerable, e.g. output from the intvname utility from the SDK-1600.</returns> public static string GetRomInfoString(this IEnumerable <string> results, RomInfoIndex index) { var result = string.Empty; if (index > RomInfoIndex.None) { var resultsCount = results.Count(); if (resultsCount > (int)index) { result = results.ElementAt((int)index); } } if (!string.IsNullOrEmpty(result)) { result = System.Text.RegularExpressions.Regex.Replace(result, @"\s+", " ").Trim(); } return(result); }
public void RomInfoEnumerable_IndexNotNoneWithNullEnumerable_ThrowsArgumentNullException(RomInfoIndex infoIndex) { IEnumerable <string> results = null; Assert.Throws <ArgumentNullException>(() => results.GetRomInfoString(infoIndex)); }