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()方法来执行用例的话,那么就需要通过命名来限制执行顺序,比如想要先执 ...
随机推荐
- hdu 3450 树状数组
思路:二分查找位置,之后是裸的树状数组. #include<set> #include<map> #include<cmath> #include<queue ...
- 移动端1px细线的处理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- backbone.Router History源码笔记
Backbone.History和Backbone.Router history和router都是控制路由的,做一个单页应用,要控制前进后退,就可以用到他们了. History类用于监听URL的变化, ...
- MongoDB - Introduction to MongoDB, MongoDB Extended JSON
JSON can only represent a subset of the types supported by BSON. To preserve type information, Mongo ...
- js实现全屏
详细内容请点击 1.window.open方式 第一种: 在已经打开的一个普通网页上,点击“全屏显示”,然后进入该网页对应的全屏模式.方法为:在网页的<body>与</body> ...
- 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
Win2k在NTFS系统下可能会出现这样的错误提示,解决办法很简单,只要在网站所在系统盘根目录给ASPNET用户读取权限就可以了,因为原因就是 Server.MapPath() 这个方法,这个方法是让 ...
- 跟我一起学习ASP.NET 4.5 MVC4.0(五)(转)
前面几篇文章介绍了一下ASP.NET MVC中的一些基础,今天我们一起来学习一下在ASP.NET MVC中控件的封装.在页面中我们会经常使用到Html对象,来程序控件,当然这里的控件不是说ASP.NE ...
- 各种LICENSE的作用--GET
许 多开发者和设计者希望把他们的作品作为开源项目共享,他们希望其他人能够利用和共享他们的代码. 而各种开源社区就是因为这个原因而充满活力.开源软件可以用于你能想象得到的任何应用程序,许多web设计人员 ...
- HDU1358:Period
第一次做KMP.还没有理解透. 在自己写一遍时没有让next[0]初始化为-1. 还有就是next应该是c++中的关键字,提交后编译错误. From: http://blog.csdn.net/lib ...
- 无限极分类sql数据库的设计
--创建测试数据表tb ) , pid ) , name )) ' , null , '广东省') ' , '广州市') ' , '深圳市') ' , '天河区') ' , '罗湖区') ' , '福 ...