public static void ConstructorTestB(MapSizeWidth width, MapSizeHeight height) { MapChipList instance = null; var errorOccured = false; try { instance = new MapChipList(width, height); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); // 件数が一致すること Assert.AreEqual(instance.Count, width.ToInt()); foreach (var columns in instance) { Assert.AreEqual(columns.Count, height.ToInt()); } }
public static void UpdateWidthTest(int initWidth, int initHeight, MapSizeWidth width) { var chips = MakeMapChipList(initWidth, false, initHeight); var instance = new MapChipList(chips); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var changedCollectionList = new List <NotifyCollectionChangedEventArgs>(); instance.CollectionChanged += (sender, args) => { changedCollectionList.Add(args); }; var changedColumnsPropertyList = new List <string>(); var changedColumnsCollectionList = new List <NotifyCollectionChangedEventArgs>(); instance.ForEach(column => { column.PropertyChanged += (sender, args) => { changedColumnsPropertyList.Add(args.PropertyName); }; column.CollectionChanged += (sender, args) => { changedColumnsCollectionList.Add(args); }; }); var errorOccured = false; try { instance.UpdateWidth(width); } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); // 件数が意図した値と一致すること Assert.AreEqual(instance.Width, width); Assert.AreEqual(instance.Height.ToInt(), initHeight); var notChangedLength = initWidth < width ? initWidth : width.ToInt(); var i = 0; // 操作しなかった項目がもとの値のままであること for (; i < notChangedLength; i++) { for (var j = 0; j < instance.Height; j++) { Assert.AreEqual(instance[i][j], MakeMapChip(i, j)); } } // 新たに追加された項目がデフォルト値であること for (; i < instance.Count; i++) { for (var j = 0; j < instance.Height; j++) { Assert.AreEqual(instance[i][j], MapChip.Default); } } // 意図したとおりプロパティ変更通知が発火していること Assert.AreEqual(changedPropertyList.Count, 3); Assert.IsTrue(changedPropertyList[0].Equals(nameof(instance.Count))); Assert.IsTrue(changedPropertyList[1].Equals(ListConstant.IndexerName)); Assert.IsTrue(changedPropertyList[2].Equals(nameof(instance.Width))); if (initWidth == width) { Assert.AreEqual(changedCollectionList.Count, 0); } else { Assert.AreEqual(changedCollectionList.Count, 1); if (initWidth > width) { Assert.IsTrue(changedCollectionList[0].Action == NotifyCollectionChangedAction.Remove); Assert.IsTrue(changedCollectionList[0].OldStartingIndex == width); Assert.IsTrue(changedCollectionList[0].OldItems.Count == initWidth - width); Assert.IsTrue(changedCollectionList[0].NewStartingIndex == -1); Assert.IsTrue(changedCollectionList[0].NewItems == null); } else { Assert.IsTrue(changedCollectionList[0].Action == NotifyCollectionChangedAction.Add); Assert.IsTrue(changedCollectionList[0].OldStartingIndex == -1); Assert.IsTrue(changedCollectionList[0].OldItems == null); Assert.IsTrue(changedCollectionList[0].NewStartingIndex == initWidth); Assert.IsTrue(changedCollectionList[0].NewItems.Count == width - initWidth); } } Assert.AreEqual(changedColumnsPropertyList.Count, 0); Assert.AreEqual(changedColumnsCollectionList.Count, 0); }