Ejemplo n.º 1
0
        public void Products_SummEqualProducts_Test()
        {
            // arrange
            Products product_one = new MilkProducts("Ряженка", 2.5, 1.3, 100);
            Products product_two = new MilkProducts("Ряженка", 3.5, 1.5, 10);
            Products product_three;

            string      expecterd_name               = "Ряженка";
            double      expecterd_purchasePrice      = 2.5909;
            double      expecterd_murkup_coefficient = 1.3181;
            double      expecterd_numberOfUnits      = 110;
            TypesOfGood expecterd_productType        = TypesOfGood.MilkProducts;

            double delta = .001;

            // act
            product_three = Products.SummEqualProduct(product_one, product_two);

            // assert
            Assert.AreEqual(expecterd_name, product_three.ProductName);
            Assert.AreEqual(expecterd_productType, product_three.ProductType);
            Assert.AreEqual(expecterd_purchasePrice, product_three.PurchasePrice, delta);
            Assert.AreEqual(expecterd_murkup_coefficient, product_three.MurkupCoefficient, delta);
            Assert.AreEqual(expecterd_numberOfUnits, product_three.NumberOfUnits);
        }
Ejemplo n.º 2
0
        public void JSON_SerializeDeserializeObject_Test()
        {
            // arrange
            Products product = new AlcoholicDrinks("Лидское", 2.3, 1.1, 50);

            string      expecterd_name               = "Лидское";
            double      expecterd_purchasePrice      = 2.3;
            double      expecterd_murkup_coefficient = 1.1;
            double      expecterd_numberOfUnits      = 50;
            TypesOfGood expecterd_productType        = TypesOfGood.AlcoholicDrinks;

            double delta = .001;

            // act
            string   json = JSONConverter.Serialize(product);
            Products product_JSON;

            JSONConverter.Deserialize(json, out product_JSON);

            // assert
            Assert.AreEqual(expecterd_name, product_JSON.ProductName);
            Assert.AreEqual(expecterd_productType, product_JSON.ProductType);
            Assert.AreEqual(expecterd_purchasePrice, product_JSON.PurchasePrice, delta);
            Assert.AreEqual(expecterd_murkup_coefficient, product_JSON.MurkupCoefficient, delta);
            Assert.AreEqual(expecterd_numberOfUnits, product_JSON.NumberOfUnits, delta);
        }
Ejemplo n.º 3
0
 public Products(string name, TypesOfGood typesOfGood, double purchasePrice, double murkup, double numberOfUnits)
 {
     ProductName       = name;
     PurchasePrice     = purchasePrice;
     MurkupCoefficient = murkup;
     NumberOfUnits     = numberOfUnits;
     PriceType         = Types.Rubles;
     ProductType       = typesOfGood;
 }
        private static TypesOfGood CreateTypeOfGoodToAdd()
        {
            Console.Write("Enter type of goods Name:");
            var name = Console.ReadLine();

            var typeOfGoodToAdd = new TypesOfGood
            {
                Type = name,
            };

            return(typeOfGoodToAdd);
        }
        public static void ChooseOperationForTypesOfGoodsRepository(ITypesOfGoodsRepository typesOfGoodsRepository, OperationForTypesOfGoodsRepository typesOgGoodsRepositoryOperation)
        {
            switch (typesOgGoodsRepositoryOperation)
            {
            case OperationForTypesOfGoodsRepository.ShowAll:
                ShowAllTypesOfGoods(typesOfGoodsRepository.Get());
                break;

            case OperationForTypesOfGoodsRepository.ShowById:
                Console.WriteLine("Enter type of good Id: ");
                if (int.TryParse(Console.ReadLine(), out var typeOfGoodId))
                {
                    Console.WriteLine(typesOfGoodsRepository.Get(typeOfGoodId));
                }
                break;

            case OperationForTypesOfGoodsRepository.Add:
                TypesOfGood typeOfGoodToAdd = CreateTypeOfGoodToAdd();
                typesOfGoodsRepository.Add(typeOfGoodToAdd);
                Console.WriteLine("New type of goods added");
                break;

            case OperationForTypesOfGoodsRepository.Update:

                TypesOfGood typeOfGoodToUpdate = null;
                Console.Write("Enter type of goods Id to update: ");
                if (int.TryParse(Console.ReadLine(), out var typeofGoodIdToUpdate))
                {
                    typeOfGoodToUpdate = typesOfGoodsRepository.Get(typeofGoodIdToUpdate);
                }
                Console.Write("Enter new name of Type of goods: ");
                typeOfGoodToUpdate.Type = Console.ReadLine();

                typesOfGoodsRepository.Update(typeOfGoodToUpdate);
                Console.WriteLine("Type of goods updated");
                break;

            case OperationForTypesOfGoodsRepository.Delete:
                Console.WriteLine("Enter type of goods Id to delete: ");
                if (int.TryParse(Console.ReadLine(), out var typeOfGoodIdToDelete))
                {
                    typesOfGoodsRepository.Delete(typeOfGoodIdToDelete);
                    Console.WriteLine("Type of goods deleted");
                }
                break;

            case OperationForTypesOfGoodsRepository.GetTypeInfoWithMaxQuantityOfGoods:
                var maxQuantityOfGoodsType = typesOfGoodsRepository.GetTypeInfoWithMaxQuantityOfGoods();
                Console.WriteLine($"Type with max quantity of goods: {maxQuantityOfGoodsType}");
                break;

            case OperationForTypesOfGoodsRepository.GetTypeInfoWithMinQuantityOfGoods:
                var minQuantityOfGoodsType = typesOfGoodsRepository.GetTypeInfoWithMinQuantityOfGoods();
                Console.WriteLine($"Type with min quantity of goods: {minQuantityOfGoodsType}");
                break;

            default:
                Environment.Exit(0);
                break;
            }
        }