Spontaneous.WebApp.Services.ModelConverter.ToViewModel.ToUserBaseInsulinCalcProfileModel C# (CSharp) Method

ToUserBaseInsulinCalcProfileModel() public method

public ToUserBaseInsulinCalcProfileModel ( UserBaseInsulinCalcProfile baseProfile ) : UserBaseInsulinCalcProfileModel
baseProfile Spontaneous.DataModel.UserBaseInsulinCalcProfile
return Spontaneous.WebApp.Models.UserBaseInsulinCalcProfileModel
        public UserBaseInsulinCalcProfileModel ToUserBaseInsulinCalcProfileModel(UserBaseInsulinCalcProfile baseProfile)
        {
            UserBaseInsulinCalcProfileModel returnProfile = null;
            if (baseProfile != null)
            {
                if(baseProfile is PumpInsulinProfile)
                {
                    returnProfile = new PumpInsulinProfileModel()
                    {
                        PumpType = (baseProfile as PumpInsulinProfile).PumpType
                    };
                }
                else if(baseProfile is RapidInsulinProfile)
                {
                    returnProfile = new RapidInsulinProfileModel()
                    {
                        BasalInsulinAmount = (baseProfile as RapidInsulinProfile).BasalInsulinAmount
                    };
                }

                returnProfile.BirthDate = baseProfile.BirthDate;
                returnProfile.DosageUnits = baseProfile.DosageUnits;
                returnProfile.InsulinCarbohydrateRatio = baseProfile.InsulinCarbohydrateRatio;
                returnProfile.MaxSugarRange = baseProfile.MaxSugarRange;
                returnProfile.MinSugarRange = baseProfile.MinSugarRange;
                returnProfile.Sex = baseProfile.Sex;
                returnProfile.UnitReductionValue = baseProfile.UnitReductionValue;
                returnProfile.UnitReductionUnits = baseProfile.UnitReductionUnits;
                returnProfile.Weight = baseProfile.Weight;
            }
            return returnProfile;
        }

Usage Example

Ejemplo n.º 1
0
        public void UserInfoEditTest_Post_ShouldRedirectToUserInfoController_FindUserData()
        {
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

            if (createStatus == MembershipCreateStatus.Success || AccountValidation.ErrorCodeToString(createStatus) == "Username already exists. Please enter a different user name.")
            {

                UserInfoController controller = new UserInfoController();
                UserProfileModel profileModel = new UserProfileModel()
                {
                    UserName = "******"
                };
                profileModel.InsulinCalcProfile = new PumpInsulinProfileModel()
                {
                    BirthDate = DateTime.Parse("25/05/1984"),
                    MinSugarRange = 110,
                    MaxSugarRange = 130,
                    Sex = Sex.Male,
                    UnitReductionValue = 1.2,
                    InsulinCarbohydrateRatio = 2,
                    Weight = 90,
                    PumpType = PumpType.InsuletOmniPod
                };

                // Act
                ActionResult result = controller.Edit(profileModel);

                ProfileBase userProfile = UserProfileFacade.GetUserProfile(model.UserName);
                SpontaneousUserModel userData = userProfile.GetUserData();
                var converter = new ToViewModel();
                UserBaseInsulinCalcProfileModel userInsulineProfile = converter.ToUserBaseInsulinCalcProfileModel(userData.BaseInsulinCalcProfile);

                // Assert

                Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
                RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
                Assert.AreEqual("UserInfo", redirectResult.RouteValues["controller"]);
                Assert.AreEqual("FindUserData", redirectResult.RouteValues["action"]);

                Assert.IsNotNull(userData.BaseInsulinCalcProfile);
                Assert.IsTrue(userData.BaseInsulinCalcProfile is PumpInsulinProfile);
                Assert.IsTrue(userInsulineProfile is PumpInsulinProfileModel);

            }
            else
            {
                Assert.IsNotNull(null);
            }
        }
All Usage Examples Of Spontaneous.WebApp.Services.ModelConverter.ToViewModel::ToUserBaseInsulinCalcProfileModel