public void Rendering_When_Current_Product_Exists_Should_Return_View_With_Non_Empty_Model() { //Arrange var product = new Product { Sku = "testsku", ProductDefinition = Guid.NewGuid() }; _catalogContext.CurrentProduct.Returns(product); //Act var result = _controller.Rendering(); //Assert var viewResult = result as ViewResult; var model = viewResult != null ? viewResult.Model as AddToBasketButtonRenderingViewModel : null; Assert.NotNull(viewResult); Assert.NotNull(model); Assert.NotEmpty(model.AddToBasketUrl); Assert.NotEmpty(model.BasketUrl); Assert.True(model.ConfirmationMessageTimeoutInMillisecs > 0); Assert.NotEmpty(model.ConfirmationMessageClientId); Assert.NotEmpty(model.ProductSku); Assert.False(model.IsProductFamily); }
private static string GetProductUrl(Ucommerce.Search.Models.Product product, Guid detailPageId) { var CatalogContext = ObjectFactory.Instance.Resolve <ICatalogContext>(); var UrlService = ObjectFactory.Instance.Resolve <IUrlService>(); if (detailPageId == Guid.Empty) { return(UrlService.GetUrl(CatalogContext.CurrentCatalog, product)); } var baseUrl = Pages.UrlResolver.GetPageNodeUrl(detailPageId); string catUrl; var productCategory = product.Categories.FirstOrDefault(); if (productCategory == null) { catUrl = CategoryModel.DefaultCategoryName; } else { var category = CatalogContext.CurrentCategories.FirstOrDefault(x => x.Guid == productCategory); catUrl = CategoryModel.GetCategoryPath(category); } var rawtUrl = string.Format("{0}/{1}", catUrl, product.Slug); string relativeUrl = string.Concat(VirtualPathUtility.RemoveTrailingSlash(baseUrl), "/", rawtUrl); string url; if (SystemManager.CurrentHttpContext.Request.Url != null) { url = UrlPath.ResolveUrl(relativeUrl, true); } else { url = Pages.UrlResolver.GetAbsoluteUrl(relativeUrl); } return(url); }