????????????
???????????? ???????[ 2016/8/12 10:11:12 ] ??????????????? ???????
?????о???????????????????????????????????????????????£?
????????????????????????????????
????DAL
using System.Collections.Generic;
using MetalsExchange.IDAL;
using MetalsExchange.DBUtility;
using MetalsExchange.Model;
namespace MetalsExchange.SQLServerDAL
{
public class Employee: IEmployee
{
public IList<CustomerInfo> GetCustomerList()
{
IList<CustomerInfo> list = new List<CustomerInfo>();
return list;
}
}
}
????IDAL
using System.Collections.Generic;
using MetalsExchange.Model;
namespace MetalsExchange.IDAL
{
public interface IEmployee
{
IList<CustomerInfo> GetCustomerList();
}
}
????BLL
using System.Collections.Generic;
using MetalsExchange.Model;
using MetalsExchange.IDAL;
namespace MetalsExchange.Bll
{
public class EmployeeBll
{
public IEmployee dal = DALFactory.DataAccess.CreateEmployee();
public IList<CustomerInfo> GetCustomerList()
{
return dal.GetCustomerList();
}
}
}
????DALFactory
using System.Configuration;
using System.Reflection;
namespace MetalsExchange.DALFactory
{
public class DataAccess
{
private static string path {
get {
string _path= ConfigurationManager.AppSettings["WebDAL"];
if (_path == null)
_path = "MetalsExchange.SQLServerDAL";
return _path;
}
}
public static IDAL.IEmployee CreateEmployee()
{
string className = path + ".Employee";
return (IDAL.IEmployee)Assembly.Load(path).CreateInstance(className);
}
}
}
???????????????????????????????????????????????????????ConfigurationManager.AppSettings["WebDAL"]?????????????????????????config??????????????????????????????????????????????·??
???????????
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using Moq;
using MetalsExchange.IDAL;
using MetalsExchange.Model;
namespace MetalsExchange.Bll.Tests
{
[TestClass()]
public class EmployeeBllTests
{
[TestMethod()]
public void GetCustomerListTest()
{
//arrange
var mock = new Mock<IEmployee>();
mock.Setup(customer => customer.GetCustomerList()).Returns(new List<CustomerInfo>());
EmployeeBll employee = new EmployeeBll();
//art
IList<CustomerInfo> list = employee.GetCustomerList();
mock.Verify();
//assert
Assert.ReferenceEquals(list?? mock.Object.GetCustomerList());
}
}
}
?????????????????????????????????????
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MetalsExchange.IDAL;
namespace MetalsExchange.DALFactory.Tests
{
[TestClass()]
public class DataAccessTests
{
[TestMethod()]
public void CreateEmployeeTest()
{
IEmployee dal = DataAccess.CreateEmployee();
Assert.IsNotNull(dal);
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11