Esempio n. 1
0
        public void PowerLowerThanZero_Warning()
        {
            DeskFan fan      = new DeskFan(new PowerSupplyLowerThan200());
            var     expected = "Warning!";
            var     actual   = fan.Work();

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public void PowerLowerThanZero_OK()
        {
            DeskFan fan      = new DeskFan(new PowerSupplyLowerThanZero());
            var     expected = "Won't work.";
            var     actual   = fan.Work();

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void PowerHigherThan_200_Explode()
        {
            var fan      = new DeskFan(new PowerSupplyHigherThan_200());
            var result   = fan.Work();
            var expected = "Explode!";

            Assert.Equal(result, expected);
        }
Esempio n. 4
0
        public void PowerLowerThan_0_OK()
        {
            var fan      = new DeskFan(new PowerSupplyLowerThan_0());
            var result   = fan.Work();
            var expected = "Can't work";

            Assert.Equal(result, expected);
        }
Esempio n. 5
0
        public void PowerHigherThan200_Warning()
        {
            var mock = new Mock <IPowerSupply>();

            mock.Setup(ps => ps.GetPower()).Returns(() => 220);
            var fan      = new DeskFan(mock.Object);
            var expected = "Warning";
            var actual   = fan.Work();

            Assert.Equal(expected, actual);
        }
Esempio n. 6
0
        public void PowerLowerThanZero_OK()
        {
            var mock = new Mock <IPowerSupply>();

            mock.Setup(ps => ps.GetPower()).Returns(() => 0);
            var fan      = new DeskFan(mock.Object);
            var expected = "Won't work.";
            var actual   = fan.Work();

            Assert.Equal(expected, actual);
        }
Esempio n. 7
0
        public void Power_150_Fine()
        {
            //Using Mock can help to save the redundant steps to create a specific class for test.
            var mock = new Mock <IPowerSupply>();

            //Lambda expression here means
            //first, create an instance with a method called "GetPower".
            //second, set the return value of that method to be 150;
            mock.Setup(ps => ps.GetPower()).Returns(() => 150);
            var fan      = new DeskFan(mock.Object);
            var result   = fan.Work();
            var expected = "Fine";

            Assert.Equal(result, expected);
        }