国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

JustMock Lite (Free Mocking Framework For .net)

2019-11-17 02:25:32
字體:
來源:轉載
供稿:網友

JustMock Lite (Free Mocking Framework For .net)

  1. 通過 Nuget 安裝

2. 官網下載(官網不行點這里)

3. 幫助文檔

商業版和免費版區別概覽

MockingContainer

測試類準備:一般來說也是業務類


    public class ClassUnderTest    {        PRivate IFirstDependency firstDep;        private ISecondDependency secondDep;        public ClassUnderTest(IFirstDependency first, ISecondDependency second)        {            this.firstDep = first;            this.secondDep = second;        }        public IList<object> CollectionMethod()        {            var firstCollection = firstDep.GetList();            return firstCollection;        }        public string StringMethod()        {            var secondString = secondDep.GetString();            return secondString;        }    }    public interface IFirstDependency    {        IList<object> GetList();    }    public interface ISecondDependency    {        string GetString();    }

  單元測試


        [TestMethod]        public void ShouldMockDependenciesWithContainer()        {            // ARRANGE            // Creating a MockingContainer of ClassUnderTest.             // To instantiate the system uder test (the container) you should use the Instance property             // For example: container.Instance.             var container = new MockingContainer<ClassUnderTest>();            string expectedString = "Test";            // Arranging: When the GetString() method from the ISecondDependecy interface             //              is called from the container, it should return expectedString.             container.Arrange<ISecondDependency>(               secondDep => secondDep.GetString()).Returns(expectedString);            // ACT - Calling SringMethod() from the mocked instance of ClassUnderTest            var actualString = container.Instance.StringMethod();            // ASSERT            Assert.AreEqual(expectedString, actualString);        }

  需要說明的是MockingContainer構造函數有一個可選參數AutoMockSettings,其中AutoMockSettings最主要的一個作用的是當ClassUnderTest有多個構造函數時,指定合適的構造函數來實例化對象

當業務類中有一個無參構造函數,一個有參構造函數,在沒有設置AutoMockSettings的情況下會默認執行無參構造函數,

可以像下面這樣來指定需要的構造函數

        AutoMockSettings settings = new AutoMockSettings            {                ConstructorArgTypes = new Type[]{                  typeof(IFirstDependency),typeof(ISecondDependency)                }            };            // ARRANGE            // Creating a MockingContainer of ClassUnderTest.             // To instantiate the system uder test (the container) you should use the Instance property             // For example: container.Instance.             var container = new MockingContainer<ClassUnderTest>(settings);

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙自县| 红河县| 改则县| 上杭县| 锦州市| 株洲市| 崇阳县| 丽水市| 元氏县| 惠东县| 冕宁县| 囊谦县| 桑日县| 甘肃省| 锦屏县| 太康县| 旌德县| 尼勒克县| 高碑店市| 双流县| 丰镇市| 方城县| 玛多县| 屏东县| 新丰县| 玛纳斯县| 达拉特旗| 信丰县| 郧西县| 金山区| 金乡县| 云和县| 六枝特区| 宣威市| 建宁县| 扎赉特旗| 柳江县| 石屏县| 宜章县| 敦煌市| 慈利县|