CopyToExtensionsTests.cs 1.8 KB

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