Ejemplo n.º 1
0
 public void Test1()
 {
     var customer = new Customer("Name", 0);
     var bill = new Bill(customer);
     bill.AddGoods(new Item(
         new SaleGood("Tomato"),
         4,
         30));
     bill.AddGoods(new Item(
         new RegularGood("Cucumber"),
         5,
         15));
     bill.AddGoods(new Item(
         new SpecialOfferGood("Radish"),
         3,
         20));
     bill.AddGoods(new Item(
         new SpecialOfferGood("Carrot"),
         6,
         27));
     bill.AddGoods(new Item(
         new SaleGood("Potato"),
         1,
         18));
     bill.AddGoods(new Item(
         new RegularGood("Onion"),
         7,
         40));
     var actual = bill.Statement();
     var expected = "Счет для Name\n\tНазвание\tЦена\tКол-воСтоимость\tСкидка\tСумма\tБонус\n\tTomato\t\t30\t4\t120\t1.2\t118.8\t1\n\tCucumber\t\t15\t5\t75\t2.25\t72.75\t3\n\tRadish\t\t20\t3\t60\t0\t60\t0\n\tCarrot\t\t27\t6\t162\t0\t162\t0\n\tPotato\t\t18\t1\t18\t0\t18\t0\n\tOnion\t\t40\t7\t280\t8.4\t271.6\t14\nСумма счета составляет 703.15\nВы заработали 18 бонусных балов";
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 2
0
 public void statementTest()
 {
     Customer customer = new Customer("Test", 10);
     Bill target = new Bill(customer);
     string actual;
     actual = target.Statement();
     var expected = "Счет для Test\n\tНазвание\tЦена\tКол-воСтоимость\tСкидка\tСумма\tБонус\nСумма счета составляет 0\nВы заработали 0 бонусных балов";
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     string filename = "BillInfo.txt";
     if (args.Length == 1)
         filename = args[0];
     FileStream fs = new FileStream(filename, FileMode.Open);
     StreamReader sr = new StreamReader(fs);
     // read customer
     string line = sr.ReadLine();
     string[] result = line.Split(':');
     string name = result[1].Trim();
     // read bonus
     line = sr.ReadLine();
     result = line.Split(':');
     int bonus = Convert.ToInt32(result[1].Trim());
     Customer customer = new Customer(name, bonus);
     Bill b = new Bill(customer);
     // read goods count
     line = sr.ReadLine();
     result = line.Split(':');
     int goodsQty = Convert.ToInt32(result[1].Trim());
     Good[] g = new Good[goodsQty];
     for (int i = 0; i < g.Length; i++)
     {
         line = sr.ReadLine();
         result = line.Split(':');
         result = result[1].Trim().Split();
         string type = result[1].Trim();
         switch (type)
         {
             case "REG": g[i] = new RegularGood(result[0]);
                 break;
             case "SAL": g[i] = new SaleGood(result[0]);
                 break;
             case "SPO": g[i] = new SpecialOfferGood(result[0]);
                 break;
         }
     }
     // read items count
     line = sr.ReadLine();
     result = line.Split(':');
     int itemsQty = Convert.ToInt32(result[1].Trim());
     for (int i = 0; i < itemsQty; i++)
     {
         line = sr.ReadLine();
         result = line.Split(':');
         result = result[1].Trim().Split();
         int gid = Convert.ToInt32(result[0].Trim());
         double price = Convert.ToDouble(result[1].Trim());
         int qty = Convert.ToInt32(result[2].Trim());
         b.AddGoods(new Item(g[gid - 1], qty, price));
     }
     string bill = b.Statement();
     Console.WriteLine(bill);
     Console.ReadKey();
 }
Ejemplo n.º 4
0
 public void Test2()
 {
     var customer = new Customer("Name", 1000);
     var bill = new Bill(customer);
     bill.AddGoods(new Item(
         new SpecialOfferGood("Tomato"),
         4,
         30));
     bill.AddGoods(new Item(
         new SpecialOfferGood("Cucumber"),
         5,
         15));
     bill.AddGoods(new Item(
         new SpecialOfferGood("Radish"),
         3,
         20));
     var actual = bill.Statement();
     var expected = "Счет для Name\n\tНазвание\tЦена\tКол-воСтоимость\tСкидка\tСумма\tБонус\n\tTomato\t\t30\t4\t120\t120\t0\t0\n\tCucumber\t\t15\t5\t75\t75\t0\t0\n\tRadish\t\t20\t3\t60\t60\t0\t0\nСумма счета составляет 0\nВы заработали 0 бонусных балов";
     Assert.AreEqual(expected, actual);
 }