Esempio n. 1
0
        public void CanWritePageResultAllToJsonUsingNewtonsoftJsonConverter()
        {
            // Arrange
            Uri uri = new Uri("http://any");
            PageResult <PageCustomer> pageResult = new PageResult <PageCustomer>(_customers, uri, 4);
            JPageResultValueConverter converter  = new JPageResultValueConverter();

            // Act
            string json = SerializeUtils.WriteJson(converter, pageResult, true);

            // Assert
            Assert.Equal(@"{
  ""items"": [
    {
      ""Id"": 1,
      ""Name"": ""XU""
    },
    {
      ""Id"": 2,
      ""Name"": ""WU""
    }
  ],
  ""nextpagelink"": ""http://any"",
  ""count"": 4
}", json);
        }
Esempio n. 2
0
        public void CanConvertWorksForPageResult(Type type, bool expected)
        {
            // Arrange
            JPageResultValueConverter converter = new JPageResultValueConverter();

            // Act & Assert
            Assert.Equal(expected, converter.CanConvert(type));
        }
Esempio n. 3
0
        public void CanWritePageResultOnlyWithEnumerableToJsonUsingNewtonsoftJsonConverter()
        {
            // Arrange
            PageResult <PageCustomer> pageResult = new PageResult <PageCustomer>(_customers, null, null);
            JPageResultValueConverter converter  = new JPageResultValueConverter();

            // Act
            string json = SerializeUtils.WriteJson(converter, pageResult);

            // Assert
            Assert.Equal("{\"items\":[{\"Id\":1,\"Name\":\"XU\"},{\"Id\":2,\"Name\":\"WU\"}]}", json);
        }
Esempio n. 4
0
        public void ReadJsonForPageResultThrowsNotImplementedException()
        {
            // Arrange
            JPageResultValueConverter converter = new JPageResultValueConverter();

            // Act
            Action test = () => converter.ReadJson(null, typeof(object), null, null);

            // Assert
            NotImplementedException exception = Assert.Throws <NotImplementedException>(test);

            Assert.Equal(SRResources.ReadPageResultNotImplemented, exception.Message);
        }