public void CreateGoods_NonExistentCategory_Create()
        {
            string imagePath = "1";
            Mock <IDataProvider> dbProvider   = new Mock <IDataProvider>();
            RozetkaGoods         realGoods    = new RozetkaGoods();
            PriceElement         priceElement = new PriceElement();

            priceElement.Value   = "100 0";
            priceElement.Unit    = "2";
            realGoods.Price      = priceElement;
            realGoods.Id         = "1";
            realGoods.Title      = "1";
            realGoods.Social_url = "1";
            realGoods.Price.Unit = "1";
            int    shopId       = 1;
            int    categoriesId = 1;
            string description  = "sdf";

            _goodsCreator = new GoodsCreator();

            dbProvider.Setup(r => r.GetCurrency(It.IsAny <string>())).Returns <Currency>(null);
            dbProvider.Setup(r => r.AddGoods(It.IsAny <AllGoods>(), It.IsAny <GoodsDescription>()));
            dbProvider.Setup(r => r.AddCurrency(It.IsAny <string>()));
            dbProvider.Setup(r => r.SaveChanges());
            bool result = _goodsCreator.CreateGoods(imagePath, dbProvider.Object, realGoods, shopId, categoriesId, description);

            Assert.IsTrue(result);

            dbProvider.Verify();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Ticket tick1 = new Ticket(1, "09-04-2020", 1, "A", 15);
            Ticket tick2 = new Ticket(1, "09-04-2020", 1, "A", 16);
            Ticket tick3 = new Ticket(1, "09-04-2020", 1, "A", 17);

            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented            = true,
                IgnoreNullValues         = true,
                IgnoreReadOnlyProperties = true
            };


            //STORE JSON OBJECT
            var jsonString = JsonSerializer.Serialize(new Ticket[] { tick1, tick2, tick3 }, options);

            Console.WriteLine(jsonString);
            File.WriteAllText("data.json", jsonString);


            //READ AND UPDATE JSON OBJECT
            string        jsonText = File.ReadAllText("data.json");
            List <Ticket> tickets  = new List <Ticket>();

            using (JsonDocument document = JsonDocument.Parse(jsonString))
            {
                JsonElement root = document.RootElement;
                JsonElement ticketsArrayElement = root;

                foreach (JsonElement ticket in ticketsArrayElement.EnumerateArray())
                {
                    //Make .NET object is values are present in JSON
                    if (ticket.TryGetProperty("Price", out JsonElement PriceElement) &&
                        ticket.TryGetProperty("Date", out JsonElement DateElement) &&
                        ticket.TryGetProperty("TheaterNumber", out JsonElement TheaterElement) &&
                        ticket.TryGetProperty("SeatNumber", out JsonElement SeatElement) &&
                        SeatElement.TryGetProperty("Row", out var RowElement) && SeatElement.TryGetProperty("Seat", out var SeatNumElement)
                        )
                    {
                        int    price         = PriceElement.GetInt32();
                        string date          = DateElement.GetString();
                        int    theaterNumber = TheaterElement.GetInt32();
                        string row           = RowElement.GetString();
                        int    seat          = SeatNumElement.GetInt32();

                        tickets.Add(new Ticket(price, date, theaterNumber, row, seat));
                    }
                }
            }

            tickets[0].Date = "DATE HAS BEEN MODIFIED";

            jsonText = JsonSerializer.Serialize(tickets, options);
            File.WriteAllText("data.json", jsonText);
        }
        /// <summary>
        /// Adds the new tier price.
        /// </summary>
        /// <param name="tierPricingModel">The tier pricing model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">tierPricingModel</exception>
        public virtual TierPricesComponent AddNewTierPrice(
            TierPriceModel tierPricingModel)
        {
            if (tierPricingModel == null)
            {
                throw new ArgumentNullException(nameof(tierPricingModel));
            }

            var cachedWindowHandle  = WrappedDriver.CurrentWindowHandle;
            var cachedWindowHandles = WrappedDriver.WindowHandles;

            AddNewTierPriceElement.Click();

            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => d.WindowHandles.Count > cachedWindowHandles.Count);

            // Switch to new window.
            var newHandle = WrappedDriver.WindowHandles
                            .Except(cachedWindowHandles)
                            .First();

            WrappedDriver.SwitchTo().Frame(newHandle);

            // Load the StartDate/EndDate components.
            StartDateComponent.Load();
            EndDateComponent.Load();

            // Enter values.
            QuantityElement.SetValue(tierPricingModel.Quantity);
            PriceElement.SetValue(tierPricingModel.Price);
            StoreElement.SelectByText(tierPricingModel.Store);
            CustomerRoleElement.SelectByText(tierPricingModel.CustomerRole);
            StartDateComponent.SetValue(tierPricingModel.StartDate);
            EndDateComponent.SetValue(tierPricingModel.EndDate);

            // Save.
            var saveEl = SaveElement; // Cache this to avoid extra lookups.

            saveEl.Click();
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => saveEl.IsStale());

            // Switch back to the original handle.
            WrappedDriver.SwitchTo().Frame(cachedWindowHandle);

            return(this);
        }
        public void Validate_SameValue_Same()
        {
            RozetkaGoods realGoods    = new RozetkaGoods();
            PriceElement priceElement = new PriceElement();

            priceElement.Value = "100 0";
            realGoods.Price    = priceElement;
            AllGoods dbGoods = new AllGoods();

            dbGoods.Price = 1000;

            CompareResult result = _validator.Validate(dbGoods, realGoods);

            CompareResult expected = CompareResult.Same;

            Assert.AreEqual(result, expected);
        }
        public void Validate_DiferentValue_NedUpdate()
        {
            RozetkaGoods realGoods    = new RozetkaGoods();
            PriceElement priceElement = new PriceElement();

            priceElement.Value = "100 0";
            realGoods.Price    = priceElement;
            AllGoods bdGoods = new AllGoods();

            bdGoods.Price = 10;

            CompareResult result = _validator.Validate(bdGoods, realGoods);

            CompareResult expected = CompareResult.NedUpdate;

            Assert.AreEqual(result, expected);
        }
        public void Update_DifferentPrise_CallSave()
        {
            AllGoods goods = new AllGoods();

            goods.Price = 100;
            RozetkaGoods realGoods    = new RozetkaGoods();
            PriceElement priceElement = new PriceElement();

            priceElement.Value = "100 0";
            realGoods.Price    = priceElement;

            Mock <IDataProvider> dbProvider = new Mock <IDataProvider>();

            dbProvider.Setup(r => r.AddChangeDynamics(It.IsAny <ChangeDynamics>()));
            dbProvider.Setup(r => r.SaveChanges());
            AllGoods result = _validator.Update(dbProvider.Object, goods, realGoods);

            int expected = 1000;

            Assert.AreEqual(result.Price, expected);
            dbProvider.VerifyAll();
        }
Esempio n. 7
0
        public static void FillSnackList()
        {
            string jsonText = File.ReadAllText("snacks.json");

            using (JsonDocument document = JsonDocument.Parse(jsonText))
            {
                JsonElement root      = document.RootElement;
                JsonElement snackList = root;
                foreach (JsonElement snack in snackList.EnumerateArray())
                {
                    if (snack.TryGetProperty("snackName", out JsonElement snackNameElement) &&
                        snack.TryGetProperty("nutritionInfo", out JsonElement nutritionInfoElement) &&
                        snack.TryGetProperty("Price", out JsonElement PriceElement))
                    {
                        string snackName     = snackNameElement.GetString();
                        string nutritionInfo = nutritionInfoElement.GetString();
                        double Price         = PriceElement.GetDouble();

                        Snacks fillSnacks = new Snacks(snackName, nutritionInfo, Price);
                        Program.snacks.Add(fillSnacks);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the price.
        /// </summary>
        /// <param name="price">The price.</param>
        /// <returns></returns>
        public virtual PricesComponent SetPrice(decimal price)
        {
            PriceElement.SetValue(price);

            return(this);
        }
Esempio n. 9
0
 /// <summary>
 /// Gets the price.
 /// </summary>
 /// <returns></returns>
 public virtual decimal GetPrice()
 {
     return(PriceElement.GetValue <decimal>());
 }