Требуется Unit Test метод в следующем классе
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 на тот, который хранится в соответствии с db
- Если он совпадает - он просто возвращает (т.е. не меняет состояние)
Как мы будем использовать Unit Test этот метод?
- Издевались над Repo
- Раскрыл сценарий "ИСКЛЮЧЕНИЕ ЧЕРЕЗ"
- Вопрос в том, как Unit Test сценарий ALL WENT WELL, т.е. пользовательский makeModel, сопоставленный с репозиторием; s makeModel
Любые предложения по дизайну, чтобы сделать этот testable наиболее приветствуется Спасибо заранее.