CopyToExtensionsTests.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. data.Add(
  12. new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 });
  13. data.Add(
  14. new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } );
  15. return data;
  16. }
  17. [Theory]
  18. [MemberData(nameof(CopyTo_Valid_Correct_TestData))]
  19. public static void CopyTo_Valid_Correct<T>(IReadOnlyList<T> source, IList<T> destination, int index, IList<T> 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. data.Add(
  28. new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 );
  29. data.Add(
  30. new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 );
  31. data.Add(
  32. new[] { 0, 1, 2 }, Array.Empty<int>(), 0 );
  33. data.Add(
  34. new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 );
  35. data.Add(
  36. new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 );
  37. return data;
  38. }
  39. [Theory]
  40. [MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))]
  41. public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException<T>(IReadOnlyList<T> source, IList<T> destination, int index)
  42. {
  43. Assert.Throws<ArgumentOutOfRangeException>(() => source.CopyTo(destination, index));
  44. }
  45. }
  46. }