public void Clear_CallsDisposer()
        {
            var isDisposeCalled = false;
            var sut             = new TranslatingObservable <Int32, String>(_source, i => i.ToString(), i => isDisposeCalled = true);

            _source.Clear();
            Assert.True(isDisposeCalled);
        }
Пример #2
0
        public ItemListViewModel(AppState appState)
        {
            _appState = appState;

            // Translate the AppState's ObservableCollection<ToDoItem> into an
            // ObservableCollection<ItemViewCellModel> which can then be used to populate a ListView
            Items = new TranslatingObservable <ToDoItem, ItemViewCellModel>(appState.Items, item => new ItemViewCellModel(appState, item));

            // Convert the AppState's SelectedItem from a ToDoItem to the corresponding ItemViewCellModel
            // so it can be bound to a ListView's SelectedItem property (the value needs to match the one
            // in the ObservableCollection<ItemViewCellModel> which is backing the ListView).
            SelectedItem = Items.GetTranslatedValueOrNull(appState.SelectedItem);

            // When the user selects an item in the list, update AppState accordingly
            SelectItemCommand = new Command <ItemViewCellModel>(itemViewCellModel =>
            {
                var selectedItem = itemViewCellModel?.ToDoItem;
                appState.SelectItem(selectedItem);
            });

            // When the AppState's SelectedItem changes, update the ListView selection accordingly
            appState.PropertyChanged += OnAppStatePropertyChanged;
        }
 public TranslatingObservableTests()
 {
     _source = new ObservableCollection <Int32>(new Int32[] { 1, 2, 3 });
     _sut    = new TranslatingObservable <Int32, String>(_source, i => i.ToString());
 }