想要单元测试以下类中的方法
public class DeviceAuthorisationService : IDeviceAuthorisationService
{
private DeviceDetailsDTO deviceDetailsDTO = null;
private IDeviceAuthorisationRepositiory deviceAuthorisationRepositiory;
public DeviceAuthorisationService(IDeviceAuthorisationRepositioryService paramDeviceAuthorisationRepository)
{
deviceAuthorisationRepositiory = paramDeviceAuthorisationRepository;
}
public void AuthoriseDeviceProfile(long paramUserID, string paramClientMakeModel)
{
if (deviceDetailsDTO == null)
GetCellPhoneDetails(userID);
if (deviceDetailsDTO.IsDeviceSelected == false)
throw new SomeCustomExceptionA();
if (deviceDetailsDTO.CellPhoneMakeModel.ToLower() != paramClientMakeModel.ToLower())
throw new SomeCustomExceptionB;
}
public void UpdateDeviceStatusToActive(long userID)
{
if (deviceDetailsDTO == null)
throw new InvalidOperationException("UnAuthorised Device Profile Found Exception");
if (deviceDetailsDTO.PhoneStatus != (short)Status.Active.GetHashCode())
deviceAuthorisationRepositiory.UpdatePhoneStatusToActive(deviceDetailsDTO.DeviceID);
}
private void GetCellPhoneDetails(long userID)
{
deviceDetailsDTO = deviceAuthorisationRepositiory.GetSelectedPhoneDetails(userID); …
Run Code Online (Sandbox Code Playgroud) public class SomeClass
{
private readonly AuthenticationService _authenticationService = null;
private readonly ProfileService _profileService = null;
public SomeClass(IAuthenticationService authenticationService, ProfileService profileService)
{
_authenticationService = authenticationService;
_bgMeterProfileService = bgMeterProfileService;
}
...
Run Code Online (Sandbox Code Playgroud)
我使用_varName作为私有变量
这是为了区分私有变量和构造函数参数.
想要在open中抛出这个代码,看看是否有更好的方法来区分私有变量和方法参数