zoukankan      html  css  js  c++  java
  • Moles Stub types

    The Moles Framework. The need for a stub framework that could be effectively used with Pex initially motivated the creation of the Moles framework for generating stub types and mole types:

    •  Stub types make it easy to test code that consumes interfaces, or non-sealed classes with overridable methods.
    •  Mole types allow detouring of hard-coded dependencies on static or non-overridable methods.

    Stub types sample.

    public interface IStudent
    {
      string GetName(string name);
    }

    public class ImpIStudent : StubBase, IStudent
    {
      public Func<string, string> GetNameString;
      public string GetName(string name)
      {
        if (GetNameString != null)
        {
          return GetNameString("str");
        }
        return null;
      }
    }


    [TestMethod()]
    public void GetNameTest()
    {
      IStudent target = CreateIStudent();
      string expected = "name...";

      var istu = new ClassLibrary1.Moles.SIStudent()
      {
        GetNameString = (name) => { return expected; }
      };

      IStudent stu = istu;

      string actual = stu.GetName(expected);

      Assert.AreEqual(expected, actual);

    }

  • 相关阅读:
    form表单的应用
    HTML列表及表格的基本应用
    Linux上安装Jdk
    docker+jenkins自动发布步骤及命令
    redis集群部署实战
    mySQL中连接字符串
    mysql触发器
    sql 设置数字长度 不足时补0
    微服务架构特性
    SQLServer2008 去除换行符
  • 原文地址:https://www.cnblogs.com/wzh206/p/3081990.html
Copyright © 2011-2022 走看看