Exemplo n.º 1
0
        public void Ctor_IContainer()
        {
            var container = new Container();
            var source    = new SubBindingSource(container);

            Assert.True(source.AllowEdit);
            Assert.True(source.AllowNew);
            Assert.True(source.AllowRemove);
            Assert.True(source.CanRaiseEvents);
            Assert.Same(container, source.Container);
            Assert.Empty(source);
            Assert.Equal(0, source.CurrencyManager.Count);
            Assert.Empty(source.CurrencyManager.Bindings);
            Assert.Same(source.CurrencyManager.Bindings, source.CurrencyManager.Bindings);
            Assert.Throws <IndexOutOfRangeException>(() => source.CurrencyManager.Current);
            Assert.True(source.CurrencyManager.IsBindingSuspended);
            Assert.Same(source, source.CurrencyManager.List);
            Assert.Equal(-1, source.CurrencyManager.Position);
            Assert.Same(source.CurrencyManager, source.CurrencyManager);
            Assert.Null(source.Current);
            Assert.Empty(source.DataMember);
            Assert.Null(source.DataSource);
            Assert.False(source.DesignMode);
            Assert.NotNull(source.Events);
            Assert.Same(source.Events, source.Events);
            Assert.Null(source.Filter);
            Assert.True(source.IsBindingSuspended);
            Assert.False(source.IsFixedSize);
            Assert.False(source.IsReadOnly);
            Assert.False(source.IsSorted);
            Assert.False(source.IsSynchronized);
            Assert.Empty(source.List);
            Assert.IsType <BindingList <object> >(source.List);
            Assert.True(source.RaiseListChangedEvents);
            Assert.NotNull(source.Site);
            Assert.Null(source.Sort);
            Assert.Null(source.SortDescriptions);
            Assert.Equal(ListSortDirection.Ascending, source.SortDirection);
            Assert.Null(source.SortProperty);
            Assert.False(source.SupportsAdvancedSorting);
            Assert.True(source.SupportsChangeNotification);
            Assert.False(source.SupportsFiltering);
            Assert.False(source.SupportsSearching);
            Assert.False(source.SupportsSorting);
            Assert.Same(source.List.SyncRoot, source.SyncRoot);
        }
Exemplo n.º 2
0
        public void Ctor_Object_String_BindingList(object dataSource, string dataMember, bool expectedAllowEdit, bool expectedAllowNew, bool expectedAllowRemove, bool expectedIsFixedSize, bool expectedReadOnly, bool expectedIsSynchronized, IList expected, Type expectedType)
        {
            var source = new SubBindingSource(dataSource, dataMember);

            Assert.Equal(expectedAllowEdit, source.AllowEdit);
            Assert.Equal(expectedAllowNew, source.AllowNew);
            Assert.Equal(expectedAllowRemove, source.AllowRemove);
            Assert.True(source.CanRaiseEvents);
            Assert.Null(source.Container);
            Assert.Equal(expected, source);
            Assert.Equal(expected.Count, source.CurrencyManager.Count);
            Assert.Empty(source.CurrencyManager.Bindings);
            Assert.Same(source.CurrencyManager.Bindings, source.CurrencyManager.Bindings);
            Assert.Equal(expected[0], source.CurrencyManager.Current);
            Assert.False(source.CurrencyManager.IsBindingSuspended);
            Assert.Same(source, source.CurrencyManager.List);
            Assert.Equal(0, source.CurrencyManager.Position);
            Assert.Same(source.CurrencyManager, source.CurrencyManager);
            Assert.Equal(expected[0], source.Current);
            Assert.Same(dataMember, source.DataMember);
            Assert.Same(dataSource, source.DataSource);
            Assert.False(source.DesignMode);
            Assert.NotNull(source.Events);
            Assert.Same(source.Events, source.Events);
            Assert.Null(source.Filter);
            Assert.False(source.IsBindingSuspended);
            Assert.Equal(expectedIsFixedSize, source.IsFixedSize);
            Assert.Equal(expectedReadOnly, source.IsReadOnly);
            Assert.False(source.IsSorted);
            Assert.Equal(expectedIsSynchronized, source.IsSynchronized);
            Assert.Equal(expected, source.List);
            Assert.NotSame(expected, source.List);
            Assert.IsType(expectedType, source.List);
            Assert.True(source.RaiseListChangedEvents);
            Assert.Null(source.Site);
            Assert.Null(source.Sort);
            Assert.Null(source.SortDescriptions);
            Assert.Equal(ListSortDirection.Ascending, source.SortDirection);
            Assert.Null(source.SortProperty);
            Assert.False(source.SupportsAdvancedSorting);
            Assert.True(source.SupportsChangeNotification);
            Assert.False(source.SupportsFiltering);
            Assert.False(source.SupportsSearching);
            Assert.False(source.SupportsSorting);
            Assert.Same(source.List.SyncRoot, source.SyncRoot);
        }
Exemplo n.º 3
0
        public void Ctor_Object_String_IBindingList(string dataMember)
        {
            PropertyDescriptor sortProperty = TypeDescriptor.GetProperties(typeof(DataClass))[0];
            var syncRoot = new object();
            var mockList = new Mock <IBindingList>(MockBehavior.Strict);

            mockList
            .Setup(p => p.Count)
            .Returns(0);
            mockList
            .Setup(p => p.AllowEdit)
            .Returns(false);
            mockList
            .Setup(p => p.AllowNew)
            .Returns(false);
            mockList
            .Setup(p => p.AllowRemove)
            .Returns(false);
            mockList
            .Setup(p => p.GetEnumerator())
            .Returns(new List <int>().GetEnumerator());
            mockList
            .Setup(p => p.IsFixedSize)
            .Returns(false);
            mockList
            .Setup(p => p.IsReadOnly)
            .Returns(false);
            mockList
            .Setup(p => p.IsSynchronized)
            .Returns(false);
            mockList
            .Setup(p => p.IsSorted)
            .Returns(true);
            mockList
            .Setup(p => p.SortDirection)
            .Returns(ListSortDirection.Descending);
            mockList
            .Setup(p => p.SortProperty)
            .Returns(sortProperty);
            mockList
            .Setup(p => p.SupportsChangeNotification)
            .Returns(false);
            mockList
            .Setup(p => p.SupportsSearching)
            .Returns(true);
            mockList
            .Setup(p => p.SupportsSorting)
            .Returns(true);
            mockList
            .Setup(p => p.SyncRoot)
            .Returns(syncRoot);

            var sortDescriptions = new ListSortDescriptionCollection();
            var mockListView     = mockList.As <IBindingListView>();

            mockListView
            .Setup(p => p.SortDescriptions)
            .Returns(sortDescriptions);
            mockListView
            .Setup(p => p.SupportsAdvancedSorting)
            .Returns(true);
            mockListView
            .Setup(p => p.SupportsFiltering)
            .Returns(true);

            var source = new SubBindingSource(mockList.Object, dataMember);

            Assert.False(source.AllowEdit);
            Assert.False(source.AllowNew);
            Assert.False(source.AllowRemove);
            Assert.True(source.CanRaiseEvents);
            Assert.Null(source.Container);
            Assert.Empty(source);
            Assert.Equal(0, source.CurrencyManager.Count);
            Assert.Empty(source.CurrencyManager.Bindings);
            Assert.Same(source.CurrencyManager.Bindings, source.CurrencyManager.Bindings);
            Assert.Throws <IndexOutOfRangeException>(() => source.CurrencyManager.Current);
            Assert.True(source.CurrencyManager.IsBindingSuspended);
            Assert.Same(source, source.CurrencyManager.List);
            Assert.Equal(-1, source.CurrencyManager.Position);
            Assert.Same(source.CurrencyManager, source.CurrencyManager);
            Assert.Null(source.Current);
            Assert.Same(dataMember, source.DataMember);
            Assert.Same(mockList.Object, source.DataSource);
            Assert.False(source.DesignMode);
            Assert.NotNull(source.Events);
            Assert.Same(source.Events, source.Events);
            Assert.Null(source.Filter);
            Assert.True(source.IsBindingSuspended);
            Assert.False(source.IsFixedSize);
            Assert.False(source.IsReadOnly);
            Assert.True(source.IsSorted);
            Assert.False(source.IsSynchronized);
            Assert.Same(mockList.Object, source.List);
            Assert.True(source.RaiseListChangedEvents);
            Assert.Null(source.Site);
            Assert.Null(source.Sort);
            Assert.Same(sortDescriptions, source.SortDescriptions);
            Assert.Equal(ListSortDirection.Descending, source.SortDirection);
            Assert.Same(sortProperty, source.SortProperty);
            Assert.True(source.SupportsAdvancedSorting);
            Assert.True(source.SupportsChangeNotification);
            Assert.True(source.SupportsFiltering);
            Assert.True(source.SupportsSearching);
            Assert.True(source.SupportsSorting);
            Assert.Same(syncRoot, source.SyncRoot);
        }