PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/test/RestSharp.Serializers.Tests/IssueCases/Issue_1444.cs

http://github.com/restsharp/RestSharp
C# | 64 lines | 40 code | 9 blank | 15 comment | 0 complexity | d5c84be2cd5762a88f92dedc4bc156c8 MD5 | raw file
  1. // Copyright © 2009-2020 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using FluentAssertions;
  18. using NUnit.Framework;
  19. using RestSharp.Deserializers;
  20. using RestSharp.Serialization.Json;
  21. namespace RestSharp.Serializers.Tests.IssueCases
  22. {
  23. // https://github.com/restsharp/RestSharp/issues/1444
  24. public class Issue_1444
  25. {
  26. [Test]
  27. public void Complex_type_deserialized_with_SimpleJson()
  28. {
  29. const string json = @"{""panes"":{""filter"":{""records"":[{""data"":{""customernumber"":""10002""}}]}}}";
  30. var actual = (new JsonDeserializer()).Deserialize<FilterBaseModel>(new RestResponse {Content = json});
  31. actual.Panes.Filter.Records.First().Data.Number.Should().Be("10002");
  32. }
  33. class FilterBaseModel
  34. {
  35. public Panes Panes { get; set; }
  36. }
  37. class Panes
  38. {
  39. public Filter Filter { get; set; }
  40. }
  41. class Filter
  42. {
  43. public List<Record> Records { get; set; }
  44. }
  45. public class Record
  46. {
  47. public Data Data { get; set; }
  48. }
  49. public class Data
  50. {
  51. [DeserializeAs(Name = "customernumber")]
  52. public string Number { get; set; }
  53. }
  54. }
  55. }