人人人人人人人人人人人人

c# Moq Ref/out 参数

 

        public interface IService
        {
            void DoSomething(ref string a);
            void DoSomething2(out string a);
        }
    

        [TestMethod]
        public void TestRefPara()
        {
            var service = new Mock<IService>();
            service.Setup(s => s.DoSomething(ref It.Ref<string>.IsAny));
            string actualValue= "value";
            service.Object.DoSomething(ref actualValue);
            Assert.AreEqual("value", actualValue);
        }

        [TestMethod]
        public void TestOutPara()
        {
            var service = new Mock<IService>();
            string outPara = "abc"; 
            string actualValue = "value";
            service.Setup(s => s.DoSomething2(out outPara)); 
            service.Object.DoSomething2(out actualValue);
            Assert.AreEqual("abc", actualValue);
        }

  

posted @ 2021-06-09 17:35  wgscd  阅读(104)  评论(0编辑  收藏  举报