StartWith.cs 984 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Linq;
  6. using Xunit;
  7. namespace Tests
  8. {
  9. public class StartWith : Tests
  10. {
  11. [Fact]
  12. public void StartWith_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.StartWith<int>(null, 5));
  15. }
  16. [Fact]
  17. public void StartWith1()
  18. {
  19. var e = Enumerable.Range(1, 5);
  20. var r = e.StartWith(0).ToList();
  21. Assert.True(Enumerable.SequenceEqual(r, Enumerable.Range(0, 6)));
  22. }
  23. [Fact]
  24. public void StartWith2()
  25. {
  26. var oops = false;
  27. var e = Enumerable.Range(1, 5).Do(_ => oops = true);
  28. var r = e.StartWith(0).Take(1).ToList();
  29. Assert.False(oops);
  30. }
  31. }
  32. }