Esempio n. 1
0
        public void 小明_连续问叔叔好_叔叔好恭喜发财万事如意身体健康扎西德勒()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.SetupSequence(fake => fake.SayHi("叔叔"))
            .Returns("叔叔好")
            .Returns("恭喜发财")
            .Returns("万事如意")
            .Returns("身体健康")
            .Returns("扎西德勒");

            //Act
            var result1 = FamilyGathering.SayHi(xiaoming.Object, "叔叔");
            var result2 = FamilyGathering.SayHi(xiaoming.Object, "叔叔");
            var result3 = FamilyGathering.SayHi(xiaoming.Object, "叔叔");
            var result4 = FamilyGathering.SayHi(xiaoming.Object, "叔叔");
            var result5 = FamilyGathering.SayHi(xiaoming.Object, "叔叔");

            //Assert
            Assert.AreEqual("叔叔好", result1);
            Assert.AreEqual("恭喜发财", result2);
            Assert.AreEqual("万事如意", result3);
            Assert.AreEqual("身体健康", result4);
            Assert.AreEqual("扎西德勒", result5);
        }
Esempio n. 2
0
        public void 小明_问stringEmpty好_抛ArgumentException()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.Setup(fake => fake.SayHi(String.Empty)).Throws(new ArgumentException());
            //Act&Assert
            Assert.ThrowsException <ArgumentException>(() => FamilyGathering.SayHi(xiaoming.Object, ""));
        }
Esempio n. 3
0
        public void 小明3岁_过年_4岁()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.SetupSet(fake => fake.Age++);
            //Act
            FamilyGathering.HappyNewYear(xiaoming.Object);
            //Assert
            xiaoming.VerifyAll();
        }
Esempio n. 4
0
        public void 小明_问亲戚好_亲戚好2(string relativeName)
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.Setup(fake => fake.SayHi(It.IsAny <string>())).Returns((string value) => $"{value}好");
            //Act
            var result = FamilyGathering.SayHi(xiaoming.Object, relativeName);

            //Assert
            Assert.AreEqual($"{relativeName}好", result);
        }
Esempio n. 5
0
        public void 小明_问叔叔好_叔叔好2()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.Setup(fake => fake.SayHi("叔叔")).Returns((string value) => $"{value}好");
            //Act
            var result = FamilyGathering.SayHi(xiaoming.Object, "叔叔");

            //Assert
            Assert.AreEqual("叔叔好", result);
        }
Esempio n. 6
0
        public void 小明3岁_问年龄_长大了3()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.SetupProperty(fake => fake.Age, 3);
            //Act
            var result = FamilyGathering.AskAge(xiaoming.Object);

            //Assert
            Assert.AreEqual("哟,3岁了,几年不见都长这么大了?", result);
        }
Esempio n. 7
0
        public void 小明3岁_问年龄_长大了2()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();

            xiaoming.Object.Age = 3;
            //Act
            var result = FamilyGathering.AskAge(xiaoming.Object);

            //Assert
            Assert.AreEqual("哟,3岁了,几年不见都长这么大了?", result);
        }
Esempio n. 8
0
        public void 老王儿子3岁_问儿子年龄_长大了2()
        {
            //Arrange
            var laowang = new Mock <IMan>();

            laowang.Setup(fake => fake.Child.Age).Returns(3);
            //Act
            var result = FamilyGathering.AskChildAge(laowang.Object);

            //Assert
            Assert.AreEqual("哟,3岁了,几年不见都长这么大了?", result);
        }
Esempio n. 9
0
        public void 小红30岁_问年龄_找对象()
        {
            //Arrange
            var xiaohon = new Mock <IMan>();

            xiaohon.Setup(fake => fake.Age).Returns(30);
            //Act
            var result = FamilyGathering.AskAge(xiaohon.Object);

            //Assert
            Assert.AreEqual("哟,30岁了,该去找个对象了吧。", result);
        }
Esempio n. 10
0
        public void 小明_第二次问叔叔好_叔叔好加2()
        {
            //Arrange
            var xiaoming = new Mock <IMan>();
            var count    = 1;

            xiaoming.Setup(fake => fake.SayHi("叔叔")).Returns((string value) => $"{value}好+{count}")
            .Callback(() => count++);
            //Act
            FamilyGathering.SayHi(xiaoming.Object, "叔叔");
            var result = FamilyGathering.SayHi(xiaoming.Object, "叔叔");

            //Assert
            Assert.AreEqual("叔叔好+2", result);
        }
Esempio n. 11
0
        public void 老王有存款1000块_发红包(int number, int account, string lastWord)
        {
            //Arrange
            var laowang = new Mock <IMan>();

            laowang.SetupProperty(fake => fake.Account, 1000);
            laowang.Setup(fake => fake.DoSomething <int>("发红包", It.IsAny <int>()))
            .Callback <string, int>(
                (something, num) => { laowang.Object.Account = laowang.Object.Account - num; })
            .Returns(() => laowang.Object.Account > 0 ? "咱有钱" : "要吃土");
            //Act
            var result = FamilyGathering.FaHongbao(laowang.Object, number, account);

            //Assert
            laowang.VerifyGet(fake => fake.Account, Times.Exactly(number * 2));
            laowang.VerifyGet(fake => fake.Name);
            laowang.Verify(fake => fake.DoSomething <int>("发红包", It.IsAny <int>()), Times.Exactly(number));
            Assert.AreEqual(lastWord, result);
        }
Esempio n. 12
0
        public void  小红100斤_吃了20斤西瓜_体重120斤名字叫不减肥就不改名的张小红()
        {
            //Arrange
            var xiaohong = new Mock <IMan>();

            xiaohong.SetupProperty(fake => fake.Name, "张小红");
            xiaohong.SetupProperty(fake => fake.Weight, 100);
            xiaohong.Setup(fake => fake.Eat(20))
            .Callback <int>(num =>
            {
                xiaohong.Object.Weight += num;
                xiaohong.Raise(fake1 => fake1.ImFull += null, new EventArgs());
            });
            //Act
            FamilyGathering.HaveDinner(xiaohong.Object, "西瓜", 20);
            //Assert
            Assert.AreEqual(120, xiaohong.Object.Weight);
            Assert.AreEqual("不减肥就不改名的张小红", xiaohong.Object.Name);
        }
Esempio n. 13
0
        public void  小红100斤_吃西瓜_体重增加名字变化(int foodNum, int weight, string name)
        {
            //Arrange
            var xiaohong = new Mock <IMan>();

            xiaohong.SetupProperty(fake => fake.Name, "张小红");
            xiaohong.SetupProperty(fake => fake.Weight, 100);
            xiaohong.Setup(fake => fake.Eat(It.IsInRange(0, 15, Range.Exclusive)))
            .Callback <int>(num =>
            {
                xiaohong.Object.Weight += num;
            });
            xiaohong.Setup(fake => fake.Eat(It.IsInRange(15, int.MaxValue, Range.Inclusive)))
            .Callback <int>(num =>
            {
                xiaohong.Object.Weight += num;
                xiaohong.Raise(fake1 => fake1.ImFull += null, new EventArgs());
            });
            //Act
            FamilyGathering.HaveDinner(xiaohong.Object, "西瓜", foodNum);
            //Assert
            Assert.AreEqual(weight, xiaohong.Object.Weight);
            Assert.AreEqual(name, xiaohong.Object.Name);
        }
        public static string AskChildAge(IMan man)
        {
            var result = FamilyGathering.AskAge(man.Child);

            return(result);
        }