public void GallonsRequested_ShouldBeGreaterThanZero() { //Arrange FuelQuote newQuote = new FuelQuote(); newQuote.GallonsRequested = 5; double expectedValue = 5; //Act double actualValue = newQuote.GallonsRequested; //Assert Assert.Equal(expectedValue, actualValue); }
public void TotalPrice_ShouldCalculate() { //Arrange FuelQuote newQuote = new FuelQuote(); newQuote.GallonsRequested = 10; double expectedValue = 25; //Act double actualValue = newQuote.TotalPrice; //Assert Assert.Equal(expectedValue, actualValue); }
public void suggestedPrice_ShouldbePresent() { //Arrange FuelQuote newQuote = new FuelQuote(); bool expected = true; //Act bool actual = false; if (newQuote.SuggestedPrice > 0) { actual = true; } //Assert Assert.Equal(expected, actual); }
public ActionResult Pricing(int clientId, FuelQuoteViewModel viewModel) { if (viewModel.FuelQuote.DeliveryDate == null || viewModel.FuelQuote.GallonRequested == 0) { viewModel.OutComeOfValidateInput = "SomeNullInput"; return(View("FuelQuoteForm", viewModel)); } using (var db = new MyDbContext()) { var queryClient = from b in db.ClientsTable select b; Client client = null; foreach (var item in queryClient) { if (item.ClientId == clientId) { client = item; } } ClientProfile clientProfile = null; var queryProfile = from b in db.ClientProfileTable select b; foreach (var item in queryProfile) { if (item.Client == client) { clientProfile = item; } } double currentPricePerGallon = 1.5; double locationFactor; double rateHistoryFactor = 0; double gallonRequestedFactor; double companyProfitFactor = 0.1; double rateFluctuation; // Get locationFactor from state if (clientProfile.State == "TX") { locationFactor = 0.02; } else { locationFactor = 0.04; } // Get rateHistoryFactor by checking in database bool ratedBefore = false; var queryHistory = from b in db.FuelQuotes select b; foreach (var item in queryHistory) { if (item.Client == client) { ratedBefore = true; } } if (ratedBefore) { rateHistoryFactor = 0.01; } // Get gallonRequestedFactor based on amount of gallon requested if (viewModel.FuelQuote.GallonRequested > 1000) { gallonRequestedFactor = 0.02; } else { gallonRequestedFactor = 0.03; } // Get rateFluctuation from the DeliveryDate (is summer if between May and July) int month = Convert.ToInt32(viewModel.FuelQuote.DeliveryDate.Substring(5, 2)); if (month >= 5 && month <= 7) { rateFluctuation = 0.04; } else { rateFluctuation = 0.03; } double margin = currentPricePerGallon * (locationFactor - rateHistoryFactor + gallonRequestedFactor + companyProfitFactor + rateFluctuation); double price = currentPricePerGallon + margin; var newFuelQuote = new FuelQuote { Client = client, DeliveryAddress = viewModel.FuelQuote.DeliveryAddress, DeliveryDate = viewModel.FuelQuote.DeliveryDate, GallonRequested = viewModel.FuelQuote.GallonRequested, SuggestedPrice = price, TotalAmountDue = price * viewModel.FuelQuote.GallonRequested }; db.FuelQuotes.Add(newFuelQuote); db.SaveChanges(); viewModel.FuelQuote = newFuelQuote; viewModel.ClientId = clientId; return(View("FuelQuoteForm", viewModel)); } }
public ActionResult ManagingProfile(int clientId, ProfileManagementViewModel profileManagmentViewModel) { if (string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Name) || string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Address1) || string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.City) || string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.State) || string.IsNullOrEmpty(profileManagmentViewModel.ClientProfile.Zipcode)) { var client = new Client { ClientId = clientId }; var clientProf = new ClientProfile { ClientProfileId = clientId }; profileManagmentViewModel = new ProfileManagementViewModel { Client = client, ClientProfile = clientProf, OutcomeOfValidatingProfiles = "SomeNullInput" }; return(View("ProfileManagementPage", profileManagmentViewModel)); } int tempNumber = 0; bool zipCodeIsValid = Int32.TryParse(profileManagmentViewModel.ClientProfile.Zipcode, out tempNumber); if (!zipCodeIsValid) { var client = new Client { ClientId = clientId }; var clientProf = new ClientProfile { ClientProfileId = clientId }; profileManagmentViewModel = new ProfileManagementViewModel { Client = client, ClientProfile = clientProf, OutcomeOfValidatingProfiles = "InvalidZipCode" }; return(View("ProfileManagementPage", profileManagmentViewModel)); } using (var db = new MyDbContext()) { ClientProfile temp = db.ClientProfileTable.SingleOrDefault(x => x.ClientProfileId == clientId); if (temp != null) { temp.Name = profileManagmentViewModel.ClientProfile.Name; temp.Address1 = profileManagmentViewModel.ClientProfile.Address1; temp.Address2 = profileManagmentViewModel.ClientProfile.Address2; temp.City = profileManagmentViewModel.ClientProfile.City; temp.State = profileManagmentViewModel.ClientProfile.State; temp.Zipcode = profileManagmentViewModel.ClientProfile.Zipcode; db.SaveChanges(); } else { var newProfile = new ClientProfile { ClientProfileId = clientId, Name = profileManagmentViewModel.ClientProfile.Name, Address1 = profileManagmentViewModel.ClientProfile.Address1, Address2 = profileManagmentViewModel.ClientProfile.Address2, City = profileManagmentViewModel.ClientProfile.City, State = profileManagmentViewModel.ClientProfile.State, Zipcode = profileManagmentViewModel.ClientProfile.Zipcode }; db.ClientProfileTable.Add(newProfile); db.SaveChanges(); } var fuelQuote = new FuelQuote { DeliveryAddress = profileManagmentViewModel.ClientProfile.Address1 + " " + profileManagmentViewModel.ClientProfile.Address2 + ", " + profileManagmentViewModel.ClientProfile.City + ", " + profileManagmentViewModel.ClientProfile.State + ", " + profileManagmentViewModel.ClientProfile.Zipcode }; var fuelQuoteViewModel = new FuelQuoteViewModel { ClientId = clientId, FuelQuote = fuelQuote, }; return(View("FuelQuoteForm", fuelQuoteViewModel)); } }