예제 #1
0
 private static void Verify <T>(PagedDataSet <T> pagedDataSet, int page, int pageSize, int totalCount)
     where T : Model, new()
 {
     Assert.AreEqual(page, pagedDataSet.Page);
     Assert.AreEqual(pageSize, pagedDataSet.PageSize);
     Assert.AreEqual(totalCount, pagedDataSet.TotalCount);
 }
예제 #2
0
        public void PagedDataSet_null_DataSet()
        {
            var expectedJson =
                @"[
   {
      ""Page"" : 0,
      ""PageSize"" : 0,
      ""TotalCount"" : 0,
      ""Data"" : null
   }
]";
            {
                var pagedDataSet = new PagedDataSet <SalesOrder>();
                Verify(pagedDataSet, 0, 0, 0);
                Assert.IsTrue(pagedDataSet.Data == null);

                Verify(pagedDataSet, expectedJson);
            }

            {
                var pagedDataSet = PagedDataSet <SalesOrder> .ParseJson(expectedJson);

                Verify(pagedDataSet, 0, 0, 0);
                Assert.IsTrue(pagedDataSet.Data == null);
            }
        }
예제 #3
0
        /// <summary>
        /// Deserializes JSON string into <see cref="PagedDataSet{T}"/> object.
        /// </summary>
        /// <param name="json">The JSON string.</param>
        /// <param name="customizer">The customizer for deserialization.</param>
        /// <returns>The deserialized object.</returns>
        public static PagedDataSet <T> ParseJson(string json, IJsonCustomizer customizer = null)
        {
            json.VerifyNotEmpty(nameof(json));

            var result  = new PagedDataSet <T>();
            var dataSet = result._dataSet;

            if (dataSet != null)
            {
                dataSet.RemoveAt(0);
            }
            JsonReader.Create(json, customizer).Deserialize(result._dataSet, true);
            return(dataSet.Count == 1 ? result : null);
        }
예제 #4
0
        public void PagedDataSet_not_null_DataSet()
        {
            var expectedJson =
                @"[
   {
      ""Page"" : 1,
      ""PageSize"" : 3,
      ""TotalCount"" : 10,
      ""Data"" : [
         {
            ""SalesOrderID"" : 71774,
            ""RevisionNumber"" : 2,
            ""OrderDate"" : ""2008-06-01T00:00:00"",
            ""DueDate"" : ""2008-06-13T00:00:00"",
            ""ShipDate"" : ""2008-06-08T00:00:00"",
            ""Status"" : 5,
            ""OnlineOrderFlag"" : false,
            ""PurchaseOrderNumber"" : ""PO348186287"",
            ""AccountNumber"" : ""10-4020-000609"",
            ""CustomerID"" : 29847,
            ""ShipToAddressID"" : 1092,
            ""BillToAddressID"" : 1092,
            ""ShipMethod"" : ""CARGO TRANSPORT 5"",
            ""CreditCardApprovalCode"" : null,
            ""TaxAmt"" : 70.4279,
            ""Freight"" : 22.0087,
            ""Comment"" : null,
            ""RowGuid"" : ""89e42cdc-8506-48a2-b89b-eb3e64e3554e"",
            ""ModifiedDate"" : ""2008-06-08T00:00:00"",
            ""SalesOrderDetails"" : [
               {
                  ""SalesOrderDetailID"" : 110562,
                  ""OrderQty"" : 1,
                  ""ProductID"" : 836,
                  ""UnitPrice"" : 356.8980,
                  ""UnitPriceDiscount"" : 0,
                  ""RowGuid"" : ""e3a1994c-7a68-4ce8-96a3-77fdd3bbd730"",
                  ""ModifiedDate"" : ""2008-06-01T00:00:00""
               },
               {
                  ""SalesOrderDetailID"" : 110563,
                  ""OrderQty"" : 1,
                  ""ProductID"" : 822,
                  ""UnitPrice"" : 356.8980,
                  ""UnitPriceDiscount"" : 0,
                  ""RowGuid"" : ""5c77f557-fdb6-43ba-90b9-9a7aec55ca32"",
                  ""ModifiedDate"" : ""2008-06-01T00:00:00""
               }
            ]
         }
      ]
   }
]";
            {
                var dataSet = DataSet <SalesOrder> .ParseJson(Json.SalesOrder_71774);

                var pagedDataSet = new PagedDataSet <SalesOrder>()
                {
                    Page       = 1,
                    PageSize   = 3,
                    TotalCount = 10,
                    Data       = dataSet
                };
                Verify(pagedDataSet, 1, 3, 10);
                Assert.IsTrue(pagedDataSet.Data == dataSet);
                Verify(pagedDataSet, expectedJson);
            }

            {
                var pagedDataSet = PagedDataSet <SalesOrder> .ParseJson(expectedJson);

                Verify(pagedDataSet, 1, 3, 10);
                Assert.IsTrue(pagedDataSet.Data.Count == 1);
                Verify(pagedDataSet, expectedJson);
            }
        }
예제 #5
0
 private static void Verify <T>(PagedDataSet <T> pagedDataSet, string json)
     where T : Model, new()
 {
     Assert.AreEqual(json, pagedDataSet.ToJsonString(true));
 }