public void CreateStorageTransactionTest(int prodID, int amount, int storage1, int storage2) { int old_id = StorageTransaction.GetNextID(); Product TestProd = SC.ProductDictionary[prodID]; if (!TestProd.StorageWithAmount.ContainsKey(storage1)) { TestProd.StorageWithAmount.TryAdd(storage1, 0); } if (!TestProd.StorageWithAmount.ContainsKey(storage2)) { TestProd.StorageWithAmount.TryAdd(storage2, 0); } int Storage1Count = TestProd.StorageWithAmount[storage1]; int Storage2Count = TestProd.StorageWithAmount[storage2]; StorageTransaction TestTrans = new StorageTransaction(TestProd, amount, storage1, storage2, SC.StorageRoomDictionary); TestTrans.Execute(); TestTrans.UploadToDatabase(); int new_id = StorageTransaction.GetNextID(); bool idCompare = new_id > old_id; bool storageCompare1 = TestProd.StorageWithAmount[storage1] == Storage1Count - amount; bool storageCompare2 = TestProd.StorageWithAmount[storage2] == Storage2Count + amount; Assert.IsTrue(idCompare && storageCompare1 && storageCompare2); }
private void button_MoveProduct_Click(object sender, RoutedEventArgs e) { Product product = _storageController.ProductDictionary[productID]; int destinationRoom = _storageController.StorageRoomDictionary.Where(x => x.Value.Name == comboBox_Destination.Text).Select(x => x.Key).First(); if (!product.StorageWithAmount.Keys.Contains(_storageController.StorageRoomDictionary.Where(x => x.Value.Name == comboBox_Destination.Text).Select(x => x.Key).First())) { product.StorageWithAmount.TryAdd(_storageController.StorageRoomDictionary.Where(x => x.Value.Name == comboBox_Destination.Text).Select(x => x.Key).First(), 0); product.UpdateInDatabase(); } int parsevalue; Int32.TryParse(textBox_ProductAmount.Text, out parsevalue); if (textBox_ProductAmount.Text != "") { StorageTransaction storageTransaction = new StorageTransaction(product, parsevalue, sourceRoom, destinationRoom, _storageController.StorageRoomDictionary); storageTransaction.Execute(); storageTransaction.UploadToDatabase(); this.Close(); } else { textBox_ProductAmount.BorderBrush = Brushes.Red; } }