Exemplo n.º 1
0
        public void TryGetChildAt_GetChildrenReturnsIList_GetEnumeratorNotCalled()
        {
            Mock <IList <Node <int> > >       mockList   = new Mock <IList <Node <int> > >();
            Mock <ITreeWalker <Node <int> > > mockWalker = new Mock <ITreeWalker <Node <int> > >();

            mockWalker
            .Setup(x => x.GetChildren(It.IsAny <Node <int> >()))
            .Returns(mockList.Object);

            Node <int> blah;

            TreeWalkerExtensions
            .TryGetChildAt(
                mockWalker.Object,
                default(Node <int>),
                0,
                out blah);

            mockList.Verify(x => x.GetEnumerator(), Times.Never);
            mockList.VerifyGet(x => x.Count, Times.Once);
        }
Exemplo n.º 2
0
        public void TryGetChildAt_GetChildrenReturnsIEnumerable_GetEnumeratorCalled()
        {
            Mock <IEnumerable <Node <int> > > mockEnumerable = new Mock <IEnumerable <Node <int> > >();
            Mock <ITreeWalker <Node <int> > > mockWalker     = new Mock <ITreeWalker <Node <int> > >();

            mockEnumerable
            .Setup(x => x.GetEnumerator())
            .Returns(Mock.Of <IEnumerator <Node <int> > >());

            mockWalker
            .Setup(x => x.GetChildren(It.IsAny <Node <int> >()))
            .Returns(mockEnumerable.Object);

            Node <int> blah;

            TreeWalkerExtensions
            .TryGetChildAt(
                mockWalker.Object,
                default(Node <int>),
                0,
                out blah);

            mockEnumerable.Verify(x => x.GetEnumerator(), Times.Once);
        }