コード例 #1
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);
        }
コード例 #2
0
        public void TestBindCollectionChangedNotRunIfParsingSequenceEqualEnumerable()
        {
            var dict = new BindableDictionary <string, byte>
            {
                { "a", 1 },
                { "b", 3 },
                { "c", 5 },
                { "d", 7 }
            };

            var enumerable = 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)
            };

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

            dict.BindCollectionChanged((_, args) => triggeredArgs = args);
            dict.Parse(enumerable);

            Assert.That(triggeredArgs, Is.Null);
        }
コード例 #3
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));
            });
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void TestDisabledNotifiesBoundLists()
        {
            var list = new BindableDictionary <int, string>();

            list.BindTo(bindableStringDictionary);

            bindableStringDictionary.Disabled = true;

            Assert.IsTrue(list.Disabled);
        }
コード例 #7
0
        public void TestDisabledNotifiesBoundDictionaries()
        {
            var dict = new BindableDictionary <string, byte>();

            dict.BindTo(bindableStringByteDictionary);

            bindableStringByteDictionary.Disabled = true;

            Assert.IsTrue(dict.Disabled);
        }
コード例 #8
0
        public void TestGetEnumeratorWhenCopyConstructorIsUsedDoesNotReturnTheEnumeratorOfTheInputtedEnumerator()
        {
            var array = new[] { new KeyValuePair <string, byte>("", 0) };

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

            var enumerator = dict.GetEnumerator();

            Assert.AreNotEqual(array.GetEnumerator(), enumerator);
        }
コード例 #9
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));
        }
コード例 #10
0
        public void TestGetEnumeratorWhenCopyConstructorIsUsedDoesNotReturnTheEnumeratorOfTheInputtedEnumerator()
        {
            var dictionary = new Dictionary <int, string> {
                { 0, "" }
            };
            var list = new BindableDictionary <int, string>(dictionary);

            var enumerator = list.GetEnumerator();

            Assert.AreNotEqual(dictionary.GetEnumerator(), enumerator);
        }
コード例 #11
0
        public void TestBindCollectionChangedWithRunImmediately()
        {
            var dictionary = new BindableDictionary <int, string>();

            NotifyCollectionChangedEventArgs triggeredArgs = null;

            dictionary.BindCollectionChanged((_, args) => triggeredArgs = args, true);

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
            Assert.That(triggeredArgs.NewItems, Is.EquivalentTo(dictionary));
        }
コード例 #12
0
        public void TestBindCollectionChangedWithoutRunningImmediately()
        {
            var dictionary = new BindableDictionary <int, string> {
                { 1, "One" }
            };

            NotifyCollectionChangedEventArgs triggeredArgs = null;

            dictionary.BindCollectionChanged((_, args) => triggeredArgs = args);

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

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

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

            Assert.That(triggeredArgs, Is.Null);
        }
コード例 #14
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);
        }
コード例 #15
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);
        }
コード例 #16
0
        public void TestBindCollectionChangedWithRunImmediately()
        {
            var dict = new BindableDictionary <string, byte> {
                { "a", 1 }
            };

            NotifyDictionaryChangedEventArgs <string, byte> triggeredArgs = null;

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

            Assert.That(triggeredArgs.Action, Is.EqualTo(NotifyDictionaryChangedAction.Add));
            Assert.That(triggeredArgs.NewItems, Is.EquivalentTo(dict));
        }
コード例 #17
0
ファイル: ConverterTests.cs プロジェクト: gstamac/AllGreen
        public void RunnersToStatusesConverterTest()
        {
            RunnersToStatusesConverter runnersToStatusesConverter = new RunnersToStatusesConverter();

            runnersToStatusesConverter.ProvideValue(null).Should().Be(runnersToStatusesConverter);

            runnersToStatusesConverter.Convert(new object[] { null, null }, typeof(IEnumerable), null, null).Should().BeNull();

            BindableCollection <RunnerViewModel> runners = new BindableCollection <RunnerViewModel>();
            RunnerViewModel runner1 = new RunnerViewModel {
                ConnectionId = "conn1", Name = "Runner 1"
            };
            RunnerViewModel runner2 = new RunnerViewModel {
                ConnectionId = "conn2", Name = "Runner 2"
            };

            runners.Add(runner1);
            runners.Add(runner2);
            BindableDictionary <string, SpecStatusViewModel> statuses = new BindableDictionary <string, SpecStatusViewModel>();

            statuses.Add("conn1", new SpecStatusViewModel {
                Status = SpecStatus.Passed, Time = 1, Duration = 1, Runner = runner1
            });
            statuses.Add("conn2", new SpecStatusViewModel {
                Status = SpecStatus.Failed, Time = 2, Duration = 2, Runner = runner2
            });

            object result = runnersToStatusesConverter.Convert(new object[] { runners, statuses }, typeof(IEnumerable), null, null);

            result.Should().BeAssignableTo <IEnumerable <SpecStatusViewModel> >();
            (result as IEnumerable <SpecStatusViewModel>).ShouldAllBeEquivalentTo(new object[] {
                new { Status = SpecStatus.Passed, Time = 1, Duration = 1, Runner = runner1 },
                new { Status = SpecStatus.Failed, Time = 2, Duration = 2, Runner = runner2 }
            },
                                                                                  o => o.Excluding(si => si.PropertyPath.EndsWith("IsNotifying") || si.PropertyPath.EndsWith("Steps") || si.PropertyPath.EndsWith("Description") || si.PropertyPath.EndsWith("DurationText")));

            runners.Add(new RunnerViewModel {
                ConnectionId = "conn3", Name = "Runner 3"
            });

            result = runnersToStatusesConverter.Convert(new object[] { runners, statuses }, typeof(IEnumerable), null, null);
            result.Should().BeAssignableTo <IEnumerable <SpecStatusViewModel> >();
            (result as IEnumerable <SpecStatusViewModel>).ShouldAllBeEquivalentTo(new object[] {
                new { Status = SpecStatus.Passed, Time = 1, Duration = 1, Runner = runner1 },
                new { Status = SpecStatus.Failed, Time = 2, Duration = 2, Runner = runner2 },
                null
            },
                                                                                  o => o.Excluding(si => si.PropertyPath.EndsWith("IsNotifying") || si.PropertyPath.EndsWith("Steps") || si.PropertyPath.EndsWith("Description") || si.PropertyPath.EndsWith("DurationText")));

            runnersToStatusesConverter.ConvertBack(null, null, null, null).Should().BeNull();
        }
コード例 #18
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);
        }
コード例 #19
0
        public void TestBindViaBindTarget()
        {
            BindableDictionary <string, byte> parentBindable = new BindableDictionary <string, byte>();

            BindableDictionary <string, byte> bindable1 = new BindableDictionary <string, byte>();
            BindableDictionary <string, byte> bindable2 = new BindableDictionary <string, byte>();

            bindable1.BindTarget = parentBindable;
            bindable2.BindTarget = parentBindable;

            parentBindable.Add("5", 1);

            Assert.That(bindable1["5"], Is.EqualTo(1));
            Assert.That(bindable2["5"], Is.EqualTo(1));
        }
コード例 #20
0
        public void TestBindViaBindTarget()
        {
            BindableDictionary <int, string> parentBindable = new BindableDictionary <int, string>();

            BindableDictionary <int, string>  bindable1 = new BindableDictionary <int, string>();
            IBindableDictionary <int, string> bindable2 = new BindableDictionary <int, string>();

            bindable1.BindTarget = parentBindable;
            bindable2.BindTarget = parentBindable;

            parentBindable.Add(5, "Test");

            Assert.That(bindable1[5], Is.EqualTo("Test"));
            Assert.That(bindable2[5], Is.EqualTo("Test"));
        }
コード例 #21
0
        private void load(OsuColour colour, LyricCheckerManager lyricCheckerManager)
        {
            Children = new[]
            {
                // todo : should all invalid tag number
                table = new TimeTagIssueTable(),
            };

            bindableReports = lyricCheckerManager.BindableReports.GetBoundCopy();
            bindableReports.BindCollectionChanged((a, b) =>
            {
                // todo : might have filter in here.
                var issues   = bindableReports.Values.SelectMany(x => x);
                table.Issues = issues.OfType <TimeTagIssue>();
            }, true);
        }
コード例 #22
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Length < 2)
            {
                return(null);
            }

            BindableCollection <RunnerViewModel>             runners  = values[0] as BindableCollection <RunnerViewModel>;
            BindableDictionary <string, SpecStatusViewModel> statuses = values[1] as BindableDictionary <string, SpecStatusViewModel>;

            if (runners != null && statuses != null)
            {
                return(GetRunnerStatuses(runners, statuses));
            }

            return(null);
        }
コード例 #23
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);
        }
コード例 #24
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);
        }
コード例 #25
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()));
        }
コード例 #26
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()));
        }
コード例 #27
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));
        }
コード例 #28
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);
        }
コード例 #29
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));
        }
コード例 #30
0
        public void TestConstructorWithItemsAddsItemsInternally()
        {
            KeyValuePair <string, byte>[] array =
            {
                new KeyValuePair <string, byte>("ok",     0),
                new KeyValuePair <string, byte>("nope",   1),
                new KeyValuePair <string, byte>("random", 2),
                new KeyValuePair <string, byte>("", 4)
            };

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

            Assert.Multiple(() =>
            {
                foreach (var(key, value) in array)
                {
                    Assert.That(dict.TryGetValue(key, out var val), Is.True);
                    Assert.That(val, Is.EqualTo(value));
                }

                Assert.AreEqual(array.Length, dict.Count);
            });
        }