| | | 1 | | using GistBackend.Types; |
| | | 2 | | |
| | | 3 | | namespace TestUtilities; |
| | | 4 | | |
| | | 5 | | public static class RandomExtensions { |
| | | 6 | | private const string Characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
| | | 7 | | |
| | | 8 | | extension(Random random) |
| | | 9 | | { |
| | 6821 | 10 | | public string NextString(int length = 50) => new( |
| | 341050 | 11 | | Enumerable.Repeat(Characters, length).Select(s => s[random.Next(s.Length)]).ToArray() |
| | 6821 | 12 | | ); |
| | | 13 | | |
| | | 14 | | public Uri NextUri(int partLength = 50) => |
| | 607 | 15 | | new($"https://www.{random.NextString(partLength)}.com/{random.NextString(partLength)}"); |
| | | 16 | | |
| | 281 | 17 | | public string[] NextArrayOfStrings(int? length = null) => Enumerable |
| | 1839 | 18 | | .Repeat("", length ?? random.Next(1, 11)).Select(_ => random.NextString()).ToArray(); |
| | | 19 | | |
| | | 20 | | public DateTime NextDateTime(DateTime? min = null, DateTime? max = null) |
| | | 21 | | { |
| | 926 | 22 | | min ??= DateTime.UnixEpoch; |
| | 926 | 23 | | max ??= DateTime.UnixEpoch.AddYears(100); |
| | 926 | 24 | | var maxSeconds = (int)(max - min).Value.TotalSeconds; |
| | 926 | 25 | | return min.Value.AddSeconds(random.Next(maxSeconds)); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public FeedType NextFeedType() => |
| | 120 | 29 | | (FeedType)random.Next(Enum.GetValues<FeedType>().Length); |
| | | 30 | | } |
| | | 31 | | } |