Example #1
0
        private IReadOnlyList <DatabaseItemDesc> MakeItemDescList(DBTypeSetting typeSetting,
                                                                  DBDataSetting dataSetting)
        {
            var result = new List <DatabaseItemDesc>();

            var itemSettingList = typeSetting.ItemSettingList;
            var valueList       = dataSetting.SettingValuesList[0];

            if (itemSettingList.Count != valueList.Count)
            {
                throw new InvalidOperationException(
                          "項目設定数と項目数が異なります。");
            }

            for (var i = 0; i < itemSettingList.Count; i++)
            {
                var desc = new DatabaseItemDesc
                {
                    ItemName           = itemSettingList[i].ItemName,
                    SpecialSettingDesc = itemSettingList[i].SpecialSettingDesc,
                    ItemType           = valueList[i].Type,
                };
                result.Add(desc);
            }

            return(result);
        }
Example #2
0
 /// <summary>
 /// DatabaseItemDescList.SetItemのイベントを生成する。
 /// </summary>
 /// <param name="outer">連係外部クラスインスタンス</param>
 /// <returns>InsertItemイベント</returns>
 private static Action <int, DBItemSetting> MakeHandler(
     DatabaseTypeDesc outer)
 {
     return((i, setting) =>
     {
         var set = new DatabaseItemDesc
         {
             ItemName = setting.ItemName,
             SpecialSettingDesc = setting.SpecialSettingDesc,
             ItemType = setting.ItemType
         };
         outer.ItemDescList[i] = set;
         outer.WritableItemValuesList.SetField(i, set.ItemType.DBItemDefaultValue);
     });
 }
 /// <summary>
 /// DatabaseItemDescList.InsertItemのイベントを生成する。
 /// </summary>
 /// <param name="outer">連係外部クラスインスタンス</param>
 /// <returns>InsertItemイベント</returns>
 private static Action <int, DBItemValue> MakeHandler(
     DatabaseTypeDesc outer)
 {
     return((i, value) =>
     {
         var set = new DatabaseItemDesc
         {
             ItemName = "",
             SpecialSettingDesc = new DBItemSpecialSettingDesc(),
             ItemType = value.Type
         };
         outer.ItemDescList.Insert(i, set);
         outer.WritableItemSettingList.Insert(i, set.ToDBItemSetting());
     });
 }
Example #4
0
        public static void ToDBItemSettingTest()
        {
            // テスト用要素
            var itemName           = (ItemName)"testItemName";
            var specialSettingDesc = new DBItemSpecialSettingDesc(DBItemSpecialSettingType.Normal,
                                                                  new[] { new DatabaseValueCase(0, "case") });
            var itemType = DBItemType.String;

            var instance = new DatabaseItemDesc();

            instance.ItemName           = itemName;
            instance.SpecialSettingDesc = specialSettingDesc;
            instance.ItemType           = itemType;
            var changedPropertyList = new List <string>();

            instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            DBItemSetting result = null;

            var errorOccured = false;

            try
            {
                result = instance.ToDBItemSetting();
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーが発生しないこと
            Assert.IsFalse(errorOccured);

            var answer = new DBItemSetting
            {
                ItemName           = itemName,
                ItemType           = itemType,
                SpecialSettingDesc = specialSettingDesc
            };

            // 取得した結果が意図した値であること
            Assert.IsTrue(result.Equals(answer));

            // プロパティ変更通知が発火していないこと
            Assert.AreEqual(changedPropertyList.Count, 0);
        }
Example #5
0
        public static void CreateForDBTypeTest()
        {
            DatabaseTypeDesc instance = null;

            var errorOccured = false;

            try
            {
                instance = DatabaseTypeDesc.Factory.CreateForDBType();
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーが発生しないこと
            Assert.IsFalse(errorOccured);

            // 初期データ数が一致すること
            Assert.AreEqual(instance.DataDescList.Count, 1);
            Assert.AreEqual(instance.DataDescList.Count, instance.DataNameList.Count);
            // 初期項目数が一致すること
            Assert.AreEqual(instance.ItemDescList.Count, 0);
            Assert.AreEqual(instance.ItemDescList.Count, instance.DBItemSettingList.Count);

            var valueList = new DBItemValueList();
            var dataDesc  = new DatabaseDataDesc("DataName", valueList);

            instance.DataDescList.Add(dataDesc);

            // データ追加後、データ数が一致すること
            Assert.AreEqual(instance.DataDescList.Count, 2);
            Assert.AreEqual(instance.DataDescList.Count, instance.DataNameList.Count);

            var itemDesc = new DatabaseItemDesc
            {
                ItemName = "ItemName",
                ItemType = DBItemType.String,
            };

            instance.ItemDescList.Add(itemDesc);

            // 項目追加後、項目数が一致すること
            Assert.AreEqual(instance.ItemDescList.Count, 1);
            Assert.AreEqual(instance.ItemDescList.Count, instance.DBItemSettingList.Count);
        }
Example #6
0
        public static void SerializeTest()
        {
            var target = new DatabaseItemDesc
            {
                ItemName = "ItemName"
            };
            var changedPropertyList = new List <string>();

            target.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            var clone = DeepCloner.DeepClone(target);

            Assert.IsTrue(clone.Equals(target));

            // プロパティ変更通知が発火していないこと
            Assert.AreEqual(changedPropertyList.Count, 0);
        }
Example #7
0
        public static void SpecialSettingDescTest(DBItemSpecialSettingDesc desc, bool isError)
        {
            var instance            = new DatabaseItemDesc();
            var changedPropertyList = new List <string>();

            instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            var errorOccured = false;

            try
            {
                instance.SpecialSettingDesc = desc;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーフラグが一致すること
            Assert.AreEqual(errorOccured, isError);

            if (!errorOccured)
            {
                var setValue = instance.SpecialSettingDesc;

                // セットした値と取得した値が一致すること
                Assert.IsTrue(setValue.Equals(desc));
            }

            // 意図したとおりプロパティ変更通知が発火していること
            if (errorOccured)
            {
                Assert.AreEqual(changedPropertyList.Count, 0);
            }
            else
            {
                Assert.AreEqual(changedPropertyList.Count, 1);
                Assert.IsTrue(changedPropertyList[0].Equals(nameof(DatabaseItemDesc.SpecialSettingDesc)));
            }
        }