예제 #1
0
        public void ShouldThrowNotSupportedExceptionWhenResetIsCalled()
        {
            var someObjs = new List <object> {
                1, 2, 3
            };
            var traversal = new TestTraversal(someObjs);

            Assert.Throws <NotSupportedException>(() => traversal.Reset());
        }
예제 #2
0
        public void ShouldReturnAvailableTraverserObjWhenNextIsCalled(object traverserObj)
        {
            var traversal = new TestTraversal(new List <object> {
                traverserObj
            });

            var actualObj = traversal.Next();

            Assert.Equal(traverserObj, actualObj);
        }
예제 #3
0
        public void ShouldReturnAllTraverserObjsWhenToListIsCalled()
        {
            var expectedObjs = new List <object> {
                1, 2, 3
            };
            var traversal = new TestTraversal(expectedObjs);

            var traversedObjs = traversal.ToList();

            Assert.Equal(expectedObjs, traversedObjs);
        }
예제 #4
0
        public void ShouldReturnTraversalsTraverserWhenNextTraverserIsCalled()
        {
            var someObjs = new List <object> {
                1, 2, 3
            };
            var traversal = new TestTraversal(someObjs);

            var traverser = traversal.NextTraverser();

            Assert.Equal(traversal.Traversers.First(), traverser);
        }
예제 #5
0
        public void ShouldDrainAllTraversersWhenIterateIsCalled()
        {
            var someObjs = new List <object> {
                1, 2, 3
            };
            var traversal = new TestTraversal(someObjs);

            var drainedTraversal = traversal.Iterate();

            Assert.Null(drainedTraversal.Next());
        }
예제 #6
0
        public void ShouldDisposeSideEffectsWhenDisposeIsCalled()
        {
            var sideEffectsMock = new Mock <ITraversalSideEffects>();
            var traversal       = new TestTraversal(new List <object>())
            {
                SideEffects = sideEffectsMock.Object
            };

            traversal.Dispose();

            sideEffectsMock.Verify(m => m.Dispose());
        }
예제 #7
0
        public void ShouldReturnAllTraverserObjWithoutDuplicatesWhenToSetIsCalled()
        {
            var traverserObjs = new List <object> {
                1, 1, 2, 3
            };
            var traversal = new TestTraversal(traverserObjs);

            var traversedObjSet = traversal.ToSet();

            Assert.Equal(3, traversedObjSet.Count);
            Assert.Equal(new HashSet <object>(traverserObjs), traversedObjSet);
        }
예제 #8
0
        public void ShouldReturnNullWhenNextIsCalledAndNoTraverserIsAvailable()
        {
            var expectedFirstObj = 1;
            var traversal        = new TestTraversal(new List <object> {
                expectedFirstObj
            });

            var actualFirstObj  = traversal.Next();
            var actualSecondObj = traversal.Next();

            Assert.Equal(expectedFirstObj, actualFirstObj);
            Assert.Null(actualSecondObj);
        }
예제 #9
0
        public void ShouldApplyStrategiesWhenNextIsCalledAndNoTraversersPresent()
        {
            const int expectedObj  = 531;
            var       testStrategy = new TestTraversalStrategy(new List <Traverser> {
                new Traverser(expectedObj)
            });
            var testTraversal = new TestTraversal(new List <ITraversalStrategy> {
                testStrategy
            });

            var actualObj = testTraversal.Next();

            Assert.Equal(expectedObj, actualObj);
        }
예제 #10
0
        public void ShouldCheckHasNext(object traverserObj)
        {
            var traversal = new TestTraversal(new List <object> {
                traverserObj
            });

            Assert.Equal(true, traversal.HasNext());
            Assert.Equal(true, traversal.HasNext());

            var actualObj = traversal.Next();

            Assert.Equal(traverserObj, actualObj);

            Assert.Equal(false, traversal.HasNext());
            Assert.Equal(false, traversal.HasNext());
        }
예제 #11
0
        public void ShouldBeUnfoldTraverserBulksWhenToListIsCalled()
        {
            var objs = new List <object> {
                1, 2, 3
            };
            var bulks = new List <long> {
                3, 2, 1
            };
            var traversal = new TestTraversal(objs, bulks);

            var traversedObjs = traversal.ToList();

            var expectedObjs = UnfoldBulks(objs, bulks);

            Assert.Equal(expectedObjs, traversedObjs);
        }
예제 #12
0
        public void ShouldReturnCorrectNrOfResultObjsWhenNextIsCalledWithAmountArgument(int nrOfResults)
        {
            var objs = new List <object>(20);

            for (var i = 0; i < 20; i++)
            {
                objs.Add(i);
            }
            var traversal = new TestTraversal(objs);

            var traversedObjs = traversal.Next(nrOfResults);

            var traversedObjsList = traversedObjs.ToList();

            Assert.Equal(nrOfResults, traversedObjsList.Count);
            for (var i = 0; i < nrOfResults; i++)
            {
                Assert.Equal(objs[i], traversedObjsList[i]);
            }
        }