TweetHarbor.Controllers.AccountController.GlobalNotificationToggle C# (CSharp) 메소드

GlobalNotificationToggle() 개인적인 메소드

private GlobalNotificationToggle ( string TweetType, bool Value ) : System.Web.Mvc.JsonResult
TweetType string
Value bool
리턴 System.Web.Mvc.JsonResult
        public JsonResult GlobalNotificationToggle(string TweetType, bool Value)
        {
            if (null != HttpContext)
            {
                var u = database.Users.FirstOrDefault(usr => usr.UserName == HttpContext.User.Identity.Name);

                if (null != u)
                {
                    switch (TweetType)
                    {
                        case "SendPrivateTweet":
                            u.SendPrivateTweet = Value;
                            break;
                        case "SendPublicTweet":
                            u.SendPublicTweet = Value;
                            break;
                        case "SendSMS":
                            u.SendSMS = Value;
                            break;
                    }
                    database.SaveChanges();
                    return Json(new JsonResultModel() { Success = true, Message = "Value has been updated" });
                }
                else
                {
                    return Json(new JsonResultModel() { Error = "User Not Found", Success = false });
                }
            }
            return Json(new JsonResultModel() { Error = "Something", Success = false });
        }

Usage Example

        public void GlobalNotificationToggle_SendPublicTweet_True_Correct()
        {
            var db = new TestTweetHarborDbContext();
            var user = UserHelper.ArrangeNewUserDefault();

            db.Users.Add(user);

            var proj = new Project()
            {
                ProjectName = "The Test Project",
                SendPrivateTweetOnFailure = true,
                SendPrivateTweetOnSuccess = true,
                SendPublicTweetOnFailure = false,
                SendPublicTweetOnSuccess = true,
                User = user
            };

            db.Projects.Add(proj);
            var ts = new TestTweetHarborTwitterService();

            var auth = new Mock<IFormsAuthenticationWrapper>();

            var controller = new AccountController(db, ts, auth.Object);

            var ident = new GenericIdentity("localtestuser");
            System.Security.Principal.GenericPrincipal c = new System.Security.Principal.GenericPrincipal(ident, new string[] { });

            controller.SetFakeControllerContext(c);

            var res = controller.GlobalNotificationToggle("SendPublicTweet", true);
            Assert.IsInstanceOfType(res.Data, typeof(JsonResultModel));
            var rm = (JsonResultModel)res.Data;
            Assert.IsTrue(rm.Success);
            Assert.IsTrue(rm.Message == "Value has been updated");

            Assert.AreEqual(true, db.Users.FirstOrDefault(u => u.UserName == ident.Name).SendPublicTweet);
        }
All Usage Examples Of TweetHarbor.Controllers.AccountController::GlobalNotificationToggle