コード例 #1
0
        public void BindingContext_RemoveCore_Invoke_Success()
        {
            var context     = new SubBindingContext();
            var source1     = new BindingSource();
            var dataSource1 = new DataSource();
            var source2     = new BindingSource();
            var dataSource2 = new DataSource();

            context.Add(dataSource1, source1.CurrencyManager);
            context.Add(dataSource2, source2.CurrencyManager);

            context.RemoveCore(dataSource1);
            Assert.Single(context);

            // Remove again.
            context.RemoveCore(dataSource1);
            Assert.Single(context);

            context.RemoveCore(dataSource2);
            Assert.Empty(context);

            // Remove again.
            context.RemoveCore(dataSource2);
            Assert.Empty(context);
        }
コード例 #2
0
        public void BindingContext_KeyEquals_Invoke_ReturnsExpected()
        {
            var context1 = new SubBindingContext();
            var context2 = new SubBindingContext();
            var context3 = new SubBindingContext();
            var context4 = new SubBindingContext();

            using var source1 = new BindingSource();
            using var source2 = new BindingSource();
            var dataSource1 = new DataSource();
            var dataSource2 = new DataSource();

            context1.Add(dataSource1, source1.CurrencyManager);
            context2.Add(dataSource1, source1.CurrencyManager);
            context3.Add(dataSource2, source1.CurrencyManager);
            context4.Add(dataSource2, source2.CurrencyManager);

            DictionaryEntry entry1 = Assert.IsType <DictionaryEntry>(Assert.Single(context1));
            DictionaryEntry entry2 = Assert.IsType <DictionaryEntry>(Assert.Single(context2));
            DictionaryEntry entry3 = Assert.IsType <DictionaryEntry>(Assert.Single(context3));
            DictionaryEntry entry4 = Assert.IsType <DictionaryEntry>(Assert.Single(context3));

            Assert.True(entry1.Key.Equals(entry1.Key));
            Assert.True(entry1.Key.Equals(entry2.Key));
            Assert.False(entry1.Key.Equals(entry3.Key));
            Assert.False(entry1.Key.Equals(entry4.Key));

            Assert.False(entry1.Key.Equals(new object()));
            Assert.False(entry1.Key.Equals(null));
        }
コード例 #3
0
        public void BindingContext_Add_InvokeMultiple_Success()
        {
            var context = new SubBindingContext();

            using var source1 = new BindingSource();
            using var source2 = new BindingSource();
            var dataSource1 = new DataSource();
            var dataSource2 = new DataSource();

            context.Add(dataSource1, source1.CurrencyManager);
            context.Add(dataSource2, source2.CurrencyManager);
            Assert.Equal(2, ((ICollection)context).Count);

            Assert.Same(source1.CurrencyManager, context[dataSource1]);
            Assert.Same(source2.CurrencyManager, context[dataSource2]);
        }
コード例 #4
0
        public void BindingContext_Add_NullDataSource_ThrowsArgumentNullException()
        {
            var context = new SubBindingContext();

            using var source = new BindingSource();
            Assert.Throws <ArgumentNullException>("dataSource", () => context.Add(null, source.CurrencyManager));
        }
コード例 #5
0
        public void BindingContext_Item_GetWithAddedDataSourceWithDataMember_ThrowsArgumentException()
        {
            var context = new SubBindingContext();

            using var source = new BindingSource();
            var dataSource = new DataSource();

            context.Add(dataSource, source.CurrencyManager);
            Assert.Throws <ArgumentException>(null, () => context[dataSource, "Property"]);
        }
コード例 #6
0
        public void BindingContext_Add_Invoke_GetReturnsExpected()
        {
            var context = new SubBindingContext();

            using var source1 = new BindingSource();
            using var source2 = new BindingSource();
            var dataSource = new DataSource();

            context.Add(dataSource, source1.CurrencyManager);
            Assert.Single(context);

            Assert.Same(source1.CurrencyManager, context[dataSource]);
            Assert.Same(source1.CurrencyManager, context[dataSource, null]);
            Assert.Same(source1.CurrencyManager, context[dataSource, string.Empty]);

            // Set new value.
            context.Add(dataSource, source2.CurrencyManager);
            Assert.Single(context);
            Assert.Same(source2.CurrencyManager, context[dataSource]);
            Assert.Same(source2.CurrencyManager, context[dataSource, null]);
            Assert.Same(source2.CurrencyManager, context[dataSource, string.Empty]);
        }
コード例 #7
0
        public void BindingContext_ClearCore_NotEmpty_Success()
        {
            var context = new SubBindingContext();
            var source  = new BindingSource();

            context.Add(new DataSource(), source.CurrencyManager);

            // Clear again.
            context.ClearCore();
            Assert.Empty(context);

            context.ClearCore();
            Assert.Empty(context);
        }
コード例 #8
0
        public void BindingContext_Contains_DataSource_ReturnsExpected()
        {
            var context = new SubBindingContext();

            using var source = new BindingSource();
            var dataSource = new DataSource();

            context.Add(dataSource, source.CurrencyManager);
            Assert.True(context.Contains(dataSource));
            Assert.True(context.Contains(dataSource, null));
            Assert.True(context.Contains(dataSource, string.Empty));
            Assert.False(context.Contains(1));
            Assert.False(context.Contains(1, null));
            Assert.False(context.Contains(1, string.Empty));
        }
コード例 #9
0
        public void BindingContext_CopyTo_Invoke_Success()
        {
            var context = new SubBindingContext();

            using var source = new BindingSource();
            var dataSource = new DataSource();

            context.Add(dataSource, source.CurrencyManager);

            var array = new object[] { 1, 2, 3 };

            ((ICollection)context).CopyTo(array, 1);
            Assert.Equal(1, array[0]);
            Assert.NotNull(Assert.IsType <DictionaryEntry>(array[1]).Key);
            Assert.Equal(source.CurrencyManager, Assert.IsType <WeakReference>(Assert.IsType <DictionaryEntry>(array[1]).Value).Target);
            Assert.Equal(3, array[2]);
        }
コード例 #10
0
        public void BindingContext_Contains_DataSourceDataMember_ReturnsExpected()
        {
            var context = new SubBindingContext();

            using var source = new BindingSource();
            var dataSource1 = new DataSource();
            var dataSource2 = new DataSource();

            context.Add(dataSource1, source.CurrencyManager);
            Assert.NotNull(context[dataSource2, "Property"]);

            Assert.True(context.Contains(dataSource1, null));
            Assert.True(context.Contains(dataSource1, string.Empty));
            Assert.False(context.Contains(dataSource1, "Property"));
            Assert.True(context.Contains(dataSource2, null));
            Assert.True(context.Contains(dataSource2, string.Empty));
            Assert.True(context.Contains(dataSource2, "Property"));
            Assert.True(context.Contains(dataSource2, "property"));
            Assert.False(context.Contains(dataSource2, "NoSuchProperty"));
            Assert.False(context.Contains(1, "Property"));
        }
コード例 #11
0
        public void BindingContext_Add_NullListManager_ThrowsArgumentNullException()
        {
            var context = new SubBindingContext();

            Assert.Throws <ArgumentNullException>("listManager", () => context.Add(1, null));
        }