using Xunit; using Aurora; using Aurora.Services.Signal; using Aurora.Cursor; using Faker; namespace AuroraSignal.test { public class CursorListTest { [Theory()] [InlineData(SortDirection.Asc)] [InlineData(SortDirection.Desc)] public void CursorListSortOnStringValue(SortDirection direction) { CursorList list = new CursorList(); list.Add(new Party() { Name = "asdf", Id = Faker.RandomNumber.Next().ToString() }); list.Add(new Party() { Name = "bsdf", Id = Faker.RandomNumber.Next().ToString() }); list.Add(new Party() { Name = "csdf", Id = Faker.RandomNumber.Next().ToString() }); CursorResult result = new Cursor(ref list) .WithSort(item => item.Value.Name, direction) .GetNextPage(); if (direction == SortDirection.Desc) { Assert.Collection(result.Result, item => item.Name.Equals("asdf"), item => item.Name.Equals("bsdf"), item => item.Name.Equals("csdf")); } else { Assert.Collection(result.Result, item => item.Name.Equals("csdf"), item => item.Name.Equals("bsdf"), item => item.Name.Equals("asdf")); } } [Theory()] [InlineData(2)] [InlineData(10)] [InlineData(49)] [InlineData(51)] [InlineData(-1)] public void CursorListSizeTest(int size) { int numOfItems = 50; CursorList list = new CursorList(); // Add items to cursor list for (int i = 0; i < numOfItems; i++) { list.Add(new Party() { Name = string.Join(" ", Faker.Lorem.Words(2)), Id = Faker.RandomNumber.Next().ToString() }); } Cursor cursor = new Cursor(ref list); if (size < 0) { Assert.Throws(() => { cursor.WithSize(size).GetNextPage(); }); } else if (size > numOfItems) { CursorResult res = cursor.WithSize(size).GetNextPage(); Assert.Equal(res.Result.Count, numOfItems); } else if (size < numOfItems && size > 0) { CursorResult res = cursor.WithSize(size).GetNextPage(); Assert.Equal(res.Result.Count, size); } } } }