Exemplo n.º 1
0
        public void JSON_SerializeDeserializeListFromFile_Test()
        {
            // arrange
            int             index        = 0;
            List <Products> product_list = new List <Products>
            {
                new AlcoholicDrinks {
                    ProductName = "Лидское", PurchasePrice = 2.3, MurkupCoefficient = 1.1, NumberOfUnits = 50
                },
                new SoftDrinks {
                    ProductName = "Krysler", PurchasePrice = 2.5, MurkupCoefficient = 1.3, NumberOfUnits = 50
                },
                new TobaccoProducts {
                    ProductName = "Winston", PurchasePrice = 2, MurkupCoefficient = 1.3, NumberOfUnits = 50
                }
            };
            double          delta = .001;
            List <Products> product_list_json;

            // act
            JSONConverter.SerializeToFile("test.json", product_list);
            JSONConverter.DeserializeFromFile("test.json", out product_list_json);

            // assert
            foreach (var item in product_list_json)
            {
                Assert.AreEqual(product_list[index].ProductName, item.ProductName);
                Assert.AreEqual(product_list[index].ProductType, item.ProductType);
                Assert.AreEqual(product_list[index].PurchasePrice, item.PurchasePrice, delta);
                Assert.AreEqual(product_list[index].MurkupCoefficient, item.MurkupCoefficient, delta);
                Assert.AreEqual(product_list[index].NumberOfUnits, item.NumberOfUnits, delta);

                index++;
            }
        }
Exemplo n.º 2
0
        public void JSON_SerializeDeserializeObjectFromFile_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;
            Products    product_JSON;

            // act
            JSONConverter.SerializeToFile("test.json", product);
            JSONConverter.DeserializeFromFile("test.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);
        }