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 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); }
void Should_Be_Able_To_Remove_Item() { // Arrange var shoppingService = new ShoppingService(_sqliteConnection); var vm = new ShoppingListViewModel(shoppingService); var item = new Item("some bought item"); vm.Add(item); // Act vm.Remove(item); // Assert Assert.DoesNotContain <Item>(vm.Items, x => x == item); Assert.DoesNotContain <Item>(shoppingService.Items, x => x == item); }
void Should_Be_Able_To_Remove_Item() { // Arrange var vm = new ShoppingListViewModel(_shoppingService); var item = new Item("some item to remove"); vm.Add(item); // Act vm.Remove(item); // Assert Assert.DoesNotContain <Item>(vm.Items, x => x == item); Assert.DoesNotContain <Item>(_shoppingService.Items, x => x == item); Assert.DoesNotContain <Item>(_shoppingService.BoughtItems, x => x == item); }