Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        public void ExecuteResult_Uses_XmlSerializer()
        {
            //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 XmlResult(new NonDataContractTestSerial { Number = 54 });

            //Act
            result.ExecuteResult(context);

            //Assert
            httpResponse.OutputStream.Position = 0;
            var reader = new StreamReader(httpResponse.OutputStream);
            Assert.Contains(reader.ReadToEnd(), "<Number>54</Number>");
        }
Пример #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());
        }
Пример #5
0
        public void ExecuteResult_With_XNode()
        {
            //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 node = new XDocument();
            node.AddFirst(" \t ");
            var result = new XmlResult {Data = node};

            //Act
            result.ExecuteResult(context);

            //Assert
            Assert.AreEqual(" \t ", httpResponse.TestString);
        }