// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace Jellyfin.Extensions.Tests { using System; using System.Collections.Generic; using Xunit; /// /// Tests for CopyTo extension methods. /// public static class CopyToExtensionsTests { /// /// Gets test data for valid CopyTo operations. /// /// The test data. public static TheoryData, IList, int, IList> CopyTo_Valid_Correct_TestData() { TheoryData, IList, int, IList> data = new TheoryData, IList, int, IList> { { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } }, { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } }, }; return data; } /// /// Tests that CopyTo correctly copies elements. /// /// The source list. /// The destination list. /// The starting index. /// The expected result. [Theory] [MemberData(nameof(CopyTo_Valid_Correct_TestData))] public static void CopyTo_Valid_Correct(IReadOnlyList source, IList destination, int index, IList expected) { source.CopyTo(destination, index); Assert.Equal(expected, destination); } /// /// Gets test data for invalid CopyTo operations that should throw. /// /// The test data. public static TheoryData, IList, int> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData() { TheoryData, IList, int> data = new TheoryData, IList, int> { { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 }, { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 }, { new[] { 0, 1, 2 }, Array.Empty(), 0 }, { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 }, { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 }, }; return data; } /// /// Tests that CopyTo throws ArgumentOutOfRangeException for invalid inputs. /// /// The source list. /// The destination list. /// The starting index. [Theory] [MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))] public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException(IReadOnlyList source, IList destination, int index) { Assert.Throws(() => source.CopyTo(destination, index)); } } }