public void CircumstancesGetterReturnsSubsetOfCicumstanceViewModelsProvidedInConstructor()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var expected = allCircumstances.Take(3);
     var actual = sut.Circumstances;
     Assert.AreEqual(expected, actual);
 }
 public void CircumstancesSetterDoesNotChangeWhenAssignedValueIsNotChanged()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var previous = sut.Circumstances;
     sut.Circumstances = previous.ToList();
     Assert.AreEqual(previous, sut.Circumstances);
     Assert.AreSame(previous, sut.Circumstances);
 }
 public void CircumstancesGetterReusesOnceComputedResult()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var actual1 = sut.Circumstances;
     var actual2 = sut.Circumstances;
     Assert.AreEqual(actual1, actual2);
     Assert.AreSame(actual1, actual2);
 }
 public void CircumstancesSetterInvalidatesGetterWhenAssignedValueIsChanged()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var previous = sut.Circumstances;
     var newValue = previous.ToList();
     newValue.Add(allCircumstances.Last());
     sut.Circumstances = newValue;
     Assert.AreEqual(newValue, sut.Circumstances);
     Assert.AreNotSame(previous, sut.Circumstances);
 }
 public void CircumstancesSetterAddsToModelWhenAssignedValueHasNewItems()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var previous = sut.Circumstances;
     var newValue = previous.ToList();
     newValue.Add(allCircumstances.Last());
     sut.Circumstances = newValue;
     Assert.AreEqual(newValue.Select(circumstance => circumstance.Id),
         insulin.Circumstances.Select(circumstance => circumstance.Id));
 }
 public void CircumstancesSetterRaisesOnPropertyChangedOnlyWhenChangeWasMade()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     sut.ChangesProperty("Circumstances", () =>
     {
         var newValue = sut.Circumstances.ToList();
         newValue.Add(allCircumstances.Last());
         sut.Circumstances = newValue;
     });
     sut.NotChangesProperty("Circumstances", () =>
     {
         sut.Circumstances = sut.Circumstances.ToList();
     });
 }
 public PatternViewModel(Pattern pattern, Factories factories,
     IList<InsulinCircumstanceViewModel> allCircumstances, bool hasAlternatives,
     IEnumerable<MealNameViewModel> names, MealNameViewModel defaultName, Navigator navigator, Action save,
     Action showAlternatives)
 {
     Pattern = pattern;
     Match = new MealItemViewModel(pattern.Match, factories);
     From = new MealViewModel(pattern.From, factories);
     From.Names = names;
     From.DefaultName = defaultName;
     Insulin = new InsulinViewModel(pattern.Insulin, factories, allCircumstances: allCircumstances);
     Before = new SugarViewModel(pattern.Before, factories);
     After = pattern.After
         .Select(sugar => new SugarViewModel(sugar, factories))
         .ToList();
     For = new MealItemViewModel(pattern.For, factories);
     HasAlternatives = hasAlternatives;
     this.navigator = navigator;
     this.save = save;
     this.showAlternatives = showAlternatives;
 }
 public void TestInitialize()
 {
     insulin = new InsulinViewModel(new Insulin(), Substitute.For<Factories>(), null);
     sugar = new SugarViewModel(new Sugar(), Substitute.For<Factories>());
     meal = new MealViewModel(new Meal(), Substitute.For<Factories>());
 }
 public void ChooseWhenInsulin()
 {
     var navigator = new Mock<Navigator>(); // Why this test isn't stable with NSubstitute instead of Moq?
     sut.Navigator = navigator.Object;
     var insulin = new Insulin { Id = Guid.NewGuid() };
     var viewModel = new InsulinViewModel(insulin, factories, new List<InsulinCircumstanceViewModel>());
     sut.Choose(viewModel);
     navigator.Verify(Navigator => Navigator.GoToInsulinEditing(insulin.Id));
 }
 public void TrivialProperties()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     Assert.AreEqual(insulin.Id, sut.Id);
     var universal = DateTime.UtcNow;
     sut.ChangesProperty("DateTime", () =>
     {
         sut.DateTime = universal;
     });
     Assert.AreEqual(universal.ToLocalTime(), sut.DateTime);
     Assert.AreEqual(universal.ToLocalTime().Date, sut.DateOnly);
     Assert.AreEqual(universal.ToLocalTime().ToShortDateInAlternativeFormat()
         + " " + universal.ToLocalTime().ToShortTimeString(), sut.DateAndTime);
     Assert.AreEqual(universal.ToLocalTime().ToShortTimeString(), sut.Time);
     Assert.AreEqual(universal.ToLocalTime().ToString("dddd") + ", " + sut.DateAndTime, sut.LongDateAndTime);
     Assert.AreEqual(insulin.Note, sut.Note);
     var note = new Fixture().Create<string>();
     sut.Note = note;
     Assert.AreEqual(note, insulin.Note);
     Assert.AreEqual(insulin.NormalBolus.ToStringOrEmpty(), sut.NormalBolus);
     sut.NormalBolus = "1.5";
     Assert.AreEqual(1.5f, insulin.NormalBolus);
     Assert.AreEqual(insulin.SquareWaveBolus.ToStringOrEmpty(), sut.SquareWaveBolus);
     sut.SquareWaveBolus = "2.5";
     Assert.AreEqual(2.5f, insulin.SquareWaveBolus);
     Assert.AreEqual(insulin.SquareWaveBolusHours.ToStringOrEmpty(), sut.SquareWaveBolusHours);
     sut.SquareWaveBolusHours = "3.5";
     Assert.AreEqual(3.5f, insulin.SquareWaveBolusHours);
 }
 public void TextAndText2()
 {
     insulin = new Insulin { Note = string.Empty };
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     sut.NormalBolus = "1";
     Assert.AreEqual("1 U", sut.Text);
     Assert.IsEmpty(sut.Text2);
     sut.SquareWaveBolus = "2";
     Assert.AreEqual("1 U 2 U for ? h", sut.Text);
     Assert.IsEmpty(sut.Text2);
     sut.SquareWaveBolusHours = "3";
     Assert.AreEqual("1 U 2 U for 3 h", sut.Text);
     Assert.IsEmpty(sut.Text2);
     sut.NormalBolus = "";
     Assert.AreEqual("2 U for 3 h", sut.Text);
     Assert.IsEmpty(sut.Text2);
     sut.Note = "note";
     Assert.AreEqual("2 U for 3 h", sut.Text);
     Assert.AreEqual("note", sut.Text2);
     sut.NormalBolus = "1";
     sut.SquareWaveBolus = "";
     Assert.AreEqual("1 U", sut.Text);
     Assert.AreEqual("note", sut.Text2);
 }
 public void Constraints()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     sut.NormalBolus = "4";
     Assert.AreEqual("3", sut.NormalBolus);
     sut.SquareWaveBolus = "4";
     Assert.AreEqual("3", sut.SquareWaveBolus);
     sut.SquareWaveBolusHours = "9";
     Assert.AreEqual("8", sut.SquareWaveBolusHours);
 }
 public void CircumstancesSummary()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var expected = allCircumstances[0].Name + ", " + allCircumstances[1].Name + ", " + allCircumstances[2].Name;
     var actual = sut.CircumstancesSummary;
     Assert.AreEqual(expected, actual);
 }
 public void CircumstancesSetterThrowsIfAssignedListIsTheSameInstance()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     var newValue = sut.Circumstances;
     sut.Circumstances = newValue;
 }
 public void CircumstancesSetterThrowsExceptionWhenAssignedValueIsNull()
 {
     var sut = new InsulinViewModel(insulin, factories, allCircumstances: allCircumstances);
     Assert.Throws<NullReferenceException>(() =>
     {
         sut.Circumstances = null;
     });
 }
 private void LoadUnsortedInsulins()
 {
     var models = factories.Insulins;
     unsortedInsulins = new List<InsulinViewModel>();
     foreach (var model in models)
     {
         var viewModel = new InsulinViewModel(model, factories, circumstances);
         unsortedInsulins.Add(viewModel);
     }
 }