Exemple #1
0
        public ItemCategory(Guid itemCategoryId, string name, ItemCategory parentItemCategory)
            : this(itemCategoryId, name)
        {
            if (parentItemCategory == null) throw new ArgumentNullException("parentItemCategory");

            ParentItemCategory = parentItemCategory;
            ParentItemCategoryId = parentItemCategory.ItemCategoryId;
        }
Exemple #2
0
 private static void AddEntities(
     DbContextImpl context, ItemCategory child, ItemCategory parent, Item item, Image img
 )
 {
     context.Set<ItemCategory>().Add(child);
     context.Set<ItemCategory>().Add(parent);
     context.Set<Item>().Add(item);
     context.Set<Image>().Add(img);
 }
Exemple #3
0
        public Item(string name, ItemCategory parentItemCategory)
        {
            if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name");
            if (parentItemCategory == null) throw new ArgumentNullException("parentItemCategory");

            Name = name;
            ParentItemCategory = parentItemCategory;
            ParentId = parentItemCategory.ItemCategoryId;
        }
Exemple #4
0
        private static void BuildItemWithImage(DbContextImpl context)
        {
            var child = new ItemCategory(Guid.NewGuid(), "Instruments");
            var parent = new ItemCategory(Guid.NewGuid(), "Music");

            var itemCategoryRelation = new ItemCategory(Guid.NewGuid(), "Instruments");

            var item = new Item("Guitar", itemCategoryRelation);

            Image img = new Image(Guid.NewGuid(), new UriType(Path), item);

               // AddEntities(context, child, parent, itemCategoryRelation, item, img);
        }
        private static IEnumerable<ItemCategory> BuildItemCategories(ItemCategory musicParentCategory, ItemCategory sportParentCategory, ItemCategory metalParentCategory, ItemCategory cricketParentCategory)
        {
            IEnumerable<ItemCategory> itemCategories = new[]
            {
                new ItemCategory(Guid.Empty, "Gen"),
                musicParentCategory,
                new ItemCategory(Guid.Empty, "Rap", musicParentCategory),
                new ItemCategory(Guid.Empty, "Opera", musicParentCategory),
                metalParentCategory,
                new ItemCategory(Guid.Empty, "Pantera", metalParentCategory),
                new ItemCategory(Guid.Empty, "Metallica", metalParentCategory),
                sportParentCategory,
                new ItemCategory(Guid.Empty, "Soccer", sportParentCategory),
                new ItemCategory(Guid.Empty, "Hockey", sportParentCategory),
                cricketParentCategory,
                new ItemCategory(Guid.Empty, "Bat", cricketParentCategory),
                new ItemCategory(Guid.Empty, "Ball", cricketParentCategory),
                new ItemCategory(Guid.Empty, "Wickets", cricketParentCategory),
            };

            return itemCategories;
        }
        public void GroupCategoryNamesAsFlatListHierarch_SortsCategoriesIntoAHierarchyOk()
        {
            var musicParentCategory = new ItemCategory(Guid.Empty, "Music");
            var sportParentCategory = new ItemCategory(Guid.Empty, "Sport");
            var metalParentCategory = new ItemCategory(Guid.Empty, "Metal", musicParentCategory);
            var cricketParentCategory = new ItemCategory(Guid.Empty, "Cricket", sportParentCategory);

            IEnumerable<ItemCategory> itemCategories = BuildItemCategories(musicParentCategory, sportParentCategory, metalParentCategory, cricketParentCategory);

            CategoryHierarchyService service = new CategoryHierarchyServiceImpl{ Separator = " > "};
            IList<string> categories = service.GroupCategoryNamesAsFlatListHierarchy(BuildParentChildGrouping(itemCategories)).ToList();

            Assert.That(categories, Is.Not.Empty);
            Assert.That(categories.Count(), Is.EqualTo(10));

            Assert.That(categories.Contains("Music > Rap"));
            Assert.That(categories.Contains("Music > Metal > Metallica"));
            Assert.That(categories.Contains("Sport > Cricket > Wickets"));

            Assert.That(categories.Distinct().Count(), Is.EqualTo(10)); // Assert all entries are unique

            Assert.That(categories.Count(s => s.Contains("Cricket")), Is.EqualTo(3));
            Assert.That(categories.Count(s => s.Contains("Metal")), Is.EqualTo(2));
        }
 public ParentChildCategory(string child, ItemCategory parent)
 {
     _child = child;
     if (parent != null)
         _parent = parent.Name;
 }
 public ItemCategoryBuilder With(ItemCategory parent)
 {
     this._parent = parent;
     return this;
 }
 public void Init()
 {
     _itemCategoryBuilder = new ItemCategoryBuilder();
     _musicParent = _itemCategoryBuilder.WithIdAndName(Id, MusicCategory).Build();
     _musicChild = _itemCategoryBuilder.With(_musicParent).WithIdAndName("057ED8FF-84D9-4263-8722-E2A963924B4B", MusicInstrumentCategory).Build();
     _musicChild2 = _itemCategoryBuilder.With(_musicParent).WithIdAndName("00F5CA2C-8717-4DBA-8A1A-8A687457B2A6", MusicVideoCategory).Build();
     _musicGrandChild = _itemCategoryBuilder.With(_musicChild).WithIdAndName("F9E6DBA6-4593-4484-B5CE-9F17266C2D5D", "Stringed").Build();
 }