public void BookDataService_CalculateTotalCost_Verify() { Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>(); var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList()); mockdb.Setup(x => x.Book).Returns(usersMockBook.Object); var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList()); mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object); var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList()); mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object); //========================================================== IBook testbook = UnitTestDBset.BookList()[3]; var bookservice = new BookDataService(mockdb.Object); var resultcost = bookservice.CalculateTotalCost().Result; IOrderCost testordercost = new OrderCost { Subtotal = 57.74, Totaltax = 5.77, TotalCost = 63.51 }; Assert.AreEqual(testordercost.Subtotal, resultcost.Subtotal); Assert.AreEqual(testordercost.Totaltax, resultcost.Totaltax); Assert.AreEqual(testordercost.TotalCost, resultcost.TotalCost); }
public Task <IOrderCost> CalculateTotalCost() { IOrderCost totalcost = new OrderCost(); try { var booklist = GetBookOrderList().Result; if (booklist != null) { foreach (var item in booklist) { IBookSale booksale = GetBookOnSale(item).Result; if (Math.Abs(booksale.DiscountedPrice()) > 0) { totalcost.Subtotal += booksale.DiscountedPrice(); } else { totalcost.Subtotal += booksale.BookDetail.Cost; } } totalcost.Subtotal = Math.Round(totalcost.Subtotal, 2); totalcost.Totaltax = Math.Round(totalcost.Subtotal * (Constant.ORDER_TAX_TOTAL), 2); totalcost.TotalCost = Math.Round((totalcost.Subtotal + totalcost.Totaltax), 2); } } catch (Exception e) { Console.WriteLine(e); } return(Task.FromResult <IOrderCost>(totalcost)); }
public void CalculateOrderCost_SpeedyShippingCorrectly() { List <PackageSizeWeight> orderPackages1 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 2f }, new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 2f }, new PackageSizeWeight { Length = 15, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 55, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 105, Width = 5, Thickness = 3, Weight = 2f } }; OrderCost orderCostNoSpeedy = CalculateOrderCost(orderPackages1, false); OrderCost orderCostWithSpeedy = CalculateOrderCost(orderPackages1, true); Assert.Equal(orderCostNoSpeedy.TotalCost, 62); Assert.Equal(orderCostWithSpeedy.TotalCost, 124); Assert.Equal(orderCostWithSpeedy.SpeedyShippingCost, 62); }
/// <summary> /// 删除订单费用表中对应的费用数据 /// </summary> /// <param name="SoId"></param> public void Delete(long SoId, string CostItemID) { OrderCost Cost = OrderCost.Finder.Find("SellOrderID=@SellOrderID and CostItem.Code=@CostItem", new OqlParam(SoId), new OqlParam(CostItemID)); if (Cost != null) { Cost.Remove(); } }
static void Main(string[] args) { List <PackageSizeWeight> inputPackages = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 1 }, new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 3 }, new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 1 }, new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 1 }, new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 2 }, new PackageSizeWeight { Length = 10, Width = 5, Thickness = 12, Weight = 6 }, new PackageSizeWeight { Length = 15, Width = 5, Thickness = 3, Weight = 2 }, new PackageSizeWeight { Length = 15, Width = 5, Thickness = 3, Weight = 8 }, new PackageSizeWeight { Length = 55, Width = 5, Thickness = 3, Weight = 5 }, new PackageSizeWeight { Length = 105, Width = 5, Thickness = 3, Weight = 7 } }; OrderCost orderCost = CalculateOrderCost(inputPackages, true); foreach (var package in orderCost.PackagesInfo) { if (package.Type == PackageType.Undefined) { Console.WriteLine("Unknown package type and cost, an error occured"); } else { Console.WriteLine(package.Type.ToString() + " package cost: $" + package.Cost.ToString() + (package.Discounted ? " (discounted)" : "")); } } Console.WriteLine("Total discounts: $" + orderCost.TotalDiscounts); if (orderCost.SpeedyShippingCost != 0) { Console.WriteLine("Speedy shipping cost: $" + orderCost.SpeedyShippingCost); } Console.WriteLine("Total cost (minus any discounts): $" + orderCost.TotalCost); }
public void CalculateOrderCost_Correctly() { List <PackageSizeWeight> orderPackages1 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 2f }, new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 2f }, new PackageSizeWeight { Length = 15, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 55, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 105, Width = 5, Thickness = 3, Weight = 2f } }; List <PackageSizeWeight> orderPackages2 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 5, Width = 2, Thickness = 1, Weight = 2f }, }; List <PackageSizeWeight> orderPackages3 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 2f }, new PackageSizeWeight { Length = 15, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 55, Width = 5, Thickness = 3, Weight = 2f }, new PackageSizeWeight { Length = 105, Width = 5, Thickness = 3, Weight = 2f } }; List <PackageSizeWeight> orderPackages4 = new List <PackageSizeWeight>(); OrderCost orderCost1 = CalculateOrderCost(orderPackages1, false); OrderCost orderCost2 = CalculateOrderCost(orderPackages2, false); OrderCost orderCost3 = CalculateOrderCost(orderPackages3, false); OrderCost orderCost4 = CalculateOrderCost(orderPackages4, false); Assert.True(orderCost1.TotalCost == 62); Assert.True(orderCost2.TotalCost == 5); Assert.True(orderCost3.TotalCost == 57); Assert.True(orderCost4.TotalCost == 0); }
/// <summary> /// 判读是否已经创建订单费用 /// </summary> /// <param name="sokey"></param> public string IsOrderCost(CreateOrderCost bpObj) { string StrMeg = string.Empty; List <FeeTypAmountDTO> dto = bpObj.FeeDTO; if (dto != null && dto.Count > 0) { using (ISession session = Session.Open()) { for (int i = 0; i < dto.Count; i++) { OrderCost cost = OrderCost.Finder.Find(string.Format("SellOrderID={0} and CostItem.Code={1}", bpObj.SoKeyID.ID, dto[i].FeeType.ID));//根据费用类型 销售订单号 if (cost == null) { //创建订单费用 SO s = bpObj.SoKeyID.GetEntity();//得到当前key的实体 if (s != null) { //国内运输费用、国际运输费用、国内其他费用、国际其他费用 费用项目取固定编码的U9标准产品费用项目档案 //根据不同的费用项目,生成不同的费用记录 long l = dto[i].FeeType.ID; if (l == 0010101) { //国内运输费 StrMeg = CreateOrderCost(s, long.Parse("0010101"), dto[i].FeeAmount); } else if (l == 0010102) { //国际运输费用 StrMeg = CreateOrderCost(s, long.Parse("0010102"), dto[i].FeeAmount); } else if (l == 0010103) { //国内其他费用 StrMeg = CreateOrderCost(s, long.Parse("0010103"), dto[i].FeeAmount); } else if (l == 0010104) { //国际其他费用 StrMeg = CreateOrderCost(s, long.Parse("0010104"), dto[i].FeeAmount); } } } } session.Commit(); } } return(StrMeg); }
public void CalculateOrderCost_ApplyMediumParcelDiscount() { List <PackageSizeWeight> orderPackages1 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 1f }, new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 5f }, new PackageSizeWeight { Length = 10, Width = 2, Thickness = 1, Weight = 1f }, }; OrderCost orderCost1 = CalculateOrderCost(orderPackages1, false); Assert.Equal(20, orderCost1.TotalCost); Assert.Equal(orderCost1.PackagesInfo[2].Discounted, true); Assert.Equal(orderCost1.PackagesInfo[2].Cost, 8); }
public static void Main() { OrderCost costs = new OrderCost { SubTotal = 100, ShippingTotal = 10, TotalTax = 1 }; if (costs.GrandTotal == 111) { Console.WriteLine("Order cost is correct"); } else { Console.WriteLine("Order cost is incorrect"); } Console.WriteLine("\n\nPress Enter to terminate"); Console.ReadLine(); }
public void CalculateOrderCost_NoValidDiscounts() { List <PackageSizeWeight> orderPackages1 = new List <PackageSizeWeight>() { new PackageSizeWeight { Length = 2, Width = 2, Thickness = 1, Weight = 1f }, new PackageSizeWeight { Length = 50, Width = 2, Thickness = 1, Weight = 5f }, new PackageSizeWeight { Length = 50, Width = 2, Thickness = 1, Weight = 5f }, new PackageSizeWeight { Length = 100, Width = 2, Thickness = 1, Weight = 1f }, }; OrderCost orderCost1 = CalculateOrderCost(orderPackages1, false); Assert.Equal(ContainsAnyDiscounts(orderCost1.PackagesInfo), false); }
private void metroButton1_Click(object sender, EventArgs e) { //variables; string ProductName; int ProductQuantity; string SupplierName; int ReceivedStatus; decimal OrderCost; string ReceivedDate; string Received; SqlConnection sqlcon = new SqlConnection(Globals_Class.ConnectionString); sqlcon.Open(); string cmd = "Select ProductName, ProductQuantity, SupplierName, ReceivedStatus, OrderCost, ReceivedDate FROM ReceiveSupplierOrder"; SqlCommand sqlcom = new SqlCommand(cmd, sqlcon); SqlDataReader reader; reader = sqlcom.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ProductName = (reader["ProductName"].ToString()); ProductQuantity = Convert.ToInt32((reader["ProductQuantity"])); SupplierName = (reader["SupplierName"].ToString()); ReceivedStatus = Convert.ToInt32((reader["ReceivedStatus"])); OrderCost = Convert.ToDecimal((reader["OrderCost"])); ReceivedDate = (reader["ReceivedDate"].ToString()); if (ReceivedStatus == 1) { Received = "Yes"; } else { Received = "No"; } Details += "\n" + "Product Name:" + " " + ProductName + "\n" + "Quantity Ordered:" + " " + ProductQuantity.ToString() + "\n" + "Supplier Name:" + " " + SupplierName + "\n" + "Received Status:" + " " + Received + "\n" + "Order Cost:" + " " + OrderCost.ToString() + "\n" + "Received Date:" + " " + ReceivedDate.ToString() + "\n"; } } reader.Close(); sqlcon.Close(); documentWriter(); }
/** * FindPath function * goal: to find the shortest path from the start location to the end location * @author Ryan Thorne * credit for A* goes to Peter Hart, Nils Nilsson and Bertram Raphael. * based on the 1959 Dijkstra algorithm from Edsger Dijkstra. * good luck figuring this out if you're not already familiar with the A* pathfinding algorithm * note: this procedure will return null instead of throwing exceptions * @param passableTiles * this is the map upon which you are generating over * @param alternatePath * determines whether or not the alternate pathing will be used * @param start * the starting position of the path * @param end * the ending position of the path * @param pathfindingCosts * choose this based on the dictionary definitions to determine what each tile costs * @return * the A* shortest path from start to finish */ public static Path findPath(Tile[,] passableTiles, bool alternatePath, Point start, Point end, int pathfindingCosts) { int x = passableTiles.GetLength(0); int y = passableTiles.GetLength(1); OrderCost o = tileWeight[pathfindingCosts]; //haha i have no error checking sucks to be you! //generate randomization values bool goof1; // goof2; if (alternatePath) { goof1 = true; //goof2 = rng.nextbool(); TODO find a place for a second goof in the program } else { goof1 = false; //goof2 = false; } if (start.equals(null) || end.equals(null)) { return(null); } if (start.getX() < 0 || start.getX() >= x) { return(null); } if (start.getY() < 0 || start.getY() >= y) { return(null); } if (end.getX() < 0 || end.getX() >= x) { return(null); } if (end.getY() < 0 || end.getY() >= y) { return(null); } LinkedList <ANode> openSet = new LinkedList <ANode> (); LinkedList <ANode> closedSet = new LinkedList <ANode> (); ANode[, ] map = new ANode[x, y]; //add mountains to the closed set of tiles not considered for paths //also create the mape of ANodes that allow for parenting for (int xIterate = 0; xIterate < x; xIterate++) { for (int yIterate = 0; yIterate < y; yIterate++) { map[xIterate, yIterate] = new ANode(xIterate, yIterate); //we need to determine which items are allowed to pass by//TODO //if the movecost to travel through this tile is 0, we cannot pass if (o.getCost(passableTiles[xIterate, yIterate].getOrder()) == 0) { closedSet.AddLast(map [xIterate, yIterate]); } } } if (closedSet.Contains(map [start.getX(), start.getY()])) { return(null); } if (closedSet.Contains(map [end.getX(), end.getY()])) { return(null); } //set initial values for the pathfinding openSet.AddLast(map [start.getX(), start.getY()]); map [start.getX(), start.getY()].distanceTraveled = 0; //start pathfinding while (openSet.First != null) { //determine next node to check ANode currentNode = null; float closestNodeDistance = float.MaxValue; foreach (ANode iterator in openSet) { if (iterator.distanceTraveled + o.getCost(passableTiles[iterator.loc.getX(), iterator.loc.getY()].getOrder()) + Point.distance(iterator.loc, end) < closestNodeDistance) { if (!goof1) { closestNodeDistance = (float)(iterator.distanceTraveled + o.getCost(passableTiles[iterator.loc.getX(), iterator.loc.getY()].getOrder()) + Point.distance(iterator.loc, end)); } currentNode = iterator; } } //here is where we check to see if we have reached the end if (currentNode.loc.equals(end)) { //since we are at the end, we must build our path to pass back Path p = new Path(); while (currentNode.parent != null) { p.push(currentNode.loc); currentNode = currentNode.parent; } return(p); } closedSet.AddLast(currentNode); openSet.Remove(currentNode); //find neighbors and set their parents //this is the relaxation step //find first neighbor (one to the right) if (currentNode.loc.getX() != 0) { if (!closedSet.Contains(map [currentNode.loc.getX() - 1, currentNode.loc.getY()])) { float newDistance = currentNode.distanceTraveled + (passableTiles[currentNode.loc.getX() - 1, currentNode.loc.getY()].getMove(0) * 10); if (!openSet.Contains(map [currentNode.loc.getX() - 1, currentNode.loc.getY()]) || newDistance < map [currentNode.loc.getX() - 1, currentNode.loc.getY()].distanceTraveled) { //set neighbors parent as currentNode map [currentNode.loc.getX() - 1, currentNode.loc.getY()].distanceTraveled = newDistance; map [currentNode.loc.getX() - 1, currentNode.loc.getY()].parent = currentNode; if (!openSet.Contains(map [currentNode.loc.getX() - 1, currentNode.loc.getY()])) { openSet.AddLast(map [currentNode.loc.getX() - 1, currentNode.loc.getY()]); } } } } //find second neighbor (one to the left) if (currentNode.loc.getX() + 1 != x) { if (!closedSet.Contains(map [currentNode.loc.getX() + 1, currentNode.loc.getY()])) { float newDistance = currentNode.distanceTraveled + (passableTiles[currentNode.loc.getX() + 1, currentNode.loc.getY()].getMove(0) * 10); if (!openSet.Contains(map [currentNode.loc.getX() + 1, currentNode.loc.getY()]) || newDistance < map [currentNode.loc.getX() + 1, currentNode.loc.getY()].distanceTraveled) { //set neighbors parent as currentNode map [currentNode.loc.getX() + 1, currentNode.loc.getY()].distanceTraveled = newDistance; map [currentNode.loc.getX() + 1, currentNode.loc.getY()].parent = currentNode; if (!openSet.Contains(map [currentNode.loc.getX() + 1, currentNode.loc.getY()])) { openSet.AddLast(map [currentNode.loc.getX() + 1, currentNode.loc.getY()]); } } } } //find third neighbor (one above) if (currentNode.loc.getY() != 0) { if (!closedSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() - 1])) { float newDistance = currentNode.distanceTraveled + (passableTiles[currentNode.loc.getX(), currentNode.loc.getY() - 1].getMove(0) * 10); if (!openSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() - 1]) || newDistance < map [currentNode.loc.getX(), currentNode.loc.getY() - 1].distanceTraveled) { //set neighbors parent as currentNode map [currentNode.loc.getX(), currentNode.loc.getY() - 1].distanceTraveled = newDistance; map [currentNode.loc.getX(), currentNode.loc.getY() - 1].parent = currentNode; if (!openSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() - 1])) { openSet.AddLast(map [currentNode.loc.getX(), currentNode.loc.getY() - 1]); } } } } //find fourth neighbor (one below) if (currentNode.loc.getY() + 1 != y) { if (!closedSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() + 1])) { float newDistance = currentNode.distanceTraveled + (passableTiles[currentNode.loc.getX(), currentNode.loc.getY() + 1].getMove(0) * 10); if (!openSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() + 1]) || newDistance < map [currentNode.loc.getX(), currentNode.loc.getY() + 1].distanceTraveled) { //set neighbors parent as currentNode map [currentNode.loc.getX(), currentNode.loc.getY() + 1].distanceTraveled = newDistance; map [currentNode.loc.getX(), currentNode.loc.getY() + 1].parent = currentNode; if (!openSet.Contains(map [currentNode.loc.getX(), currentNode.loc.getY() + 1])) { openSet.AddLast(map [currentNode.loc.getX(), currentNode.loc.getY() + 1]); } } } } } //there is no path:. return null as diagnostics information or as indication that tile cannot reach other tile w/o flying return(null); }