public void Should_add_item_to_stock() { var item = new Item("desk", 32); var item2 = new Item("shelf", 27); _subject.AddItem(item); _subject.AddItem(item2); Assert.That(_subject.Items, Is.EquivalentTo(new[] { item, item2 })); }
public void TestDefaultUpdater1() { Item item = new Item { Name = "foo", SellIn = 5, Quality = 10 }; Stock.AddItem(item, DefaultUpdater.Instance); // [R4.1] Expectations.Add(new Expectation(9, 4)); Expectations.Add(new Expectation(8, 3)); Expectations.Add(new Expectation(7, 2)); Expectations.Add(new Expectation(6, 1)); Expectations.Add(new Expectation(5, 0)); // [R4.2] Expectations.Add(new Expectation(3, -1)); Expectations.Add(new Expectation(1, -2)); // [R4.3] Expectations.Add(new Expectation(0, -3)); Expectations.Add(new Expectation(0, -4)); CheckItemEvolution(item); }
public void TestTicketUpdater() { Item item = new Item { Name = "Ticket", SellIn = 12, Quality = 3 }; Stock.AddItem(item, ConcertTicketUpdater.Instance); // [R4.6] Expectations.Add(new Expectation(4, 11)); Expectations.Add(new Expectation(5, 10)); Expectations.Add(new Expectation(7, 9)); Expectations.Add(new Expectation(9, 8)); Expectations.Add(new Expectation(11, 7)); Expectations.Add(new Expectation(13, 6)); Expectations.Add(new Expectation(15, 5)); Expectations.Add(new Expectation(18, 4)); Expectations.Add(new Expectation(21, 3)); Expectations.Add(new Expectation(24, 2)); Expectations.Add(new Expectation(27, 1)); Expectations.Add(new Expectation(30, 0)); Expectations.Add(new Expectation(0, -1)); Expectations.Add(new Expectation(0, -2)); CheckItemEvolution(item); }
public void TestDefaultUpdater2() { Item item = new Item { Name = "Cake", SellIn = 0, Quality = 3 }; Stock.AddItem(item, DefaultUpdater.Instance); Expectations.Add(new Expectation(1, -1)); CheckItemEvolution(item); }
public void TestLegendaryUpdater() { Item item = new Item { Name = "Sulfuras", SellIn = 5, Quality = 1515 }; Stock.AddItem(item, LegendaryItemUpdater.Instance); // [R5] and [R7] Expectations.Add(new Expectation(1515, 5)); CheckItemEvolution(item); }
public static void Main(string[] args) { Console.WriteLine("OMGHAI!"); Stock stock = new Stock(); stock.AddItem(new Item { Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20 }, DefaultUpdater.Instance); stock.AddItem(new Item { Name = "Aged Brie", SellIn = 2, Quality = 0 }, CheeseUpdater.Instance); stock.AddItem(new Item { Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7 }, DefaultUpdater.Instance); stock.AddItem(new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80 }, LegendaryItemUpdater.Instance); stock.AddItem(new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80 }, LegendaryItemUpdater.Instance); stock.AddItem(new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 15, Quality = 20 }, ConcertTicketUpdater.Instance); stock.AddItem(new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 10, Quality = 49 }, ConcertTicketUpdater.Instance); stock.AddItem(new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 5, Quality = 49 }, ConcertTicketUpdater.Instance); // this conjured item does not work properly yet stock.AddItem(new Item { Name = "Conjured Mana Cake", SellIn = 3, Quality = 6 }, ConjuredItemsUpdater.Instance); for (int i = 0; i < 31; i++) { Console.WriteLine("-------- day " + i + " --------"); stock.Dump(Console.Out); stock.UpdateQuality(); } }
public void TestConjuredItemsUpdater() { Item item = new Item { Name = "Conjured meatball", SellIn = 5, Quality = 17 }; Stock.AddItem(item, ConjuredItemsUpdater.Instance); // [R6] Expectations.Add(new Expectation(15, 4)); Expectations.Add(new Expectation(13, 3)); Expectations.Add(new Expectation(11, 2)); Expectations.Add(new Expectation(9, 1)); Expectations.Add(new Expectation(7, 0)); Expectations.Add(new Expectation(3, -1)); Expectations.Add(new Expectation(0, -2)); CheckItemEvolution(item); }
public void TestCheeseUpdater() { Item item = new Item { Name = "Blue cheese", SellIn = 5, Quality = 3 }; Stock.AddItem(item, CheeseUpdater.Instance); // [R4.5] Expectations.Add(new Expectation(4, 4)); CheckItemEvolution(item); // [R4.4] for (int i = 0; i < 100; i++) { Stock.UpdateQuality(); } Assert.AreEqual(50, item.Quality); }
private void SaveRecord() { StockItemDetails clsDetails = new StockItemDetails(); clsDetails.StockID = Convert.ToInt64(lblStockID.Text); clsDetails.ProductID = Convert.ToInt64(cboProductCode.SelectedItem.Value); clsDetails.VariationMatrixID = Convert.ToInt64(cboVariation.SelectedItem.Value); clsDetails.ProductUnitID = Convert.ToInt32(cboProductUnit.SelectedItem.Value); clsDetails.StockTypeID = Convert.ToInt16(txtStockTypeCode.ToolTip); clsDetails.StockDate = DateTime.Now; clsDetails.Quantity = Convert.ToDecimal(txtQuantity.Text); clsDetails.Remarks = txtRemarks.Text; clsDetails.PurchasePrice = Convert.ToDecimal(txtPurchasePrice.Text); StockDirections StockDirection = (StockDirections)Enum.Parse(typeof(StockDirections), txtStockDirection.Text); Security.AccessUserDetails clsAccessUserDetails = (Security.AccessUserDetails)Session["AccessUserDetails"]; Stock clsStock = new Stock(); clsStock.AddItem(int.Parse(cboBranch.SelectedItem.Value), lblTransactionNo.Text, clsAccessUserDetails.Name, clsDetails, StockDirection); clsStock.CommitAndDispose(); }
public void CanAddItemToInventory() { inventory.AddItem(new Item()); inventory.Size().Should().Be(1); }
static void Main(string[] args) { Item it = new Item("Generic Item", 3); FoodItem fi = new FoodItem("Food", 4, new Date(3, 2, 2016), new Date(3, 2, 2017)); RefrigeratedItem ri = new RefrigeratedItem("Refrig", 6, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1); ElectronicItem ei = new ElectronicItem("Elec", 7, new Date(4, 10, 2017)); List <Item> stKolBo = new List <Item>(100); stKolBo.Add(it); stKolBo.Add(fi); stKolBo.Add(ri); stKolBo.Add(ei); Stock stk = new Stock(); stk.AddItem(it); stk.AddItem(fi); stk.AddItem(ri); stk.AddItem(ei); //Console.WriteLine(fi); //Console.WriteLine(stk); //stk.AddItem(ri); //stk.AddItem(fi); //stk.AddItem(ri); //stk.AddItem(fi); stk.AddItem(new RefrigeratedItem("Refrig1", 2, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig2", 2, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig3", 10, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig4", 2, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig5", 23, new Date(6, 12, 2016), new Date(6, 12, 2019), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig6", 2, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1)); stk.AddItem(new RefrigeratedItem("Refrig7", 13, new Date(6, 12, 2016), new Date(6, 12, 2020), -10, -1)); RefrigeratedItem riAdd = new RefrigeratedItem("Leben", 2, new Date(6, 12, 2016), new Date(6, 12, 2018), -10, -1); stk.AddItem(riAdd); stk.RemoveItem(riAdd); stk.Order(9); int refrigCount = stk.HowMany(-6); stk.RemoveAfterDate(new Date(1, 1, 2019)); }
private void Upload() { if ((txtPath.PostedFile != null) && (txtPath.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(txtPath.PostedFile.FileName); string SaveLocation = "/RetailPlus/temp/uploaded_" + fn; txtPath.PostedFile.SaveAs(SaveLocation); XmlTextReader reader = new XmlTextReader(SaveLocation); reader.WhitespaceHandling = WhitespaceHandling.None; Stock clsStock = new Stock(); clsStock.GetConnection(); string strStockTransactionNo = null; long StockID = 0; long ContactID = 0; int UnitID = 0; long ProductGroupID = 0; long ProductSubGroupID = 0; long ProductID = 0; long ProductBaseMatrixID = 0; VariationDetails clsVariationDetails; int VariationID = 0; StockItemDetails clsStockItemDetails = new StockItemDetails(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Stock") { strStockTransactionNo = reader.GetAttribute("TransactionNo"); StockID = clsStock.Details(reader.GetAttribute("TransactionNo")).StockID; if (StockID > 0) { clsStock.CommitAndDispose(); Label1.Text = "<b>This file has already been added to inventory.<br />"; Label1.Text += "Please refer to transaction No: " + strStockTransactionNo + ".</b>"; reader.Close(); return; } Contacts clsContact = new Contacts(clsStock.Connection, clsStock.Transaction); ContactID = clsContact.Details(reader.GetAttribute("ContactCode")).ContactID; if (ContactID == 0) { ContactDetails clsContactDetails = new ContactDetails(); clsContactDetails.ContactCode = reader.GetAttribute("ContactCode"); clsContactDetails.ContactName = reader.GetAttribute("ContactName"); clsContactDetails.ContactGroupID = Convert.ToInt32(reader.GetAttribute("ContactGroupID")); clsContactDetails.ModeOfTerms = (ModeOfTerms)Enum.Parse(typeof(ModeOfTerms), reader.GetAttribute("ModeOfTerms")); clsContactDetails.Terms = Convert.ToInt32(reader.GetAttribute("Terms")); clsContactDetails.Address = reader.GetAttribute("Address"); clsContactDetails.BusinessName = reader.GetAttribute("BusinessName"); clsContactDetails.TelephoneNo = reader.GetAttribute("TelephoneNo"); clsContactDetails.Remarks = reader.GetAttribute("Remarks"); clsContactDetails.Debit = Convert.ToDecimal(reader.GetAttribute("Debit")); clsContactDetails.Credit = Convert.ToDecimal(reader.GetAttribute("Credit")); clsContactDetails.IsCreditAllowed = Convert.ToBoolean(reader.GetAttribute("IsCreditAllowed")); clsContactDetails.CreditLimit = Convert.ToDecimal(reader.GetAttribute("CreditLimit")); ContactID = clsContact.Insert(clsContactDetails); } StockDetails clsStockDetails = new StockDetails(); clsStockDetails.TransactionNo = reader.GetAttribute("TransactionNo"); clsStockDetails.StockTypeID = Convert.ToInt16(Constants.STOCK_TYPE_TRANSFER_FROM_BRANCH_ID); clsStockDetails.StockDate = DateTime.Now; clsStockDetails.SupplierID = ContactID; clsStockDetails.Remarks = reader.GetAttribute("StockRemarks") + Environment.NewLine + "Original Stock Date: " + reader.GetAttribute("StockDate"); StockItemDetails[] itemDetails = new StockItemDetails[0]; clsStockDetails.StockItems = itemDetails; StockID = clsStock.Insert(clsStockDetails); } else if (reader.Name == "Item") { Data.Unit clsUnit = new Data.Unit(clsStock.Connection, clsStock.Transaction); UnitID = clsUnit.Details(reader.GetAttribute("ProductUnitCode")).UnitID; if (UnitID == 0) { UnitDetails clsUnitDetails = new UnitDetails(); clsUnitDetails.UnitCode = reader.GetAttribute("ProductUnitCode"); clsUnitDetails.UnitName = reader.GetAttribute("ProductUnitName"); UnitID = clsUnit.Insert(clsUnitDetails); } ProductGroup clsProductGroup = new ProductGroup(clsStock.Connection, clsStock.Transaction); ProductGroupID = clsProductGroup.Details(reader.GetAttribute("ProductGroupCode")).ProductGroupID; if (ProductGroupID == 0) { Label1.Text += "inserting product group...."; ProductGroupDetails clsProductGroupDetails = new ProductGroupDetails(); clsProductGroupDetails.ProductGroupCode = reader.GetAttribute("ProductGroupCode"); clsProductGroupDetails.ProductGroupName = reader.GetAttribute("ProductGroupName"); clsProductGroupDetails.UnitDetails = new UnitDetails { UnitID = UnitID }; clsProductGroupDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price")); clsProductGroupDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice")); clsProductGroupDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount")); clsProductGroupDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT")); clsProductGroupDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT")); clsProductGroupDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax")); ProductGroupID = clsProductGroup.Insert(clsProductGroupDetails); } ProductSubGroup clsProductSubGroup = new ProductSubGroup(clsStock.Connection, clsStock.Transaction); ProductSubGroupID = clsProductSubGroup.Details(reader.GetAttribute("ProductSubGroupCode")).ProductSubGroupID; if (ProductSubGroupID == 0) { Label1.Text += "inserting product sub-group...."; ProductSubGroupDetails clsProductSubGroupDetails = new ProductSubGroupDetails(); clsProductSubGroupDetails.ProductGroupID = ProductGroupID; clsProductSubGroupDetails.ProductSubGroupCode = reader.GetAttribute("ProductSubGroupCode"); clsProductSubGroupDetails.ProductSubGroupName = reader.GetAttribute("ProductSubGroupName"); clsProductSubGroupDetails.BaseUnitID = UnitID; clsProductSubGroupDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price")); clsProductSubGroupDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice")); clsProductSubGroupDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount")); clsProductSubGroupDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT")); clsProductSubGroupDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT")); clsProductSubGroupDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax")); ProductSubGroupID = clsProductSubGroup.Insert(clsProductSubGroupDetails); } Products clsProduct = new Products(clsStock.Connection, clsStock.Transaction); ProductID = clsProduct.Details(reader.GetAttribute("BarCode")).ProductID; if (ProductID == 0) { Label1.Text += "inserting product...."; ProductDetails clsProductDetails = new ProductDetails(); clsProductDetails.ProductCode = reader.GetAttribute("ProductCode"); clsProductDetails.BarCode = reader.GetAttribute("BarCode"); clsProductDetails.ProductDesc = reader.GetAttribute("ProductDesc"); clsProductDetails.ProductGroupID = ProductGroupID; clsProductDetails.ProductSubGroupID = ProductSubGroupID; clsProductDetails.ProductDesc = reader.GetAttribute("ProductDesc"); clsProductDetails.BaseUnitID = UnitID; clsProductDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price")); clsProductDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice")); clsProductDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount")); clsProductDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT")); clsProductDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT")); clsProductDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax")); clsProductDetails.Quantity = 0; clsProductDetails.MinThreshold = Convert.ToDecimal(reader.GetAttribute("MinThreshold")); clsProductDetails.MaxThreshold = Convert.ToDecimal(reader.GetAttribute("MaxThreshold")); clsProductDetails.SupplierID = Contacts.DEFAULT_SUPPLIER_ID; ProductID = clsProduct.Insert(clsProductDetails); } //ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(clsStock.Connection, clsStock.Transaction); //ProductBaseMatrixID = clsProductVariationsMatrix.BaseDetails(0, 0, ProductID, reader["ItemBaseVariationDescription"].ToString()).MatrixID; //if (ProductBaseMatrixID == 0) //{ // ProductBaseMatrixDetails clsBaseDetails = new ProductBaseMatrixDetails(); // clsBaseDetails.ProductID = ProductID; // clsBaseDetails.Description = reader.GetAttribute("ItemBaseVariationDescription"); // clsBaseDetails.UnitID = UnitID; // clsBaseDetails.Price = Convert.ToDecimal(reader.GetAttribute("Price")); // clsBaseDetails.PurchasePrice = Convert.ToDecimal(reader.GetAttribute("PurchasePrice")); // clsBaseDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(reader.GetAttribute("IncludeInSubtotalDiscount")); // clsBaseDetails.Quantity = 0; // clsBaseDetails.VAT = Convert.ToDecimal(reader.GetAttribute("VAT")); // clsBaseDetails.EVAT = Convert.ToDecimal(reader.GetAttribute("EVAT")); // clsBaseDetails.LocalTax = Convert.ToDecimal(reader.GetAttribute("LocalTax")); // clsBaseDetails.MinThreshold = Convert.ToDecimal(reader.GetAttribute("MinThreshold")); // clsBaseDetails.MaxThreshold = Convert.ToDecimal(reader.GetAttribute("MaxThreshold")); // ProductBaseMatrixID = clsProductVariationsMatrix.InsertBaseVariation(clsBaseDetails); // clsBaseDetails.MatrixID = ProductBaseMatrixID; //} clsStockItemDetails = new StockItemDetails(); clsStockItemDetails.StockID = StockID; clsStockItemDetails.ProductID = ProductID; clsStockItemDetails.VariationMatrixID = ProductBaseMatrixID; clsStockItemDetails.ProductUnitID = UnitID; clsStockItemDetails.StockTypeID = Convert.ToInt16(Constants.STOCK_TYPE_TRANSFER_FROM_BRANCH_ID); clsStockItemDetails.StockDate = DateTime.Now; clsStockItemDetails.Quantity = Convert.ToDecimal(reader.GetAttribute("ItemQuantity")); clsStockItemDetails.Remarks = reader.GetAttribute("ItemRemarks"); Security.AccessUserDetails clsAccessUserDetails = (Security.AccessUserDetails)Session["AccessUserDetails"]; clsStock.AddItem(Constants.BRANCH_ID_MAIN, strStockTransactionNo, clsAccessUserDetails.Name, clsStockItemDetails, StockDirections.Increment); } else if (reader.Name == "Variation" && reader.GetAttribute("VariationCode") != null) { Variation clsVariation = new Variation(clsStock.Connection, clsStock.Transaction); VariationID = clsVariation.Details(reader.GetAttribute("VariationCode")).VariationID; if (VariationID == 0) { clsVariationDetails = new VariationDetails(); clsVariationDetails.VariationCode = reader.GetAttribute("VariationCode"); clsVariationDetails.VariationType = reader.GetAttribute("VariationType"); VariationID = clsVariation.Insert(clsVariationDetails); } ProductVariationDetails clsProductVariationDetails = new ProductVariationDetails(); clsProductVariationDetails.ProductID = ProductID; clsProductVariationDetails.VariationID = VariationID; ProductVariations clsProductVariation = new ProductVariations(clsStock.Connection, clsStock.Transaction); if (clsProductVariation.isExist(clsProductVariationDetails) == false) { long ProductVariationID = clsProductVariation.Insert(clsProductVariationDetails); } } else if (reader.Name == "VariationMatrix" && reader.GetAttribute("VariationCode") != null) { Variation clsVariation = new Variation(clsStock.Connection, clsStock.Transaction); VariationID = clsVariation.Details(reader.GetAttribute("VariationCode")).VariationID; if (VariationID == 0) { clsVariationDetails = new VariationDetails(); clsVariationDetails.VariationCode = reader.GetAttribute("VariationCode"); clsVariationDetails.VariationType = reader.GetAttribute("VariationType"); VariationID = clsVariation.Insert(clsVariationDetails); } ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(clsStock.Connection, clsStock.Transaction); if (clsProductVariationsMatrix.isExist(ProductBaseMatrixID, VariationID) == false) { ProductVariationsMatrixDetails clsProductVariationsMatrixDetails = new ProductVariationsMatrixDetails(); clsProductVariationsMatrixDetails.ProductID = ProductID; clsProductVariationsMatrixDetails.MatrixID = ProductBaseMatrixID; clsProductVariationsMatrixDetails.VariationID = VariationID; clsProductVariationsMatrixDetails.Description = reader.GetAttribute("Description"); clsProductVariationsMatrix.SaveVariation(clsProductVariationsMatrixDetails); } } else { Label1.Text = "<b>Reader Name:<b>" + reader.Name + "<br />"; } break; case XmlNodeType.Text: Label1.Text = "<b>" + reader.LocalName + ":<b>" + reader.Value + "<br />"; break; } } reader.Close(); clsStock.CommitAndDispose(); Label1.Text = "<b>Transaction No.: " + strStockTransactionNo + " has been successfully transferred.<br />"; } else { Response.Write("Please select a file to upload."); } }