PocoDataTests.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using PetaPoco.Core;
  3. using Shouldly;
  4. using Xunit;
  5. namespace PetaPoco.Tests.Unit.Core
  6. {
  7. public class PocoDataTests
  8. {
  9. [Fact]
  10. public void GetFactory_GivenTypeWithNotPublicConstructor_ShouldThrow()
  11. {
  12. var pd = PocoData.ForObject(TestEntity.Instance, "Id", new ConventionMapper());
  13. Should.Throw<InvalidOperationException>(() => pd.GetFactory("", "", 1, 1, null, null));
  14. }
  15. [Fact]
  16. public void PD_ResultColumn_NotInAutoSelect()
  17. {
  18. var pd = PocoData.ForType(typeof(PocoWithResultColumn), new ConventionMapper());
  19. pd.QueryColumns.ShouldBe(new[] { "RegularProperty" });
  20. }
  21. [Fact]
  22. public void PD_IncludedResultColumn_InAutoSelect()
  23. {
  24. var pd = PocoData.ForType(typeof(PocoWithIncludedResultColumn), new ConventionMapper());
  25. pd.QueryColumns.ShouldBe(new[] { "RegularProperty", "ResultProperty" });
  26. }
  27. public class TestEntity
  28. {
  29. public static TestEntity Instance => new TestEntity("");
  30. private TestEntity(string arg1)
  31. {
  32. }
  33. }
  34. public class PocoWithResultColumn
  35. {
  36. public string RegularProperty { get; set; }
  37. [ResultColumn]
  38. public string ResultProperty { get; set; }
  39. }
  40. public class PocoWithIncludedResultColumn
  41. {
  42. public string RegularProperty { get; set; }
  43. [ResultColumn(IncludeInAutoSelect.Yes)]
  44. public string ResultProperty { get; set; }
  45. }
  46. }
  47. }