public void GetEnumerator_EnumerateFull_EnumeratesOnlyOnce()
        {
            // arrange
            var enumerable = new NonRepeatableEnumerable <int>(Enumerable.Range(1, 5));

            // act
            var list = enumerable.ToList();

            // assert
            list.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5 });
            enumerable.Should().BeEmpty();
        }
        public void GetEnumerator_EnumerateParital_EnumeratesInParts()
        {
            // arrange
            var enumerable = new NonRepeatableEnumerable <int>(Enumerable.Range(1, 5));

            // act
            var list = enumerable.Take(3).ToList();

            // assert
            list.Should().BeEquivalentTo(new[] { 1, 2, 3 });
            enumerable.Should().BeEquivalentTo(new[] { 4, 5 });
        }
Exemplo n.º 3
0
        public void Chunk_WithPartialConsuming_ShouldWork()
        {
            // arrange
            var values = new NonRepeatableEnumerable <int>(Enumerable.Range(1, 10));

            // act
            var result = values.Chunk(4).Take(2).ToList();

            // assert
            result.Should().HaveCount(2);
            result.First().Should().BeEquivalentTo(new[] { 1, 2, 3, 4 });
            result.Second().Should().BeEquivalentTo(new[] { 5, 6, 7, 8 });
            values.Should().BeEquivalentTo(new[] { 9, 10 });
        }
Exemplo n.º 4
0
        public void IsNullOrEmpty_ConsumingEnumerableGiven_BehavesCorrectly()
        {
            // arrange
            var empty  = new NonRepeatableEnumerable <string>(new List <string>());
            var filled = new NonRepeatableEnumerable <string>(new List <string> {
                "abc", "def"
            });

            // act
            var resultEmpty  = empty.IsNullOrEmpty();
            var resultFilled = filled.IsNullOrEmpty();

            // assert
            resultEmpty.Should().BeTrue();
            resultFilled.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void ContainAll_ConsumingEnumerableGiven_BehavesCorrectly()
        {
            // arrange
            var matching = new NonRepeatableEnumerable <string>(new List <string> {
                "abc", "dev", "ghi"
            });
            var notMatching = new NonRepeatableEnumerable <string>(new List <string> {
                "abc", "ghi"
            });

            // act
            var matchingResult    = matching.ContainAll("ghi", "dev");
            var notMatchingResult = notMatching.ContainAll("ghi", "dev");

            // assert
            matchingResult.Should().BeTrue();
            notMatchingResult.Should().BeFalse();
        }