EntityFramework 用Moles的mock

Notice: 当constructor为private的时候,new MXxxxxxx().Instance , 否则就可以直接new, 但要moles constructor


using
System.Data.Objects.Moles; public void GetProjectInfoTest() { MXTRACHoldingDBEntities.AllInstances.GetProjectSettingString = (obj, fileName) => { MObjectResult01<ProjectInfo> result = new MObjectResult01<ProjectInfo>(); result.Bind( new List<ProjectInfo>() { new ProjectInfo() { ProjectName = "Project", ProjectDescription = "Description", //other properties } }); return result.Instance; }; //other codes and Assert }
原文地址:https://www.cnblogs.com/DelPiero/p/2719863.html