代码之家  ›  专栏  ›  技术社区  ›  Ian Warburton

第一次摩尔测试-未发生重定向

  •  0
  • Ian Warburton  · 技术社区  · 14 年前

    这是密码。按正常方式调用getParentPath!

        [TestMethod]
        [HostType("Moles")]
        public void GetParentPath_slashOnEnd_returns()
        {
            var sapi = new MPhotobucketApi();
            sapi.GetParentPathString = s => s;
    
            var api = new PhotobucketApi();
            var parentPath = api.GetParentPath("hello/world/");
    
            Assert.AreEqual(parentPath, "hello");
        }
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Peli    14 年前

    按照编写测试的方式,重定向只适用于SAPI中嵌入的运行时实例。您需要截取photobucketapi的构造器,并截取photobucketapi的“未来”实例:

    MPhotobucketApi.Contructor = (me) => {
        new MPhotobucketApi { GetParentPathString = s => s }; 
    };
    ...
    

    另一个方法是通过执行以下操作重定向所有实例的getParentPath:

    MPhotobucketApi.AllInstances.GetParentPathString = (me, s) => s;
    ...
    
    推荐文章