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.
 
 
 

43 lines
1.2 KiB

  1. using Dapper;
  2. using Xunit;
  3. namespace DotNetCore.CAP.SqlServer.Test
  4. {
  5. [Collection("sqlserver")]
  6. public class SqlServerStorageTest : DatabaseTestHost
  7. {
  8. [Fact]
  9. public void Database_IsExists()
  10. {
  11. var master = ConnectionUtil.GetMasterConnectionString();
  12. using (var connection = ConnectionUtil.CreateConnection(master))
  13. {
  14. var databaseName = ConnectionUtil.GetDatabaseName();
  15. var sql = $@"
  16. IF EXISTS (SELECT * FROM sysdatabases WHERE name = N'{databaseName}')
  17. SELECT 'True'
  18. ELSE
  19. SELECT 'False'";
  20. var result = connection.QueryFirst<bool>(sql);
  21. Assert.True(result);
  22. }
  23. }
  24. [Theory]
  25. [InlineData("[Cap].[Published]")]
  26. [InlineData("[Cap].[Received]")]
  27. public void DatabaseTable_IsExists(string tableName)
  28. {
  29. using (var connection = ConnectionUtil.CreateConnection())
  30. {
  31. var sql = $@"
  32. IF OBJECT_ID(N'{tableName}',N'U') IS NOT NULL
  33. SELECT 'True'
  34. ELSE
  35. SELECT 'False'";
  36. var result = connection.QueryFirst<bool>(sql);
  37. Assert.True(result);
  38. }
  39. }
  40. }
  41. }