Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>CapMonsterCloud.Client.IntegrationTests</RootNamespace>
Expand Down
195 changes: 97 additions & 98 deletions CapMonsterCloud.Client.IntegrationTests/Gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,123 +3,122 @@
using System.Linq;
using System.Security.Cryptography;

namespace CapMonsterCloud.Client.IntegrationTests
namespace CapMonsterCloud.Client.IntegrationTests;

public static class Gen
{
public static class Gen
private static readonly Random Rnd = new();

public static int RandomInt()
{
private static readonly Random Rnd = new();
return RandomInt(
minValue: int.MinValue,
maxValue: int.MaxValue);
}

public static int RandomInt()
{
return RandomInt(
minValue: int.MinValue,
maxValue: int.MaxValue);
}
public static int RandomInt(
int minValue,
int maxValue = int.MaxValue)
{
return Rnd.Next(
minValue: minValue,
maxValue: maxValue);
}

public static int RandomInt(
int minValue,
int maxValue = int.MaxValue)
public static long RandomLong(
long minValue,
long maxValue)
{
if (maxValue <= minValue)
{
return Rnd.Next(
minValue: minValue,
maxValue: maxValue);
throw new ArgumentOutOfRangeException(nameof(maxValue), "max must be > min!");
}

public static long RandomLong(
long minValue,
long maxValue)
{
if (maxValue <= minValue)
{
throw new ArgumentOutOfRangeException(nameof(maxValue), "max must be > min!");
}

ulong uRange = (ulong)(maxValue - minValue);

ulong ulongRand;
do
{
byte[] buf = new byte[8];
Rnd.NextBytes(buf);
ulongRand = (ulong)BitConverter.ToInt64(buf, 0);
}
while (ulongRand > ulong.MaxValue - (((ulong.MaxValue % uRange) + 1) % uRange));

return (long)(ulongRand % uRange) + minValue;
}
ulong uRange = (ulong)(maxValue - minValue);

public static decimal RandomDecimal()
ulong ulongRand;
do
{
return RandomDecimal(
minValue: decimal.MinValue,
maxValue: decimal.MaxValue);
byte[] buf = new byte[8];
Rnd.NextBytes(buf);
ulongRand = (ulong)BitConverter.ToInt64(buf, 0);
}
while (ulongRand > ulong.MaxValue - (((ulong.MaxValue % uRange) + 1) % uRange));

public static decimal RandomDecimal(
decimal minValue,
decimal maxValue)
{
return Convert.ToDecimal(RandomDouble((double)minValue, (double)maxValue));
}
return (long)(ulongRand % uRange) + minValue;
}

public static double RandomDouble(
double minValue,
double maxValue) =>
minValue + (Rnd.NextDouble() * (maxValue - minValue));
public static decimal RandomDecimal()
{
return RandomDecimal(
minValue: decimal.MinValue,
maxValue: decimal.MaxValue);
}

public static string RandomString()
{
return RandomString(36);
}

public static string RandomString(int length)
{
var values = Enumerable.Repeat(0, (length / 36) + 1).Select(x => Guid.NewGuid().ToString());
return string.Join(string.Empty, values).Substring(0, length);
}
public static decimal RandomDecimal(
decimal minValue,
decimal maxValue)
{
return Convert.ToDecimal(RandomDouble((double)minValue, (double)maxValue));
}

public static T RandomElement<T>(this IEnumerable<T> elements) =>
elements.OrderBy(x => RandomString()).First();
public static double RandomDouble(
double minValue,
double maxValue) =>
minValue + (Rnd.NextDouble() * (maxValue - minValue));

public static T RandomEnum<T>()
{
var enumValues = Enum.GetValues(typeof(T)).Cast<T>();
return enumValues.RandomElement();
}
public static string RandomString()
{
return RandomString(36);
}

public static string RandomString(int length)
{
var values = Enumerable.Repeat(0, (length / 36) + 1).Select(x => Guid.NewGuid().ToString());
return string.Join(string.Empty, values).Substring(0, length);
}

public static List<T> ListOfValues<T>(Func<T> createFunc) =>
ListOfValues(createFunc, 5);
public static T RandomElement<T>(this IEnumerable<T> elements) =>
elements.OrderBy(x => RandomString()).First();

public static List<T> ListOfValues<T>(Func<T> createFunc, int count)
{
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
return Enumerable.Repeat(0, count).Select(x => createFunc()).ToList();
}
public static T RandomEnum<T>()
{
var enumValues = Enum.GetValues(typeof(T)).Cast<T>();
return enumValues.RandomElement();
}

public static T[] ArrayOfValues<T>(Func<T> createFunc) =>
ArrayOfValues(createFunc, 5);
public static List<T> ListOfValues<T>(Func<T> createFunc) =>
ListOfValues(createFunc, 5);

public static T[] ArrayOfValues<T>(Func<T> createFunc, int count)
{
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
return Enumerable.Repeat(0, count).Select(x => createFunc()).ToArray();
}
public static List<T> ListOfValues<T>(Func<T> createFunc, int count)
{
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
return Enumerable.Repeat(0, count).Select(x => createFunc()).ToList();
}

public static bool RandomBool() => Rnd.NextDouble() >= 0.5;

public static string RandomGuid()
{
return Guid.NewGuid().ToString();
}

public static string UserAgent()
{
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36";
}

public static Uri RandomUri()
{
return new Uri($"https://{RandomString()}.zennolab.com");
}
public static T[] ArrayOfValues<T>(Func<T> createFunc) =>
ArrayOfValues(createFunc, 5);

public static T[] ArrayOfValues<T>(Func<T> createFunc, int count)
{
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
return Enumerable.Repeat(0, count).Select(x => createFunc()).ToArray();
}

public static bool RandomBool() => Rnd.NextDouble() >= 0.5;

public static string RandomGuid()
{
return Guid.NewGuid().ToString();
}

public static string UserAgent()
{
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36";
}

public static Uri RandomUri()
{
return new Uri($"https://{RandomString()}.zennolab.com");
}
}
Loading