예제 #1
0
 public ObservableCollectionSynchronizerTests()
 {
     collection1   = new ObservableCollection <int>(new[] { 1, 2, 3 });
     collection2   = new ObservableCollection <string>();
     _synchronizer = new ObservableCollectionSynchronizer <int, string>(collection1, collection2,
                                                                        (x) => x.ToString());
 }
 public void Setup()
 {
     _destination     = new ObservableCollection <string>();
     _sync            = new ObservableCollectionSynchronizer <string>(_destination);
     _source1         = new ObservableCollection <int>();
     _source2         = new ObservableCollection <string>();
     _source1Selector = (i => i.ToString());
 }
예제 #3
0
 public BindableGrid()
 {
     ColumnSyncronizer = new ObservableCollectionSynchronizer <ColumnDefinition> {
         Destination = ColumnDefinitions
     };
     RowSyncronizer = new ObservableCollectionSynchronizer <RowDefinition> {
         Destination = RowDefinitions
     };
 }
예제 #4
0
        public void Should_Be_Disposable()
        {
            var reference = new WeakReference(_synchronizer);

            Assert.True(reference.IsAlive);

            _synchronizer.Dispose();
            _synchronizer = null;

            GC.Collect();

            Assert.False(reference.IsAlive);
        }
예제 #5
0
        public void ElementInitiallyAdded_CollectionContainsElement()
        {
            var integerList = new ObservableCollection <int> {
                1, 3
            };
            var stringList = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            Assert.Equal(2, stringList.Count);
            Assert.Equal("1", stringList.First());
            Assert.Equal("3", stringList.Last());
        }
예제 #6
0
        public void ElementInserted_CollectionContainsElement()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(3);
            integerList.Insert(1, 2);

            Assert.Equal(3, stringList.Count);
            Assert.Equal("1", stringList[0]);
            Assert.Equal("2", stringList[1]);
            Assert.Equal("3", stringList[2]);
        }
예제 #7
0
        public void ElementsCleared_CollectionIsEmpty()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(2);
            integerList.Add(3);
            integerList.Add(4);

            integerList.Clear();

            Assert.Empty(stringList);
        }
예제 #8
0
        public void ElementRemovedAt_CollectionNotContainsElement()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(2);
            integerList.Add(3);
            integerList.Add(4);

            integerList.RemoveAt(2);

            Assert.Equal(3, stringList.Count);
            Assert.Equal("1", stringList[0]);
            Assert.Equal("2", stringList[1]);
            Assert.Equal("4", stringList[2]);
        }
예제 #9
0
        public void Dispose_CollectionDoesntUpdateAnymore()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var synchronizer =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(3);

            synchronizer.Dispose();

            integerList.Add(6);
            integerList.Add(7);

            Assert.Equal(2, stringList.Count);
            Assert.Equal("1", stringList.First());
            Assert.Equal("3", stringList.Last());
        }
예제 #10
0
파일: Program.cs 프로젝트: mastertnt/XRay
        /// <summary>
        /// Main entry point of the application.
        /// </summary>
        /// <param name="pArguments">The arguments.</param>
        static void Main(string[] pArguments)
        {
            ObservableCollection <int>    lSourceCollection = new ObservableCollection <int>();
            ObservableCollection <string> lTargetCollection = new ObservableCollection <string>();
            ObservableCollectionSynchronizer <int, string> lSynchronizer = new ObservableCollectionSynchronizer <int, string>(lSourceCollection, lTargetCollection);

            Console.WriteLine("Add a single value in source");
            lSourceCollection.Add(12);
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);

            Console.WriteLine("Add multiple values in source");
            lSourceCollection.Add(17);
            lSourceCollection.Add(18);
            lSourceCollection.Add(12);
            lSourceCollection.Add(14);
            lSourceCollection.Add(14);
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);

            Console.WriteLine("Remove a value duplicated in target");
            lTargetCollection.Remove("12");
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);

            Console.WriteLine("Insert a single value in target");
            lTargetCollection.Insert(1, "34");
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);

            Console.WriteLine("Remove a value duplicated in source");
            lSourceCollection.Remove(12);
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);

            Console.WriteLine("Clear source");
            lSourceCollection.Clear();
            Console.WriteLine(lSynchronizer.ToString());
            Debug.Assert(lTargetCollection.Count == lSourceCollection.Count);
        }
예제 #11
0
        public void ElementMoved_CollectionContainsElementAtRightPosition()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(2);
            integerList.Add(3);
            integerList.Add(4);

            integerList.Move(1, 3);

            Assert.Equal(4, stringList.Count);
            Assert.Equal("1", stringList[0]);
            Assert.Equal("3", stringList[1]);
            Assert.Equal("4", stringList[2]);
            Assert.Equal("2", stringList[3]);
        }
예제 #12
0
        public void ElementReplaced_CollectionContainsNewElement()
        {
            var integerList = new ObservableCollection <int>();
            var stringList  = new ObservableCollection <string>();

            var _ =
                new ObservableCollectionSynchronizer <int, string>(integerList, stringList, x => x.ToString(),
                                                                   x => x.ToString());

            integerList.Add(1);
            integerList.Add(2);
            integerList.Add(3);
            integerList.Add(4);

            integerList[2] = 5;

            Assert.Equal(4, stringList.Count);
            Assert.Equal("1", stringList[0]);
            Assert.Equal("2", stringList[1]);
            Assert.Equal("5", stringList[2]);
            Assert.Equal("4", stringList[3]);
        }
예제 #13
0
 public void Setup()
 {
     _destination = new ObservableCollection <string>();
     _sync        = new ObservableCollectionSynchronizer <string>(_destination);
     _source      = new ObservableCollection <string>();
 }
예제 #14
0
 public BindableGrid()
 {
     ColumnSyncronizer = new ObservableCollectionSynchronizer<ColumnDefinition> {Destination = ColumnDefinitions};
     RowSyncronizer = new ObservableCollectionSynchronizer<RowDefinition> {Destination = RowDefinitions};
 }
예제 #15
0
 public void Stop()
 {
     this._Selector.SelectionChanged -= selector_SelectionChanged;
     this._Connector.Stop();
     this._Connector = null;
 }
예제 #16
0
 public void Start()
 {
     this._Selector.SelectionChanged += selector_SelectionChanged;
     if(this._Connector != null) {
         throw new InvalidOperationException();
     }
     this._Connector = this._Collection.NotifyToCollectionWeak(GetSelectedItemsList(this._Selector));
 }