コード例 #1
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);
        }
コード例 #2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                repository = new VerbRepository();
                await repository.LoadAll();

                VerbGrid.ItemsSource = repository.Verbs;
            }
            catch (SqlException)
            {
                try
                {
                    string path = AppDomain.CurrentDomain.BaseDirectory + @"\Data\data.json";
                    string text = File.ReadAllText(path);
                    VerbGrid.ItemsSource = JSONConverter <Verb> .Deserialize(text);
                }
                catch (DirectoryNotFoundException)
                {
                    MessageBox.Show("Something has happened with database and data!");
                }
            }
        }
コード例 #3
0
        public void JSON_SerializeDeserializeList_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;

            // act
            string          json = JSONConverter.Serialize(product_list);
            List <Products> product_list_json;

            JSONConverter.Deserialize(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++;
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets a <see cref="HIBPBreach"/> of the specified <paramref name="site"/>.
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public async Task <HIBPBreach> GetSingleSiteBreach(string site)
        {
            var data = _client.GetStringAsync($"breach/{site}");

            return(JSONConverter.Deserialize <HIBPBreach>(await data));
        }
コード例 #5
0
        /// <summary>
        /// Gets all the <see cref="HIBPBreach"/> stores on the server.
        /// </summary>
        /// <returns></returns>
        public async Task <List <HIBPBreach> > GetAllBreachesAsync()
        {
            var data = _client.GetStringAsync("breaches");

            return(JSONConverter.Deserialize <List <HIBPBreach> >(await data));
        }
コード例 #6
0
        /// <summary>
        /// Gets all the <see cref="HIBPBreach"/> <paramref name="email"/> appears in.
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task <List <HIBPBreach> > GetBreachesAsync(string email)
        {
            var data = _client.GetStringAsync($"breachedaccount/{email}");

            return(JSONConverter.Deserialize <List <HIBPBreach> >(await data));
        }
コード例 #7
0
        /// <summary>
        /// Generate a string out of the list of actions stored in the actionJson string.
        /// Generates the proper javascript call based on the action type.
        /// </summary>
        /// <param name="actionsJson">A json array of the actions</param>
        /// <returns></returns>
        private string GenerateIfElseBody(string actionsJson, AttributeTypeCode operand1Type)
        {
            StringBuilder sb = new StringBuilder();
            JSONConverter <List <RuleAction> > converter = new JSONConverter <List <RuleAction> >();

            try
            {
                List <RuleAction> actions = converter.Deserialize(actionsJson);
                foreach (RuleAction action in actions)
                {
                    string targetName = action.target; // can be a section or a field
                    string message    = action.message;
                    string value      = action.value;

                    switch (action.type)
                    {
                    case "Show Field":
                        sb.Append($"setVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Field":
                        sb.Append($"setVisible(\"{targetName}\",false);\n");
                        break;

                    case "Enable Field":
                        sb.Append($"setDisabled(\"{targetName}\",false);\n");
                        break;

                    case "Disable Field":
                        sb.Append($"setDisabled(\"{targetName}\",true);\n");
                        break;

                    case "Set Field Value":
                        AttributeTypeCode actionTargetType = GetAttributeType(Service, EntityName, targetName);
                        bool nonTextualValue = actionTargetType == AttributeTypeCode.Picklist || actionTargetType == AttributeTypeCode.Boolean || actionTargetType == AttributeTypeCode.Money || actionTargetType == AttributeTypeCode.Integer || actionTargetType == AttributeTypeCode.Double || actionTargetType == AttributeTypeCode.Decimal;
                        if (nonTextualValue)
                        {
                            sb.Append($"setValue(\"{targetName}\",{value});\n");
                        }
                        else
                        {
                            sb.Append($"setValue(\"{targetName}\",\"{value}\");\n");
                        }
                        break;

                    case "Make Required":
                        sb.Append($"setRequired(\"{targetName}\",true,\"{message}\");\n");
                        break;

                    case "Make not Required":
                        sb.Append($"setRequired(\"{targetName}\",false);\n");
                        break;

                    case "Prevent Past Date":
                        sb.Append($"blockPastDate(\"{targetName}\",\"{message}\");\n");
                        break;

                    case "Prevent Future Date":
                        sb.Append($"blockFutureDate(\"{targetName}\",\"{message}\");\n");
                        break;

                    case "Show Section":
                        sb.Append($"setSectionVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Section":
                        sb.Append($"setSectionVisible(\"{targetName}\",false);\n");
                        break;

                    case "Show Tab":
                        sb.Append($"setTabVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Tab":
                        sb.Append($"setTabVisible(\"{targetName}\",false);\n");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(sb.ToString());
        }
コード例 #8
0
ファイル: VerbRepository.cs プロジェクト: tkmik/Eng
 private IEnumerable <Verb> Deserialize(string json)
 {
     return(JSONConverter <Verb> .Deserialize(json));
 }
コード例 #9
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     RootClass newClass = JSONConverter.Deserialize <RootClass>(JSONBox.Text);
 }