public void TestInsertAndGetByUidWithDecimalQuantity() { InventoryTransferProxy proxy = new InventoryTransferProxy(); InventoryTransferDto dto1 = this.GetInventoryTransfer4(); proxy.Insert(dto1); Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save."); InventoryTransferDto dto2 = (InventoryTransferDto)proxy.GetByUid(dto1.Uid); AssertEqual(dto1, dto2); }
public void TestInsertAndGetByUidDoNotBalance() { InventoryTransferProxy proxy = new InventoryTransferProxy(); InventoryTransferDto dto1 = this.GetInventoryTransfer3(); try { proxy.Insert(dto1); throw new Exception("Expected exception not thrown."); } catch (RestException rex) { Assert.AreEqual("The Inventory Transfer is not balanced. The total of all line items must equal to 0.", rex.Message, "Incorrect error message."); } }
public void TestDelete() { CrudProxy proxy = new InventoryTransferProxy(); InventoryTransferDto dto1 = this.GetInventoryTransfer1(); proxy.Insert(dto1); proxy.DeleteByUid(dto1.Uid); try { proxy.GetByUid(dto1.Uid); throw new Exception("The expected exception was not thrown."); } catch (RestException ex) { Assert.AreEqual("RecordNotFoundException", ex.Type, "Incorrect exception type."); } }
public void BuildComboItem() { ComboItemProxy proxy = new ComboItemProxy(); ComboItemDto comboItemDto = this.GetComboItem01(); proxy.Insert(comboItemDto); ComboItemDto comboItem = (ComboItemDto)proxy.GetByUid(comboItemDto.Uid); // We need to insert stock first using a purchase CrudProxy invoiceProxy = new InvoiceProxy(); InvoiceDto dto = new InvoiceDto(TransactionType.Purchase, InvoiceLayout.Item); dto.Date = DateTime.Today.Date; dto.ContactUid = this.MrSmith.Uid; dto.Summary = "Add stock do we can build ComboItems"; dto.Notes = "From REST"; dto.DueOrExpiryDate = dto.Date.AddMonths(1); dto.Status = InvoiceStatus.Invoice; dto.InvoiceNumber = "I123"; dto.PurchaseOrderNumber = "<Auto Number>"; decimal unitsToBuild = 12.25M; foreach(ComboItemLineItemDto itemInCombo in comboItem.Items) { // "purchase" all the items that are part of this combo item so we have valid stock ItemInvoiceItemDto item = new ItemInvoiceItemDto(); item.Quantity = itemInCombo.Quantity * unitsToBuild; item.InventoryItemUid = itemInCombo.Uid; item.Description = "Purchasing: " + itemInCombo.Code; item.TaxCode = TaxCode.ExpInclGst; item.UnitPriceInclTax = 99.95M; dto.Items.Add(item); } invoiceProxy.Insert(dto); // Download stock info before InventoryItemProxy inventoryItemProxy = new InventoryItemProxy(); InventoryItemDto inventoryItem = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid); decimal stockOnHand = inventoryItem.StockOnHand; // Build the item! BuildComboItemResult result = proxy.Build(comboItemDto.Uid, unitsToBuild); Assert.AreNotEqual(0, result.Uid); Assert.IsNotNull(result.LastUpdatedUid); inventoryItem = (InventoryItemDto)inventoryItemProxy.GetByUid(comboItemDto.Uid); decimal newStockOnHand = inventoryItem.StockOnHand; Assert.AreEqual(stockOnHand + unitsToBuild, newStockOnHand, "We have one extra item in stock"); // Read Inventory Transfer details InventoryTransferProxy transferProxy = new InventoryTransferProxy(); InventoryTransferDto transfer = (InventoryTransferDto)transferProxy.GetByUid(result.Uid); Assert.AreEqual(comboItem.Items.Count+1, transfer.Items.Count); // +1 as we have the combo item the first one // confirm first item is the combo with +1 InventoryTransferItemDto comboItemTransfer = (InventoryTransferItemDto)transfer.Items[0]; Assert.AreEqual(comboItemDto.Uid, comboItemTransfer.InventoryItemUid); Assert.AreEqual(unitsToBuild, comboItemTransfer.Quantity); for (int i = 0; i < comboItem.Items.Count; i++) { ComboItemLineItemDto line = comboItem.Items[i]; InventoryTransferItemDto item = (InventoryTransferItemDto)transfer.Items[i+1]; Assert.AreEqual(line.Uid, item.InventoryItemUid); Assert.AreEqual(line.Quantity * unitsToBuild, -item.Quantity); } }
public void TestUpdate() { InventoryTransferProxy proxy = new InventoryTransferProxy(); InventoryTransferDto dto1 = this.GetInventoryTransfer1(); proxy.Insert(dto1); Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save."); dto1.Notes = "Updated inventory transfer"; dto1.Items.AddRange(this.GetInventoryTransfer2().Items); proxy.Update(dto1); InventoryTransferDto dto2 = (InventoryTransferDto)proxy.GetByUid(dto1.Uid); AssertEqual(dto1, dto2); }