Пример #1
0
        public void RemoveTest()
        {
            var col = new MyNewCollection("TestCollection", 10);

            col.Remove(0);
            Assert.AreEqual(9, col.Count);
        }
Пример #2
0
        public void CollectionCountChangedEventTest()
        {
            var col1    = new MyNewCollection("FirstCol", 10);
            var journal = new Journal();

            col1.CollectionCountChanged += journal.OnCollectionCountChanged;
            col1.Remove(5);
            col1.AddRandom();
            col1.Add((Food) new Food().CreateRandom());
            Assert.IsTrue(journal.ToString().Contains("Удаление"));
            Assert.IsTrue(journal.ToString().Contains("Добавление"));
        }
Пример #3
0
        public static void Actions(MyNewCollection collection)
        {
            collection.Print();
            Console.WriteLine("1- Выбрать товар");
            Console.WriteLine("2- Сортировка товара по цене");
            Console.WriteLine("3- Удалить товар");

            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Введите индекс товара");
                try
                {
                    int     index   = InputValidator.InputPositive();
                    Product product = collection[index];
                    string  name    = Console.ReadLine();
                    string price
                    product.ChangeProduct();

                    collection.ChangeProduct(index, product);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Товара нет в списке");
                }

                Actions(collection);
                break;

            case "2":
                collection.SortByPrice();
                collection.Print();
                Actions(collection);
                break;

            case "3":
                try
                {
                    int     index   = InputValidator.InputPositive();
                    Product product = collection[index];
                    collection.Remove(product);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Товара нельзя удалить");
                }
                break;

            default:
                Actions(collection);
                break;
            }
        }
Пример #4
0
        public void RemoveErrorTest()
        {
            var col = new MyNewCollection("TestCollection", 10);

            try
            {
                col.Remove(10);
                Assert.Fail();
            }
            catch
            {
            }
        }