public void OrderItemsCatalog(string orderBy) { ShopModel model = (ShopModel)Session["model"]; ItemCatalogFacilitator.ItemSorttype type = ItemCatalogFacilitator.ItemSorttype.NAME_AZ; switch (orderBy) { case "PRICE_HL": type = ItemCatalogFacilitator.ItemSorttype.PRICE_HL; break; case "PRICE_LH": type = ItemCatalogFacilitator.ItemSorttype.PRICE_LH; break; case "NAME_AZ": type = ItemCatalogFacilitator.ItemSorttype.NAME_AZ; break; case "NAME_ZA": type = ItemCatalogFacilitator.ItemSorttype.NAME_ZA; break; } model.itemCatalog = ItemCatalogFacilitator.OrderItems(type, model.itemCatalog); Session["model"] = model; }
public void OrderItemsTest() { // create dummy items List <Item> itemList = new List <Item>(); Item item1 = new Item { itemID = 1, name = "A", sellingPrice = 25 }; Item item2 = new Item { itemID = 2, name = "B", sellingPrice = 10 }; Item item3 = new Item { itemID = 3, name = "C", sellingPrice = 100 }; itemList.Add(item1); itemList.Add(item2); itemList.Add(item3); itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.NAME_AZ, itemList); // should be in alphabetical order from A - Z if (itemList[0].name != "A") { Assert.Fail(); } if (itemList[1].name != "B") { Assert.Fail(); } if (itemList[2].name != "C") { Assert.Fail(); } // now check alphabetical order Z-A itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.NAME_ZA, itemList); if (itemList[0].name != "C") { Assert.Fail(); } if (itemList[1].name != "B") { Assert.Fail(); } if (itemList[2].name != "A") { Assert.Fail(); } // now check price Low - High itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.PRICE_LH, itemList); // should be in order item2, item1, item3 if (itemList[0] != item2) { Assert.Fail(); } if (itemList[1] != item1) { Assert.Fail(); } if (itemList[2] != item3) { Assert.Fail(); } // now check price High - Low itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.PRICE_HL, itemList); // should be in order item3, item1, item2 if (itemList[0] != item3) { Assert.Fail(); } if (itemList[1] != item1) { Assert.Fail(); } if (itemList[2] != item2) { Assert.Fail(); } }