You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Objects.cs 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using Luticate2.Auth.Utils.Business.Converters.ObjectConverterDescriptor;
  5. namespace Luticate2.Auth.Tests.Business.ObjectConverter
  6. {
  7. public static class StaticDbo
  8. {
  9. public static bool StaticField;
  10. public static bool StaticProperty { get; set; }
  11. }
  12. public class TestDbo1
  13. {
  14. public Guid Id { get; set; }
  15. public string Name { get; set; }
  16. public IList<TestDbo2> TestDbo2s { get; set; }
  17. public override string ToString()
  18. {
  19. throw new NotImplementedException();
  20. }
  21. }
  22. public class TestDbo2
  23. {
  24. public Guid Id { get; set; }
  25. public string Name { get; set; }
  26. public string NameVirtual { get; set; }
  27. public TestDbo1 TestDbo1 { get; set; }
  28. public TestDbo2 Parent { get; set; }
  29. public TestDbo1 Unused { get; set; }
  30. public int NotOptionalInt { get; set; }
  31. }
  32. public class TestModel1
  33. {
  34. public Guid id { get; set; }
  35. public string name { get; set; }
  36. public ICollection<TestModel2> test_model2 { get; set; }
  37. }
  38. public class TestModel2
  39. {
  40. public Guid id { get; set; }
  41. public string name { get; set; }
  42. public Guid test_model1_id { get; set; }
  43. public TestModel1 test_model1 { get; set; }
  44. public TestModel2 parent { get; set; }
  45. public int? optional_int { get; set; }
  46. }
  47. public class LuOcdTest1 : LuObjectConverterDescriptor<TestDbo1, TestModel1>
  48. {
  49. public LuOcdTest1()
  50. {
  51. AddStaticMemberConverter(x => x.Id, y => y.id);
  52. AddStaticMemberConverter(x => x.Name, y => y.name);
  53. AddStaticMemberConverter(x => x.TestDbo2s, y => y.test_model2);
  54. AddStaticMethodConverter(
  55. (Expression<Func<TestDbo1, string>>)(x => x.ToString()),
  56. (Expression<Func<TestModel1, string>>)(x => x.id + ": " + x.name)
  57. );
  58. }
  59. }
  60. public class LuOcdTest2 : LuObjectConverterDescriptor<TestDbo2, TestModel2>
  61. {
  62. public LuOcdTest2()
  63. {
  64. AddStaticMemberConverter(x => x.Id, y => y.id);
  65. AddStaticMemberConverter(x => x.Name, y => y.name);
  66. AddStaticMemberConverter(x => x.NameVirtual, y => y.name + " " + y.name);
  67. AddStaticMemberConverter(x => x.TestDbo1, y => y.test_model1);
  68. AddStaticMemberConverter(x => x.Parent, y => y.parent);
  69. AddStaticMemberConverter(x => x.NotOptionalInt, y => y.optional_int ?? -1);
  70. AddNullMemberConverter<TestDbo1>(x => x.Unused);
  71. }
  72. }
  73. }