Inheritance: ToViewModelConverter
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);
            }
        }
Ejemplo n.º 2
0
        //
        // GET: /User/Create
        public ActionResult Edit(string userName)
        {
            try
            {
                UserProfileModel userProfile = null;
                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.Massage = "User Name is null or empty";
                    return RedirectToAction("FindUserData");
                }
                else
                {
                    var userProfielBase = UserProfileFacade.GetUserProfile(userName);
                    if (UserProfileFacade.CheckIfJustCreatedProfile(userProfielBase))
                    {
                        ViewBag.Massage = "User not exist.";
                        return RedirectToAction("FindUserData", new { userName = userName });
                    }
                    else
                    {
                        var converter = new ToViewModel();
                        userProfile = converter.ToUserProfileModel(userProfielBase);
                    }

                    if (userProfile.InsulinCalcProfile == null)
                    {
                        UserBaseInsulinCalcProfileModel userInsulineProfile = new PumpInsulinProfileModel();
                        userProfile.InsulinCalcProfile = userInsulineProfile;
                    }
                }

                ViewData["reductionUnits"] = DropDownListForHelper.GetSelectListForEnumType<UnitReductionUnits>();
                ViewData["dosageUnits"] = DropDownListForHelper.GetSelectListForEnumType<DosageUnits>();
                ViewData["pumps"] = DropDownListForHelper.GetSelectListForEnumType<PumpType>();
                ViewData["sexes"] = DropDownListForHelper.GetSelectListForEnumType<Sex>();

                return View(userProfile);
            }
            catch (Exception e)
            {
                log.ErrorFormat("[Edit] Error: Exception={0}.", e.Message);
                return View();
            }
        }
Ejemplo n.º 3
0
        public void ToViewModelTest_ShouldConverToViewModelRegularCarbohydrateLevel()
        {
            Dish dish1 = new Dish()
            {
                Name = "dish1",
                Description = "description1",
                NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 },
                BaseLineNutritionFacts = new NutritionFacts() { TotalCarbohydrate = 1 }
            };

            ToViewModelConverter converter = new ToViewModel();

            DishModel dishModel1 = converter.ToDishModel(dish1, "111111");

            Assert.IsTrue(dishModel1.NutritionFacts.TotalCarbohydrate == 2);
        }
Ejemplo n.º 4
0
        public void ToViewModelTest_ShouldConverWithMenuPartIdParameter()
        {
            Dish dish1 = new Dish()
            {
                Name = "dish1",
                Description = "description1",
                NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 },
                BaseLineNutritionFacts = new NutritionFacts() { TotalCarbohydrate = 1 }
            };

            ToViewModelConverter converter = new ToViewModel();

            DishModel dishModel1 = converter.ToDishModel(dish1, "111111", 3);

            Assert.IsTrue(dishModel1.MenuPartId == 3);
        }
Ejemplo n.º 5
0
        public string GetUserProfile(string userName)
        {
            try
            {
                UserProfileModel userProfile = null;
                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.Massage = "User Name is null or empty";
                }
                else
                {
                    var userProfielBase = UserProfileFacade.GetUserProfile(userName);
                    if (UserProfileFacade.CheckIfJustCreatedProfile(userProfielBase))
                    {
                        ViewBag.Massage = "User not exist.";
                    }
                    else
                    {
                        var converter = new ToViewModel();
                        userProfile = converter.ToUserProfileModel(userProfielBase);
                    }

                    if (userProfile.InsulinCalcProfile == null)
                    {
                        UserBaseInsulinCalcProfileModel userInsulineProfile = new PumpInsulinProfileModel();
                        //{
                        //    BirthDate = DateTime.UtcNow,
                        //    MinSugarRange = 110,
                        //    MaxSugarRange = 130,
                        //    Sex = Sex.Male,
                        //    UnitReductionValue = 1.2,
                        //    InsulinCarbohydrateRatio = 2,
                        //    Weight = 90
                        //};

                        //UserBaseInsulinCalcProfileModel userInsulineProfile = new RapidInsulinProfileModel()
                        //{
                        //    BirthDate = DateTime.Parse("25/05/1984"),
                        //    MinSugarRange = 110,
                        //    MaxSugarRange = 130,
                        //    Sex = Sex.Male,
                        //    UnitReductionValue = 1.2,
                        //    InsulinCarbohydrateRatio = 2,
                        //    Weight = 90,
                        //    BasalInsulinAmount = 3.4
                        //};
                        userProfile.InsulinCalcProfile = userInsulineProfile;
                    }
                }
                //var jsonResult = Json(userProfile, JsonRequestBehavior.AllowGet);
                //return jsonResult;
                var jsonResult = JsonConvert.SerializeObject(userProfile, Formatting.Indented, new StringEnumConverter());
                return jsonResult;
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[GetUserProfile] exception={0}.", ex);
                //return Json(null, JsonRequestBehavior.AllowGet);
                return null;
                //throw;
            }
        }
Ejemplo n.º 6
0
 public static UserBaseInsulinCalcProfileModel GetUserInsulinCalcProfileModel()
 {
     try
     {
         log.InfoFormat("[GetUserInsulinCalcProfileModel] ");
         UserBaseInsulinCalcProfileModel returnValue = null;
         UserBaseInsulinCalcProfile baseInsulinProfile = GetUserInsulinCalcProfile();
         if (baseInsulinProfile != null)
         {
             ToViewModel converter = new ToViewModel();
             returnValue = converter.ToUserBaseInsulinCalcProfileModel(baseInsulinProfile);
         }
         return returnValue;
     }
     catch (Exception e)
     {
         log.ErrorFormat("[GetUserInsulinCalcProfileModel] Error, Exception={0}.", e.Message);
         return null;
     }
 }
Ejemplo n.º 7
0
        public ActionResult FindUserData(string userName)
        {
            string userNameStr = string.IsNullOrEmpty(userName) ? "" : userName;
            log.InfoFormat("[FindUserData] userName={0}.", userNameStr);
            string returnString = "";
            UserBaseInsulinCalcProfileModel userInsulineProfile = null;
            try
            {
                if (!string.IsNullOrEmpty(userName))
                {
                    ProfileBase userProfile = UserProfileFacade.GetUserProfile(userName);
                    if (UserProfileFacade.CheckIfJustCreatedProfile(userProfile))
                    {
                        returnString = "User not exist.";
                    }
                    else
                    {
                        SpontaneousUserModel userData = userProfile.GetUserData();
                        if (userData != null)
                        {
                            ViewBag.LastActivityDate = userProfile.LastActivityDate;
                            ViewBag.LastUpdatedDate = userProfile.LastUpdatedDate;
                            ViewBag.UserName = userProfile.UserName;
                            ViewBag.IsAnonymous = userProfile.IsAnonymous;
                            ViewBag.UserType = userProfile.GetUserType();

                            if (userData.BaseInsulinCalcProfile != null)
                            {
                                var converter = new ToViewModel();
                                userInsulineProfile = converter.ToUserBaseInsulinCalcProfileModel(userData.BaseInsulinCalcProfile);
                            }

                            if(!string.IsNullOrEmpty(userProfile.UserName))
                            {
                                var roles = Roles.GetRolesForUser(userProfile.UserName);
                                ViewBag.UserRole = roles != null && roles.Length > 0 ? roles[0] : "";
                            }

                            string jsonResult = Newtonsoft.Json.JsonConvert.SerializeObject(userData);
                            returnString = jsonResult;
                        }
                        else
                        {
                            ViewBag.userProfileJson = "User data not found.";
                            returnString = "User data not found.";
                        }
                    }
                }
                else
                {
                    ViewBag.UserDataJson = "UserName invalid or empty, try again.";
                    returnString = "UserName invalid or empty, try again.";
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("[FindUserData] Exception={0}.", e.Message);
                ViewBag.UserDataJson(e.Message);
                returnString = e.Message;

            }
            ViewBag.UserDataJson = returnString;
            //return View((object)returnString);
            return View(userInsulineProfile);
        }