Initial commit
This commit is contained in:
commit
595820961e
19 changed files with 4921 additions and 0 deletions
59
Mosaic.Test/TestBase.cs
Normal file
59
Mosaic.Test/TestBase.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#region test helper class - ignore
|
||||
|
||||
global using FluentAssertions;
|
||||
global using Xunit;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mosaic.Test;
|
||||
|
||||
public abstract class TestBase
|
||||
{
|
||||
protected static bool CheckField<TClass, TField>(TClass instance, TField expectedValue, string expectedName)
|
||||
{
|
||||
var field = typeof(TClass)
|
||||
.GetField(expectedName, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (field == null
|
||||
|| field.FieldType != typeof(TField))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
object? value = field.GetValue(instance);
|
||||
return value != null && value.Equals(expectedValue);
|
||||
}
|
||||
|
||||
protected static string Prefix(string n) => $"_{n}";
|
||||
|
||||
protected static Tile[] CreateSampleTiles(int set = 1)
|
||||
{
|
||||
return set switch
|
||||
{
|
||||
1 =>
|
||||
[
|
||||
new Tile(TileStyle.Polished, 10, 10),
|
||||
new Tile(TileStyle.FancyColor, 15, 30),
|
||||
new Tile(TileStyle.Raw, 200, 200),
|
||||
new Tile(TileStyle.Ornate, 20, 20)
|
||||
],
|
||||
2 => CreateTiles(20, 20, TileStyle.FancyColor, 100)
|
||||
.Concat(CreateTiles(35, 35, TileStyle.Polished, 350))
|
||||
.Concat(CreateTiles(200, 100, TileStyle.Raw, 80))
|
||||
.ToArray(),
|
||||
_ => []
|
||||
};
|
||||
|
||||
static Tile[] CreateTiles(int width, int height, TileStyle style, int amount)
|
||||
{
|
||||
var tiles = new Tile[amount];
|
||||
var idx = 0;
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
tiles[idx++] = new Tile(style, width, height);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
Loading…
Add table
Add a link
Reference in a new issue