コード例 #1
0
        public void TestRemoveNotifiesBoundListSubscriptions()
        {
            const int    key  = 0;
            const string item = "item";

            bindableStringDictionary.Add(key, item);
            var listA = new BindableDictionary <int, string>();

            listA.BindTo(bindableStringDictionary);

            NotifyCollectionChangedEventArgs triggeredArgsA1 = null;
            NotifyCollectionChangedEventArgs triggeredArgsA2 = null;

            listA.CollectionChanged += (_, args) => triggeredArgsA1 = args;
            listA.CollectionChanged += (_, args) => triggeredArgsA2 = args;

            var listB = new BindableDictionary <int, string>();

            listB.BindTo(bindableStringDictionary);

            NotifyCollectionChangedEventArgs triggeredArgsB1 = null;
            NotifyCollectionChangedEventArgs triggeredArgsB2 = null;

            listB.CollectionChanged += (_, args) => triggeredArgsB1 = args;
            listB.CollectionChanged += (_, args) => triggeredArgsB2 = args;

            bindableStringDictionary.Remove(key);

            Assert.That(triggeredArgsA1, Is.Not.Null);
            Assert.That(triggeredArgsA2, Is.Not.Null);
            Assert.That(triggeredArgsB1, Is.Not.Null);
            Assert.That(triggeredArgsB2, Is.Not.Null);
        }
コード例 #2
0
        public void TestRemoveNotifiesBoundLists()
        {
            const int    key  = 0;
            const string item = "item";

            bindableStringDictionary.Add(key, item);
            var listA = new BindableDictionary <int, string>();

            listA.BindTo(bindableStringDictionary);
            var listB = new BindableDictionary <int, string>();

            listB.BindTo(bindableStringDictionary);
            var listC = new BindableDictionary <int, string>();

            listC.BindTo(bindableStringDictionary);

            bindableStringDictionary.Remove(key);

            Assert.Multiple(() =>
            {
                Assert.False(listA.Contains(key));
                Assert.False(listB.Contains(key));
                Assert.False(listC.Contains(key));
            });
        }
コード例 #3
0
        public void TestRemoveNotifiesBoundDictionarySubscriptions()
        {
            const string item = "item";

            bindableStringByteDictionary.Add(item, 0);
            var dictA = new BindableDictionary <string, byte>();

            dictA.BindTo(bindableStringByteDictionary);

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgsA1 = null;
            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgsA2 = null;

            dictA.CollectionChanged += (_, args) => triggeredArgsA1 = args;
            dictA.CollectionChanged += (_, args) => triggeredArgsA2 = args;

            var dictB = new BindableDictionary <string, byte>();

            dictB.BindTo(bindableStringByteDictionary);

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgsB1 = null;
            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgsB2 = null;

            dictB.CollectionChanged += (_, args) => triggeredArgsB1 = args;
            dictB.CollectionChanged += (_, args) => triggeredArgsB2 = args;

            bindableStringByteDictionary.Remove(item);

            Assert.That(triggeredArgsA1, Is.Not.Null);
            Assert.That(triggeredArgsA2, Is.Not.Null);
            Assert.That(triggeredArgsB1, Is.Not.Null);
            Assert.That(triggeredArgsB2, Is.Not.Null);
        }
コード例 #4
0
        public void TestBindCollectionChangedNotRunIfBoundToSequenceEqualDictionary()
        {
            var dict = new BindableDictionary <string, byte>
            {
                { "a", 1 },
                { "b", 3 },
                { "c", 5 },
                { "d", 7 }
            };

            var otherDict = new BindableDictionary <string, byte>
            {
                { "a", 1 },
                { "b", 3 },
                { "c", 5 },
                { "d", 7 }
            };

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

            dict.BindCollectionChanged((_, args) => triggeredArgs = args);
            dict.BindTo(otherDict);

            Assert.That(triggeredArgs, Is.Null);
        }
コード例 #5
0
        public void TestDisabledNotifiesBoundDictionaries()
        {
            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            bindableStringByteDictionary.Disabled = true;

            Assert.IsTrue(dict.Disabled);
        }
コード例 #6
0
        public void TestAddWithStringNotifiesBoundDictionary(string key, byte value)
        {
            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            bindableStringByteDictionary.Add(key, value);

            Assert.That(dict, Contains.Key(key));
        }
コード例 #7
0
        public void TestDisabledNotifiesBoundLists()
        {
            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            bindableStringDictionary.Disabled = true;

            Assert.IsTrue(list.Disabled);
        }
コード例 #8
0
        protected override void OnApply()
        {
            base.OnApply();

            lyricPieces.Clear();
            lyricPieces.Add(new DefaultLyricPiece(HitObject));

            SingersBindable.BindTo(HitObject.SingersBindable);
            LayoutIndexBindable.BindTo(HitObject.LayoutIndexBindable);
            TranslateTextBindable.BindTo(HitObject.TranslateTextBindable);
        }
コード例 #9
0
        public void TestAddWithStringNotifiesBoundList(string str)
        {
            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            var item = new KeyValuePair <int, string>(0, str);

            bindableStringDictionary.Add(item);

            Assert.Contains(item, list);
        }
コード例 #10
0
        protected override void OnApply()
        {
            base.OnApply();

            TextBindable.BindTo(HitObject.TextBindable);
            TimeTagsBindable.BindTo(HitObject.TimeTagsBindable);
            RubyTagsBindable.BindTo(HitObject.RubyTagsBindable);
            RomajiTagsBindable.BindTo(HitObject.RomajiTagsBindable);
            SingersBindable.BindTo(HitObject.SingersBindable);
            LayoutIndexBindable.BindTo(HitObject.LayoutIndexBindable);
            TranslateTextBindable.BindTo(HitObject.TranslateTextBindable);
        }
コード例 #11
0
        public void TestRemoveNotifiesBoundDictionary()
        {
            const string item = "item";

            bindableStringByteDictionary.Add(item, 0);
            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            bindableStringByteDictionary.Remove(item);

            Assert.IsEmpty(dict);
        }
コード例 #12
0
        public void TestRemoveNotifiesBoundList()
        {
            const int    key  = 0;
            const string item = "item";

            bindableStringDictionary.Add(key, item);
            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            bindableStringDictionary.Remove(key);

            Assert.IsEmpty(list);
        }
コード例 #13
0
        public void TestClearNotifiesBoundBindable()
        {
            var bindableList = new BindableDictionary <int, string>();

            bindableList.BindTo(bindableStringDictionary);
            for (int i = 0; i < 5; i++)
            {
                bindableStringDictionary.Add(i, "testA");
            }
            for (int i = 0; i < 5; i++)
            {
                bindableList.Add(i + 5, "testA");
            }

            bindableStringDictionary.Clear();

            Assert.IsEmpty(bindableList);
        }
コード例 #14
0
        public void TestSetNotifiesBoundDictionaries()
        {
            bindableStringByteDictionary.Add("0", 0);

            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

            dict.CollectionChanged += (_, args) => triggeredArgs = args;

            bindableStringByteDictionary["0"] = 1;

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyDictionaryChangedAction.Replace));
            Assert.That(triggeredArgs.OldItems, Is.EquivalentTo(new KeyValuePair <string, byte>("0", 0).Yield()));
            Assert.That(triggeredArgs.NewItems, Is.EquivalentTo(new KeyValuePair <string, byte>("0", 1).Yield()));
        }
コード例 #15
0
        public void TestClearNotifiesBoundBindable()
        {
            var bindableDict = new BindableDictionary <string, byte>();

            bindableDict.BindTo(bindableStringByteDictionary);
            for (byte i = 0; i < 5; i++)
            {
                bindableStringByteDictionary.Add($"testA{i}", i);
            }
            for (byte i = 0; i < 5; i++)
            {
                bindableDict.Add($"testB{i}", i);
            }

            bindableStringByteDictionary.Clear();

            Assert.IsEmpty(bindableDict);
        }
コード例 #16
0
        public void TestRemoveNotifiesBoundDictionarySubscription()
        {
            const string item = "item";

            bindableStringByteDictionary.Add(item, 0);
            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

            dict.CollectionChanged += (_, args) => triggeredArgs = args;

            bindableStringByteDictionary.Remove(item);

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyDictionaryChangedAction.Remove));
            Assert.That(triggeredArgs.OldItems, Is.EquivalentTo(new KeyValuePair <string, byte>(item, 0).Yield()));
        }
コード例 #17
0
        public void TestRemoveNotifiesBoundListSubscription()
        {
            const int    key  = 0;
            const string item = "item";

            bindableStringDictionary.Add(key, item);
            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            NotifyCollectionChangedEventArgs triggeredArgs = null;

            list.CollectionChanged += (_, args) => triggeredArgs = args;

            bindableStringDictionary.Remove(key);

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyCollectionChangedAction.Remove));
            Assert.That(triggeredArgs.OldItems, Has.One.Items.EqualTo(new KeyValuePair <int, string>(key, item)));
            Assert.That(triggeredArgs.OldStartingIndex, Is.EqualTo(0));
        }
コード例 #18
0
        public void TestSetNotifiesBoundLists()
        {
            bindableStringDictionary.Add(0, "0");

            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            NotifyCollectionChangedEventArgs triggeredArgs = null;

            list.CollectionChanged += (_, args) => triggeredArgs = args;

            bindableStringDictionary[0] = "1";

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyCollectionChangedAction.Replace));
            Assert.That(triggeredArgs.OldItems, Is.EquivalentTo(new KeyValuePair <int, string>(0, "0").Yield()));
            Assert.That(triggeredArgs.NewItems, Is.EquivalentTo(new KeyValuePair <int, string>(0, "1").Yield()));
            Assert.That(triggeredArgs.OldStartingIndex, Is.Zero);
            Assert.That(triggeredArgs.NewStartingIndex, Is.Zero);
        }
コード例 #19
0
        public void TestBindCollectionChangedEventsRanIfBoundToDifferentDictionary()
        {
            var firstDictContents = new[]
            {
                new KeyValuePair <string, byte>("a", 1),
                new KeyValuePair <string, byte>("b", 3),
                new KeyValuePair <string, byte>("c", 5),
                new KeyValuePair <string, byte>("d", 7),
            };

            var otherDictContents = new[]
            {
                new KeyValuePair <string, byte>("a", 2),
                new KeyValuePair <string, byte>("b", 4),
                new KeyValuePair <string, byte>("c", 6),
                new KeyValuePair <string, byte>("d", 8),
                new KeyValuePair <string, byte>("e", 10),
            };

            var dict      = new BindableDictionary <string, byte>(firstDictContents);
            var otherDict = new BindableDictionary <string, byte>(otherDictContents);

            var triggeredArgs = new List <NotifyDictionaryChangedEventArgs <string, byte> >();

            dict.BindCollectionChanged((_, args) => triggeredArgs.Add(args));
            dict.BindTo(otherDict);

            Assert.That(triggeredArgs, Has.Count.EqualTo(2));

            var removeEvent = triggeredArgs.SingleOrDefault(ev => ev.Action == NotifyDictionaryChangedAction.Remove);

            Assert.That(removeEvent, Is.Not.Null);
            Assert.That(removeEvent.OldItems, Is.EquivalentTo(firstDictContents));

            var addEvent = triggeredArgs.SingleOrDefault(ev => ev.Action == NotifyDictionaryChangedAction.Add);

            Assert.That(addEvent, Is.Not.Null);
            Assert.That(addEvent.NewItems, Is.EquivalentTo(otherDict));
        }
コード例 #20
0
        public void TestClearDoesNotNotifyBoundBindablesBeforeClear()
        {
            var bindableDictA = new BindableDictionary <string, byte>();

            bindableDictA.BindTo(bindableStringByteDictionary);
            var bindableDictB = new BindableDictionary <string, byte>();

            bindableDictB.BindTo(bindableStringByteDictionary);
            var bindableDictC = new BindableDictionary <string, byte>();

            bindableDictC.BindTo(bindableStringByteDictionary);
            for (byte i = 0; i < 5; i++)
            {
                bindableStringByteDictionary.Add($"testA{i}", i);
            }
            for (byte i = 0; i < 5; i++)
            {
                bindableDictA.Add($"testB{i}", i);
            }
            for (byte i = 0; i < 5; i++)
            {
                bindableDictB.Add($"testC{i}", i);
            }
            for (byte i = 0; i < 5; i++)
            {
                bindableDictC.Add($"testD{i}", i);
            }

            Assert.Multiple(() =>
            {
                Assert.IsNotEmpty(bindableDictA);
                Assert.IsNotEmpty(bindableDictB);
                Assert.IsNotEmpty(bindableDictC);
            });

            bindableStringByteDictionary.Clear();
        }
コード例 #21
0
        public void TestClearDoesNotNotifyBoundBindablesBeforeClear()
        {
            var bindableListA = new BindableDictionary <int, string>();

            bindableListA.BindTo(bindableStringDictionary);
            var bindableListB = new BindableDictionary <int, string>();

            bindableListB.BindTo(bindableStringDictionary);
            var bindableListC = new BindableDictionary <int, string>();

            bindableListC.BindTo(bindableStringDictionary);
            for (int i = 0; i < 5; i++)
            {
                bindableStringDictionary.Add(i, "testA");
            }
            for (int i = 0; i < 5; i++)
            {
                bindableListA.Add(i + 5, "testA");
            }
            for (int i = 0; i < 5; i++)
            {
                bindableListB.Add(i + 10, "testA");
            }
            for (int i = 0; i < 5; i++)
            {
                bindableListC.Add(i + 15, "testA");
            }

            Assert.Multiple(() =>
            {
                Assert.IsNotEmpty(bindableListA);
                Assert.IsNotEmpty(bindableListB);
                Assert.IsNotEmpty(bindableListC);
            });

            bindableStringDictionary.Clear();
        }
コード例 #22
0
        public void TestRemoveNotifiesBoundDictionaries()
        {
            const string item = "item";

            bindableStringByteDictionary.Add(item, 0);
            var dictA = new BindableDictionary <string, byte>();

            dictA.BindTo(bindableStringByteDictionary);
            var dictB = new BindableDictionary <string, byte>();

            dictB.BindTo(bindableStringByteDictionary);
            var dictC = new BindableDictionary <string, byte>();

            dictC.BindTo(bindableStringByteDictionary);

            bindableStringByteDictionary.Remove(item);

            Assert.Multiple(() =>
            {
                Assert.False(dictA.ContainsKey(item));
                Assert.False(dictB.ContainsKey(item));
                Assert.False(dictC.ContainsKey(item));
            });
        }