public void When_HasNoSeoRecords_Expect_Null() { var category = new catalogModel.Category(); var result = category.Outlines.GetSeoPath(_store, new Language("en-US"), null); Assert.Null(result); }
public static Category ToCategory(this catalogDto.Category categoryDto, Language currentLanguage, Store store) { var result = new Category { Id = categoryDto.Id, CatalogId = categoryDto.CatalogId, Code = categoryDto.Code, Name = categoryDto.Name, ParentId = categoryDto.ParentId, TaxType = categoryDto.TaxType, Outline = categoryDto.Outlines.GetOutlinePath(store.Catalog), SeoPath = categoryDto.Outlines.GetSeoPath(store, currentLanguage, null) }; if (result.Outline != null) { //Need to take virtual parent from outline (get second last) because for virtual catalog category.ParentId still points to a physical category result.ParentId = result.Outline.Split("/").Reverse().Skip(1).Take(1).FirstOrDefault() ?? result.ParentId; } result.Url = "/" + (result.SeoPath ?? "category/" + categoryDto.Id); if (!categoryDto.SeoInfos.IsNullOrEmpty()) { var seoInfoDto = categoryDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>()) .GetBestMatchingSeoInfos(store, currentLanguage) .FirstOrDefault(); if (seoInfoDto != null) { result.SeoInfo = seoInfoDto.ToSeoInfo(); } } if (result.SeoInfo == null) { result.SeoInfo = new SeoInfo { Slug = categoryDto.Id, Title = categoryDto.Name }; } if (categoryDto.Images != null) { result.Images = categoryDto.Images.Select(ToImage).ToArray(); result.PrimaryImage = result.Images.FirstOrDefault(); } if (categoryDto.Properties != null) { result.Properties = categoryDto.Properties .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase)) .Select(p => ToProperty(p, currentLanguage)) .ToList(); } return(result); }
public void When_MissingAnyParentSeoRecord_Expect_Null() { var category = new catalogModel.Category { Outlines = new List <catalogModel.Outline> { new catalogModel.Outline { Items = new List <catalogModel.OutlineItem> { new catalogModel.OutlineItem { SeoObjectType = "Catalog", }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo>(), }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "parent1" }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "parent2" }, } }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "category1" }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "category2" }, }, }, }, }, }, }; var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null); Assert.Null(result); }
public virtual Category ToCategory(catalogDto.Category categoryDto, Language currentLanguage, Store store) { var result = new Category { Id = categoryDto.Id, CatalogId = categoryDto.CatalogId, Code = categoryDto.Code, Name = categoryDto.Name, ParentId = categoryDto.ParentId, TaxType = categoryDto.TaxType, Outline = categoryDto.Outlines.GetOutlinePath(store.Catalog), SeoPath = categoryDto.Outlines.GetSeoPath(store, currentLanguage, null) }; result.Url = "~/" + (result.SeoPath ?? "category/" + categoryDto.Id); if (!categoryDto.SeoInfos.IsNullOrEmpty()) { var seoInfoDto = categoryDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>()) .GetBestMatchingSeoInfos(store, currentLanguage) .FirstOrDefault(); if (seoInfoDto != null) { result.SeoInfo = seoInfoDto.ToSeoInfo(); } } if (result.SeoInfo == null) { result.SeoInfo = new SeoInfo { Slug = categoryDto.Id, Title = categoryDto.Name }; } if (categoryDto.Images != null) { result.Images = categoryDto.Images.Select(ToImage).ToArray(); result.PrimaryImage = result.Images.FirstOrDefault(); } if (categoryDto.Properties != null) { result.Properties = categoryDto.Properties .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase)) .Select(p => ToProperty(p, currentLanguage)) .ToList(); } return(result); }
private catalogDto.Category AddCategory(catalogDto.Catalog catalog, string categoryId, params string[] slugs) { var result = new catalogDto.Category { Id = categoryId, CatalogId = catalog.Id, Outlines = new List <catalogDto.Outline>() }; _categories.Add(result); _catalogSeoRecords.AddRange(slugs.Select(s => CreateSeoInfo("Category", categoryId, s))); return(result); }
public void When_ProductHasVirtualParent_Expect_KeepProduct() { var category = new catalogModel.Category { Outlines = new List <catalogModel.Outline> { new catalogModel.Outline { Items = new List <catalogModel.OutlineItem> { new catalogModel.OutlineItem { SeoObjectType = "Catalog", }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "virtual-parent1" }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "virtual-parent2" }, } }, new catalogModel.OutlineItem { SeoObjectType = "CatalogProduct", HasVirtualParent = true, SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "product1" }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "product2" }, }, }, }, }, }, }; var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null); Assert.Equal("virtual-parent2/product2", result); }
public virtual Category ToCategory(catalogDto.Category categoryDto, Language currentLanguage, Store store) { var result = ServiceLocator.Current.GetInstance <CatalogFactory>().CreateCategory(); result.InjectFrom <NullableAndEnumValueInjecter>(categoryDto); if (!categoryDto.SeoInfos.IsNullOrEmpty()) { var seoInfoDto = categoryDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>()) .GetBestMatchingSeoInfos(store, currentLanguage) .FirstOrDefault(); if (seoInfoDto != null) { result.SeoInfo = seoInfoDto.ToSeoInfo(); } } if (result.SeoInfo == null) { result.SeoInfo = new SeoInfo { Slug = categoryDto.Id, Title = categoryDto.Name }; } result.Url = "~/" + categoryDto.Outlines.GetSeoPath(store, currentLanguage, "category/" + categoryDto.Id); result.Outline = categoryDto.Outlines.GetOutlinePath(store.Catalog); if (categoryDto.Images != null) { result.Images = categoryDto.Images.Select(i => i.ToImage()).ToArray(); result.PrimaryImage = result.Images.FirstOrDefault(); } if (categoryDto.Properties != null) { result.Properties = categoryDto.Properties .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase)) .Select(p => p.ToProperty(currentLanguage)) .ToList(); } return(result); }
public void When_HasSeoRecords_Expect_ShortPath() { var category = new catalogModel.Category { Outlines = new List <catalogModel.Outline> { new catalogModel.Outline { Items = new List <catalogModel.OutlineItem> { new catalogModel.OutlineItem { SeoObjectType = "Catalog", }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "category1" }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "category2" }, }, } }, }, }, }; var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null); Assert.Equal("category2", result); }
public static Category ToCategory(this catalogDto.Category categoryDto, Language currentLanguage, Store store) { return(CatalogConverterInstance.ToCategory(categoryDto, currentLanguage, store)); }
public void When_HasInactiveSeoRecords_Expect_OnlyActiveRecords() { var category = new catalogModel.Category { Outlines = new List <catalogModel.Outline> { new catalogModel.Outline { Items = new List <catalogModel.OutlineItem> { new catalogModel.OutlineItem { SeoObjectType = "Catalog", }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "inactive-parent1", IsActive = false }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "active-parent1", IsActive = true }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "inactive-parent2", IsActive = false }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "active-parent2", IsActive = true }, } }, new catalogModel.OutlineItem { SeoObjectType = "Category", SeoInfos = new List <catalogModel.SeoInfo> { new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "inactive-category1", IsActive = false }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "active-category1", IsActive = true }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "inactive-category2", IsActive = false }, new catalogModel.SeoInfo { StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "active-category2", IsActive = true }, }, }, }, }, }, }; var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null); Assert.Equal("active-parent2/active-category2", result); }