public void TestInput1() { terminal.BulkScan("ABCDABA"); var expectedTotal = 13.25; var actualTotal = terminal.CalculateTotal(); Assert.AreEqual(expectedTotal, actualTotal, delta: expectedTotal / 100); }
public void TestCase1() { // arrange _posTerminal.Scan("ABCDABA"); // act, assert Assert.AreEqual(13.25, _posTerminal.CalculateTotal()); }
public void TestSetPricing() { terminal.SetPricing('A', 1.25, Tuple.Create(3, 3.0)); terminal.ScanProduct('A'); var expectedTotal = 1.25; var actualTotal = terminal.CalculateTotal(); Assert.AreEqual(expectedTotal, actualTotal, delta: expectedTotal / 100); }
public void ShouldCalculateTotalCorrectly(string[] productCodes, decimal expectedTotalPrice) { foreach (var code in productCodes) { _terminal.Scan(code); } var totalPrice = _terminal.CalculateTotal(); Assert.Equal(expectedTotalPrice, totalPrice); }
public double CalculateTotalTest_ABCDABA(string input) { var objProduct = new PurchasedProduct(); objProduct = terminal1.ScanProductsByBarcode(input); DataTable dt = new DataTable(); dt = terminal2.SetPricing(objProduct.Name); double sum = 0; sum = terminal.CalculateTotal(dt); return(sum); }
public void CalculateTotal_ABCD_Total7And25() { // Arrange var expectedTotal = 7.25M; // Act _terminal.Scan('A'); _terminal.Scan('B'); _terminal.Scan('C'); _terminal.Scan('D'); var total = _terminal.CalculateTotal(); // Assert Assert.AreEqual(expectedTotal, total); }
static void Main(string[] args) { var path = @"C:\Users\Acer_PC\Desktop\products.csv"; ICsvManipulator csvManipulator = new CsvManipulator(path); IProductService productService = new ProductService(csvManipulator); IPointOfSaleTerminal pointOfSaleTerminal = new PointOfSaleTerminal(productService); pointOfSaleTerminal.SetPrice("A", 1.25, 3, 3.00); pointOfSaleTerminal.SetPrice("B", 4.25, 0, 0.00); pointOfSaleTerminal.SetPrice("C", 1.00, 6, 5.00); pointOfSaleTerminal.SetPrice("D", 0.75, 0, 0.00); //ABCDABA pointOfSaleTerminal.Set("A"); pointOfSaleTerminal.Set("B"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("D"); pointOfSaleTerminal.Set("A"); pointOfSaleTerminal.Set("B"); pointOfSaleTerminal.Set("A"); var result = pointOfSaleTerminal.CalculateTotal(); pointOfSaleTerminal.ResetBusket(); System.Console.WriteLine(result); //CCCCCCC pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("C"); result = pointOfSaleTerminal.CalculateTotal(); pointOfSaleTerminal.ResetBusket(); System.Console.WriteLine(result); //ABCD pointOfSaleTerminal.Set("A"); pointOfSaleTerminal.Set("B"); pointOfSaleTerminal.Set("C"); pointOfSaleTerminal.Set("D"); result = pointOfSaleTerminal.CalculateTotal(); pointOfSaleTerminal.ResetBusket(); System.Console.WriteLine(result); System.Console.ReadKey(); }
public void CalculateTotal_Should_Return_Correct_Sum(string productCodes, double totalPrice) { // arrange IPointOfSaleTerminal terminal = new PointOfSaleTerminal(); IReadOnlyDictionary <string, ProductPricingSettings> settings = new Dictionary <string, ProductPricingSettings> { { "A", new ProductPricingSettings(1.25, 3, 3) }, { "B", new ProductPricingSettings(4.25) }, { "C", new ProductPricingSettings(1, 5, 6) }, { "D", new ProductPricingSettings(0.75) }, { "E", new ProductPricingSettings(1, 0.75, 1) } }; terminal.SetPricing(settings); foreach (char productCode in productCodes) { terminal.Scan(productCode.ToString()); } // act double result = terminal.CalculateTotal(); // assert Assert.Equal(totalPrice, result); }
public void CalculateTotal() { var terminal = new PointOfSaleTerminal(this._mockCart.Object, this._mockProductRepository.Object); var result = terminal.CalculateTotal(); result.ShouldBe(100d); }
public void Test16_CalculateTotal_ScannedProductABCD_CalculateTotalEqual7_25() { // Arrange var terminal = new PointOfSaleTerminal(); List <IProduct> productListActual = new List <IProduct> { new Product("A"), new Product("B"), new Product("C"), new Product("D") }; terminal.SetProductList(productListActual); int ReturnValueForCodeA_priceSet = terminal.SetPricing("A", 1.25f, 3, 3.0f); int ReturnValueForCodeB_priceSet = terminal.SetPricing("B", 4.25f); int ReturnValueForCodeC_priceSet = terminal.SetPricing("C", 1.0f, 6, 5.0f); int ReturnValueForCodeD_priceSet = terminal.SetPricing("D", 0.75f); terminal.ScanProduct("A"); terminal.ScanProduct("B"); terminal.ScanProduct("C"); terminal.ScanProduct("D"); // Act float actualTotal = terminal.CalculateTotal(); // Assert float expectedTotal = 7.25f; Assert.AreEqual(expectedTotal, actualTotal, "The calculated total is wrong and should be 7.25"); }
public void CalculateTotal_ShouldCallCalculateTotal() { mockCartService.Setup(m => m.CalculateTotal()).Verifiable(); terminal.CalculateTotal(); mockCartService.Verify(); }
public void CalculateTotal_Should_Throw_ArgumentException_If_ProductPricingSettings_Is_Null_or_Empty() { // arrange IPointOfSaleTerminal terminal = new PointOfSaleTerminal(); // assert Assert.Throws <ArgumentException>(() => terminal.CalculateTotal()); }
public void CalculateTotal_ProductsCodesShouldHaveExpectedPrice(decimal expectedPrice, string[] productCodes) { productCodes.ToList().ForEach(productCode => terminal.Scan(productCode)); var result = terminal.CalculateTotal(); Assert.Equal(expectedPrice, result); }
public void Test(string itemList, decimal expectedTotal) { foreach (var itemName in itemList.ToCharArray()) { _terminal.Scan(itemName.ToString()); } Assert.AreEqual(expectedTotal, _terminal.CalculateTotal()); }
public void Terminal_Scan_Should_Return_Total(string scan_items, decimal expected_total) { foreach (char ch in scan_items) { _terminal.ScanProduct(ch.ToString()); } Assert.AreEqual(expected_total, _terminal.CalculateTotal()); }
static void Main(string[] args) { var products = new List <ProductDTO> { new ProductDTO { Code = "A", RetailPrice = 1.25m, VolumePrice = 3m, VolumeQuantity = 3 }, new ProductDTO { Code = "B", RetailPrice = 4.25m }, new ProductDTO { Code = "C", RetailPrice = 1m, VolumePrice = 5m, VolumeQuantity = 6 }, new ProductDTO { Code = "D", RetailPrice = 0.75m } }; PointOfSaleTerminal terminal1 = new PointOfSaleTerminal(); terminal1.SetPricing(products); terminal1.Scan("A"); terminal1.Scan("B"); terminal1.Scan("C"); terminal1.Scan("D"); terminal1.Scan("A"); terminal1.Scan("B"); terminal1.Scan("A"); Console.WriteLine($"ABCDABA - 13.25???{terminal1.CalculateTotal()}"); PointOfSaleTerminal terminal2 = new PointOfSaleTerminal(); terminal2.SetPricing(products); terminal2.Scan("C"); terminal2.Scan("C"); terminal2.Scan("C"); terminal2.Scan("C"); terminal2.Scan("C"); terminal2.Scan("C"); terminal2.Scan("C"); Console.WriteLine($"CCCCCCC - 6???{terminal2.CalculateTotal()}"); PointOfSaleTerminal terminal3 = new PointOfSaleTerminal(); terminal3.SetPricing(products); terminal3.Scan("A"); terminal3.Scan("B"); terminal3.Scan("C"); terminal3.Scan("D"); Console.WriteLine($"ABCD - 7.25???{terminal3.CalculateTotal()}"); Console.ReadLine(); }
public void AllUnknown() { decimal expected = 0.00M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct("F"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
public decimal?CalculatePrice(IEnumerable <string> inputs) { _terminal.SetPricing(_pricesRepository.GetPrices()); foreach (var productName in inputs) { _terminal.Scan(productName); } return(_terminal.CalculateTotal()); }
private void Perform_ATest(string productCode, double expected) { //Arrange productOrder = terminal.Scan(productCode, productOrder); productOrder = terminal.SetPricing(productOrder); //Act double actual = terminal.CalculateTotal(productOrder); //Assert Assert.AreEqual(expected, actual); }
public void TwoValidCodesInOneString() { decimal expected = 0.00M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct("AA"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
public void SingleD() { decimal expected = 0.75M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct("D"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
static void Main(string[] args) { string order = "ABCD"; PointOfSaleTerminal terminal = new PointOfSaleTerminal(); char[] arr = order.ToCharArray(); terminal.orderList = order.ToCharArray().Select(c => c.ToString()).ToList(); terminal.pricingObj = new List <PricingOfItems>(); terminal.pricingObj = terminal.SetPricing(); double result = terminal.CalculateTotal(terminal); }
static void Main(string[] args) { var terminal = new PointOfSaleTerminal(); terminal.SetPricing('A', 1.25, Tuple.Create(3, 3.0)); terminal.SetPricing('B', 4.25); terminal.SetPricing('C', 1.00, Tuple.Create(6, 5.0)); terminal.SetPricing('D', 0.75); terminal.BulkScan("ABC"); Console.WriteLine(terminal.CalculateTotal()); }
public void A1LessFromCombination() { decimal expected = 2.50M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct("A"); terminal.ScanProduct("A"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
public void EmptyWithValidCodes() { decimal expected = 2.00M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct(""); terminal.ScanProduct("A"); terminal.ScanProduct("D"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
public void ChangePriceOfD() { decimal expected = 1.00M; var terminal = new PointOfSaleTerminal(); terminal.SetPricing("D", 1.00); terminal.ScanProduct("D"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
public void Should_CalculateTotal(string products, double expectedTotal) { //Arrange var prices = new Dictionary <string, Price>(); prices.Add("A", new VolumePrice(1.25, 3, 3)); prices.Add("B", new Price(4.25)); prices.Add("C", new VolumePrice(1, 6, 5)); prices.Add("D", new Price(0.75)); _terminal.SetPricing(prices); //Act foreach (var productCode in products) { _terminal.Scan(productCode.ToString()); } var actualTotal = _terminal.CalculateTotal(); //Assert Assert.AreEqual(expectedTotal, actualTotal); }
public void ApplyDiscountCard_WithDefaultDiscountCard_CorrectTotalValue(int productsCount, decimal expectedResult) { var terminal = new PointOfSaleTerminal( new ProductsPriceSetBuilder() .AddProduct(DefaultProductCode.ToString(), 100.0M, 3, 200.0M) .GetAllProducts()); var discountCard = CreateDefaultDiscountCard(); ScanStringAsChars(terminal, new string(DefaultProductCode, productsCount)); AssertDecimalEquals(expectedResult, terminal.CalculateTotal(discountCard)); }
public void UnknownStartWithValidCodes() { decimal expected = 2.75M; var terminal = new PointOfSaleTerminal(); terminal.ScanProduct("F"); terminal.ScanProduct("C"); terminal.ScanProduct("C"); terminal.ScanProduct("D"); decimal result = terminal.CalculateTotal(); Assert.AreEqual(expected, result); }
[Test] //Given input to check public void TotalPriceAfterDiscountForSevenSameProduct() { //Arrange PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal(); Product C = new Product("C", 7, 1); //Act pointOfSale.ScanProduct(C); double result = pointOfSale.CalculateTotal(); //Assert Assert.AreEqual(6, result); }
static void Main( string[] args ) { if (1 != args.Length) { System.Console.WriteLine("Usage: PointOfSaleTernimal <command file>"); } else { PointOfSaleTerminal terminal = new PointOfSaleTerminal(); System.IO.StreamReader priceFile = new System.IO.StreamReader(args[0]); string line = priceFile.ReadLine(); if (null != line) { terminal.SetPricing(line); while ((line = priceFile.ReadLine()) != null) { terminal.Scan(line); } } System.Console.WriteLine("Total sale: $" + terminal.CalculateTotal()); } }