小编Ven*_*u b的帖子

单元测试返回void的方法

想要单元测试以下类中的方法

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)

c# unit-testing dependency-injection

14
推荐指数
3
解决办法
2万
查看次数

需要C#命名建议

 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中抛出这个代码,看看是否有更好的方法来区分私有变量和方法参数

c# naming-conventions

0
推荐指数
1
解决办法
83
查看次数