Exemplo n.º 1
0
        public void Simple()
        {
            var mocks   = new MockRepository();
            var visitor = mocks.StrictMock <IVisitor <int> >();

            Expect.Call(visitor.HasCompleted).Return(false);
            visitor.Visit(1);

            Expect.Call(visitor.HasCompleted).Return(false);
            visitor.Visit(2);

            Expect.Call(visitor.HasCompleted).Return(false);
            visitor.Visit(3);

            Expect.Call(visitor.HasCompleted).Return(false);
            visitor.Visit(4);

            mocks.ReplayAll();

            var l = new List <int> {
                1, 2, 3, 4
            };

            l.AcceptVisitor(visitor);

            mocks.VerifyAll();
        }
Exemplo n.º 2
0
        public void Null_Visitor()
        {
            var l = new List <int> {
                1, 2, 3, 4
            };

            l.AcceptVisitor(null);
        }
Exemplo n.º 3
0
        public void Null_Visitor()
        {
            var l = new List <int> {
                1, 2, 3, 4
            };

            Assert.Throws <ArgumentNullException>(() => l.AcceptVisitor(null));
        }
Exemplo n.º 4
0
        public void Find()
        {
            var list = new List <int>();

            list.AddRange(new[] { 3, 4, 76, 34, 50, 23, 45 });

            var visitor = new ComparableFindingVisitor <int>(50);

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor <int>(50);
            list.Clear();
            list.AddRange(new[] { 50, 3, 4, 76, 34, 23, 45 });

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor <int>(50);
            list.Clear();
            list.AddRange(new[] { 3, 4, 76, 34, 23, 45, 50 });

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor <int>(50);
            list.Clear();
            list.AddRange(new[] { 3, 4, 76, 34, 23, 45 });

            list.AcceptVisitor(visitor);
            Assert.IsFalse(visitor.Found);
            Assert.IsFalse(visitor.HasCompleted);
        }
Exemplo n.º 5
0
        public void Simple()
        {
            var visitor = new Mock <IVisitor <int> >();

            visitor.Setup(x => x.HasCompleted).Returns(false);

            var l = new List <int> {
                1, 2, 3, 4
            };

            l.AcceptVisitor(visitor.Object);
            visitor.Verify(x => x.Visit(1));
            visitor.Verify(x => x.Visit(2));
            visitor.Verify(x => x.Visit(3));
            visitor.Verify(x => x.Visit(4));
        }
Exemplo n.º 6
0
        public void ActionShouldBeCalledOnEveryObject()
        {
            var list = new List <int> {
                1, 2, -3
            };


            var recorded = new List <int>();
            var visitor  = new ActionVisitor <int>(x => recorded.Add(x));

            list.AcceptVisitor(visitor);

            Assert.Contains(1, recorded);
            Assert.Contains(2, recorded);
            Assert.Contains(-3, recorded);
        }
Exemplo n.º 7
0
        public void ActionShouldBeCalledOnEveryObject()
        {
            var list = new List <int>
            {
                1, 2, -3
            };

            var mockRepository = new MockRepository();

            // Just looking for an interface with a method that matches Action<T> - temporarily settled on list.
            var recorder = mockRepository.StrictMock <IList <int> >();

            recorder.Add(1);
            recorder.Add(2);
            recorder.Add(-3);

            mockRepository.ReplayAll();

            var visitor = new ActionVisitor <int>(recorder.Add);

            list.AcceptVisitor(visitor);

            mockRepository.VerifyAll();
        }