public void OptionSetBeanTest01()
        {
            LocalizedLabel lLabel  = new LocalizedLabel("Option1", 1041);
            LocalizedLabel lLabel2 = new LocalizedLabel("Option2", LANG_CODE);

            PicklistAttributeMetadata meta = new PicklistAttributeMetadata();

            meta.OptionSet = new OptionSetMetadata()
            {
                Name        = "optionSet",
                DisplayName = new Label("optiondisplay", LANG_CODE),
                Options     =
                {
                    new OptionMetadata(new Label(lLabel,    null),      1),
                    new OptionMetadata(new Label("Option2", LANG_CODE), 2),
                    new OptionMetadata(new Label(lLabel2,   null), 3)
                }
            };

            OptionSetBean cls = new OptionSetBean(meta);

            Assert.True(cls.HasOptionSet());
            Assert.AreEqual("Option1", cls.GetValue(1), "ラベルあり");
            Assert.Null(cls.GetValue(2), "ラベルなし");
            Assert.AreEqual("Option2", cls.GetValue(3), "ラベルあり");
        }
        public void OptionSetBeanTest04()
        {
            LocalizedLabel lLabel = new LocalizedLabel("Option1", 1041);

            StringAttributeMetadata meta = new StringAttributeMetadata();

            OptionSetBean cls = new OptionSetBean(meta);

            Assert.False(cls.HasOptionSet());
        }
        /// <summary>
        /// 選択リストの表示値を取得する
        /// </summary>
        /// <param name="attributes"></param>
        public void SetOptionSetData(AttributeMetadata[] attributes)
        {
            _optionSetMap = new Dictionary <string, OptionSetBean>();

            foreach (AttributeMetadata attr in attributes)
            {
                // 表示用にオプションセットのマップを保持しておく
                OptionSetBean bean = new OptionSetBean(attr);

                if (bean.HasOptionSet())
                {
                    _optionSetMap.Add(attr.LogicalName, bean);
                }
            }
        }
        /// <summary>
        /// データをグリッドビューに設定
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dataGrid"></param>
        public void SetDataGridValues(EntityCollection data, DataGridView dataGrid)
        {
            for (int i = 0; i < data.Entities.Count; i++)
            {
                Entity entity = data.Entities[i];

                dataGrid.Rows.Add();

                for (int j = 0; j < dataGrid.Columns.Count; j++)
                {
                    string key = dataGrid.Columns[j].DataPropertyName;

                    if (entity.Attributes.ContainsKey(key))
                    {
                        Object attr = entity.Attributes[key];

                        if (attr is OptionSetValue)
                        {
                            int optionKey = ((OptionSetValue)attr).Value;

                            if (_optionSetMap.ContainsKey(key))
                            {
                                OptionSetBean bean = _optionSetMap[key];
                                dataGrid.Rows[i].Cells[j].Value = bean.GetValue(optionKey);
                            }
                            else
                            {
                                dataGrid.Rows[i].Cells[j].Value = optionKey;
                            }
                        }
                        else if (attr is EntityReference)
                        {
                            dataGrid.Rows[i].Cells[j].Value = ((EntityReference)attr).Id;
                        }
                        else if (attr is Money)
                        {
                            dataGrid.Rows[i].Cells[j].Value = ((Money)attr).Value;
                        }
                        else
                        {
                            dataGrid.Rows[i].Cells[j].Value = attr;
                        }
                    }
                }
            }
        }
        public void OptionSetBeanTest03()
        {
            LocalizedLabel lLabel = new LocalizedLabel("Option1", 1041);

            StatusAttributeMetadata meta = new StatusAttributeMetadata();

            meta.OptionSet = new OptionSetMetadata()
            {
                Name        = "optionSet",
                DisplayName = new Label("optiondisplay", LANG_CODE),
                Options     =
                {
                    new OptionMetadata(new Label(lLabel, null), 1)
                }
            };

            OptionSetBean cls = new OptionSetBean(meta);

            Assert.True(cls.HasOptionSet());
            Assert.AreEqual("Option1", cls.GetValue(1), "ラベルあり");
        }