public async Task IncrementCounter(string counterName) { var counter = (await counterService.GetAllCounters()).FirstOrDefault(c => c.Name.Equals(counterName)); if (counter == null) { return; } await counterService.IncrementCount(counter); messenger.PostMessage(await CreateCountersChangedMessage()); }
public async Task LoadCounters() { Counters.Clear(); var counters = await service.GetAllCounters().ConfigureAwait(false); foreach (var counter in counters) { var viewModel = new CounterViewModel(service, navigationService); viewModel.Prepare(counter); Counters.Add(viewModel); } }
public async Task LoadCounters() { Counters.Clear(); var counters = await service.GetAllCounters(); foreach (Counter c in counters) { var viewModel = new CounterViewModel(service); viewModel.Prepare(c); Counters.Add(viewModel); } }
public async Task LoadCounters() //LoadCounters loads the counters from the service and populates the observable collection with the view models prepared with counters { Counters.Clear(); //LoadCounters has been tweaked to clear all counters before reloading var counters = await service.GetAllCounters(); foreach (var counter in counters) //for each counter, create an instance of CountrViewModel, prepared using that counter and add to observable collection { var viewModel = new CountrViewModel(service, //The service is passed to the constructor of the CountrViewModel navigationService); //Passes the navigation service through to the CounterViewModel constructor viewModel.Prepare(counter); Counters.Add(viewModel); } }
public async Task LoadCounters() { Counters.Clear(); var counters = await service.GetAllCounters(); Console.WriteLine("Tatiana: inside LoadCounters() in CountersViewModel.cs; counters number = " + counters); foreach (var counter in counters) { var viewModel = new CounterViewModel(service, navigationService); viewModel.Prepare(counter); Counters.Add(viewModel); } }
public async Task LoadCounters() { var newCounters = new ObservableCollection <CounterViewModel>(); var counters = await service.GetAllCounters(); foreach (var counter in counters) { var viewModel = new CounterViewModel(service, navigationService); viewModel.Prepare(counter); newCounters.Add(viewModel); } Counters = newCounters; }
public async Task GetAllCounters_ReturnsAllCountersFromTheRepository() { var counters = new List <Counter> { new Counter { Name = "Counter1" }, new Counter { Name = "Counter2" } }; repo.Setup(r => r.GetAll()).ReturnsAsync(counters); var results = await service.GetAllCounters(); CollectionAssert.AreEqual(results, counters); }
public async Task GetAllCounters() { var counters = new List <Counter> { new Counter { Name = "counter1" }, new Counter { Name = "counter2" }, }; A.CallTo(() => _repo.GetAll()).Returns(counters); var result = await _subject.GetAllCounters(); result.ShouldBeSameAs(counters); }
public async Task LoadCounters_GetsCounters() { var counters = new List <Counter> { new Counter { Name = "one" }, new Counter { Name = "two" }, }; A.CallTo(() => _service.GetAllCounters()).Returns(counters); await _subject.LoadCounters(); _subject.Counters[0].Name.ShouldBe("one"); _subject.Counters[1].Name.ShouldBe("two"); }
public async Task GetAllCounters_GetFromRepository() { // Arrange var counters = new List <Counter>() { new Counter("AAA"), new Counter("BBB"), new Counter("CCC") }; repository.Setup(r => r.GetCounters()).ReturnsAsync(counters); //Act var result = await service.GetAllCounters(); // Assert repository.Verify(r => r.GetCounters()); Assert.AreEqual(counters, result); }
public async Task GetAllCounters_ReturnAllCountersFromTheRepository() { //Arrange var counters = new List <Counter> { new Counter { Name = "Counter1" }, new Counter { Name = "Counter2" } }; repo.Setup(r => r.GetAll()).ReturnsAsync(counters); //Sets up the GetAll method to return a defined list of counters //ACt var results = await service.GetAllCounters(); //Assert CollectionAssert.AreEqual(results, counters); //Asserts that the collections contain the same items }