public async Task <Subcategory> AddAsync(Subcategory subcategory) { Guard.Against.NullInvalid(subcategory, Resources.Subcategory_Invalid_ErrorMessage); Guard.Against.NullString(subcategory.Name, Resources.Subcategory_InvalidName_ErrorMessage); Guard.Against.LessOne(subcategory.CategoryId, Resources.Category_InvalidId_ErrorMessage); if (!await _categoryRepository.ExistAsync(subcategory.CategoryId)) { var message = string.Format(Resources.Category_NotFoundById_ErrorMessage, subcategory.CategoryId); throw new RutrackerException(message, ExceptionEventTypes.InvalidParameters); } if (await _subcategoryRepository.ExistAsync(x => x.Name == subcategory.Name)) { var message = string.Format(Resources.Subcategory_AlreadyExistsName_ErrorMessage, subcategory.Name); throw new RutrackerException(message, ExceptionEventTypes.InvalidParameters); } subcategory.AddedDate = _dateService.Now(); var result = await _subcategoryRepository.AddAsync(subcategory); await _unitOfWork.SaveChangesAsync(); return(result); }
public async Task ExistAsync_10_ReturnsValidIsExist() { // Arrange const int expectedId = SubcategoriesCount; const bool expectedCondition = true; // Act var isExist = await _subcategoryRepository.ExistAsync(expectedId); // Assert Assert.Equal(expectedCondition, isExist); }
public async Task <Torrent> AddAsync(Torrent torrent) { Guard.Against.NullInvalid(torrent, Resources.Torrent_Invalid_ErrorMessage); Guard.Against.NullString(torrent.Name, Resources.Torrent_InvalidName_ErrorMessage); Guard.Against.NullString(torrent.Content, Resources.Torrent_InvalidContent_ErrorMessage); Guard.Against.LessOne(torrent.SubcategoryId, Resources.Torrent_InvalidSubcategoryId_ErrorMessage); if (!await _subcategoryRepository.ExistAsync(torrent.SubcategoryId)) { throw new RutrackerException( string.Format(Resources.Subcategory_NotFoundById_ErrorMessage, torrent.SubcategoryId), ExceptionEventTypes.InvalidParameters); } torrent.TrackerId = null; torrent.Hash = null; torrent.Size = 0; torrent.IsStockTorrent = false; torrent.AddedDate = _dateService.Now(); var result = await _torrentRepository.AddAsync(torrent); await _unitOfWork.SaveChangesAsync(); var containerName = result.Id.ToString().PadLeft(10, '0'); await _storageService.CreateContainerAsync(containerName); return(result); }