1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using System;
using System.Drawing;
using Moq;
using Xamarin.PropertyEditing.Drawing;
namespace Xamarin.PropertyEditing.Tests
{
static class Helpers
{
public static void SetTarget (this Mock<IObjectEditor> editor, object target)
{
editor.SetupGet (e => e.Target).Returns (target);
editor.SetupGet (oe => oe.TargetType).Returns (target.GetType ().ToTypeInfo ());
}
public static TEnum Next<TEnum>(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 ()
);
}
}
|