/// <summary> /// This method is used calculate board cost depends on the properties values of this class /// </summary> /// <returns></returns> public double CalculateBoardCost() { try { if (this.FromDate == null || this.ToDate == null) { throw new ApplicationException("From and To Date must be provided."); } string xmlDocPath = Path.Combine(HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data"), "PurpleBoardsLeases.xml"); XDocument xDoc = XDocument.Load(xmlDocPath); this.DaysOrder = (int)((DateTime)this.ToDate - (DateTime)this.FromDate).TotalDays + 1; if (this.DaysOrder < 0) { return(0); } this.PricePerDay = PurpleBoardPriceXMLHelper.GetPriceByFilter(xDoc, this.Property.State, this.BoardSize, this.DaysOrder); this.Discount = PurpleBoardPriceXMLHelper.GetDiscountRate(xDoc, this.Property.State, this.DaysOrder); this.Cost = Math.Round(PricePerDay * DaysOrder, 2); return(this.Cost); } catch (Exception) { // We can log exception in database or somewhere to further assessment return(0); } }
public double TestForGetDiscountRate(string state, int daysOrder) { PathProviderXML pathProvider = new PathProviderXML(); string xmlDocPath = pathProvider.GetPathForTest(); XDocument xDoc = XDocument.Load(xmlDocPath); return(PurpleBoardPriceXMLHelper.GetDiscountRate(xDoc, state, daysOrder)); }
public void GetPriceWithoutSomeFilters(string state, string boardSize, int daysOrder) { PathProviderXML pathProvider = new PathProviderXML(); string xmlDocPath = pathProvider.GetPathForTest(); XDocument xDoc = XDocument.Load(xmlDocPath); Assert.That(() => PurpleBoardPriceXMLHelper.GetPriceByFilter(xDoc, state, boardSize, daysOrder), Throws.TypeOf <ApplicationException>()); }