Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

44 rindas
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].[Queue]")]
  27. [InlineData("[Cap].[Received]")]
  28. public void DatabaseTable_IsExists(string tableName)
  29. {
  30. using (var connection = ConnectionUtil.CreateConnection())
  31. {
  32. var sql = $@"
  33. IF OBJECT_ID(N'{tableName}',N'U') IS NOT NULL
  34. SELECT 'True'
  35. ELSE
  36. SELECT 'False'";
  37. var result = connection.QueryFirst<bool>(sql);
  38. Assert.True(result);
  39. }
  40. }
  41. }
  42. }