Ejemplo n.º 1
0
        public void Index_EmptyRequestParams_ReturnViewResultWithPagedCustomerList()
        {
            const string expectedCustomerFullName = "南宁财嘉";

            _mockICustomerInfoService.Setup(c => c.GetPagedCustomers()).Returns(new List <Customer> {
                new Customer {
                    CustomerFullName = expectedCustomerFullName
                }
            });
            CustomerInfoController controller = new CustomerInfoController(_mockICustomerInfoService.Object);
            ViewResult             result     = controller.Index() as ViewResult;
            var customers = (List <Customer>)result.ViewData.Model;

            Assert.AreEqual(expectedCustomerFullName, customers[0].CustomerFullName);
        }
Ejemplo n.º 2
0
        public void Index_EmptyRequestParams_ReturnViewDataWithMessageData()
        {
            const string           key = "Message", value = "MyHome";
            CustomerInfoController controller = new CustomerInfoController(_mockICustomerInfoService.Object);
            var httpContext = new Mock <HttpContextBase>();
            var request     = new Mock <HttpRequestBase>();
            var queryString = new NameValueCollection();

            queryString.Add(key, value);
            request.Setup(r => r.QueryString).Returns(queryString);
            httpContext.Setup(ht => ht.Request).Returns(request.Object);
            var controllerContext = new ControllerContext();

            controllerContext.HttpContext = httpContext.Object;
            controller.ControllerContext  = controllerContext;
            var result   = controller.Index() as ViewResult;
            var viewData = result.ViewData;

            Assert.AreEqual(value, viewData[key]);
        }