示例#1
0
 public void FindInsulinCircumstanceById()
 {
     var expected = new InsulinCircumstance { Id = Guid.NewGuid() };
     factories.Setup(f => f.InsulinCircumstances).Returns(new List<InsulinCircumstance> { expected });
     var finder = new FinderImpl(factories.Object);
     var actual = finder.FindInsulinCircumstanceById(expected.Id);
     Assert.AreSame(expected, actual);
 }
示例#2
0
 public void FindInsulinByMeal_IfNoInsulinsInHour_ReturnsNull()
 {
     var insulin1 = new Insulin { DateTime = DateTime.Now.AddHours(1.1) };
     var insulin2 = new Insulin { DateTime = DateTime.Now.AddHours(-1.1) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin1, insulin2 });
     var finder = new FinderImpl(factories.Object);
     var meal = new Meal { DateTime = DateTime.Now };
     var insulin = finder.FindInsulinByMeal(meal);
     Assert.IsNull(insulin);
 }
示例#3
0
 public void FindInsulinByMeal_IfTwoInsulinsInHour_ReturnsCloserInsulin()
 {
     var insulin1 = new Insulin { DateTime = DateTime.Now.AddHours(0.9) };
     var insulin2 = new Insulin { DateTime = DateTime.Now.AddHours(-0.8) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin1, insulin2 });
     var finder = new FinderImpl(factories.Object);
     var meal = new Meal { DateTime = DateTime.Now };
     var insulin = finder.FindInsulinByMeal(meal);
     Assert.AreSame(insulin2, insulin);
 }
示例#4
0
 public FactoriesImpl()
 {
     factoryCreator = new FactoryCreator(this);
     Finder = new FinderImpl(this);
     DefaultEntities = new DefaultEntitiesImpl(this);
 }
示例#5
0
 public void FindMealByInsulin_IfMealInHourAfter_ReturnsMeal()
 {
     var meal1 = new Meal { DateTime = DateTime.Now.AddHours(0.9) };
     var meal2 = new Meal { DateTime = DateTime.Now.AddHours(-1.1) };
     factories.Setup(f => f.Meals).Returns(new List<Meal> { meal1, meal2 });
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var meal = finder.FindMealByInsulin(insulin);
     Assert.AreSame(meal1, meal);
 }
示例#6
0
 public void FindSugarsAfterInsulin_IfSugarsInFourHoursAfter_ReturnsThoseSugars()
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddHours(1) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddHours(3.5) };
     var sugar3 = new Sugar { DateTime = DateTime.Now.AddHours(5) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2, sugar3 });
     factories.Setup(f => f.Insulins).Returns(new List<Insulin>());
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var sugars = finder.FindSugarsAfterInsulin(insulin, 4);
     Assert.IsTrue(Enumerable.SequenceEqual(new List<Sugar> { sugar1, sugar2 }, sugars));
 }
示例#7
0
 public void FindSugarsAfterInsulin_SortsReturnedSugarsChronologically()
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddHours(2) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddHours(1) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2 });
     factories.Setup(f => f.Insulins).Returns(new List<Insulin>());
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var sugars = finder.FindSugarsAfterInsulin(insulin, 4);
     Assert.IsTrue(Enumerable.SequenceEqual(new List<Sugar> { sugar2, sugar1 }, sugars));
 }
示例#8
0
 public void FindSugarsAfterInsulin_IfAnotherInsulinSoonerThanFourHoursLater_ReturnsOnlySugarsBeforeThisInsulin(
     int removeMinutes)
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddHours(1) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddHours(2) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2 });
     var insulin1 = new Insulin { DateTime = DateTime.Now };
     var insulin2 = new Insulin { DateTime = sugar2.DateTime.AddMinutes(-removeMinutes) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin1, insulin2 });
     var finder = new FinderImpl(factories.Object);
     var sugars = finder.FindSugarsAfterInsulin(insulin1, 4);
     Assert.IsTrue(Enumerable.SequenceEqual(new List<Sugar> { sugar1 }, sugars));
 }
示例#9
0
 public void FindSugarsAfterInsulin_IfNoSugarsInThreeHoursAfter_ReturnsEmpty()
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddHours(3.1) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddHours(-1) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2 });
     factories.Setup(f => f.Insulins).Returns(new List<Insulin>());
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var sugars = finder.FindSugarsAfterInsulin(insulin, 3);
     Assert.AreEqual(0, sugars.Count);
 }
示例#10
0
 public void FindSugarsAfterInsulin_DoesntReturnSugarsWhichIsAtSameTimeAsInsulin()
 {
     var sugar = new Sugar { DateTime = DateTime.Now };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar });
     factories.Setup(f => f.Insulins).Returns(new List<Insulin>());
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = sugar.DateTime };
     var sugars = finder.FindSugarsAfterInsulin(insulin, 2);
     Assert.IsEmpty(sugars);
 }
示例#11
0
 public void FindSugarsAfterInsulin_IfAnotherInsulinFourHoursLater_DoesntReturnSugarsFourHoursLater()
 {
     var now = DateTime.Now;
     var sugar1 = new Sugar { DateTime = now.AddHours(4) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1 });
     var insulin1 = new Insulin { DateTime = now };
     var insulin2 = new Insulin { DateTime = now.AddHours(4) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin1, insulin2 });
     var finder = new FinderImpl(factories.Object);
     var sugars = finder.FindSugarsAfterInsulin(insulin1, 4);
     Assert.IsEmpty(sugars);
 }
示例#12
0
 public void FindSugarBeforeInsulin_ReturnsSugarWhichIsAtSameTimeAsInsulin()
 {
     var sugar = new Sugar { DateTime = DateTime.Now };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar });
     factories.Setup(f => f.Insulins).Returns(new List<Insulin>());
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = sugar.DateTime };
     var foundSugar = finder.FindSugarBeforeInsulin(insulin);
     Assert.AreSame(sugar, foundSugar);
 }
示例#13
0
 public void FindSugarBeforeInsulin_IfTwoSugarsInAQuarter_ReturnsLatestSugar()
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddMinutes(-14) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddMinutes(-10) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2 });
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var sugar = finder.FindSugarBeforeInsulin(insulin);
     Assert.AreSame(sugar2, sugar);
 }
示例#14
0
 public void FindSugarBeforeInsulin_IfNoSugarsInAQuarterBefore_ReturnsNull()
 {
     var sugar1 = new Sugar { DateTime = DateTime.Now.AddMinutes(5) };
     var sugar2 = new Sugar { DateTime = DateTime.Now.AddMinutes(-16) };
     factories.Setup(f => f.Sugars).Returns(new List<Sugar> { sugar1, sugar2 });
     var finder = new FinderImpl(factories.Object);
     var insulin = new Insulin { DateTime = DateTime.Now };
     var sugar = finder.FindSugarBeforeInsulin(insulin);
     Assert.IsNull(sugar);
 }
示例#15
0
 public void FindNextInsulin_ReturnsNullIfNoNextInsulin()
 {
     var insulin1 = new Insulin { DateTime = DateTime.Now };
     var insulin2 = new Insulin { DateTime = DateTime.Now.AddHours(-1) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin2 });
     var finder = new FinderImpl(factories.Object);
     var insulin = finder.FindNextInsulin(insulin1);
     Assert.IsNull(insulin);
 }
示例#16
0
 public void FindNextInsulin_ReturnsFirstChronologicallyFollowingInsulin()
 {
     var insulin1 = new Insulin { DateTime = DateTime.Now };
     var insulin2 = new Insulin { DateTime = DateTime.Now.AddHours(2) };
     var insulin3 = new Insulin { DateTime = DateTime.Now.AddHours(1) };
     factories.Setup(f => f.Insulins).Returns(new List<Insulin> { insulin2, insulin3 });
     var finder = new FinderImpl(factories.Object);
     var insulin = finder.FindNextInsulin(insulin1);
     Assert.AreSame(insulin3, insulin);
 }