public ShoppingList()
        {
            this.InitializeComponent();
            
            ViewModel = new ShoppingListViewModel(ServiceRegistrar.ShoppingService(App.SqliteConnection));
            ShoppingListView.ItemsSource = ViewModel.Items;

            // Developer will want to return to none selection when selected items are zero
            ShoppingListView.SelectionChanged += OnSelectionChanged;

            // With this property we enable that the left edge tap visual indicator shows 
            // when user press the listviewitem left edge 
            // and also the ItemLeftEdgeTapped event will be fired 
            // when user releases the pointer
            ShoppingListView.IsItemLeftEdgeTapEnabled = true;

            // This is event that will be fired when user releases the pointer after
            // pressing on the left edge of the ListViewItem
            ShoppingListView.ItemLeftEdgeTapped += OnEdgeTapped;

            // We set the state of the commands on the appbar
            SetCommandsVisibility(ShoppingListView);

            // This is how devs can handle the back button
            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            this._inflater = inflater;
            View view = inflater.Inflate(Resource.Layout.ic_tab_shopping_list, null);

            ViewModel = new ShoppingListViewModel(ServiceRegistrar.ShoppingService(MainActivity.SqliteConnection));

            _shoppingListView = view.FindViewById<ListView>(Resource.Id.ShoppingListView);

            var newItemEditText = view.FindViewById<EditText>(Resource.Id.NewItemEditText);

            Button addItemButton = view.FindViewById<Button>(Resource.Id.AddButton);

            _shoppingListView.Adapter = ViewModel.Items.GetAdapter(GetItemView);

            addItemButton.Click += delegate
            {
                var title = newItemEditText.Text;

                if (!string.IsNullOrEmpty(title))
                {
                    ViewModel.Add(new Item(title));
                }

                newItemEditText.Text = "";
            };

            _shoppingListView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs e)
            {
                ViewModel.Remove(this.ViewModel.Items.ElementAt(e.Position));
            };

            return view;
        }
        void Should_Be_Able_To_Add_Item()
        {
            // Arrange
            var shoppingService = new ShoppingService(_sqliteConnection);
            var vm = new ShoppingListViewModel(shoppingService);
            var item = new Item("some bought item");

            // Act
            vm.Add(item);

            // Assert
            Assert.Contains<Item>(vm.Items, x => x == item);
            Assert.Contains<Item>(shoppingService.Items, x => x == item);
        }
 public ShoppingListTableSource()
 {
     ViewModel = new ShoppingListViewModel(ServiceRegistrar.ShoppingService(Application.SqliteConnection));
 }