Пример #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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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());
        }
Пример #7
0
 public string Handle(ChangeUserName message)
 {
     return message.Name;
 }
Пример #8
0
 public int Handle(ChangeUserName message)
 {
     return 42;
 }
Пример #9
0
 public void Handle(ChangeUserName message)
 {
     //do persistence
 }
Пример #10
0
 public void Handle(ChangeUserName message)
 {
     Count++;
 }
Пример #11
0
 public void Handle(ChangeUserName message)
 {
     Console.WriteLine(message.Name);
 }