コード例 #1
0
ファイル: AccountController.cs プロジェクト: nivertech/Olive
        public ActionResult Edit(int accountId)
        {
            Contract.Requires<InvalidOperationException>(this.ClientService != null);
            Contract.Requires<InvalidOperationException>(this.SessionPersister != null);
            Contract.Requires<ArgumentException>(accountId > 0, "accountId");

            if (!this.SessionPersister.HasSession)
            {
                return this.RedirectToLogin();
            }

            var account = this.ClientService.GetAccount(this.SessionPersister.SessionId, accountId);

            var viewModel = new EditViewModel { AccountId = accountId, DisplayName = account.DisplayName };

            return this.View(viewModel);
        }
コード例 #2
0
ファイル: EditTests.cs プロジェクト: nivertech/Olive
        public void WithViewModelRendersWithoutExceptions()
        {
            var view = new Edit();

            try
            {
                RouteTable.Routes.Add("Account_Edit", new Route("Account/Edit/{accountId}", new MvcRouteHandler()));
            }
            catch (ArgumentException)
            {
                // Already exists, which is ok.
            }

            var viewModel = new EditViewModel { AccountId = 123, DisplayName = null };

            var html = view.RenderAsHtml(viewModel);
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: nivertech/Olive
        public ActionResult Edit(EditViewModel model)
        {
            Contract.Requires<InvalidOperationException>(this.ClientService != null);
            Contract.Requires<InvalidOperationException>(this.SessionPersister != null);
            Contract.Requires<ArgumentNullException>(model != null, "model");
            Contract.Requires<ArgumentException>(model.AccountId > 0, "model.AccountId > 0");
            ////Contract.Requires<ArgumentException>(model.AccountId == accountId, "model.AccountId == accountId");

            if (!this.SessionPersister.HasSession)
            {
                return this.RedirectToLogin();
            }

            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            this.ClientService.EditCurrentAccount(this.SessionPersister.SessionId, model.AccountId, model.DisplayName);
            return this.RedirectToAction(string.Empty, "Account");
        }
コード例 #4
0
ファイル: EditTests.cs プロジェクト: nivertech/Olive
        public void WithoutViewModelRendersWithoutExceptions()
        {
            var view = new Edit();

            var viewModel = new EditViewModel { AccountId = 612345 };

            try
            {
                RouteTable.Routes.Add("Account_Edit", new Route("Account/Edit/{accountId}", new MvcRouteHandler()));
            }
            catch (ArgumentException)
            {
                // Already exists, which is ok.
            }

            var html = view.RenderAsHtml(viewModel);

            Assert.IsNotNull(html.DocumentNode.SelectSingleNode("//form"), "Form missing");
            Assert.IsNotNull(
                html.DocumentNode.SelectSingleNode("//input[@type='text' and @name='DisplayName' and @value='']"),
                "DisplayName textbox missing.");
            Assert.IsNotNull(html.DocumentNode.SelectSingleNode("//input[@type='submit']"), "Submit button missing");
            Assert.IsNotNull(html.DocumentNode.SelectSingleNode("//a[@href='/Account']"), "Cancel link missing");
        }