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);

  

     

JustMock Lite (Free Mocking Framework For .net)的更多相关文章

  1. Testing with a mocking framework (EF6 onwards)

    When writing tests for your application it is often desirable to avoid hitting the database.  Entity ...

  2. 什么是Mocking framework?它有什么用?

    原位地址:http://codetunnel.com/blog/post/what-is-a-mocking-framework-why-is-it-useful 今天我想讲下关于mocking fr ...

  3. Mocking framework

    [译] 什么是Mocking framework?它有什么用? 原位地址:http://codetunnel.com/blog/post/what-is-a-mocking-framework-why ...

  4. What is a mocking framework? Why is it useful?

    Today I want to talk about mocking frameworks and why they are useful. In order to do that I first n ...

  5. 什么是Mocking framework?它有什么用?(转)

    今天我想讲下关于mocking frameworks,并且解释下他为什么有用处.我将给你们展示用和不用mocking framework两种测试方法. 假设我们已经有了一个Driver类: publi ...

  6. Googletest - Google Testing and Mocking Framework

    Googletest - Google Testing and Mocking Framework https://github.com/google/googletest

  7. 利用Mocking Framework 单元测试Entity Framework

    一.前言 在实际编写程序时,往往需要与数据库打交道,在单元测试中直接使用数据库又显得太重,如果可以方便的编写一些测试数据,这样更易于检测功能.如何模拟数据库行为便是本篇的主题.微软有教程说明Moq E ...

  8. 第一篇:Entity Framework 简介

    先从ORM说起吧,很多年前,由于.NET的开源组件不像现在这样发达,更别说一个开源的ORM框架,出于项目需要,以及当时OOP兴起(总不至于,在项目里面全是SQL语句),就自己开始写ORM框架.要开发O ...

  9. Entity Framework版本历史概览

    转自:http://www.cnblogs.com/fecktty2013/archive/2014/09/26/entityframework-overview.html EF版本 .net fra ...

随机推荐

  1. yum配置文件详解

    yum是什么: Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包,自动解决包的倚赖性问题,它能便于管理大量系统的更新问题. yum特点:可以同时配置多 ...

  2. ASP.NET MVC 4+ T.JPager使用

    一.同步Link模式 var pagecount = TCalcPager.CalcPageCount(count, pageSize); var page = new TBuilderLinkPag ...

  3. 【9-7】XML学习笔记01

    Tips XML标签大小写敏感: XML文件一般使用国际化通用的编码“utf-8”,所以平时看到的XML文件的头部都会有这样的代码: <?xml version="1.0" ...

  4. vtk第一个程序

    首先 设置环境变量 解决方案资源管理器 选中项目名字 而不是ALL_BUILD 选项卡 项目-属性 右侧 附加依赖项->编辑 kernel32.libuser32.libgdi32.libwin ...

  5. hdu1757 A Simple Math Problem

    Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x > ...

  6. poj 3744 Scout YYF I(概率dp,矩阵优化)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5020   Accepted: 1355 Descr ...

  7. 【bzoj3573】[HNOI2014]米特运输

    题目描述 米特是D星球上一种非常神秘的物质,蕴含着巨大的能量.在以米特为主要能源的D星上,这种米特能源的运输和储存一直是一个大问题.D星上有N个城市,我们将其顺序编号为1到N,1号城市为首都.这N个城 ...

  8. uva.10020 Minimal coverage(贪心)

    10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...

  9. W3Cschool菜鸟教程离线版下载链接

    请在电脑上打开以下链接进行下载w3cschool 离线版(chm):http://pan.baidu.com/s/1bniwRCV(最新,2014年10月21日更新)w3cschool 离线版(htm ...

  10. Windows下MySQL 5.6安装及配置详细图解

    一.安装前的准备 1.下载安装程序包,可到MySQL官方网站http://www.mysql.com/下载,如图1-1: 图1-1 下载后的安装文件如图1-2所示: 图1-2 二.安装 1.双击下载的 ...