public ActionResult SetCustomer(int id, int value) { var entity = SalesQuote.Find(id); var item = Customer.TryFind(value); if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (item != null) { entity.Customer = item; entity.Contact = null; entity.ShipTo = null; if (item.SalesPerson == null) { entity.SalesPerson = CurrentUser.Employee; } else { entity.SalesPerson = item.SalesPerson; } if (entity.Terms == PaymentTerms.NetD && !entity.Customer.HasCredit) { entity.Terms = PaymentTerms.Immediate; } switch (entity.Terms) { case PaymentTerms.Immediate: entity.DueDate = entity.Date; break; case PaymentTerms.NetD: entity.DueDate = entity.Date.AddDays(entity.Customer.CreditDays); break; } entity.Updater = CurrentUser.Employee; entity.ModificationTime = DateTime.Now; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = id, value = entity.FormattedValueFor(x => x.Customer), terms = entity.Terms, termsText = entity.Terms.GetDisplayName(), dueDate = entity.FormattedValueFor(x => x.DueDate), salesPerson = entity.SalesPerson.Id, salesPersonName = entity.SalesPerson.Name })); }
public ActionResult SetDate(int id, DateTime?value) { var entity = SalesQuote.Find(id); if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (value != null) { entity.Date = value.Value; entity.Updater = CurrentUser.Employee; entity.ModificationTime = DateTime.Now; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = id, value = entity.FormattedValueFor(x => x.Date) })); }
public void GetFinishCost__Test() { ExteriorFinish exteriorFinishChosen = new ExteriorFinish(); SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, exteriorFinishChosen); decimal expectedFinishCost; decimal standard = 202.02M; decimal pearlized = 404.04M; decimal custom = 606.06M; switch (exteriorFinishChosen) { case ExteriorFinish.Custom: expectedFinishCost = custom; break; case ExteriorFinish.Pearlized: expectedFinishCost = pearlized; break; case ExteriorFinish.Standard: expectedFinishCost = standard; break; default: expectedFinishCost = 0.00M; break; } decimal actualFinishCost = salesQuote.FinishCost; Assert.AreEqual(expectedFinishCost, actualFinishCost); }
public void Constructor_VehicleSalesPrice_TradeInAmount_SalesTaxRate_Accessories_Finish_Test() { //Arrange decimal vehicleSalesPrice = 10000; decimal tradeInAmount = 2000; decimal salesTaxRate = 0.1m; Accessories accessories = Accessories.LeatherInterior; ExteriorFinish finish = ExteriorFinish.Custom; SalesQuote salesQuote = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate, accessories, finish); PrivateObject target = new PrivateObject(salesQuote); //Act decimal expectedVehicleSalesPrice = 10000; decimal expectedTradeInAmount = 2000; decimal expectedSalesTaxRate = 0.1m; Accessories expectedAccessories = Accessories.LeatherInterior; ExteriorFinish expectedFinish = ExteriorFinish.Custom; decimal actualVehicleSalesPrice = (decimal)target.GetField("vehicleSalesPrice"); decimal actualTradeInAmount = (decimal)target.GetField("tradeInAmount"); Accessories actualAccessories = (Accessories)target.GetField("accessoriesChosen"); ExteriorFinish actualFinish = (ExteriorFinish)target.GetField("exteriorFinishChosen"); decimal actualSalesRate = 0.1m; //Assert Assert.AreEqual(expectedVehicleSalesPrice, actualVehicleSalesPrice); Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount); Assert.AreEqual(expectedAccessories, actualAccessories); Assert.AreEqual(expectedFinish, actualFinish); Assert.AreEqual(expectedSalesTaxRate, actualSalesRate); }
public void SetTradeInAmountSpecial_Test() { //Arrange decimal vehicleSalesPrice = 10000; decimal tradeInAmount = 2000; decimal salesTaxRate = 0.1m; Accessories accessories = Accessories.LeatherInterior; ExteriorFinish finish = ExteriorFinish.Custom; SalesQuote salesQuote = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate, accessories, finish); //Act decimal expcetedTradeInAmount = 2000; //Assert try { salesQuote.TradeInAmount = -1000; Assert.Fail("Did not throw ArgumentOutOfRangeException as expected."); } catch (ArgumentOutOfRangeException) { PrivateObject abc = new PrivateObject(salesQuote); decimal actualTradeInAmount = (decimal)abc.GetField("tradeInAmount"); Assert.AreEqual(expcetedTradeInAmount, actualTradeInAmount); } }
public void SalesQuote_WithNoAccessoriesAndFinishChosen_VehicleSalesPrice_Greater_Exception_Test() { decimal vehicleSalesPrice = 0.1M; decimal tradeInAmount = 0.3M; decimal salesTaxRate = 4M; SalesQuote actualSalesQuote = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate); }
public void SalesQuote_Test() { decimal vehicleSalePrice = 0.1M; decimal tradeInAmount = 0.2M; decimal salesTaxRate = 0.1M; Accessories accessoriesChosen = new Accessories(); ExteriorFinish exteriorFinishChosen = new ExteriorFinish(); SalesQuote salesQuote = new SalesQuote(vehicleSalePrice, tradeInAmount, salesTaxRate, accessoriesChosen, exteriorFinishChosen); decimal expectedVehicleSalePrice = 0.1M; decimal expectedTradeInAmount = 0.2M; decimal expectedSalesTaxRate = 0.1M; Accessories expectedAccessoriesChosen = new Accessories(); ExteriorFinish expectedExteriorFinishChosen = new ExteriorFinish(); PrivateObject target = new PrivateObject(salesQuote); decimal actualVehicleSalePrice = (decimal)target.GetField("vehicleSalePrice"); decimal actualTradeInAmount = (decimal)target.GetField("tradeInAmount"); decimal actualSalesTaxRate = (decimal)target.GetField("salesTaxRate"); Accessories actualAccessoriesChosen = (Accessories)target.GetField("accessoriesChosen"); ExteriorFinish actualExteriorFinishChosen = (ExteriorFinish)target.GetField("exteriorFinishChosen"); Assert.AreEqual(expectedSalesTaxRate, actualSalesTaxRate); Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount); Assert.AreEqual(expectedVehicleSalePrice, actualVehicleSalePrice); Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen); Assert.AreEqual(expectedExteriorFinishChosen, actualExteriorFinishChosen); }
public ActionResult SetShipTo(int id, int value) { var entity = SalesQuote.Find(id); var item = Address.TryFind(value); if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (item != null) { entity.ShipTo = item; entity.Updater = CurrentUser.Employee; entity.ModificationTime = DateTime.Now; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = id, value = entity.ShipTo.ToString() })); }
public void GetAccessoryCost_StereoSystem_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.StereoSystem, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(505.05m, salesQuote.AccessoryCost); }
public void AccessoriesChosen__Get_LeatherInterior_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.LeatherInterior, ExteriorFinish.None); Accessories expectedAccessoriesChosen = Accessories.LeatherInterior; Accessories actualAccessoriesChosen = salesQuote.AccessoriesChosen; Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen); }
public void GetAccessoriesChosen_All_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.All, ExteriorFinish.None); Accessories expectedAccessoriesChosen = Accessories.All; Accessories actualAccessoriesChosen = salesQuote.AccessoriesChosen; Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen); }
public void GetAccessoryCost_None_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.None, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(0, salesQuote.AccessoryCost); }
public void GetAccessoryCost_ComputerNavigation_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.ComputerNavigation, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(1515.15m, salesQuote.AccessoryCost); }
public void GetAmountDue_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard); decimal expectedAmountDue = 262.556M; decimal actualAmountDue = salesQuote.AmountDue; Assert.AreEqual(expectedAmountDue, actualAmountDue); }
public void GetSalesTax_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard); decimal expectedSalesTax = 60.636M; decimal actualSalesTax = salesQuote.SalesTax; Assert.AreEqual(expectedSalesTax, actualSalesTax); }
public void GetSubTotal_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard); decimal expectedSubTotal = 202.12M; decimal actualSubTotal = salesQuote.SubTotal; Assert.AreEqual(expectedSubTotal, actualSubTotal); }
public void GetExteriorChosen_Standard_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard); ExteriorFinish expectedExteriorChosen = ExteriorFinish.Standard; ExteriorFinish actualExteriorChosen = salesQuote.ExteriorFinishChosen; Assert.AreEqual(expectedExteriorChosen, actualExteriorChosen); }
public void GetAccessoryCost_LeatherInterior_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(1010.10m, salesQuote.AccessoryCost); }
public void GetAccessoryCost_StereoAndLeather_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.StereoAndLeather, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(1515.15m, salesQuote.AccessoryCost); }
public void GetFinishCost_Pearlized_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(404.04m, salesQuote.FinishCost); }
public void GetAccessoryCost_LeatherAndNavigation_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Pearlized); //Assert Assert.AreEqual(2525.25m, salesQuote.AccessoryCost); }
public void SetVehicleSalesPrice_EqualToZero_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Custom); //Act salesQuote.VehicleSalePrice = 0; }
public void GetFinishCost_Standard_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Standard); //Assert Assert.AreEqual(202.02m, salesQuote.FinishCost); }
public void GetAccessoriesChosen_LeatherAndNavigation_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.LeatherAndNavigation, ExteriorFinish.None); Accessories expectedAccessoriesChosen = Accessories.LeatherAndNavigation; Accessories actualAccessoriesChosen = salesQuote.AccessoriesChosen; Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen); }
public void SetTradeInAmount_LessThanZero_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Custom); //Act salesQuote.TradeInAmount = -1; }
public void AccessoriesChosen_Get_StereoSystem_Test() { SalesQuote salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.StereoSystem, ExteriorFinish.None); Accessories expectedAccessoriesChosen = Accessories.StereoSystem; Accessories actualAccessoriesChosen = salesQuote.AccessoriesChosen; Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen); }
public void GetFinishCost_None_Test() { //Arrange SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.None); //Assert Assert.AreEqual(0, salesQuote.FinishCost); }
public void TradeInAmount_Get_Test() { decimal tradeInAmount = 0.4M; SalesQuote salesQuote = new SalesQuote(0.3M, tradeInAmount, 0.3M, Accessories.None, ExteriorFinish.None); decimal expectedTradeInAmount = 0.4M; decimal actualTradeInAmount = salesQuote.TradeInAmount; Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount); }
public void TradeInAmountChanged_Test() { this.eventActual = null; SalesQuote salesQuote = new SalesQuote(20000, 2000, 0.2m, Accessories.ComputerNavigation, ExteriorFinish.Custom); salesQuote.TradeInAmountChanged += TestHandler; salesQuote.TradeInAmount = 1000; Assert.AreEqual("Event triggered.", eventActual); }
public void ExteriorFinishChosenChanged_Test() { this.eventActual = null; SalesQuote salesQuote = new SalesQuote(20000, 2000, 0.2m, Accessories.ComputerNavigation, ExteriorFinish.Custom); salesQuote.ExteriorFinishChosenChanged += TestHandler; salesQuote.ExteriorFinishChosen = ExteriorFinish.Pearlized; Assert.AreEqual("Event triggered.", eventActual); }
public ActionResult New() { var dt = DateTime.Now; var item = new SalesQuote (); item.Store = WebConfig.Store; if (item.Store == null) { return View ("InvalidStore"); } if (!CashHelpers.ValidateExchangeRate ()) { return View ("InvalidExchangeRate"); } // Store and Serial try { item.Serial = (from x in SalesQuote.Queryable where x.Store.Id == item.Store.Id select x.Serial).Max () + 1; } catch { item.Serial = 1; } item.Customer = Customer.TryFind (WebConfig.DefaultCustomer); item.SalesPerson = CurrentUser.Employee; item.Date = dt; item.Terms = PaymentTerms.Immediate; item.DueDate = DateTime.Now.AddDays ((WebConfig.DefaultDueDaysAdded)); item.Currency = WebConfig.DefaultCurrency; item.ExchangeRate = CashHelpers.GetTodayDefaultExchangeRate (); item.Creator = CurrentUser.Employee; item.CreationTime = dt; item.Updater = item.Creator; item.ModificationTime = dt; using (var scope = new TransactionScope ()) { item.CreateAndFlush (); } return RedirectToAction ("Edit", new { id = item.Id }); }