public void WHEN_CategoryId_Is_Invalid_SHOULD_Throw_ArgumentException() { _repository = _container.CreateInstance <CategoryRepository>(); var param = new GetCategoriesPathParam { Scope = GetRandom.String(10), CultureInfo = _cultureInfo, CategoryId = "Z" }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => _repository.GetCategoriesPathAsync(param)); // Assert exception.ParamName.Should().Be("categoryId"); }
/// <summary> /// Gets the categories path from the provided categoryId to the root category. /// </summary> /// <param name="param">The parameter.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">param</exception> public virtual async Task <CategoryViewModel[]> GetCategoriesPathAsync(GetCategoriesPathParam param) { if (param == null) { throw new ArgumentNullException("param"); } var categoriesPath = await _categoryRepository.GetCategoriesPathAsync(param).ConfigureAwait(false); var categoriesPathViewModel = categoriesPath.Select(category => { var categoryViewModelParam = new CreateCategoryViewModelParam(category, param.CultureInfo); return(CreateCategoryViewModel(categoryViewModelParam)); }); return(categoriesPathViewModel.ToArray()); }
/// <summary> /// Gets the categories path from the provided categoryId to the root category. /// </summary> /// <param name="param">The parameter.</param> /// <returns> /// Categories path starting at provided category up to root category. /// </returns> /// <exception cref="System.ArgumentNullException">param</exception> public async Task <List <Category> > GetCategoriesPathAsync(GetCategoriesPathParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CategoryId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CategoryId)), nameof(param)); } var categoriesTree = await GetCategoriesTreeAsync(param.Scope).ConfigureAwait(false); return(BuildPathFromTree(categoriesTree, param.CategoryId)); }
/// <summary> /// Gets the categories path from the provided categoryId to the root category. /// </summary> /// <param name="param">The parameter.</param> /// <returns> /// Categories path starting at provided category up to root category. /// </returns> /// <exception cref="System.ArgumentNullException">param</exception> public async Task <List <Category> > GetCategoriesPathAsync(GetCategoriesPathParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Scope"), "param"); } if (string.IsNullOrWhiteSpace(param.CategoryId)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CategoryId"), "param"); } var categoriesTree = await GetCategoriesTreeAsync(param.Scope).ConfigureAwait(false); return(BuildPathFromTree(categoriesTree, param.CategoryId)); }