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.
 
 
 

71 rivejä
1.9 KiB

  1. using Xunit;
  2. using Dapper;
  3. namespace DotNetCore.CAP.SqlServer.Test
  4. {
  5. public class SqlServerStorageTest : DatabaseTestHost
  6. {
  7. [Fact]
  8. public void Database_IsExists()
  9. {
  10. var master = ConnectionUtil.GetMasterConnectionString();
  11. using (var connection = ConnectionUtil.CreateConnection(master))
  12. {
  13. var databaseName = ConnectionUtil.GetDatabaseName();
  14. var sql = $@"
  15. IF EXISTS (SELECT * FROM sysdatabases WHERE name = N'{databaseName}')
  16. SELECT 'True'
  17. ELSE
  18. SELECT 'False'";
  19. var result = connection.QueryFirst<bool>(sql);
  20. Assert.Equal(true, result);
  21. }
  22. }
  23. [Fact]
  24. public void DatabaseTable_Published_IsExists()
  25. {
  26. using (var connection = ConnectionUtil.CreateConnection())
  27. {
  28. var sql = @"
  29. IF OBJECT_ID(N'[CAP].[Published]',N'U') IS NOT NULL
  30. SELECT 'True'
  31. ELSE
  32. SELECT 'False'";
  33. var result = connection.QueryFirst<bool>(sql);
  34. Assert.Equal(true, result);
  35. }
  36. }
  37. [Fact]
  38. public void DatabaseTable_Queue_IsExists()
  39. {
  40. using (var connection = ConnectionUtil.CreateConnection())
  41. {
  42. var sql = @"
  43. IF OBJECT_ID(N'[CAP].[Queue]',N'U') IS NOT NULL
  44. SELECT 'True'
  45. ELSE
  46. SELECT 'False'";
  47. var result = connection.QueryFirst<bool>(sql);
  48. Assert.Equal(true, result);
  49. }
  50. }
  51. [Fact]
  52. public void DatabaseTable_Received_IsExists()
  53. {
  54. using (var connection = ConnectionUtil.CreateConnection())
  55. {
  56. var sql = @"
  57. IF OBJECT_ID(N'[CAP].[Received]',N'U') IS NOT NULL
  58. SELECT 'True'
  59. ELSE
  60. SELECT 'False'";
  61. var result = connection.QueryFirst<bool>(sql);
  62. Assert.Equal(true, result);
  63. }
  64. }
  65. }
  66. }