コード例 #1
0
        public void MockAnyAdd()
        {
            var mockIAdd = new Mock <IAdds>();

            mockIAdd.Setup(m => m.Add(It.IsAny <int>(), It.IsAny <int>())).Returns(4);
            Arithmetic arithmetic = new Arithmetic(mockIAdd.Object);
            int        res        = arithmetic.Add(1, 2);

            Assert.Equal(4, res);
        }
コード例 #2
0
        public void MockAdd()
        {
            var mockIAdd = new Mock <IAdds>();

            mockIAdd.Setup(m => m.Add(1, 2)).Returns(2);
            Arithmetic arithmetic = new Arithmetic(mockIAdd.Object);
            int        res        = arithmetic.Add(1, 2);

            Assert.Equal(2, res);
            res = arithmetic.Add(1, 4);//
            Assert.Equal(0, res);
        }
コード例 #3
0
        public void Divide()
        {
            Arithmetic arithmetic = new Arithmetic();

            Assert.Throws <DivideByZeroException>(() => arithmetic.Divide(1, 0));
        }