CopyToExtensionsTests.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using Xunit;
  4. namespace Jellyfin.Extensions.Tests
  5. {
  6. public static class CopyToExtensionsTests
  7. {
  8. public static TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>> CopyTo_Valid_Correct_TestData()
  9. {
  10. var data = new TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>>
  11. {
  12. { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } },
  13. { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } }
  14. };
  15. return data;
  16. }
  17. [Theory]
  18. [MemberData(nameof(CopyTo_Valid_Correct_TestData))]
  19. public static void CopyTo_Valid_Correct(IReadOnlyList<int> source, IList<int> destination, int index, IList<int> expected)
  20. {
  21. source.CopyTo(destination, index);
  22. Assert.Equal(expected, destination);
  23. }
  24. public static TheoryData<IReadOnlyList<int>, IList<int>, int> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData()
  25. {
  26. var data = new TheoryData<IReadOnlyList<int>, IList<int>, int>
  27. {
  28. { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 },
  29. { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 },
  30. { new[] { 0, 1, 2 }, Array.Empty<int>(), 0 },
  31. { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 },
  32. { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 }
  33. };
  34. return data;
  35. }
  36. [Theory]
  37. [MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))]
  38. public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException(IReadOnlyList<int> source, IList<int> destination, int index)
  39. {
  40. Assert.Throws<ArgumentOutOfRangeException>(() => source.CopyTo(destination, index));
  41. }
  42. }
  43. }