次のクラスのメソッドをユニットテストしたい
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);
if (deviceDetailsDTO == null)
throw new SomeCustomException()
}
}
ノート:
- メソッド名=AuthoriseDeviceProfileはvoidを返します
- このメソッドは、userSentMakeModelをdbmatchに格納されているものと照合します
- 一致する場合-単に戻ります(つまり、状態を変更しません)
このメソッドをどのように単体テストしますか?
- レポを嘲笑しました
- 「THROWSEXCEPTION」のシナリオをカバーしました
- 問題は、ALL WENTWELLのシナリオをユニットテストする方法です。つまり、ユーザーのmakeModelがリポジトリと一致します。
これをテスト可能にするための設計上の提案は大歓迎です。よろしくお願いします。