StartWithTest.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.Collections.Generic;
  6. using System.Text;
  7. using System.Linq;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public class StartWithTest : Tests
  12. {
  13. [Fact]
  14. public void StartWith_Arguments()
  15. {
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.StartWith<int>(null, 5));
  17. }
  18. [Fact]
  19. public void StartWith1()
  20. {
  21. var e = Enumerable.Range(1, 5);
  22. var r = e.StartWith(0).ToList();
  23. Assert.True(Enumerable.SequenceEqual(r, Enumerable.Range(0, 6)));
  24. }
  25. [Fact]
  26. public void StartWith2()
  27. {
  28. var oops = false;
  29. var e = Enumerable.Range(1, 5).Do(_ => oops = true);
  30. var r = e.StartWith(0).Take(1).ToList();
  31. Assert.False(oops);
  32. }
  33. }
  34. }