Esempio n. 1
0
        public async Task Post_Edit_with_invalid_modelState()
        {
            var form = new ClientEditorForm();

            controller.ModelState.AddModelError("somekey", "some error");

            var result = await controller.Edit(form) as ViewResult;

            Assert.AreEqual(result.Model, form, "it should redisplay the form");

            mediator.DidNotReceive()
            .SendAsync(Arg.Any <AddOrEditClientCommand>())
            .IgnoreAwaitForNSubstituteAssertion();
        }
Esempio n. 2
0
        public async Task Get_Create()
        {
            var form = new ClientEditorForm();

            mediator.SendAsync(Arg.Any <ClientEditorFormQuery>())
            .Returns(Task.FromResult(form));

            var result = await controller.Create() as ViewResult;

            Assert.AreEqual(result.Model, form);

            mediator.Received()
            .SendAsync(Arg.Any <ClientEditorFormQuery>())
            .IgnoreAwaitForNSubstituteAssertion();
        }
Esempio n. 3
0
        public async Task Post_Edit_with_vaid_model_state()
        {
            var form     = new ClientEditorForm();
            var clientId = 42;

            mediator.SendAsync(Arg.Any <AddOrEditClientCommand>())
            .Returns(Task.FromResult(new SuccessResult(clientId) as ICommandResult));

            var result = await controller.Edit(form) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual(result.RouteValues["action"], "Show", "it should redirect to the show page");
            Assert.AreEqual(result.RouteValues["id"], clientId, "it should redirect to the generated client id");
        }
Esempio n. 4
0
        public async Task Get_Edit_with_valid_id()
        {
            var id   = new int?(42);
            var form = new ClientEditorForm();

            mediator.SendAsync(Arg.Any <ClientEditorFormQuery>())
            .Returns(Task.FromResult(form));

            var result = await controller.Edit(id) as ViewResult;

            Assert.AreEqual(result.Model, form);

            mediator.Received()
            .SendAsync(Arg.Is <ClientEditorFormQuery>(q => q.ClientId == id))
            .IgnoreAwaitForNSubstituteAssertion();
        }
Esempio n. 5
0
        public async Task Post_Edit_with_vaid_model_state_failure()
        {
            var form          = new ClientEditorForm();
            var failureMesage = "some error text";

            mediator.SendAsync(Arg.Any <AddOrEditClientCommand>())
            .Returns(Task.FromResult(new FailureResult(failureMesage) as ICommandResult));

            var result = await controller.Edit(form) as ViewResult;

            Assert.AreEqual(result.Model, form);

            Assert.IsFalse(controller.ModelState.IsValid);

            Assert.IsTrue(controller.ModelState[""]
                          .Errors.Any(e => e.ErrorMessage.Equals(failureMesage)));
        }
Esempio n. 6
0
        public async Task <ActionResult> Create(ClientEditorForm form)
        {
            Logger.Trace("Create::Post");

            if (ModelState.IsValid)
            {
                var result = await mediator.SendAsync(new AddOrEditClientCommand(form, ModelState));

                if (result.IsSuccess)
                {
                    return(RedirectToAction("Show", new { Id = result.Result }));
                }

                ModelState.AddModelError("", result.Result.ToString());
            }

            return(View(form));
        }