public void CalculatesTotalPrice( [Frozen] IOrderPriceService orderPriceService, [Frozen] IShippingPriceCalculator shippingPriceCalculator, TotalPriceCalculator sut) { orderPriceService.GetPrice().Returns(45); shippingPriceCalculator.Calculate().Returns(5); var result = sut.Calculate(); result.Should().Be(50); }
private void CalculateSinglePrice() { try { int units = int.Parse(txtAmount.Text); if (txtPrice.Text != String.Empty) { decimal pricePerUnit = decimal.Parse(txtPrice.Text); txtTotalPrice.Text = TotalPriceCalculator.Calculate(units, pricePerUnit).ToString(); } } catch (Exception priceValueException) { labelError.Text = priceValueException.Message; } }
public ActionResult AddLocalReservation(LocalReservationViewModel lrVM) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } else { if (ModelState.IsValid) { int totalDays = (lrVM.DateTo - lrVM.DateFrom).Days; bool isCorrectDate = true; var now = DateTime.Now; var checkDate = new DateTime(now.Year, now.Month, now.Day); if (checkDate > lrVM.DateFrom) { isCorrectDate = false; } if (totalDays <= 30 && isCorrectDate) { //send a request on the main server and await for the response DTOHelper dtoHlp = new DTOHelper(); MyRemoteServices.AgentEndpointPortClient aepc = new MyRemoteServices.AgentEndpointPortClient(); MyRemoteServices.addLocalReservationRequest alrRequest = dtoHlp.GetLocalReservationRequest(lrVM); MyRemoteServices.addLocalReservationResponse alrResponse = aepc.addLocalReservation(alrRequest); if (alrResponse.responseWrapper.success) { //save localy using (var ctx = new ApplicationDbContext()) { BookingUnit myUnit = ctx.BookingUnits.FirstOrDefault(x => x.Id == lrVM.BookingUnitId); TotalPriceCalculator totPrCalc = new TotalPriceCalculator(); double totalPrice = totPrCalc.CalculateTotalPrice(lrVM.BookingUnitId, lrVM.DateFrom, lrVM.DateTo); Reservation localReservation = new Reservation { ReservationStatus = ReservationStatus.WAITING, SubjectName = lrVM.ReserveeFirstName, SubjectSurname = lrVM.ReserveeLastName, From = lrVM.DateFrom, To = lrVM.DateTo, BookingUnit = myUnit, TotalPrice = totalPrice, MainServerId = (long)alrResponse.responseWrapper.responseBody }; //add the new item ctx.Reservations.Add(localReservation); //save changes ctx.SaveChanges(); } } else { //some error happened, retry TempData["error"] = alrResponse.responseWrapper.message; return(RedirectToAction("LocalReservation", "Agent", new { bookingUnitId = lrVM.BookingUnitId })); } TempData["success"] = "Successfully added a local reservation of the unit: " + lrVM.BookingUnitName; return(RedirectToAction("AgentPage", "Agent")); } else { //max days limit or begin date exception TempData["error"] = "The begin date must be today's date or greater. The maximum number of days for one reservation is 30"; return(RedirectToAction("LocalReservation", "Agent", new { bookingUnitId = lrVM.BookingUnitId })); } } else { //invalid VM exception TempData["error"] = "Some form atributes are incorrect"; return(RedirectToAction("LocalReservation", "Agent", new { bookingUnitId = lrVM.BookingUnitId })); } } }