diff --git a/test/primitive/Primitive.Array.cs b/test/primitive/Primitive.Array.cs index 473e15f..eb58343 100644 --- a/test/primitive/Primitive.Array.cs +++ b/test/primitive/Primitive.Array.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using Byter; using Xunit; namespace Test.Primitives; @@ -7,5 +10,150 @@ public partial class Primitives [Fact] public void _Array() { + _Array1(); + _Array2(); + _Array3(); + } + + private void _Array1() + { + Primitive primitive = new(); + + string[] list = + [ + + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + ]; + + primitive.Add.Array(list); + + Assert.Equal(list, primitive.Get.Array()); + Assert.True(primitive.IsValid); + } + + private void _Array2() + { + Primitive primitive = new(); + + List[] list = new List> + { + new() + { + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + }, + new() + { + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + }, + new() + { + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + }, + }.ToArray(); + + primitive.Add.Array(list); + + var myList = primitive.Get.Array>(); + Assert.Equal(list, myList); + for (int i = 0; i < list.Length; i++) + { + Assert.Equal(list[i], myList[i]); + } + + Assert.True(primitive.IsValid); + } + + private void _Array3() + { + Primitive primitive = new(); + + Array3Info[] list = new List + { + new() + { + Number = int.MaxValue, + String = Guid.NewGuid().ToString(), + Bool = true, + List = + [ + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString() + ], + Array = + [ + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString() + ], + SubClass = new() + { + String = Guid.NewGuid().ToString() + } + }, + new() + { + Number = int.MinValue, + String = Guid.NewGuid().ToString(), + Bool = false, + List = + [ + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString() + ], + Array = + [ + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString() + ], + SubClass = new() + { + String = Guid.NewGuid().ToString() + } + } + }.ToArray(); + + primitive.Add.Array(list); + + var myList = primitive.Get.Array(); + + Assert.NotNull(myList); + + for (int i = 0; i < list.Length; i++) + { + Assert.Equal(list[i].Number, myList[i].Number); + Assert.Equal(list[i].String, myList[i].String); + Assert.Equal(list[i].Bool, myList[i].Bool); + Assert.Equal(list[i].List, myList[i].List); + Assert.Equal(list[i].Array, myList[i].Array); + Assert.Equal(list[i].SubClass?.String, myList[i].SubClass?.String); + } + + Assert.True(primitive.IsValid); + } + + private class Array3Info + { + public int Number { get; set; } + public string? String { get; set; } + public bool Bool { get; set; } + public List? List { get; set; } + public string[]? Array { get; set; } + public Sub? SubClass { get; set; } + + public class Sub + { + public string? String { get; set; } + } } } \ No newline at end of file