Example #1
3
        public void CanGetResult()
        {
            var mediator = new Mediator();
            mediator.Subscribe<ChangeUserName, string>(message => new ReturnsName().Handle(message));

            var command = new ChangeUserName { Name = "Foo Bar" };
            var result = mediator.Send<ChangeUserName, string>(command);

            Assert.AreEqual("Foo Bar", result);
        }
Example #2
0
        public virtual async Task <ActionResult> Put(ChangeUserName command)
        {
            if (command == null)
            {
                return(View(MVC.Errors.Views.BadRequest));
            }

            var view = await _queries.Execute(new UserViewBy(command.UserId));

            if (view == null)
            {
                return(HttpNotFound());
            }

            if (!ModelState.IsValid)
            {
                var model = new ChangeUserNameModel
                {
                    UserView = view,
                    Command  = command,
                };

                return(View(MVC.Security.Views.User.Settings, model));
            }

            await _commands.Execute(command);

            Response.ClientCookie(command.SignedIn.Id, _queries);
            return(RedirectToAction(await MVC.UserName.Index()));
        }
Example #3
0
        public void CanSubscribeAIntResultWithoutAFunc()
        {
            var mediator = new Mediator();

            mediator.Subscribe<ChangeUserName, int>(message => new Returns42().Handle(message));

            var command = new ChangeUserName { Name = "Foo Bar" };
            var result = mediator.Send<ChangeUserName, int>(command);
            Assert.AreEqual(42, result);
        }
Example #4
0
        public void CanSendWithoutResult()
        {
            var mediator = new Mediator();

            var counter = new Counter();
            mediator.Subscribe<ChangeUserName>(counter.Handle);

            var command = new ChangeUserName { Name = "Foo Bar" };
            mediator.Send(command);
            Assert.AreEqual(1, counter.Count);
        }
Example #5
0
        public void CanGetResultWithASecondVoidHandler()
        {
            var mediator = new Mediator();

            mediator.Subscribe<ChangeUserName, string>(message =>
            {
                var r = new ReturnsName().Handle(message);
                new ConsoleLogger().Handle(message);
                return r;
            });

            var command = new ChangeUserName { Name = "Foo Bar" };
            var result = mediator.Send<ChangeUserName, string>(command);
            Assert.AreEqual("Foo Bar", result);
        }
Example #6
0
        public virtual ActionResult ValidatePut(ChangeUserName command)
        {
            //System.Threading.Thread.Sleep(new Random().Next(5000, 5001));
            if (command == null)
            {
                Response.StatusCode = 400;
                return Json(null);
            }

            var result = new ValidatedFields(ModelState);

            //ModelState[command.PropertyName(x => x.UserName)].Errors.Clear();
            //result = new ValidatedFields(ModelState, command.PropertyName(x => x.UserName));

            return new CamelCaseJsonResult(result);
        }
Example #7
0
        public virtual ActionResult ValidatePut(ChangeUserName command)
        {
            //System.Threading.Thread.Sleep(new Random().Next(5000, 5001));
            if (command == null)
            {
                Response.StatusCode = 400;
                return(Json(null));
            }

            var result = new ValidatedFields(ModelState);

            //ModelState[command.PropertyName(x => x.UserName)].Errors.Clear();
            //result = new ValidatedFields(ModelState, command.PropertyName(x => x.UserName));

            return(new CamelCaseJsonResult(result));
        }
Example #8
0
    //ユーザ名変更
    public static void changeName(string newName)
    {
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("user");

        query.WhereEqualTo("userName", getUserName());
        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            //検索成功したら
            if (e == null)
            {
                //HighScoreのほうの名前も変える
                NCMBQuery <NCMBObject> query2 = new NCMBQuery <NCMBObject>("HighScore");
                query2.WhereEqualTo("userName", getUserName());
                query2.FindAsync((List <NCMBObject> objList2, NCMBException e2) =>
                {
                    if (e2 == null)
                    {
                        objList2[0]["userName"] = newName;
                        objList2[0].SaveAsync();
                    }
                });


                objList[0]["userName"] = newName;

                objList[0].SaveAsync((NCMBException se) =>
                {
                    if (e == null)
                    {
                        NCMBUser.LogInAsync(newName, PlayerInformation.password);
                    }
                });

                userName = newName;
                PlayerInformation.setNamePass(newName, PlayerInformation.password);
                PhotonNetwork.playerName = newName;

                ChangeUserName.setMessage("変更しました");
            }
            else
            {
                ChangeUserName.setMessage("エラー" + e.ErrorCode + ":" + e.Message);
                return;
            }
        });
    }
Example #9
0
        public virtual async Task<ActionResult> Put(ChangeUserName command)
        {
            if (command == null) return View(MVC.Errors.Views.BadRequest);

            var view = await _queries.Execute(new UserViewBy(command.UserId));
            if (view == null) return HttpNotFound();

            if (!ModelState.IsValid)
            {
                var model = new ChangeUserNameModel
                {
                    UserView = view,
                    Command = command,
                };

                return View(MVC.Security.Views.User.Settings, model);
            }

            await _commands.Execute(command);
            Response.ClientCookie(command.SignedIn.Id, _queries);
            return RedirectToAction(await MVC.UserName.Index());
        }
Example #10
0
 public string Handle(ChangeUserName message)
 {
     return message.Name;
 }
Example #11
0
 public int Handle(ChangeUserName message)
 {
     return 42;
 }
Example #12
0
 public void Handle(ChangeUserName message)
 {
     //do persistence
 }
Example #13
0
 public void Handle(ChangeUserName message)
 {
     Count++;
 }
Example #14
0
 public void Handle(ChangeUserName message)
 {
     Console.WriteLine(message.Name);
 }