UnitTest
using Bll;
using Model;
using Dal; using NUnit.Framework;
using NUnit.Mocks;
using System.ServiceModel;
using Constant; namespace OES.Nunit
{
/// <summary>
/// This class is used for test use business logic layer.
/// </summary>
[TestFixture]
public class UserNumit
{
private DynamicMock mock = null;
private IUserDal userDal = null;
private IUserBll userBll = null;
private User user = null; [SetUp]
public void Initialize()
{
user = new User();
user.UserName = "a1";
user.Password = "";
user.RoleType = "student";
}
[Test]
public void LogOn()
{
mock = new DynamicMock(typeof(IUserDal));
userDal = (IUserDal)mock.MockInstance;
userBll = new UserBll();
userBll = new UserBll(userDal);
mock.ExpectAndReturn("RetrieveUserByUserName", user, user.UserName);
User getUser = userBll.RetrieveUserByUserName(user.UserName);
Assert.IsNotNull(getUser, "User is not null");
} [Test]
public void LogOnException()
{
mock = new DynamicMock(typeof(IUserDal));
userDal = (IUserDal)mock.MockInstance;
userBll = new UserBll();
userBll = new UserBll(userDal); mock.ExpectAndThrow("RetrieveUserByUserName", new UserException(), user.UserName);
Assert.Throws<FaultException<MyExceptionContainer>>(
() => this.userBll.RetrieveUserByUserName(user.UserName)
);
}
[Test]
public void ChangePassword()
{
mock = new DynamicMock(typeof(IUserDal));
userDal = (IUserDal)mock.MockInstance;
userBll = new UserBll();
userBll = new UserBll(userDal);
string[] str = new string[] { "", "" };
mock.ExpectAndReturn("UpdatePassword", , str);
bool isChangePassword = userBll.UpdatePassword(str[], str[]);
Assert.True(isChangePassword, "Changed password");
} [Test]
public void ChangePasswordException()
{
mock = new DynamicMock(typeof(IUserDal));
userDal = (IUserDal)mock.MockInstance;
userBll = new UserBll();
userBll = new UserBll(userDal);
string[] str = new string[] { "", "" }; mock.ExpectAndThrow("UpdatePassword", new UserException(), str);
Assert.Throws<FaultException<MyExceptionContainer>>(
() => this.userBll.UpdatePassword(str[],str[])
);
} [TestFixtureTearDown]
~UserNumit()
{
userBll = null;
user = null;
userDal = null;
}
}
}
UnitTest的更多相关文章
- python_单元测试unittest
Python自带一个单元测试框架是unittest模块,用它来做单元测试,它里面封装好了一些校验返回的结果方法和一些用例执行前的初始化操作. 步骤1:首先引入unittest模块--import un ...
- python单元测试unittest
单元测试作为任何语言的开发者都应该是必要的,因为时隔数月后再回来调试自己的复杂程序时,其实也是很崩溃的事情.虽然会很快熟悉内容,但是修改和 调试将是一件痛苦的事情,如果你在修改了代码后出现问题的话,而 ...
- Python 下的unittest测试框架
unittest测试框架,直接上图吧: data:数据:主要格式为CSV:读取方式:csv.reade: public:封装的模块:通用的模块单独封装,所需参数设置为变量: testcase:测试用例 ...
- Python unittest appium
import unittest from appium import webdriver from appium.common.exceptions import NoSuchContextExcep ...
- selenium-webdriver(python) (十六) --unittest 框架
学习unittest 很好的一个切入点就是从selenium IDE 录制导出脚本.相信不少新手学习selenium 也是从IED 开始的. IDE学习参考: 菜鸟学自动化测试(一)----selen ...
- Node.js的UnitTest单元测试
body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } 在专业化的软件开发过程中,无论什么平台语言,现在都需要UnitTes ...
- unittest使用过程中sys.exit(not self.result.wasSuccessful())
起因: 在运行下面的unittest过程中出现了个Traceback: 被测试脚本: # splitter.py def split(line, types=None, delimiter=None) ...
- 三言两语聊Python模块–单元测试模块unittest
实际上unittest模块才是真正意义上的用于测试的模块,功能强大的单元测试模块. 继续使用前面的例子: # splitter.py def split(line, types=None, delim ...
- unittest测试驱动之HTMLTestRunner.py
对于自动化来说,测试报告是必须的,在敏捷化的团队中,团队中的成员需要自动化这边提供自动化的测试报告,来判断系统的整体质量以及下一步的测试策略.单元测试库生成测试输出到控制台的窗口上,但是这样的结果看起 ...
- unittest可能面临的问题以及解决方法
问题1:用例的执行顺序 当使用unittest.main()时,用例的执行是按照ascall值的顺序来执行的,所以如果使用main()方法来执行用例的话,那么就需要通过命名来限制执行顺序,比如想要先执 ...
随机推荐
- Linux常用命令之sed
标题:sed命令的使用 作用:sed(stream editer)是以行为单位处理文本数据,可以对数据按行进行选取(显示打印).替换.删除和新增等功能. 工作流程:sed是一个流编辑器,它可以对从标准 ...
- node.js学习的资源整理
node中文社区 Node.js专业中文社区:https://cnodejs.org/ node文档 node.js 中文api :http://nodeapi.ucdok.com/ node.js入 ...
- [转]div内容底部对齐
本文转自:http://blog.csdn.net/hellomy/article/details/5889833 <html> <head> <meta http-eq ...
- Linq To Csv 实例简说
http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library 详细源代码在这里 https://github.com/mperdeck/L ...
- 浅析js中的this
this的用法 this在日常javascript编码中很常见, 但是一直以来没有好好总结过. 今天在这里好好总结一下. 本文只讨论浏览器环境. this指向全局 var name = "w ...
- sql将表中的某个字段进行排序
. update tempTable set field1 = rownum from( select field1, ROW_NUMBER() over(order by fieldId) rown ...
- Part 12 DateTime functions in SQL Server
DateTime functions in SQL Server IsDate, Day, Month, Year and DateName DateTime functions in SQL Ser ...
- OS中常用的调度算法总结 (转)
http://blog.chinaunix.net/uid-25132162-id-361291.html 一.常见的批处理作业调度算法 1.先来先服务调度算法(FCFS):就是按照各个作业进入系统的 ...
- 通过js判断手机访问跳转到手机站
第一种方法: <script> ){ //pc //window.location.href="电脑网址"; }else{ //shouji window.locati ...
- 4月12日学习笔记——jQuery管理包装集
创建新的元素 (1)使用 HTML DOM 创建元素 //使用 Dom 标准创建元素 var select = document.createElement("select"); ...