/// <summary> /// Updates the list of items in the model using the ItemCollector /// Called at specific interval from models timer /// Fires the <see cref="LoadingListEvent"/> both before and after /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void UpdateShoppingList(object sender = null, ElapsedEventArgs e = null) { try { if (_loginModel.Username != null) { if (LoadingListEvent != null) { LoadingListEvent(this, new LoadingEvent(LoadingEvent.LoadingState.Started)); } ShoppingList = (await _itemCollector.GetAll(_loginModel.Username)).ToList(); if (LoadingListEvent != null) { LoadingListEvent(this, new LoadingEvent(LoadingEvent.LoadingState.Done)); } } } catch (Exception ex) { Log.File.Exception(ex); if (LoadingListEvent != null) { LoadingListEvent(this, new LoadingEvent(LoadingEvent.LoadingState.Error)); } } }
public void Constructor_CollectorReturns4Items_SutHolds4Items() { _itemCollector.GetAll("Henrik").Returns(new List <Item>() { new Item(), new Item(), new Item(), new Item() }); _shoppingListModel = new ScheduledShoppingListModel(_itemCollector, _scheduler, _loginModel); _sut = new ShoppingListViewModel(_shoppingListModel); Assert.That(_sut.ShoppingList.Count, Is.EqualTo(4)); }
public void AddItem_CollectorGetAllReturnsId3_ItemToAddIdis3() { Item testItem = new Item() { ItemId = 0, Name = "Hej" }; //_collector.Add(new Item(), 0).ReturnsForAnyArgs(3); _collector.GetAll("").ReturnsForAnyArgs(new List <Item>() { new Item() { ItemId = 3, Name = "Hej" } }); _uut.AddItem(testItem); Assert.That(_uut.ShoppingList[0].ItemId, Is.EqualTo(3)); }