コード例 #1
0
        public void CreateUpdatePortfolioReturnView()
        {
            portfolioService.Setup(c => c.CreateOrUpdatePortfolio(It.IsAny <PortfolioDTO>(), It.IsAny <string>()))
            .Returns((PortfolioDTO i, string id) => 1);
            mock = new Mock <PortfolioController>(portfolioService.Object)
            {
                CallBase = true
            };
            mock.SetupGet(p => p.Mapper).Returns(AutoMapperWebConfiguration.GetConfiguration().CreateMapper());
            portfolioController = mock.Object;
            var controllerContext = new Mock <ControllerContext>();
            var principal         = new Mock <IPrincipal>();

            principal.Setup(p => p.IsInRole("Administrator")).Returns(true);
            principal.SetupGet(x => x.Identity.Name).Returns("userName");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            portfolioController.ControllerContext = controllerContext.Object;

            var result = portfolioController.Save(new PortfolioModel {
                Id = 1, Name = "Update Name"
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual(1, portfolioController.TempData["PortfolioId"]);
        }
コード例 #2
0
        protected void Application_Start()
        {
            AutofacConfig.ConfigureContainer();
            MapperConfiguration = AutoMapperWebConfiguration.GetConfiguration();
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            log4net.Config.XmlConfigurator.Configure();
        }
コード例 #3
0
        public void CreatePortfolio_Success()
        {
            positionService.Setup(m => m.CreateOrUpdatePosition(It.IsAny <PositionDTO>(), It.IsAny <int?>()))
            .Callback((PositionDTO position, int?i) => ListPositions.Add(position));
            mock = new Mock <PositionController>(positionService.Object)
            {
                CallBase = true
            };
            mock.SetupGet(p => p.Mapper).Returns(AutoMapperWebConfiguration.GetConfiguration().CreateMapper());
            positionController = mock.Object;

            JsonResult result = (JsonResult)positionController.Save(new PositionModel {
                Id = 7
            }, 1);

            Assert.IsTrue(ListPositions.Count() == 4);
        }
コード例 #4
0
        public void CreatePortfolio_ReturnPartialViewWithData()
        {
            positionService.Setup(c => c.GetPosition(It.IsAny <int>()))
            .Returns((int i) => ListPositions.FirstOrDefault(c => c.Id == i));
            mock = new Mock <PositionController>(positionService.Object)
            {
                CallBase = true
            };
            mock.SetupGet(p => p.Mapper).Returns(AutoMapperWebConfiguration.GetConfiguration().CreateMapper());
            positionController = mock.Object;

            var result = positionController.Save(1) as PartialViewResult;

            Assert.IsNotNull(result);
            var resultPosition = (PositionModel)result.Model;

            Assert.IsTrue(resultPosition.Id == positionm1.Id);
            Assert.IsTrue(resultPosition.Name == positionm1.Name);
        }