示例#1
0
        public void Constructor_Sets_Data()
        {
            //Act
            var result = new JsonResult2(54);

            //Assert
            Assert.AreEqual(54, result.Data);
        }
示例#2
0
        public void ExecuteResult_With_ContentEncoding()
        {
            //Arrange
            var httpResponse = new FakeResponse();
            var httpContext = MockRepository.GenerateMock<HttpContextBase>();
            httpContext.Expect(x => x.Response).Return(httpResponse);
            var context = new ControllerContext(httpContext, new RouteData(), new TestController());
            var result = new JsonResult2 { Data = 54, ContentEncoding = Encoding.UTF32 };

            //Act
            result.ExecuteResult(context);

            //Assert
            Assert.AreEqual(Encoding.UTF32, httpResponse.ContentEncoding);
        }
示例#3
0
        public void ExecuteResult_Without_ContentType()
        {
            //Arrange
            var httpResponse = new FakeResponse();
            var httpContext = MockRepository.GenerateMock<HttpContextBase>();
            httpContext.Expect(x => x.Response).Return(httpResponse);
            var context = new ControllerContext(httpContext, new RouteData(), new TestController());
            var result = new JsonResult2 { Data = 54 };

            //Act
            result.ExecuteResult(context);

            //Assert
            Assert.AreEqual("application/json", httpResponse.ContentType);
        }
示例#4
0
        public void ExecuteResult_Serializes_Data()
        {
            //Arrange
            var httpResponse = new FakeResponse();
            var httpContext = MockRepository.GenerateMock<HttpContextBase>();
            httpContext.Expect(x => x.Response).Return(httpResponse);
            var context = new ControllerContext(httpContext, new RouteData(), new TestController());
            var result = new JsonResult2(new TestSerial {Number = 54});

            //Act
            result.ExecuteResult(context);

            //Assert
            httpResponse.OutputStream.Position = 0;
            var reader = new StreamReader(httpResponse.OutputStream);
            Assert.AreEqual("{\"Number\":54}", reader.ReadToEnd());
        }