예제 #1
0
        public void should_has_total_field_if_specified()
        {
            var model = new List<CategoryView>{
                    new CategoryView{Id=1, Name="Jere"},
                    new CategoryView{Id=2, Name="tom"}};

            var commonResult = new CommonActionResult(_requestRepoMock.Object, model, Delimiters.Default);
            commonResult.Total = 12;
            var ret = commonResult.ToString();

            Assert.Equal("{\"result\":0,\"desc\":\"成功\",\"count\":2,\"host\":null,\"total\":12,\"data\":[{\"Id\":1,\"Name\":\"Jere\"},{\"Id\":2,\"Name\":\"tom\"}]}", ret);
        }
예제 #2
0
        public void should_append_custom_header_values()
        {
            var model = new List<CategoryView>{
                    new CategoryView{Id=1, Name="Jere"},
                    new CategoryView{Id=2, Name="tom"}};

            var commonResult = new CommonActionResult(_requestRepoMock.Object, model, Delimiters.Default);
            commonResult.CustomResultHeaders.Add(new CustomHeaderItem { Key = "key1", Value = "value1", IsValueType = false });
            commonResult.CustomResultHeaders.Add(new CustomHeaderItem { Key = "key2", Value = "22", IsValueType = true });
            var ret = commonResult.ToString();

            Assert.Equal("{\"result\":0,\"desc\":\"成功\",\"count\":2,\"host\":null,\"key1\":\"value1\",\"key2\":22,\"data\":[{\"Id\":1,\"Name\":\"Jere\"},{\"Id\":2,\"Name\":\"tom\"}]}", ret);
        }