public GetTaxRateResponse GetTaxInfo(string stateAbbreviation) { ListTaxResponse taxResponse = _taxRepository.LoadTaxInfo(ConfigurationManager.AppSettings["TaxFilePath"].ToString()); GetTaxRateResponse response = new GetTaxRateResponse(); if (taxResponse.Success) { var taxInfo = taxResponse.TaxList; var stateCheck = (from tax in taxInfo where tax.StateAbbreviation == stateAbbreviation select tax).ToArray(); if (stateCheck.Any()) { response.TaxRate = stateCheck[0].TaxRate; response.Success = true; } else { response.Success = false; response.Message = "We cannot do work in that state!"; } } else { response.Success = false; response.Message = taxResponse.Message; } return(response); }
public async void GetTaxRate_Expect_Sucsess() { // Setup var mockResponse = new GetTaxRateResponse() { Rate = new TaxRate { City = "Saint Pete", Zip = "33701", State_rate = "10.99" } }; _apiClient.Setup(x => x.GetAsync <GetTaxRateResponse>(It.IsAny <string>())) .Returns(Task.FromResult(mockResponse)).Verifiable(); // Act var actualResponse = await _taxRepository.GetTaxRateResponse("https://sample.com") as GetTaxRateResponse; // Assert // Assert Assert.NotNull(actualResponse); Assert.NotNull(actualResponse.Rate); Assert.Equal("Saint Pete", actualResponse.Rate.City); Assert.Equal("33701", actualResponse.Rate.Zip); Assert.Equal("10.99", actualResponse.Rate.State_rate); }
public async void GetTaxRates_ValidInput_Expect_Success() { // Setup var mockResponse = new GetTaxRateResponse() { Rate = new TaxRate { City = "Saint Pete", Zip = "33701", State_rate = "10.99" } }; _taxProvider.Setup(x => x.GetTaxRates(It.IsAny <GetTaxRateRequest>())) .Returns(Task.FromResult(mockResponse)).Verifiable(); // Act var actualResponse = await _taxController.GetTaxRates(It.IsAny <GetTaxRateRequest>()) as OkObjectResult; var data = actualResponse.Value as GetTaxRateResponse; // Assert Assert.NotNull(actualResponse); Assert.NotNull(data); Assert.NotNull(data.Rate); Assert.Equal("Saint Pete", data.Rate.City); Assert.Equal("33701", data.Rate.Zip); Assert.Equal("10.99", data.Rate.State_rate); }
public async void GetTaxRates_ValidData_Expect_Success() { // Setup var mockResponse = new GetTaxRateResponse() { Rate = new TaxRate { City = "Saint Pete", Zip = "33701", State_rate = "10.99" } }; _taxRepository.Setup(x => x.GetTaxRateResponse(It.IsAny <string>())) .Returns(Task.FromResult(mockResponse)).Verifiable(); _taxProviderValidator.Setup(x => x.ValidateGetTaxRateRequest(It.IsAny <GetTaxRateRequest>())); // Act var actualResponse = await _taxProvider.GetTaxRates(It.IsAny <GetTaxRateRequest>()) as GetTaxRateResponse; // Assert Assert.NotNull(actualResponse); Assert.Equal("Saint Pete", actualResponse.Rate.City); Assert.Equal("33701", actualResponse.Rate.Zip); Assert.Equal("10.99", actualResponse.Rate.State_rate); }
public Order CalculateOrderCosts(Order order) { GetTaxRateResponse taxInfo = GetTaxInfo(order.State); GetProductResponse productResponse = GetProductInfo(order.FloorType); Product orderProduct = productResponse.ProductInfo; order.TaxRate = taxInfo.TaxRate; order.CostPerSquareFoot = orderProduct.CostPerSquareFoot; order.LaborCostPerSquareFoot = orderProduct.LaborCostPerSquareFoot; order.MaterialCost = (orderProduct.CostPerSquareFoot * order.Area); order.LaborCost = (orderProduct.LaborCostPerSquareFoot * order.Area); order.Tax = (order.LaborCost + order.MaterialCost) * (taxInfo.TaxRate / 100); order.Total = order.LaborCost + order.MaterialCost + order.Tax; return(order); }
public LoadOrderResponse LoadNewOrder(Order order, string date) { LoadOrderResponse response = new LoadOrderResponse(); GetTaxRateResponse taxInfo = GetTaxInfo(order.State); response.Order = order; if (response.Order.Area < 100) { response.Success = false; response.Message = "The minimum order area is 100 square feet!"; return(response); } if (!taxInfo.Success) { response.Success = false; response.Message = taxInfo.Message; return(response); } if (DateTime.TryParse(date, out DateTime orderDate)) { if (orderDate.CompareTo(DateTime.Now) <= 0) { response.Success = false; response.Message = "The Date for the work to be done must be in the future."; return(response); } } if (response.Order.CustomerName == "") { response.Success = false; response.Message = "Customer name cannot be blank."; return(response); } else { response.Success = true; response.Order.OrderNumber = GetOrderNumber(date); CalculateOrderCosts(response.Order); } return(response); }
public static string GetStateAbbreviationFromUser(string prompt) { OrderManager manager = OrderManagerFactory.Create(); while (true) { Console.Write(prompt); string input = Console.ReadLine(); GetTaxRateResponse response = manager.GetTaxInfo(input); if (!response.Success) { Console.WriteLine(response.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); continue; } return(input); } }