using System; using System.Drawing; using Moq; using Xamarin.PropertyEditing.Drawing; namespace Xamarin.PropertyEditing.Tests { static class Helpers { public static void SetTarget (this Mock editor, object target) { editor.SetupGet (e => e.Target).Returns (target); editor.SetupGet (oe => oe.TargetType).Returns (target.GetType ().ToTypeInfo ()); } public static TEnum Next(this Random rand) { if (!typeof (TEnum).IsEnum) throw new InvalidOperationException ("Can't use GetRandomValue with a non-enum type."); var values = (TEnum[])Enum.GetValues (typeof (TEnum)); var index = rand.Next (0, values.Length); return values[index]; } public static byte NextByte(this Random rand) { return (byte)rand.Next (0, 256); } public static CommonColor NextColor(this Random rand) => new CommonColor( rand.NextByte(), rand.NextByte(), rand.NextByte(), rand.NextByte()); static char[] vowels = new[] { 'a', 'e', 'i', 'o', 'u' }; static char[] consonnants = new[] { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'z' }; static char GetVowel (this Random rand) => vowels[rand.Next (0, vowels.Length)]; static char GetConsonnant (this Random rand) => consonnants[rand.Next (0, vowels.Length)]; public static string NextFilename (this Random rand, string extension) => rand.NextString () + extension; public static string NextString (this Random rand) => string.Concat ( rand.GetConsonnant (), rand.GetVowel (), rand.GetConsonnant (), rand.GetVowel (), rand.GetConsonnant (), rand.GetVowel () ); } }