public static void UpdateDatabaseSpecialCaseTest(bool isUseAddition, int caseNumber, string description, bool isError) { var instance = new CommonEventSpecialNumberArgDesc.InnerDescDatabase(); instance.SetDatabaseUseAdditionalItemsFlag(isUseAddition); var changedDescPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedDescPropertyList.Add(args.PropertyName); }; var changedSpecialArgCaseListPropertyList = new List <string>(); instance.SpecialArgCaseList.PropertyChanged += (sender, args) => { changedSpecialArgCaseListPropertyList.Add(args.PropertyName); }; var changedSpecialArgCaseListCollectionArgList = new List <NotifyCollectionChangedEventArgs>(); instance.SpecialArgCaseList.CollectionChanged += (sender, args) => { changedSpecialArgCaseListCollectionArgList.Add(args); }; var errorOccured = false; try { instance.UpdateDatabaseSpecialCase(caseNumber, description); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); // 意図したとおりプロパティ変更通知が発火していること if (isError) { Assert.AreEqual(changedDescPropertyList.Count, 0); Assert.AreEqual(changedSpecialArgCaseListPropertyList.Count, 0); Assert.AreEqual(changedSpecialArgCaseListCollectionArgList.Count, 0); } else { Assert.AreEqual(changedDescPropertyList.Count, 0); Assert.AreEqual(changedSpecialArgCaseListPropertyList.Count, 1); Assert.IsTrue(changedSpecialArgCaseListPropertyList[0] .Equals(ListConstant.IndexerName)); Assert.AreEqual(changedSpecialArgCaseListCollectionArgList.Count, 1); Assert.AreEqual(changedSpecialArgCaseListCollectionArgList[0].Action, NotifyCollectionChangedAction.Replace); } }
public static void GetAllSpecialCaseDescriptionTest(bool isUseAddition, string strMinus1, string strMinus2, string strMinus3, int resultLength) { var instance = new CommonEventSpecialNumberArgDesc.InnerDescDatabase(); instance.SetDatabaseUseAdditionalItemsFlag(isUseAddition); if (strMinus1 != null) { instance.UpdateDatabaseSpecialCase(-1, strMinus1); } if (strMinus2 != null) { instance.UpdateDatabaseSpecialCase(-2, strMinus2); } if (strMinus3 != null) { instance.UpdateDatabaseSpecialCase(-3, strMinus3); } var changedDescPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedDescPropertyList.Add(args.PropertyName); }; var changedSpecialArgCaseListPropertyList = new List <string>(); instance.SpecialArgCaseList.PropertyChanged += (sender, args) => { changedSpecialArgCaseListPropertyList.Add(args.PropertyName); }; var changedSpecialArgCaseListCollectionArgList = new List <NotifyCollectionChangedEventArgs>(); instance.SpecialArgCaseList.CollectionChanged += (sender, args) => { changedSpecialArgCaseListCollectionArgList.Add(args); }; var errorOccured = false; try { instance.GetAllSpecialCaseDescription(); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); // 意図した値が取得できること var caseDescList = instance.GetAllSpecialCaseDescription(); var caseDescListCount = caseDescList.Count; Assert.AreEqual(caseDescListCount, resultLength); if (caseDescListCount == 3) { Assert.AreEqual(caseDescList[0], strMinus1 ?? string.Empty); Assert.AreEqual(caseDescList[1], strMinus2 ?? string.Empty); Assert.AreEqual(caseDescList[2], strMinus3 ?? string.Empty); } // プロパティ変更通知が発火していないこと Assert.AreEqual(changedDescPropertyList.Count, 0); Assert.AreEqual(changedSpecialArgCaseListPropertyList.Count, 0); Assert.AreEqual(changedSpecialArgCaseListCollectionArgList.Count, 0); }