MssqlQueryLinqTests.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Shouldly;
  3. using Xunit;
  4. namespace PetaPoco.Tests.Integration.Databases.MSSQL
  5. {
  6. [Collection("Mssql")]
  7. public class MssqlQueryLinqTests : BaseQueryLinqTests
  8. {
  9. private readonly StorePerson _storePerson = new StorePerson
  10. {
  11. Id = Guid.NewGuid(),
  12. Age = 18,
  13. Name = "Peta"
  14. };
  15. public MssqlQueryLinqTests()
  16. : base(new MssqlDBTestProvider())
  17. {
  18. }
  19. [Fact]
  20. public void Exists_GivenPrimaryKeyMatchingOneRecordAndPocoWithSchema_ShouldBeTrue()
  21. {
  22. var pk = DB.Insert(_storePerson);
  23. DB.Exists<StorePerson>(pk).ShouldBeTrue();
  24. }
  25. [Fact]
  26. public void Exists_GivenSqlStringMatchingOneRecordAndPocoWithSchema_ShouldBeTrue()
  27. {
  28. DB.Insert(_storePerson);
  29. DB.Exists<StorePerson>($"WHERE {DB.Provider.EscapeSqlIdentifier("Age")} = @0", 18).ShouldBeTrue();
  30. }
  31. /// <summary>
  32. /// Support the older syntax of starting witha WHERE clause.
  33. /// </summary>
  34. [Fact]
  35. public void Exists_Regression_GivenSqlStringMatchingOneRecordAndPocoWithSchema_ShouldBeTrue()
  36. {
  37. DB.Insert(_storePerson);
  38. DB.Exists<StorePerson>($"{DB.Provider.EscapeSqlIdentifier("Age")} = @0", 18).ShouldBeTrue();
  39. }
  40. [TableName("store.People")]
  41. [PrimaryKey("Id", AutoIncrement = false)]
  42. public class StorePerson
  43. {
  44. [Column]
  45. public Guid Id { get; set; }
  46. [Column(Name = "FullName")]
  47. public string Name { get; set; }
  48. [Column]
  49. public long Age { get; set; }
  50. }
  51. }
  52. }