public PastPurchases() { this.InitializeComponent(); ViewModel = new PastPurchasesViewModel(ServiceRegistrar.ShoppingService(App.SqliteConnection)); PastPurchasesListView.ItemsSource = ViewModel.Items; // Developer will want to return to none selection when selected items are zero PastPurchasesListView.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 PastPurchasesListView.IsItemLeftEdgeTapEnabled = true; // This is event that will be fired when user releases the pointer after // pressing on the left edge of the ListViewItem PastPurchasesListView.ItemLeftEdgeTapped += OnEdgeTapped; // We set the state of the commands on the appbar SetCommandsVisibility(PastPurchasesListView); // This is how devs can handle the back button SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; }
public void Add_Item() { // Arrange var shoppingService = new ShoppingService(_sqliteConnection); var vm = new PastPurchasesViewModel(shoppingService); var item = new BoughtItem("item 1"); // Act vm.Add(item); // Assert Assert.Contains<BoughtItem>(vm.Items, x => x == item); }
public void Copy_Item_To_Shopping_List() { // Arrange var shoppingService = new ShoppingService(_sqliteConnection); var vm = new PastPurchasesViewModel(shoppingService); var itemTitle = "item1"; var item = new BoughtItem(itemTitle); vm.Add(item); // Act vm.CopyItemToShoppingList(item); // Assert Assert.Equal(1, shoppingService.Items.Count); Assert.Contains<Item>(shoppingService.Items, x => x.Title == itemTitle); }
public void Add_Item_Already_Added() { // Arrange var shoppingService = new ShoppingService(_sqliteConnection); var vm = new PastPurchasesViewModel(shoppingService); var item = new BoughtItem("item 1"); vm.Add(item); var item2 = new BoughtItem("item 1"); // Act vm.Add(item); // Assert Assert.Equal(1, vm.Items.Count); Assert.Equal(2, vm.Items.First().BoughtCount); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this._inflater = inflater; View view = inflater.Inflate(Resource.Layout.ic_tab_past_purchases, null); ViewModel = new PastPurchasesViewModel(ServiceRegistrar.ShoppingService(MainActivity.SqliteConnection)); _pastPurchasesListView = view.FindViewById<ListView>(Resource.Id.PastPurchasesListView); _pastPurchasesListView.Adapter = ViewModel.Items.GetAdapter(GetItemView); _pastPurchasesListView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs e) { ViewModel.CopyItemToShoppingList(this.ViewModel.Items.ElementAt(e.Position)); }; return view; }
public PastPurchasesTableSource() { ViewModel = new PastPurchasesViewModel(ServiceRegistrar.ShoppingService(Application.SqliteConnection)); }