public void Discounts_UpdateTest() { var repository = new DiscountRepository(); var list = repository.GetAll(); Assert.IsTrue(list.Count() > 0); }
public void Discounts_OrderByDiscountTest() { var repository = new DiscountRepository(); var list = repository.OrderByDiscount(); Assert.IsTrue(list.Count() > 0); }
private void EditDiscount() { DiscountRepository discrep = new DiscountRepository(); Discounts disc = (Discounts)binSourceBusStation.Current; List <BusinessTickets> busTicketsD = DeleteTicketsANDFlights(disc); discrep.Delete(disc); Discounts newdisc = new Discounts(); newdisc.DiscountName = disc.DiscountName; newdisc.Size = disc.Size; newdisc.Information = disc.Information; discrep.Create(newdisc); if (busTicketsD.Count > 0) { BusinessTickets bustick = new BusinessTickets(); BusinessTicketsRepository bustickrep = new BusinessTicketsRepository(); for (int i = 0; i < busTicketsD.Count; i++) { bustick.ReleaseDate = busTicketsD[i].ReleaseDate; bustick.FlightId = busTicketsD[i].FlightId; bustick.SeatId = busTicketsD[i].SeatId; bustick.DiscountId = newdisc.DiscountId; bustick.Sold = busTicketsD[i].Sold; bustick.Reserve = busTicketsD[i].Reserve; bustick.Canceled = busTicketsD[i].Canceled; bustickrep.Create(bustick); } } MessageBox.Show("Discount Edit"); }
public void GetDiscountResultForDiscountedEmployeeWithLetterAinLastNameTest() { var options = SetupWithDiscountCriteria(); var dependentList = new List <Dependent>(); using (var context = new DiscountContext(options)) { var discountRepository = new DiscountRepository(context); var discountCriteria = discountRepository.GetDiscountCriteria().Result; var discountCalculationResult = discountRepository.GetDiscountResult(1, "Rick", "Amber", dependentList).Result; Assert.AreEqual(900.00m, discountCalculationResult.TotalYearlyBenefitCost); Assert.AreEqual(500.00m, discountCriteria.BaseDependentBenefitCost); Assert.AreEqual(1000.00m, discountCriteria.BaseEmployeeBenefitCost); Assert.AreEqual(.1m, discountCriteria.DiscountPerctentageRate); Assert.AreEqual('A', discountCriteria.DiscountQualifier); Assert.AreEqual(2000.00m, discountCriteria.EmployeeBiWeeklyBasePay); Assert.AreEqual(26, discountCriteria.TotalYearlyCheckDisbursment); context.Database.EnsureDeleted(); } }
public void GetDiscountForExistingUserRoleTest() { IDiscountRepository discountRepository = new DiscountRepository(new JewelryStoreDbContext(_dbContextOptions)); var userRoleId = _userRoles.First().Id; var discount = discountRepository.GetDiscountByUserRole(userRoleId); Assert.Equal(_discounts.First(x => x.UserRoleId.Equals(userRoleId)).DiscountPer, discount.DiscountPer); }
public void GetDiscountForNonExistingUserRoleTest() { IDiscountRepository discountRepository = new DiscountRepository(new JewelryStoreDbContext(_dbContextOptions)); var userRoleId = Guid.NewGuid(); var discount = discountRepository.GetDiscountByUserRole(userRoleId); Assert.Null(discount); }
public void GetDiscountResultForOneDiscountedDependentTwoNonDiscountedDependentsWithLetterAinLastNameTest() { var options = SetupWithDiscountCriteria(); var dependentList = new List <Dependent>(); var newDependent = new Dependent { EmployeeId = 1, FirstName = "Jane", LastName = "Amber", CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; dependentList.Add(newDependent); var newDependentTwo = new Dependent { EmployeeId = 1, FirstName = "Jane", LastName = "Jolly", CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; dependentList.Add(newDependentTwo); var newDependentThree = new Dependent { EmployeeId = 1, FirstName = "Jane", LastName = "Doe", CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; dependentList.Add(newDependentThree); using (var context = new DiscountContext(options)) { var discountRepository = new DiscountRepository(context); var discountCriteria = discountRepository.GetDiscountCriteria().Result; var discountCalculationResult = discountRepository.GetDiscountResult(1, "Rick", "Grimes", dependentList).Result; Assert.AreEqual(1450.00m, discountCalculationResult.TotalDependentBenefitCost); Assert.AreEqual(500.00m, discountCriteria.BaseDependentBenefitCost); Assert.AreEqual(1000.00m, discountCriteria.BaseEmployeeBenefitCost); Assert.AreEqual(.1m, discountCriteria.DiscountPerctentageRate); Assert.AreEqual('A', discountCriteria.DiscountQualifier); Assert.AreEqual(2000.00m, discountCriteria.EmployeeBiWeeklyBasePay); Assert.AreEqual(26, discountCriteria.TotalYearlyCheckDisbursment); context.Database.EnsureDeleted(); } }
public TicketService(TicketListAllQuery ticketListAllQuery, TicketRepository ticketRepository, ProgramRepository programRepository, DiscountRepository discountRepository, CustomerRepository customerRepository, CompanyRepository companyRepository) { this.ticketListAllQuery = ticketListAllQuery; this.companyRepository = companyRepository; this.customerRepository = customerRepository; this.ticketRepository = ticketRepository; this.programRepository = programRepository; this.discountRepository = discountRepository; }
public RepositoryBasketDiscountPolicyAdapter(DiscountRepository repository) { if (repository == null) { throw new ArgumentNullException("repository"); } this.repository = repository; }
public void RepositoryIsCorrect([Frozen] DiscountRepository expectedRepository, DiscountCampaign sut) { // Fixture setup // Exercise system DiscountRepository result = sut.Repository; // Verify outcome Assert.Equal(expectedRepository, result); // Teardown }
public MainViewModel(ShopNetworkContext dbCont) { _subGroupRepository = new SubGroupRepository(dbCont); _groupRepository = new GroupRepository(dbCont); _personRepository = new PersonRepository(dbCont); _pictureRepository = new PictureRepository(dbCont); _adminRepository = new AdminRepository(dbCont); _discountRepository = new DiscountRepository(dbCont); _productRepository = new ProductRepository(dbCont); _newsRepository = new NewsRepository(dbCont); _cartRepository = new CartRepository(dbCont); }
public RepositoryFactory(AllegrettoContext context) { _context = context; Baskets = new BasketRepository(_context); Categories = new CategoryRepository(_context); Customers = new CustomerRepository(_context); Discounts = new DiscountRepository(_context); Orders = new OrderRepository(_context); Products = new ProductRepository(_context); Users = new UserRepository(_context); Countries = new CountryReposytory(_context); }
public void Setup() { var specialOfferRepository = new SpecialOfferRepository(); var discountRepository = new DiscountRepository(); _discountService = new DiscountService(discountRepository); _specialOfferService = new SpecialOfferService(specialOfferRepository); _shelfItemRepository = new ShelfItemRepository(); _basketService = new BasketService(_discountService, _specialOfferService); }
public void CreateWithNullRepositoryWillThrow() { // Fixture setup var fixture = new RepositoryFixture(); DiscountRepository nullRepository = null; // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => fixture.Build <RepositoryBasketDiscountPolicy>() .FromFactory(() => new RepositoryBasketDiscountPolicy(nullRepository)) .OmitAutoProperties() .CreateAnonymous()); // Teardown }
public static void Init(TestContext tc) { var productRepository = new ProductRepository(); productRepository.AddOrUpdate(new Product { SKU = "TST_A01", Description = "Apple", Price = 0.5m }); productRepository.AddOrUpdate(new Product { SKU = "TST_B15", Description = "Biscuits", Price = 0.3m }); productRepository.AddOrUpdate(new Product { SKU = "TST_C40", Description = "Coffee", Price = 1.8m }); productRepository.AddOrUpdate(new Product { SKU = "TST_T23", Description = "Tissues", Price = 0.99m }); var discountRepository = new DiscountRepository(); discountRepository.AddOrUpdate(new Discount { Id = Guid.NewGuid(), ProductSKU = "TST_A01", Quantity = 3, Price = 1.3m }); discountRepository.AddOrUpdate(new Discount { Id = Guid.NewGuid(), ProductSKU = "TST_B15", Quantity = 2, Price = .45m }); }
public Task <IEnumerable <Discount> > SearchAsync(string searchText) { if (searchText != null) { var allDiscounts = DiscountRepository.Get(); var lowerSearchText = searchText.ToLower(); return(Task.FromResult(allDiscounts .Where(d => d.Conditions.ToLower().Contains(lowerSearchText) || d.VendorName.ToLower().Contains(lowerSearchText)) .AsEnumerable())); } return(DiscountRepository.GetAllAsync()); }
public AdminController(EmployeeRepository employeeRepository, DependentRepository dependentRepository, BenefitSettingsRepository benefitSettingsRepository, DiscountRepository discountRepository, DiscountTypeRepository discountTypeRepository, DiscountConditionTypeRepository discountConditionTypeRepository, StateRepository stateRepository) { EmployeeRepository = employeeRepository; DependentRepository = dependentRepository; BenefitSettingsRepository = benefitSettingsRepository; DiscountRepository = discountRepository; DiscountTypeRepository = discountTypeRepository; DiscountConditionTypeRepository = discountConditionTypeRepository; StateRepository = stateRepository; }
public async Task <IEnumerable <Discount> > SearchAsync(string searchText) { var allDiscounts = DiscountRepository.Get(); if (searchText != null) { var searchResults = await GetSearchResultsAsync(searchText); var searchResultsIds = searchResults.Select(s => s.Id).ToList(); return(allDiscounts .Where(d => searchResultsIds.Contains(d.Id)) .AsEnumerable() .OrderBy(d => searchResultsIds.IndexOf(d.Id))); } return(allDiscounts); }
static void Main(string[] args) { ICustomerRepository customerRepo = new CustomerRepository(); IProductRepository productRepo = new ProductRepository(); IOrderRepository ordersRepo = new OrderRepository(); IDiscountRepository discountRepo = new DiscountRepository(); IDiscountCalculatorService discountService = new DiscountCalculatorService(); var product = productRepo.GetAll.First(); var discounts = discountRepo.GetAll.ToList(); product.Discount = discounts[1]; addToStore(product, 10); addToStore(product, 5); addToStore(product, 15); Console.WriteLine(discountService.Calculate(Cart)); Console.ReadKey(); }
public void GetDiscountCriteriaTest() { var options = SetupWithDiscountCriteria(); using (var context = new DiscountContext(options)) { var discountRepository = new DiscountRepository(context); var discountCriteria = discountRepository.GetDiscountCriteria().Result; Assert.AreEqual(500.00m, discountCriteria.BaseDependentBenefitCost); Assert.AreEqual(1000.00m, discountCriteria.BaseEmployeeBenefitCost); Assert.AreEqual(.1m, discountCriteria.DiscountPerctentageRate); Assert.AreEqual('A', discountCriteria.DiscountQualifier); Assert.AreEqual(2000.00m, discountCriteria.EmployeeBiWeeklyBasePay); Assert.AreEqual(26, discountCriteria.TotalYearlyCheckDisbursment); context.Database.EnsureDeleted(); } }
private static void Main() { try { var shelfItemRepository = new ShelfItemRepository(); var shelfItems = shelfItemRepository.GetShelfItems().ToArray(); var discountRepository = new DiscountRepository(); var discounts = discountRepository.GetActiveDiscounts().ToArray(); var specialOfferRepository = new SpecialOfferRepository(); var specialOffers = specialOfferRepository.GetActiveSpecialOffers().ToArray(); DisplayShelfItems(shelfItems, discounts, specialOffers); IDiscountService discountService = new DiscountService(discountRepository); ISpecialOfferService specialOfferService = new SpecialOfferService(specialOfferRepository); using (var basketService = new BasketService(discountService, specialOfferService)) { BasketHandler(shelfItems, basketService); PrintCustomerReceipt(specialOffers, discounts, basketService); } ReadLine(); } catch (Exception ex) { WriteLine("\n\n"); ILogger logger = new ConsoleLogger(); logger.LogException(ex); ReadLine(); } }
public void ApplyDiscount() { // Get all discounts List <Discount> discounts = DiscountRepository.GetDiscounts(); if (discounts == null || discounts.Count == 0) { return; } foreach (Discount discount in discounts) { // Get source product BasketItem sourceProduct = this.Items.FirstOrDefault(i => i.Product.Id == discount.SourceProductId); if (sourceProduct != null) { // Check if source item meets the discount criteria int numberOfItemsToDiscount = sourceProduct.Quantity / discount.SourceProductQuantity; if (numberOfItemsToDiscount != 0) { // Get target item BasketItem targetProduct = this.Items.FirstOrDefault(i => i.Product.Id == discount.TargetProductId); if (targetProduct != null) { // Logging helper for AppliedDiscounts property Log(discount.Name, numberOfItemsToDiscount, targetProduct.Product.Name); decimal originalPrice = targetProduct.Product.Price; decimal discountAmount = (originalPrice * discount.DiscountFactor) * numberOfItemsToDiscount; targetProduct.Total -= discountAmount; } } } } }
protected void RebindDiscount(int discountId, bool isReload = false) { if (isReload) { _discountRepository = new DiscountRepository(); } // Discount Products var products = _productRepository.SearchProductsByCode(); var productDiscount = _discountRepository.SearchProductsByDiscountId(discountId); DdlHotels.DataSource = products.Except(productDiscount, new ProductComparer()); DdlHotels.DataTextField = "HotelAndProductName"; DdlHotels.DataValueField = "ProductId"; DdlHotels.DataBind(); List <DiscountProducts> discountHotels = _discountRepository.GetDiscountsProductsById(discountId); RptHotelListings.DataSource = discountHotels; RptHotelListings.DataBind(); // Discount Subscriptions var subscriptions = _discountRepository.SubscriptionsList.Where(s => !s.IsDelete && s.IsActive).ToList(); var subscriptionDiscount = _discountRepository.SearchSubscriptionsByDiscountId(discountId); DdlSubscription.DataSource = subscriptions.Except(subscriptionDiscount, new SubscriptionComparer()); DdlSubscription.DataTextField = "Name"; DdlSubscription.DataValueField = "Id"; DdlSubscription.DataBind(); List <DiscountSubscriptions> discountSubscriptionses = _discountRepository.GetDiscountSubscriptionsById(discountId); RptSubscriptionListings.DataSource = discountSubscriptionses; RptSubscriptionListings.DataBind(); }
public DiscountService() { _discountRepository = new DiscountRepository(); _bookRepository = new BookRepository(); }
public DiscountService(DiscountRepository repository) : base(repository) { }
public void TestInitialize() { var random = new Mock <Random>(); discountRepository = new DiscountRepository(random.Object); }
static void Main(string[] args) { ItemRepository itemRepo = null; ReceiptRepository recieptRepo = null; TransactionRepository transactionRepo = null; DiscountRepository discountRepo = null; DiscountTransactionRepository discountTransactionRepo = null; Console.WriteLine("Welcome to cash register, type help for assistance."); while (true) { string input = Console.ReadLine(); input = input.ToUpper(); switch (input) { case "EXIT": { return; } case "HELP": { Console.WriteLine("- Enter EXIT to exit this application"); Console.WriteLine("- Enter CLS to clear the screen"); Console.WriteLine("- Enter BEGIN to begin a new transaction"); Console.WriteLine("- Enter PURCHASE to buy an item"); Console.WriteLine("- Enter COUPON to enter discount"); Console.WriteLine("- Enter TOTAL to view the total"); Console.WriteLine("- Enter LIST to view the receipt"); Console.WriteLine("- Enter END to finish the transaction\r\n"); break; } case "CLS": { Console.Clear(); break; } case "BEGIN": { try { if (recieptRepo == null) { recieptRepo = new ReceiptRepository(); Console.WriteLine("\r\n" + input + " - reciept #" + recieptRepo._receipt.Id + "\r\n"); } else { Console.WriteLine("\r\n" + "Please end current transaction using the END command"); } } catch (Exception e) { Console.WriteLine("\r\n" + e.InnerException); } break; } case "PURCHASE": { try { if (recieptRepo == null) { Console.WriteLine("\r\n" + "Please begin a new transaction using the BEGIN command."); } else { itemRepo = new ItemRepository(); Console.WriteLine("\r\n" + "- Enter Product Name or SKU"); string purchaseInput = Console.ReadLine(); decimal quantity; itemRepo.Find(purchaseInput); if (itemRepo._item != null) { //ask for weight or quantity here? quantity = RequestDecimal(String.Format("\r\n" + "Please enter a quantity of {0}", purchaseInput)); Console.WriteLine("\r\n" + "- Entered {0} of {1}", quantity.ToString(), purchaseInput); transactionRepo = new TransactionRepository(); transactionRepo.New(recieptRepo._receipt.Id, itemRepo._item.Id, quantity); } else { //add suggestions (e.g. did you mean X?) Console.WriteLine("\r\n" + "- {0} was not found in the inventory", purchaseInput); } } } catch (Exception e) { Console.WriteLine(e.InnerException); } break; } case "COUPON": { try { if (recieptRepo == null) { Console.WriteLine("\r\n" + "Please begin a new transaction using the BEGIN command."); } else { discountRepo = new DiscountRepository(); Console.WriteLine("\r\n" + "- Enter Code or SKU"); string discountInput = Console.ReadLine(); discountRepo.Find(discountInput); if (discountRepo._discount != null) { Console.WriteLine("\r\n" + "- Entered {0}", discountRepo._discount.Code); //check validity then apply if (discountRepo.IsValid(recieptRepo._receipt.Id)) { discountTransactionRepo = new DiscountTransactionRepository(); discountTransactionRepo.New(recieptRepo._receipt.Id, discountRepo._discount.Id, discountRepo._discount.ItemId); Console.WriteLine(discountTransactionRepo.WriteTotal(recieptRepo._receipt.Id)); } else { Console.WriteLine("\r\n" + "- {0} was not a valid coupon", discountInput); } } else { Console.WriteLine("\r\n" + "- {0} was not a valid coupon", discountInput); } } } catch (Exception e) { Console.WriteLine("\r\n" + e.InnerException); } break; } case "TOTAL": { try { discountTransactionRepo = new DiscountTransactionRepository(); Console.WriteLine("\r\n" + input); if (recieptRepo == null) { Console.WriteLine("\r\n" + "Please begin a new transaction using the BEGIN command."); } else { //total and discounts Console.WriteLine("\r\n" + discountTransactionRepo.WriteTotal(recieptRepo._receipt.Id)); } } catch (Exception e) { Console.WriteLine("\r\n" + e.InnerException); } break; } case "LIST": { try { Console.WriteLine(input); if (recieptRepo == null) { Console.WriteLine("\r\n" + "Please begin a new transaction using the BEGIN command."); } else { Console.WriteLine("\r\n" + recieptRepo.WriteList()); } } catch { Console.WriteLine("\r\n" + errormsg); } break; } case "END": { try { //print receipt here recieptRepo = null; Console.WriteLine("\r\n" + "Transaction ended"); } catch { Console.WriteLine("\r\n" + errormsg); } break; } default: { Console.WriteLine("\r\n" + errormsg); break; } } } }
public RepositoryBasketDiscountPolicy(DiscountRepository discountRepository) { _discountRepository = discountRepository; }
public DiscountService() { repository = new DiscountRepository(); }
static void Main(string[] args) { var productRepository = new ProductRepository(); var ruleRepository = new RuleRepository(productRepository); var discountRepository = new DiscountRepository(ruleRepository, productRepository); var compiler = new DiscountCompiler(); var compiledDiscounts = compiler.Compile(discountRepository.GetFromSource()); var discountManager = new DiscountManager(compiledDiscounts); var basket = new Basket(discountManager); var products = productRepository.GetFromSource().ToArray(); var butter = products[0]; var milk = products[1]; var bread = products[2]; basket.AddProducts(new BasketItem(1, butter), new BasketItem(1, milk), new BasketItem(1, bread)); var logger = new FileLogger(); Console.WriteLine("Case 1: "); var summary1 = basket.CalculateSum(); Console.WriteLine(summary1); logger.Log(summary1); basket.Clear(); basket.AddProducts(new BasketItem(2, butter), new BasketItem(2, bread)); Console.WriteLine("Case 2: "); var summary2 = basket.CalculateSum(); Console.WriteLine(summary2); logger.Log(summary2); basket.Clear(); basket.AddProducts(new BasketItem(4, milk)); Console.WriteLine("Case 3: "); var summary3 = basket.CalculateSum(); Console.WriteLine(summary3); logger.Log(summary3); basket.Clear(); basket.AddProducts(new BasketItem(2, butter), new BasketItem(1, bread), new BasketItem(8, milk)); Console.WriteLine("Case 4:"); var summary4 = basket.CalculateSum(); Console.WriteLine(summary4); logger.Log(summary4); basket.Clear(); basket.AddProducts(new BasketItem(2, butter), new BasketItem(1, bread), new BasketItem(9, milk)); Console.WriteLine("Case 5:"); var summary5 = basket.CalculateSum(); Console.WriteLine(summary5); logger.Log(summary5); }