Inheritance: UserBaseInsulinCalcProfile
        public void CreaeteFromMealAndUserDataTest_ShouldCreateUserMealProfileObjectWithCorrectCalculatedCarbsDeviation_and_MealCarbsAmount_Properies()
        {
            Meal userMeal = new Meal()
            {
                Id = Guid.NewGuid(),
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170,
                CarbAmount = 85
            };
            string userName = "******";
            UserBaseInsulinCalcProfile insulineProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 40,
                InsulinCarbohydrateRatio = 12.5,
                MaxSugarRange = 150
            };
            SpontaneousUserModel userData = new SpontaneousUserModel()
            {
                BaseInsulinCalcProfile = insulineProfile,
            };

            //act
            UserMealProfileFactory mealFactory = new UserMealProfileFactory();
            UserMealProfile mealProfile = mealFactory.CreaeteFromMealAndUserData(userMeal, userName, userData);

            AlgorithmCalculations.AlgorithmResult algResult = AlgorithmCalculations.CalcMealCarbsDeviation(userMeal, mealProfile.UserInsulinProfile);

            //assert
            Assert.IsNotNull(mealProfile);
            Assert.AreEqual(mealProfile.CalculatedCarbsDeviation, algResult.Result);
            Assert.AreEqual(mealProfile.MealCarbsAmount, mealProfile.ExpectedCarbsAmount + algResult.Result);
        }
        public void CreaeteFromMealAndUserDataTest_ShouldCreateUserMealProfileObjectWithAllRelevantDataOfInputParameters()
        {
            Meal userMeal = new Meal()
            {
                Id = Guid.NewGuid(),
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            string userName = "******";
            UserBaseInsulinCalcProfile insulineProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 40,
                InsulinCarbohydrateRatio = 12.5,
                MaxSugarRange = 150
            };
            SpontaneousUserModel userData = new SpontaneousUserModel()
            {
                BaseInsulinCalcProfile = insulineProfile,
            };

            //act
            UserMealProfileFactory mealFactory = new UserMealProfileFactory();
            UserMealProfile mealProfile = mealFactory.CreaeteFromMealAndUserData(userMeal, userName, userData);

            //assert
            Assert.IsNotNull(mealProfile);
            Assert.AreEqual(mealProfile.MealId, userMeal.Id);
            Assert.AreEqual(mealProfile.UserName, userName);
            Assert.AreEqual(mealProfile.UserInsulinProfile, insulineProfile);
        }
        public UserBaseInsulinCalcProfile ToInsulinProfileBaseModel(UserBaseInsulinCalcProfileModel insulinProfile)
        {
            UserBaseInsulinCalcProfile returnValue = null;
            if(insulinProfile is PumpInsulinProfileModel)
            {
                returnValue = new PumpInsulinProfile()
                {
                    PumpType = ((PumpInsulinProfileModel)insulinProfile).PumpType
                };
            }
            else if(insulinProfile is RapidInsulinProfileModel)
            {
                returnValue = new RapidInsulinProfile()
                {
                    BasalInsulinAmount = ((RapidInsulinProfileModel)insulinProfile).BasalInsulinAmount
                };
            }
            //returnValue.BirthDate = insulinProfile.BirthDate;
            returnValue.DosageUnits = insulinProfile.DosageUnits;
            returnValue.InsulinCarbohydrateRatio = insulinProfile.InsulinCarbohydrateRatio;
            returnValue.MaxSugarRange = insulinProfile.MaxSugarRange;
            returnValue.MinSugarRange = insulinProfile.MinSugarRange;
            returnValue.Sex = insulinProfile.Sex;
            returnValue.UnitReductionValue = insulinProfile.UnitReductionValue;
            returnValue.UnitReductionUnits = insulinProfile.UnitReductionUnits;
            returnValue.Weight = insulinProfile.Weight;

            return returnValue;
        }
        public void VerifyMealCarbsTest_ShouldConvertUnitsToMgDlIfMmolL()
        {
            Meal meal = new Meal()
            {
                CarbAmount = 30,
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            UserBaseInsulinCalcProfile insulinCalcProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 2.4975,
                UnitReductionUnits = UnitReductionUnits.mmolL,
                InsulinCarbohydrateRatio = 12.5,
                DosageUnits = DosageUnits.IU,
                MaxSugarRange = 150
            };

            var carbsDeviation = AlgorithmCalculations.CalcMealCarbsDeviation(meal, insulinCalcProfile);

            //Assert
            Assert.AreEqual(Convert.ToInt32(carbsDeviation.Result), 33);
        }
        public void VerifyMealCarbsTest_ShouldReturnExtreamNegativeDoubleIfNoNecesseryParameters()
        {
            Meal correctMeal = new Meal()
            {
                CarbAmount = 30,
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            Meal meal1 = new Meal()
            {
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            Meal meal2 = new Meal()
            {
                CarbAmount = 30,
                PostMealSugarLevel = 170
            };
            Meal meal3 = new Meal()
            {
                CarbAmount = 30,
                PreMealSugarLevel = 290
            };
            UserBaseInsulinCalcProfile correctInsulinCalcProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 45,
                UnitReductionUnits = UnitReductionUnits.mgDL,
                InsulinCarbohydrateRatio = 12.5,
                DosageUnits = DosageUnits.IU,
                MaxSugarRange = 150
            };
            UserBaseInsulinCalcProfile insulinCalcProfile1 = new RapidInsulinProfile()
            {
                UnitReductionUnits = UnitReductionUnits.mgDL,
                InsulinCarbohydrateRatio = 12.5,
                DosageUnits = DosageUnits.IU,
                MaxSugarRange = 150
            };
            UserBaseInsulinCalcProfile insulinCalcProfile2 = new RapidInsulinProfile()
            {
                UnitReductionValue = 45,
                UnitReductionUnits = UnitReductionUnits.mgDL,
                DosageUnits = DosageUnits.IU,
                MaxSugarRange = 150
            };
            UserBaseInsulinCalcProfile insulinCalcProfile3 = new RapidInsulinProfile()
            {
                UnitReductionValue = 45,
                UnitReductionUnits = UnitReductionUnits.mgDL,
                InsulinCarbohydrateRatio = 12.5,
                DosageUnits = DosageUnits.IU,
            };

            var carbsDeviation1 = AlgorithmCalculations.CalcMealCarbsDeviation(meal1, correctInsulinCalcProfile);
            var carbsDeviation2 = AlgorithmCalculations.CalcMealCarbsDeviation(meal2, correctInsulinCalcProfile);
            var carbsDeviation3 = AlgorithmCalculations.CalcMealCarbsDeviation(meal3, correctInsulinCalcProfile);
            var carbsDeviation4 = AlgorithmCalculations.CalcMealCarbsDeviation(correctMeal, insulinCalcProfile1);
            var carbsDeviation5 = AlgorithmCalculations.CalcMealCarbsDeviation(correctMeal, insulinCalcProfile2);
            var carbsDeviation6 = AlgorithmCalculations.CalcMealCarbsDeviation(correctMeal, insulinCalcProfile3);

            //Assert
            Assert.AreEqual(carbsDeviation1.Status, "Unsuccess");
            Assert.AreEqual(carbsDeviation2.Status, "Unsuccess");
            Assert.AreEqual(carbsDeviation3.Status, "Unsuccess");
            Assert.AreEqual(carbsDeviation4.Status, "Unsuccess");
            Assert.AreEqual(carbsDeviation5.Status, "Unsuccess");
            Assert.AreEqual(carbsDeviation6.Status, "Unsuccess");
        }
        public void CreaeteFromMealAndUserDataTest_ShouldReturnNullIfOneOfInputParametersIsNullOrEmpty()
        {
            Meal userMeal = new Meal()
            {
                Id = Guid.NewGuid(),
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            string userName = "******";
            UserBaseInsulinCalcProfile insulineProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 40,
                InsulinCarbohydrateRatio = 12.5,
                MaxSugarRange = 150
            };
            SpontaneousUserModel userData = new SpontaneousUserModel()
            {
                BaseInsulinCalcProfile = insulineProfile,
            };

            //act
            UserMealProfileFactory mealFactory = new UserMealProfileFactory();
            UserMealProfile mealProfile1 = mealFactory.CreaeteFromMealAndUserData(null, userName, userData);
            UserMealProfile mealProfile2 = mealFactory.CreaeteFromMealAndUserData(userMeal, null, userData);
            UserMealProfile mealProfile3 = mealFactory.CreaeteFromMealAndUserData(userMeal, userName, null);

            //assert
            Assert.IsNull(mealProfile1);
            Assert.IsNull(mealProfile2);
            Assert.IsNull(mealProfile3);
        }