コード例 #1
0
        public void Does_ExerciseInterface_Call_DoSomething()
        {
            //arrange
            var mock = new Mock <IDemoOne>();

            mock.Setup(x => x.DoSomething(It.IsAny <bool>()))
            .Returns <bool>(b => b ? 1 : 0);

            var demo = new DemoClass(mock.Object);

            //act
            Assert.AreEqual(1, demo.ExerciseInterface());

            //assert
            mock.Verify(x => x.DoSomething(true), Times.Once());
            mock.Verify(x => x.DoSomething(false), Times.Never());
        }
コード例 #2
0
ファイル: MoqTests.cs プロジェクト: sjeyaram/partcover.net4
        public void Does_ExerciseInterface_Call_DoSomething()
        {
            //arrange
            var mock = new Mock<IDemoOne>();

            mock.Setup(x => x.DoSomething(It.IsAny<bool>()))
                .Returns<bool>(b => b ? 1 : 0);

            var demo = new DemoClass(mock.Object);

            //act
            Assert.AreEqual(1, demo.ExerciseInterface());

            //assert
            mock.Verify(x => x.DoSomething(true), Times.Once());
            mock.Verify(x => x.DoSomething(false), Times.Never());
        }