PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Misc/ReadAheadEnumerableTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 69 lines | 44 code | 11 blank | 14 comment | 0 complexity | 66bf32207b4857b63428b76c50a7d3ab MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2015-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using FluentAssertions;
  21. using MongoDB.Driver.Core.Misc;
  22. using Xunit;
  23. namespace MongoDB.Driver.Core.Misc
  24. {
  25. public class ReadAheadEnumerableTests
  26. {
  27. [Fact]
  28. public void Should_return_all_items()
  29. {
  30. var items = new[] { 1, 2, 3 };
  31. var subject = new ReadAheadEnumerable<int>(items);
  32. var list = subject.ToList();
  33. list.Count.Should().Be(3);
  34. list.Should().ContainInOrder(1, 2, 3);
  35. }
  36. [Fact]
  37. public void Should_behave_correctly()
  38. {
  39. var items = new[] { 1, 2, 3 };
  40. var subject = new ReadAheadEnumerable<int>(items);
  41. var enumerator = (ReadAheadEnumerable<int>.ReadAheadEnumerator)subject.GetEnumerator();
  42. Action act = () => { int temp = enumerator.Current; };
  43. act.ShouldThrow<InvalidOperationException>();
  44. enumerator.MoveNext().Should().BeTrue();
  45. enumerator.Current.Should().Be(1);
  46. enumerator.HasNext.Should().BeTrue();
  47. enumerator.MoveNext().Should().BeTrue();
  48. enumerator.Current.Should().Be(2);
  49. enumerator.HasNext.Should().BeTrue();
  50. enumerator.MoveNext().Should().BeTrue();
  51. enumerator.Current.Should().Be(3);
  52. enumerator.HasNext.Should().BeFalse();
  53. enumerator.MoveNext().Should().BeFalse();
  54. act = () => { int temp = enumerator.Current; };
  55. act.ShouldThrow<InvalidOperationException>();
  56. }
  57. }
  58. }