public void LoadsItems()
 {
     factories.Insulins.Returns(fixture.CreateMany<Insulin>(2).ToList());
     factories.Sugars.Returns(fixture.CreateMany<Sugar>(2).ToList());
     factories.Meals.Returns(fixture.CreateMany<Meal>(2).ToList());
     var date1 = DateTime.Today;
     var date2 = DateTime.Today.AddHours(3);
     factories.Meals.First().DateTime = date2;
     factories.Sugars.First().DateTime = date2;
     factories.Insulins.First().DateTime = date2;
     factories.Meals.ElementAt(1).DateTime = date1;
     factories.Sugars.ElementAt(1).DateTime = date1;
     factories.Insulins.ElementAt(1).DateTime = date1;
     var sut = new JournalViewModel.JournalLoader(viewModel);
     sut.LoadAsync();
     var expected = new DateTime[] { date1, date1, date1, date2, date2, date2 };
     var actual = viewModel.Items.Select(item => item.DateTime).ToList();
     Assert.AreEqual(expected, actual);
     var enumerator = viewModel.Items.GetEnumerator();
     enumerator.MoveNext();
     Assert.IsInstanceOf<MealViewModel>(enumerator.Current);
     enumerator.MoveNext();
     Assert.IsInstanceOf<SugarViewModel>(enumerator.Current);
     enumerator.MoveNext();
     Assert.IsInstanceOf<InsulinViewModel>(enumerator.Current);
     enumerator.MoveNext();
     Assert.IsInstanceOf<MealViewModel>(enumerator.Current);
     enumerator.MoveNext();
     Assert.IsInstanceOf<SugarViewModel>(enumerator.Current);
     enumerator.MoveNext();
     Assert.IsInstanceOf<InsulinViewModel>(enumerator.Current);
 }
 public void LoadsCircumstancesAndReturnsUnsorted()
 {
     var sut = new JournalViewModel.JournalLoader(factories, sortCircumstances: false, sortNames: false,
         workerFactory: new BackgroundWorkerSyncFactory());
     var expected = factories.InsulinCircumstances;
     var actual = sut.Circumstances;
     Assert.AreEqual(expected.Select(circumstance => circumstance.Id).ToList(),
         actual.Select(circumstance => circumstance.Id).ToList());
 }
 public void LoadsNamesAndReturnsSorted()
 {
     var sut = new JournalViewModel.JournalLoader(factories, sortCircumstances: false, sortNames: true,
         workerFactory: new BackgroundWorkerSyncFactory());
     var expected = factories.MealNames
         .OrderBy(name => name.Name);
     var actual = sut.Names;
     Assert.AreEqual(expected.Select(name => name.Id).ToList(),
         actual.Select(name => name.Id).ToList());
 }
 public void ProvidesNamesToMealViewModel()
 {
     factories.Meals.Returns(fixture.CreateMany<Meal>(1).ToList());
     var sut = new JournalViewModel.JournalLoader(viewModel);
     sut.LoadAsync();
     Assert.AreSame(sut.Names, viewModel.Items.Cast<MealViewModel>().First().Names);
 }
 public void ProvidesAllCircumstancesToInsulinViewModel()
 {
     factories.Insulins.Returns(fixture.CreateMany<Insulin>(1).ToList());
     var sut = new JournalViewModel.JournalLoader(viewModel);
     sut.LoadAsync();
     Assert.AreEqual(sut.Circumstances, viewModel.Items.Cast<InsulinViewModel>().First().AllCircumstances());
 }
 public void MakesDefaultName()
 {
     var sut = new JournalViewModel.JournalLoader(viewModel);
     Assert.AreEqual(factories.DefaultEntities.MealName.Name, sut.DefaultName.Name);
 }
 public void MakesDatesAndSortsMeals()
 {
     factories.Meals.Returns(fixture.CreateMany<Meal>(100).ToList());
     factories.Meals[0].DateTime = yesterday;
     factories.Meals[1].DateTime = today;
     for (int i = 2; i < 100; i++)
         factories.Meals[i].DateTime = today.AddDays(-i);
     var sut = new JournalViewModel.JournalLoader(viewModel);
     sut.LoadAsync();
     Assert.AreEqual(today, viewModel.Dates[0].Date);
     Assert.AreEqual(yesterday, viewModel.Dates[1].Date);
     Assert.AreEqual(today, viewModel.Items[0].Date.Date);
     Assert.AreEqual(yesterday, viewModel.Items[1].Date.Date);
     Assert.IsFalse(viewModel.Dates[viewModel.Dates.Count - 2].IsGroupOfOlder);
     Assert.IsTrue(viewModel.Dates[viewModel.Dates.Count - 1].IsGroupOfOlder);
 }
 public void MakesDatesAndSortsItems()
 {
     factories.Insulins.Returns(fixture.CreateMany<Insulin>(50).ToList());
     factories.Sugars.Returns(fixture.CreateMany<Sugar>(1).ToList());
     factories.Insulins[0].DateTime = yesterday;
     factories.Insulins[1].DateTime = today;
     for (int i = 2; i < 49; i++)
         factories.Insulins[i].DateTime = today.AddDays(-i);
     factories.Insulins[49].DateTime = factories.Insulins[48].DateTime.AddMinutes(2);
     factories.Sugars.First().DateTime = factories.Insulins[48].DateTime;
     var sut = new JournalViewModel.JournalLoader(viewModel);
     sut.LoadAsync();
     Assert.AreEqual(today, viewModel.Dates[0].Date);
     Assert.AreEqual(yesterday, viewModel.Dates[1].Date);
     Assert.AreEqual(today, viewModel.Items[0].Date.Date);
     Assert.AreEqual(yesterday, viewModel.Items[1].Date.Date);
     Assert.IsFalse(viewModel.Dates[viewModel.Dates.Count - 2].IsGroupOfOlder);
     Assert.IsTrue(viewModel.Dates[viewModel.Dates.Count - 1].IsGroupOfOlder);
     Assert.IsTrue(
         viewModel.Items.IndexOf(viewModel.Items.First(vm => vm.DateTime == factories.Insulins[48].DateTime)) >
         viewModel.Items.IndexOf(viewModel.Items.First(vm => vm.DateTime == factories.Insulins[49].DateTime)));
     Assert.IsInstanceOf<SugarViewModel>(viewModel.Items.ElementAt(viewModel.Items.Count - 2));
 }