コード例 #1
0
ファイル: JsonResultTests.cs プロジェクト: jmkelly/Tinyweb
        public void ProcessResult_WhenCreatedWithCollection_ReturnsCorrectJsonRepresentation()
        {
            var response = new FakeResponseContext();
            var result = new JsonResult(new List<CustomType> { new CustomType { Data = "data1", Number = 1 }, new CustomType { Data = "data2", Number = 2 } });

            result.ProcessResult(null, response);

            Assert.That(response.ContentType, Is.EqualTo("application/json"));
            Assert.That(response.Response, Is.EqualTo("[{\"Data\":\"data1\",\"Number\":1},{\"Data\":\"data2\",\"Number\":2}]"));
        }
コード例 #2
0
ファイル: JsonResultTests.cs プロジェクト: jmkelly/Tinyweb
        public void ProcessResult_WhenCreatedWithCustomObject_ReturnsCorrectJsonRepresentation()
        {
            var response = new FakeResponseContext();
            var result = new JsonResult(new CustomType { Data = "data", Number = 50 });

            result.ProcessResult(null, response);

            Assert.That(response.ContentType, Is.EqualTo("application/json"));
            Assert.That(response.Response, Is.EqualTo("{\"Data\":\"data\",\"Number\":50}"));
        }
コード例 #3
0
ファイル: JsonResultTests.cs プロジェクト: jmkelly/Tinyweb
        public void ProcessResult_WhenCreatedWithAnonymousObject_ReturnsCorrectJsonRepresentation()
        {
            var response = new FakeResponseContext();
            var result = new JsonResult(new { message = "hello world", number = 42 });

            result.ProcessResult(null, response);

            Assert.That(response.ContentType, Is.EqualTo("application/json"));
            Assert.That(response.Response, Is.EqualTo("{\"message\":\"hello world\",\"number\":42}"));
        }