首页 > 代码库 > UnitTest
UnitTest
#region File Header & Copyright Notice/* * Copyright (C) 2014 XXX, INC. All Rights Reserved. * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT BE USED * OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF XXX, INC. */#endregionusing 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 = "1"; 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[] { "1", "123" }; mock.ExpectAndReturn("UpdatePassword", 1, str); bool isChangePassword = userBll.UpdatePassword(str[0], str[1]); 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[] { "1", "123" }; mock.ExpectAndThrow("UpdatePassword", new UserException(), str); Assert.Throws<FaultException<MyExceptionContainer>>( () => this.userBll.UpdatePassword(str[0],str[1]) ); } [TestFixtureTearDown] ~UserNumit() { userBll = null; user = null; userDal = null; } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。