コード例 #1
0
        public void ExecuteResult_Ok()
        {
            //Arrange
            var data = new List <List <string> >()
            {
                new List <string> {
                    "hallo", "österreich"
                }
            };

            var httpRequest = new Mock <HttpRequestBase>();

            httpRequest.Setup(h => h.HttpMethod)
            .Returns("POST");
            var httpResponse = new Mock <HttpResponseBase>();

            httpResponse.Setup(x => x.ContentEncoding)
            .Returns(Encoding.UTF8);
            string result = string.Empty;

            httpResponse.Setup(x => x.Write(It.IsAny <string>()))
            .Callback((string s) => result = s);
            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(h => h.Request)
            .Returns(httpRequest.Object);
            httpContext.Setup(h => h.Response)
            .Returns(httpResponse.Object);
            DataTableResult dataTableResult = new DataTableResult("1", 10, 10, data);

            //Act
            dataTableResult.ExecuteResult(new ControllerContext {
                HttpContext = httpContext.Object
            });
            //Assert
            Assert.AreEqual(@"{""aaData"":[[""hallo"",""österreich""]],""iTotalDisplayRecords"":10,""iTotalRecords"":10,""sColumns"":null}", result);
        }