Пример #1
0
        public ViewResult AddOrEditPortfolio(int? id)
        {
            //if no id given, send user to an empty form
            if (id == null)
            {
                return View(new AdminPortfolioFull());
            }

            var project = _portfolioRepo.GetPortfolioProject((int)id);

            //otherwise, if project exists, load its info into 
            //the form to be edited
            if (project != null)
            {
                var model = new AdminPortfolioFull
                {
                    Description = project.Description,
                    Id = project.Id,
                    ImgUrl = project.ImgUrl,
                    LinkUrl = project.LinkUrl,
                    Name = project.Name,
                    Technologies = project.Technologies
                };
                return View(model);
            }

            //if it does not exist, send back to main portfolio project page
            return View("Portfolio", GetAllProjectsForVm());
        }
Пример #2
0
        public ActionResult AddOrEditPortfolio(AdminPortfolioFull model)
        {
            //if model state is valid, save the project to db
            if (ModelState.IsValid)
            {
                var project = new PortfolioProject
                {
                    Description = model.Description,
                    Id = model.Id,
                    ImgUrl = model.ImgUrl,
                    LinkUrl = model.LinkUrl,
                    Name = model.Name,
                    Technologies = model.Technologies
                };
                _portfolioRepo.SavePortfolioProject(project);
                return RedirectToAction("Portfolio");
            }

            //if model not valid, send user back to form with partial model
            return View(model);
        }
        public void CannotSaveInvalidPortfolioChanges()
        {
            var target = GetAdminController();
            target.ModelState.AddModelError("error", "error");

            var project = new AdminPortfolioFull
            {
                Id = 3,
                Name = "A New Project",
                Description = "desc",
                ImgUrl = "/Content",
                LinkUrl = "www.sample.com",
                Technologies = "C#, Java"
            };

            var result = target.AddOrEditPortfolio(project);
            portfolioMock.Verify(m => m.SavePortfolioProject(It.IsAny<PortfolioProject>()), Times.Never);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public void CanSaveValidPortfolioChanges()
        {
            var mockedBlog = new Mock<IBlogPostRepository>();
            var mockedPortfolio = new Mock<IPortfolioProjectRepository>();
            var target = new AdminController(mockedBlog.Object, mockedPortfolio.Object);

            var project = new AdminPortfolioFull
            {
                Id = 3,
                Name = "A New Project",
                Description = "desc",
                ImgUrl = "/Content",
                LinkUrl = "www.sample.com",
                Technologies = "C#, Java"
            };

            var sameProject = new PortfolioProject
            {
                Id = 3,
                Name = "A New Project",
                Description = "desc",
                ImgUrl = "/Content",
                LinkUrl = "www.sample.com",
                Technologies = "C#, Java"
            };
            
            //mockedPortfolio.Setup(m => m.SavePortfolioProject(sameProject)).Returns(sameProject);
            
            var result = target.AddOrEditPortfolio(project);

            portfolioMock.Verify(m => m.SavePortfolioProject(sameProject));

            Assert.IsInstanceOfType(result, typeof (RedirectResult));
        }