public ActionResult GetSearchProductsByAjax(SearchProductRequest request) { SearchProductRequest productSearchRequest = GenarateSeachRequest(request); SearchProductResponse response = service.SearchByProductName(productSearchRequest, SearchType.SearchString); return(Json(response)); }
public void EvalProductsTaxMiddleware_TaxNotCalculatedWithoutResponseGroup_Success() { // Arrange var mapper = new Mock <IMapper>(); var taxProviderSearchService = new Mock <ITaxProviderSearchService>(); var genericPipelineLauncher = new Mock <IGenericPipelineLauncher>(); var evalProductsTaxMiddleware = new EvalProductsTaxMiddleware(mapper.Object, taxProviderSearchService.Object, genericPipelineLauncher.Object); var response = new SearchProductResponse() { TotalCount = 1, Results = new List <ExpProduct>() { new ExpProduct() }, Query = new SearchProductQuery() { CurrencyCode = "USD" } }; //Act evalProductsTaxMiddleware.Run(response, resp => Task.CompletedTask); // Assert taxProviderSearchService.Verify(x => x.SearchTaxProvidersAsync(It.IsAny <TaxProviderSearchCriteria>()), Times.Never); }
/// <summary> /// Get ProductView contain list product of selected category /// </summary> /// <param name="id">id of category</param> /// <returns></returns> public ActionResult SearchProduct(string searchString, int?searchType) { SearchType type; if (searchType == null) { type = SearchType.SearchString; } else { type = (SearchType)searchType; } SearchProductRequest request = CreateInitialSearchRequest(searchString); SearchProductResponse response = service.SearchByProductName(request, type); PopulateStatusDropDownList(); PopulateCategoryList(); switch (type) { case SearchType.AllProduct: { @ViewBag.SearchTitle = "Tất cả các sản phẩm"; break; } case SearchType.SearchString: { @ViewBag.SearchTitle = "Từ khóa : " + request.SearchString; break; } case SearchType.NewProducts: { @ViewBag.SearchTitle = "Sản phẩm mới"; break; } case SearchType.BestSellProducts: { @ViewBag.SearchTitle = "Sản phẩm HOT"; break; } } return(View("SearchResult", response)); }
public void EvalProductsTaxMiddleware_TaxRatesCalculated_Success() { // Arrange var taxProvider = new Mock <TaxProvider>(); taxProvider.Object.IsActive = true; var mapper = new Mock <IMapper>(); var taxProviderSearchService = new Mock <ITaxProviderSearchService>(); taxProviderSearchService.Setup(x => x.SearchTaxProvidersAsync(It.IsAny <TaxProviderSearchCriteria>())) .ReturnsAsync(() => new TaxProviderSearchResult() { TotalCount = 1, Results = new List <TaxProvider>() { taxProvider.Object } }); var genericPipelineLauncher = new Mock <IGenericPipelineLauncher>(); var evalProductsTaxMiddleware = new EvalProductsTaxMiddleware(mapper.Object, taxProviderSearchService.Object, genericPipelineLauncher.Object); var response = new SearchProductResponse() { TotalCount = 1, Results = new List <ExpProduct>() { new ExpProduct() }, Query = new SearchProductQuery() { CurrencyCode = "USD", IncludeFields = new List <string>() { "price" } //ResponseGroup.LoadPrices }, }; //Act Action action = () => evalProductsTaxMiddleware.Run(response, resp => Task.CompletedTask); // Assert action.Should().NotThrow(); taxProviderSearchService.Verify(x => x.SearchTaxProvidersAsync(It.IsAny <TaxProviderSearchCriteria>()), Times.Once); taxProvider.Verify(x => x.CalculateRates(It.IsAny <TaxEvaluationContext>()), Times.Once); }
/// <summary> /// Search product by name /// </summary> /// <param name="request"></param> /// <returns></returns> public SearchProductResponse SearchByProductName(SearchProductRequest request, SearchType searchType) { IEnumerable <ecom_Products> foundProducts = GetAllProductsMatchingSearchString(request, searchType); SearchProductResponse response = new SearchProductResponse() { CategoryIds = request.CategoryIds, NumberOfTitlesFound = foundProducts.Count(), TotalNumberOfPages = (int)Math.Ceiling((double)foundProducts.Count() / request.NumberOfResultsPerPage), CurrentPage = request.Index, SearchString = request.SearchString, SortBy = (int)request.SortBy, BrandIds = request.BrandIds, Products = CropProductListToSatisfyGivenIndex(foundProducts, request.Index, request.NumberOfResultsPerPage).ConvertToProductSummaryViews(), Brands = foundProducts.Select(p => p.ecom_Brands).Where(b => b != null).Distinct().ToList().ConvertToBrandSummaryViews()// return list Brand exist in group product belong to selected category }; return(response); }
public SearchProductResponse SearchProduct(SearchProductRequest request) { SearchProductResponse res = new SearchProductResponse(); string strSP = SqlCommandStore.uspSearchProduct; try { using (SqlCommand cmd = new SqlCommand(strSP)) { cmd.Parameters.Add("ProductCode", SqlDbType.VarChar, 20).Value = request.ProductCode; cmd.Parameters.Add("ProductName", SqlDbType.NVarChar, 100).Value = request.ProductName; cmd.Parameters.Add("FromPrice", SqlDbType.Decimal, 18).Value = request.FromPrice; cmd.Parameters.Add("ToPrice", SqlDbType.Decimal, 18).Value = request.ToPrice; cmd.Parameters.Add("Status", SqlDbType.Int).Value = request.Status; cmd.Parameters.Add("CategoryID", SqlDbType.BigInt).Value = request.CategoryID; cmd.Parameters.Add("@Return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; DataSet ds = DB.ExecuteSPDataSet(cmd); res.Code = (ReturnCode)Convert.ToInt32(cmd.Parameters["@Return"].Value); if (res.Code != ReturnCode.Success) { DB.RollBackTran(); return(res); } DataRow[] rows = new DataRow[ds.Tables[0].Rows.Count]; rows = new DataRow[ds.Tables[0].Rows.Count]; ds.Tables[0].Rows.CopyTo(rows, 0); res.products = rows.Select(row => new ProductModel(row)).ToList(); return(res); } } catch (Exception ex) { LogWriter.WriteLogException(ex); res.Code = ReturnCode.Fail; return(res); } }
public void EvalProductsTaxMiddleware_TaxesApply_Success() { // Arrange var currency = new Currency(Language.InvariantLanguage, "USD") { RoundingPolicy = new DefaultMoneyRoundingPolicy() }; var productPrice = new Mock <ProductPrice>(currency).Object; productPrice.TaxPercentRate = 0; productPrice.ListPrice = new Money(100m, currency); productPrice.DiscountAmount = new Money(0m, currency); productPrice.ProductId = "someId"; var taxProvider = new Mock <TaxProvider>(); taxProvider.Object.IsActive = true; taxProvider.Setup(x => x.CalculateRates(It.IsAny <TaxEvaluationContext>())) .Returns(() => new List <TaxRate>() { new TaxRate() { Currency = "USD", Rate = 50, Line = new TaxLine() { Id = "someId", Quantity = 0 } } }); var mapper = new Mock <IMapper>(); var taxProviderSearchService = new Mock <ITaxProviderSearchService>(); taxProviderSearchService.Setup(x => x.SearchTaxProvidersAsync(It.IsAny <TaxProviderSearchCriteria>())) .ReturnsAsync(() => new TaxProviderSearchResult() { TotalCount = 0, Results = new List <TaxProvider>() { taxProvider.Object } }); var genericPipelineLauncher = new Mock <IGenericPipelineLauncher>(); var evalProductsTaxMiddleware = new EvalProductsTaxMiddleware(mapper.Object, taxProviderSearchService.Object, genericPipelineLauncher.Object); var response = new SearchProductResponse() { TotalCount = 1, Results = new List <ExpProduct>() { new ExpProduct() { AllPrices = new List <ProductPrice>() { productPrice } } }, Query = new SearchProductQuery() { CurrencyCode = "USD", IncludeFields = new List <string>() { "price" } }, }; //Act Action action = () => evalProductsTaxMiddleware.Run(response, resp => Task.CompletedTask); // Assert action.Should().NotThrow(); taxProviderSearchService.Verify(x => x.SearchTaxProvidersAsync(It.IsAny <TaxProviderSearchCriteria>()), Times.Once); taxProvider.Verify(x => x.CalculateRates(It.IsAny <TaxEvaluationContext>()), Times.Once); productPrice.TaxPercentRate.Should().Be(0.5m); }