Esempio n. 1
0
        public void AsOneTime()
        {
            var source = new[] { 1, 2, 3 };

            OneTimeEnumerable <int> result = source.AsOneTime();

            Assert.That(result, Is.EqualTo(source));
        }
Esempio n. 2
0
        public void GetEnumerator_ThrowsForSecondCall()
        {
            var source = Enumerable.Range(1, 3);

            var oneTime = new OneTimeEnumerable <int> (source);

            Assert.That(() => oneTime.GetEnumerator(), Throws.Nothing);
            Assert.That(
                () => oneTime.GetEnumerator(),
                Throws.TypeOf <InvalidOperationException> ().With.Message.EqualTo("OneTimeEnumerable can only be iterated once."));
        }
        public void When_collection_is_IEnumerable_it_should_be_evaluated_only_once()
        {
            // Arrange
            IEnumerable <int> collection = new OneTimeEnumerable <int>(1);

            // Act
            Action act = () => collection.Should().ContainSingle();

            // Assert
            act.Should().NotThrow();
        }
Esempio n. 4
0
        public void GetEnumerator_ReturnedEnumeratorDoesNotSupportReset()
        {
            var source = new[] { 1, 2, 3 };

            var oneTimeEnumerator = new OneTimeEnumerable <int> (source).GetEnumerator();

            oneTimeEnumerator.MoveNext();

            Assert.That(
                () => oneTimeEnumerator.Reset(),
                Throws.TypeOf <NotSupportedException>().With.Message.EqualTo("OneTimeEnumerator does not support Reset()."));
        }
Esempio n. 5
0
        public void When_a_collection_does_not_contain_the_unexpected_items_it_should_not_be_enumerated_twice()
        {
            // Arrange
            var collection = new OneTimeEnumerable <int>(1, 2, 3);

            // Act
            Action act = () => collection.Should().OnlyContain(i => i > 3);

            // Assert
            act.Should().Throw <XunitException>().WithMessage(
                "Expected collection to contain only items matching*");
        }
            public void When_a_collection_contains_the_unexpected_item_it_should_not_be_enumerated_twice()
            {
                // Arrange
                var collection = new OneTimeEnumerable <int>(1, 2, 3);

                // Act
                Action act = () => collection.Should().NotContain(2);

                // Assert
                act.Should().Throw <XunitException>().WithMessage(
                    "Expected collection*to not contain 2.");
            }