public TestBase() { // Adding JSON file into IConfiguration. var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true); Configuration = config.Build(); // Integration Test Setup var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); // Configuration for TaxCalculatorDb var builder = new DbContextOptionsBuilder <TaxCalculatorDbContext>(); builder.UseSqlServer(Configuration.GetConnectionString("TaxCalculationConnetion")) .UseInternalServiceProvider(serviceProvider); _dbContext = new TaxCalculatorDbContext(builder.Options); _dbContext.Database.EnsureCreated(); taxRepository = new TaxRepository(_dbContext); TaxCalculatorInitializer.Initialize(_dbContext); }
public static string GetOrderStateFromUser(string prompt) { while (true) { Header(); Console.Write(prompt); string input = Console.ReadLine(); if (TaxRepository.GetTaxRate(input.ToUpper()) == -1) { Header(); Console.WriteLine("You must enter valid state initials. (MN, OH, PA, MI, IN)"); Console.WriteLine("Press any key to return."); Console.ReadKey(); } else { if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input)) { Header(); Console.WriteLine("You must enter a state."); Console.WriteLine("Press any key to return."); Console.ReadKey(); } else { return(input); } } } }
public Order CalculateOrder(Order order) { List <Product> products = ProductRepository.GetProducts(); foreach (var product in products) { if (order.ProductType == product.ProductType) { order.CostPerSquareFoot = product.CostPerSquareFoot; order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; break; } } order.MaterialCost = order.Area * order.CostPerSquareFoot; order.LaborCost = order.Area * order.LaborCostPerSquareFoot; List <Tax> taxes = TaxRepository.GetTaxes(); foreach (var tax in taxes) { if (tax.StateAbbreviation == order.State) { order.Tax = (order.MaterialCost + order.LaborCost) * (tax.TaxRate / 100); order.TaxRate = tax.TaxRate; } } order.Total = order.MaterialCost + order.LaborCost + order.Tax; order.Area = decimal.Round(order.Area, 2); order.CostPerSquareFoot = decimal.Round(order.CostPerSquareFoot, 2); order.LaborCostPerSquareFoot = decimal.Round(order.LaborCostPerSquareFoot, 2); order.MaterialCost = decimal.Round(order.MaterialCost, 2); order.LaborCost = decimal.Round(order.LaborCost, 2); order.Total = decimal.Round(order.Total, 2); return(order); }
public static OrderManager Create() { string mode = ConfigurationManager.AppSettings["Mode"].ToString(); IOrderRepository orderRepository; ITaxRepository taxRepository; IProductRepository productRepository; switch (mode) { case "Test": orderRepository = new TestOrderRepository(); taxRepository = new TestTaxRepository(); productRepository = new TestProductRepository(); return(new OrderManager(orderRepository, taxRepository, productRepository)); case "Production": orderRepository = new FileOrderRepository(); taxRepository = new TaxRepository(); productRepository = new ProductRepository(); return(new OrderManager(orderRepository, taxRepository, productRepository)); default: throw new Exception("Mode value in app config is not valid"); } }
public void Less_or_equal_than_zero_tax_rate_should_throw_exception() { const decimal taxRate = -10m; var taxStore = new TaxRepository(); taxStore.StoreTaxRate(taxRate); }
public TaxRepositoryUnitTests() { _mockLogger = new Mock <ILogger <TaxRepository> >(); _mockTaxService = new Mock <ITaxService>(); _mockApiClient = new Mock <IApiClient>(); _repository = new TaxRepository(_mockApiClient.Object, _mockLogger.Object); }
private void GetStateAndTax(Order newOrder) { var taxloader = new TaxRepository(); List <Tax> taxList = taxloader.LoadTaxesAndStatesFromFile(); int count = 0; bool isNotValidState = true; do { Console.Write("We operate in the following States:\n"); foreach (var tax in taxList) { Console.WriteLine("{0}", tax.State); } Console.WriteLine("\nWhich of these states are you in?: "); string userInput = Console.ReadLine().ToUpper(); foreach (var taxSchedule in taxList) { if (taxSchedule.State == userInput) { count++; newOrder.State = userInput; newOrder.TaxRate = taxSchedule.TaxRate; isNotValidState = false; } } if (count == 0) { Console.WriteLine("You entered:{0}. That is not a valid state! Make sure you abbreviate, i.e.'OH' ", userInput); } } while (isNotValidState); }
public void Execute() { IUserIO userIO = new UserIO(); userIO.Clear(); FlooringManager manager = FlooringFactoryManager.Create(); Order order = new Order(); userIO.WriteLine("CREATE NEW ORDER: "); userIO.WriteLine(""); userIO.WriteLine(new string('=', 60)); userIO.WriteLine(""); order.OrderDate = HelperMethods.GetDateTime("Please enter the date of order: "); order.CustomerName = HelperMethods.GetCustomerName("Please enter the customers name: "); order.State = HelperMethods.GetStateTax(TaxRepository.GetTaxes()); order.ProductType = HelperMethods.GetProductInformation(ProductRepository.GetProducts()); order.Area = HelperMethods.GetDecimalFromString("Enter the Area: "); order = manager.CalculateOrder(order); userIO.DisplayOrder(order); if (HelperMethods.GetYesNoAnswerFromUser("Would you like to create this order?")) { userIO.WriteLine("Order has succesfully been created."); AddOrderResponse response = manager.AddOrder(order); } else { userIO.WriteLine("Order was not created."); } }
public void A_ChangedTax_modifies_Existing_country_in_the_database() { var bootStrapper = new BootStrapper(); bootStrapper.StartServices(); var serviceEvents = bootStrapper.GetService<IServiceEvents>(); //1.- Create message var aggr = GenerateRandomAggregate(); //2.- Create the tuple in the database var repository = new TaxRepository(_configuration.TestServer); repository.Insert(aggr); //3.- Change the aggregate aggr.NameKeyId = StringExtension.RandomString(10); aggr.CountryId = Guid.NewGuid(); aggr.SapCode = StringExtension.RandomString(2); aggr.CurrencyId = Guid.NewGuid(); aggr.BaseAmount = decimal.Round(Convert.ToDecimal(new Random().NextDouble()), 2 , MidpointRounding.AwayFromZero); aggr.Amount = decimal.Round(Convert.ToDecimal(new Random().NextDouble()), 2, MidpointRounding.AwayFromZero); //4.- Emit message var message = GenerateMessage(aggr); message.MessageType = typeof(ChangedTax).Name; serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message }); //5.- Load the saved country var tax = repository.Get(aggr.Id); //6.- Check equality Assert.True(ObjectExtension.AreEqual(aggr, tax)); }
public void Greater_or_equal_to_hundred_tax_rate_should_throw_exception() { const decimal taxRate = 110m; var taxStore = new TaxRepository(); taxStore.StoreTaxRate(taxRate); }
public static decimal JustTax(decimal taxRate, ProductType Type, int areaSqFt, string state) { decimal costBeforeTax = Calculations.CalculateCost(Type, areaSqFt); taxRate = TaxRepository.GetTaxRate(state); return(taxRate * costBeforeTax); }
private static TaxRepository StoreTaxRate() { Console.WriteLine("------------------------- Site Administrator ---------------"); Console.WriteLine("Please Enter tax rate:"); var taxRate = decimal.Parse(Console.ReadLine()); var taxRepository = new TaxRepository(); taxRepository.StoreTaxRate(taxRate); return(taxRepository); }
private static void CalculateGiftAid(TaxRepository taxRepository, EventSupplement selectedEventSupplement) { Console.WriteLine("Please Enter donation amount:"); var donation = decimal.Parse(Console.ReadLine()); var giftAidCalculator = new Model.GiftAidCalculator(taxRepository); Console.WriteLine("Your gift aid amount is:"); Console.WriteLine(giftAidCalculator.CalculateGiftAidAmount(donation, selectedEventSupplement)); }
public void Initialize() { //Arrange var databaseFactory = new DatabaseFactory(); var unitOfWork = new UnitOfWork(databaseFactory); ITaxRepository _taxRepository = new TaxRepository(databaseFactory); _taxService = new TaxService(_taxRepository); }
private void UpdateTaxRate(Order selectedOrder) { TaxRepository t = new TaxRepository(); var taxList = t.LoadTaxesAndStatesFromFile(); var res = taxList.Find(p => p.State == selectedOrder.State); //or where instead of find and extra line? selectedOrder.TaxRate = res.TaxRate; //Tax taxObj = res.First(); //selectedOrder.TaxRate = taxObj.TaxRate; }
public OrderService(RequestContext c) { context = c; Orders = OrderRepository.InstantiateForDatabase(c); Taxes = TaxRepository.InstantiateForDatabase(c); TaxSchedules = TaxScheduleRepository.InstantiateForDatabase(c); ShippingZones = ZoneRepository.InstantiateForDatabase(c); Transactions = OrderTransactionRepository.InstantiateForDatabase(c); ShippingMethods = ShippingMethodRepository.InstantiateForDatabase(c); }
public OrderService(HccRequestContext c, OrderRepository orders, TaxRepository taxes, TaxScheduleRepository taxSchedules, ZoneRepository shippingZones, OrderTransactionRepository transactions, ShippingMethodRepository shippingMethods, StoreSettingsRepository settings, RMARepository returnsRepo) : this(c) { }
static void Main(string[] args) { IOrderRepository orderRepo = new OrderRepository(); IProductRepository ProductRepo = new ProductRepository(); ITaxRepository TaxRepo = new TaxRepository(); IOrderService oS = new OrderService(orderRepo, ProductRepo, TaxRepo); OrderView oV = new OrderView(); OrderController oC = new OrderController(oS, oV); oC.Run(); }
public static OrderService InstantiateForDatabase(RequestContext c) { return(new OrderService(c, OrderRepository.InstantiateForDatabase(c), TaxRepository.InstantiateForDatabase(c), TaxScheduleRepository.InstantiateForDatabase(c), ZoneRepository.InstantiateForDatabase(c), OrderTransactionRepository.InstantiateForDatabase(c), ShippingMethodRepository.InstantiateForDatabase(c), Accounts.StoreSettingsRepository.InstantiateForDatabase(c))); }
public static decimal StateAssociatedTax(string stateAbbreviation) { TaxRepository taxRepo = new TaxRepository(); Dictionary <string, decimal> stateChoices = new Dictionary <string, decimal>(); foreach (var x in taxRepo.Taxes()) { stateChoices.Add(x.StateAbbreviation, x.TaxRate); } return(stateChoices[stateAbbreviation]); }
public void CaluclatorTest() { string taxFile = "Taxes"; string productFile = "Products"; string testFIle = "testFile"; var saveInput = new List <Order>(); var testOrder = new Order(); var tax = new TaxRepository(); var taxList = tax.LoadTaxesAndStatesFromFile(); }
public void Stored_tax_rate_should_be_retrievable() { const decimal taxRate = 25m; var taxStore = new TaxRepository(); taxStore.StoreTaxRate(taxRate); var taxRateValue = taxStore.RetrieveTaxRate(); Assert.AreEqual(taxRate, taxRateValue); }
public async Task CreateOrderTest_AU() { // Arrange TaxDataContext countryTaxDataContext = new TaxDataContext(_connectionString); OrderDataContext orderDataContext = new OrderDataContext(_connectionString); ITaxRepository taxRepository = new TaxRepository(countryTaxDataContext); IOrderRepository orderRepository = new OrderRepository(orderDataContext); ITaxCalculator taxCalculator = new TaxCalculator(taxRepository); IOrderCalculationService orderCalculation = new OrderCalculationService(taxCalculator); IOrderService orderService = new OrderService(orderRepository, orderCalculation); var date = DateTime.Now; var orderIdStr = date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.Millisecond.ToString(); int orderIdUK = int.Parse(orderIdStr); var orderUK = new Order(); orderUK.Id = orderIdUK; orderUK.Customer = new Customer() { Id = 1, Country = "AU" }; orderUK.Items = new List <orderItem>() { new orderItem() { Code = "D", Description = "Product D", Price = 10, Quantity = 1 }, new orderItem() { Code = "E", Description = "Product E", Price = 20, Quantity = 1 } }; //Act orderService.CreateOrder(orderUK); var singleOrderUk = await orderService.ViewOrderAsyn(orderUK.Id); //Assert Assert.AreEqual(33, singleOrderUk.Total); }
public void CanSellInState(string stateAbbreviation, string stateName, decimal taxRate, bool expectedResult) { TaxRepository repo = new TaxRepository(); Tax stateTax = new Tax() { StateAbbreviation = stateAbbreviation, StateName = stateName, TaxRate = taxRate }; Assert.AreEqual(expectedResult, true); }
static void Main(string[] args) { var io = new FileDataProvider(args[0]); var repo = new TaxRepository(); var records = io.GetTaxRecords(); foreach (var item in records) { item.ID = null; repo.Create(item); } }
public void CanReadTaxesFromFile() { TaxRepository repo = new TaxRepository(); List <Tax> taxes = repo.Taxes(); Assert.AreEqual(7, taxes.Count()); Tax check = taxes[1]; Assert.AreEqual("OH", check.StateAbbreviation); Assert.AreEqual("Ohio", check.StateName); Assert.AreEqual(7.14M, check.TaxRate); }
public ProductCrudHandler(ProductRepository productRepository, CategoryRepository categoryRepository, WerehouseRepository werehouseRepository, TaxRepository taxRepository, UnitOfMeasureRepository unitOfMeasureRepository) : base(productRepository) { _productRepository = productRepository; _categoryRepository = categoryRepository; _werehouseRepository = werehouseRepository; _taxRepository = taxRepository; _unitOfMeasureRepository = unitOfMeasureRepository; _fromDto = FromDto; _fromEntity = FromEntity; _updateEntity = UpdateEntity; }
public void LoadTaxes(string stateAbb, string stateName, decimal taxRate, bool expectedResult) { TaxRepository repo = new TaxRepository(); Taxes tax = new Taxes(); tax.StateAbbreviation = stateAbb; tax.StateName = stateName; tax.TaxRate = taxRate; Taxes actual = repo.LoadTaxes(stateAbb); Assert.AreEqual(stateAbb, actual.StateAbbreviation); Assert.AreEqual(stateName, actual.StateName); Assert.AreEqual(taxRate, actual.TaxRate); }
public void LoadTaxes() { TaxRepository repo = new TaxRepository(); Taxes tax = repo.LoadTaxes("OH"); tax.StateAbbreviation = "OH"; tax.StateName = "Ohio"; tax.TaxRate = 6.25M; Taxes actual = repo.LoadTaxes("OH"); Assert.AreEqual("OH", actual.StateAbbreviation); Assert.AreEqual("Ohio", actual.StateName); Assert.AreEqual(6.25M, actual.TaxRate); }
public void A_RegisteredRegion_creates_a_new_currency_in_the_database() { var bootStrapper = new BootStrapper(); bootStrapper.StartServices(); var serviceEvents = bootStrapper.GetService<IServiceEvents>(); //1.- Create message var aggr = GenerateRandomAggregate(); var message = GenerateMessage(aggr); //2.- Emit message serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message }); //3.- Load the saved country var repository = new TaxRepository(_configuration.TestServer); var tax = repository.Get(aggr.Id); //4.- Check equality Assert.True(ObjectExtension.AreEqual(aggr, tax)); }
public static string GetRequiredStateFromUser(string prompt, bool isEdit = false) { TaxRepository stateRepo = new TaxRepository(); while (true) { Console.Write(prompt); PrintAllStates(stateRepo.Taxes()); Console.WriteLine("Please choose a state by abbreviation"); List <string> stateChoices = new List <string>(); foreach (var x in stateRepo.Taxes()) { stateChoices.Add(x.StateAbbreviation.Trim(' ')); } return(IsValidInput(stateChoices, isEdit)); } }
public OrderService(RequestContext c, OrderRepository orders, TaxRepository taxes, TaxScheduleRepository taxSchedules, ZoneRepository shippingZones, OrderTransactionRepository transactions, ShippingMethodRepository shippingMethods, Accounts.StoreSettingsRepository settings) { context = c; Orders = orders; Taxes = taxes; TaxSchedules = taxSchedules; ShippingZones = shippingZones; Transactions = transactions; ShippingMethods = shippingMethods; this.storeSettings = settings; }
public void A_UnregisteredTax_modifies_Existing_country_in_the_database() { var bootStrapper = new BootStrapper(); bootStrapper.StartServices(); var serviceEvents = bootStrapper.GetService<IServiceEvents>(); //1.- Create message var aggr = GenerateRandomAggregate(); //2.- Create the tuple in the database var repository = new TaxRepository(_configuration.TestServer); repository.Insert(aggr); //3.- Emit message var message = GenerateMessage(aggr); message.MessageType = typeof(UnregisteredTax).Name; serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message }); var tax = repository.Get(aggr.Id); Assert.Null(tax); }
public void Init() { ctx = EFContext.CreateContext(); repo = new TaxRepository(ctx); }