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);
            }
        }
Пример #2
0
        public ActionResult Edit(UserProfileModel userProfile)
        {
            try
            {
                log.InfoFormat("[Edit] HttpPost.");
                if (ModelState.IsValid)
                {
                    ProfileBase profileBase = UserProfileFacade.GetUserProfile(userProfile.UserName);
                    string userTypeStr = userProfile.UserType;
                    if (!string.IsNullOrEmpty(userTypeStr))
                    {
                        profileBase.SetUserType(userTypeStr);
                    }

                    if (!string.IsNullOrEmpty(userProfile.UserRole) && Roles.RoleExists(userProfile.UserRole))
                    {
                        try
                        {
                            Roles.AddUserToRole(userProfile.UserName, userProfile.UserRole);
                        }
                        catch (Exception e)
                        {
                            ViewBag.UserRoleException = e.Message;
                        }
                    }
                    if (userProfile.InsulinCalcProfile != null)
                    {
                        profileBase.SetUserInsulinCalcProfile(userProfile.InsulinCalcProfile);
                    }
                    return RedirectToAction("FindUserData", new { userName = profileBase.UserName });
                }
                else
                {
                    ViewData["reductionUnits"] = DropDownListForHelper.GetSelectListForEnumType<UnitReductionUnits>(UnitReductionUnits.mmolL);
                    ViewData["dosageUnits"] = DropDownListForHelper.GetSelectListForEnumType<DosageUnits>(DosageUnits.mg);
                    ViewData["pumps"] = DropDownListForHelper.GetSelectListForEnumType<PumpType>(PumpType.RocheAccuChekCombo);
                    ViewData["sexes"] = DropDownListForHelper.GetSelectListForEnumType<Sex>(Sex.Male);
                    return View(userProfile);
                }

            }
            catch (Exception e)
            {
                log.ErrorFormat("[Edit] HttpPost: Error Exception={0}.", e.Message);
                ViewBag.Exception = e.Message;
                return View(userProfile);
            }
        }
Пример #3
0
 //public override RestaurantModel ToRestaurantModel(RestaurantBasicData restaurantData, bool withMenu = true, string lang = DefaultLang)
 //{
 //    return restaurantData.ToRestaurantModel(withMenu, lang);
 //}
 public UserProfileModel ToUserProfileModel(ProfileBase profileBase)
 {
     UserProfileModel userProf = null;
     if (profileBase != null)
     {
         userProf = new UserProfileModel()
         {
             UserName = profileBase.UserName,
             UserType = profileBase.GetUserType()
         };
         if (!string.IsNullOrEmpty(userProf.UserName))
         {
             var userRoles = Roles.GetRolesForUser(userProf.UserName);
             userProf.UserRole = userRoles != null && userRoles.Length > 0 ? userRoles[0] : "";
         }
         var userData = profileBase.GetUserData();
         if (userData != null && userData.BaseInsulinCalcProfile != null)
         {
             userProf.InsulinCalcProfile = ToUserBaseInsulinCalcProfileModel(userData.BaseInsulinCalcProfile);
         }
     }
     return userProf;
 }