Exemplo n.º 1
0
        public void MockPropertyOnInterfaceCanWork()
        {
            var student = new Student();

            var mock = new Mock<IProduct>();
            mock.Setup(p => p.Color).Returns("Red");

            var showColor = student.ShowColor(mock.Object);
            Assert.AreEqual("Red", showColor);
            mock.Verify();
        }
Exemplo n.º 2
0
        public void MockPropertyOnClassCanNotWork()
        {
            var student = new Student();

            var mock = new Mock<Product>();
            mock.Setup(p => p.Price).Returns(16.55);

            var showPrice = student.ShowPrice(mock.Object);
            Assert.AreEqual("Expensive", showPrice);
            mock.Verify();
        }
Exemplo n.º 3
0
        public void MockClassNonVirtualMethodDoesNotWork()
        {
            var student = new Student();

            var mock = new Mock<Product>();
            mock.Setup(p => p.GetColor()).Returns("Red");

            var showColor1 = student.ShowColor1(mock.Object);
            Assert.AreEqual("Red", showColor1);
            mock.Verify();
        }
Exemplo n.º 4
0
        public void MockMethodOnInterfaceCanWork()
        {
            var student = new Student();

            var mock = new Mock<IProduct>();
            mock.Setup(p => p.GetPrice()).Returns(17.00);

            var showPrice1 = student.ShowPrice1(mock.Object);
            Assert.AreEqual("Expensive", showPrice1);
            mock.Verify();
        }
Exemplo n.º 5
0
        public void MockAbstractClassAbstractPropertyCanWork()
        {
            var student = new Student();

            var mock = new Mock<AbstractProduct>();
            mock.Setup(p => p.Color).Returns("Red");

            var showColor2 = student.ShowColor2(mock.Object);
            Assert.AreEqual("Red", showColor2);
            mock.Verify();
        }