public async Task GetReceivedMessageAsync_Test() { var sql = $@" INSERT INTO [Cap].[Received]([Name],[Group],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) OUTPUT INSERTED.Id VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; var receivedMessage = new CapReceivedMessage { Name = "SqlServerStorageConnectionTest", Content = "", Group = "mygroup", StatusName = StatusName.Scheduled }; var insertedId = default(int); using (var connection = ConnectionUtil.CreateConnection()) { insertedId = connection.QueryFirst <int>(sql, receivedMessage); } var message = await _storage.GetReceivedMessageAsync(insertedId); Assert.NotNull(message); Assert.Equal(StatusName.Scheduled, message.StatusName); Assert.Equal("SqlServerStorageConnectionTest", message.Name); Assert.Equal("mygroup", message.Group); }
public void DatabaseTable_IsExists(string tableName) { using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString)) { var sql = $"SELECT TABLE_SCHEMA+'.'+TABLE_NAME FROM {_dbName}.INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA+'.'+TABLE_NAME='{tableName}'"; var result = connection.QueryFirstOrDefault <string>(sql); Assert.NotNull(result); Assert.True(tableName.Equals(result, System.StringComparison.CurrentCultureIgnoreCase)); } }
private void DeleteAllData() { var conn = ConnectionUtil.GetConnectionString(); using (var connection = ConnectionUtil.CreateConnection(conn)) { connection.Execute($@" TRUNCATE TABLE cap.published; TRUNCATE TABLE cap.received;"); } }
public void Database_IsExists() { using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString)) { var databaseName = ConnectionUtil.GetDatabaseName(); var sql = $@"select name From dbo.sysdatabases where name= '{databaseName}'"; var result = connection.QueryFirstOrDefault <string>(sql); Assert.NotNull(result); Assert.True(databaseName.Equals(result, System.StringComparison.CurrentCultureIgnoreCase)); } }
private void CreateDatabase() { var masterConn = ConnectionUtil.GetMasterConnectionString(); var databaseName = ConnectionUtil.GetDatabaseName(); using (var connection = ConnectionUtil.CreateConnection(masterConn)) { connection.Execute($@" DROP DATABASE IF EXISTS {databaseName}; CREATE DATABASE {databaseName};"); } }
private void CreateDatabase() { var masterConn = ConnectionUtil.GetMasterConnectionString(); var databaseName = ConnectionUtil.GetDatabaseName(); using (var connection = ConnectionUtil.CreateConnection(masterConn)) { connection.Execute($@" IF NOT EXISTS (SELECT * FROM sysdatabases WHERE name = N'{databaseName}') CREATE DATABASE [{databaseName}];"); } }
protected DatabaseTestHost() { Logger = new Mock <ILogger <SqlServerStorage> >().Object; CapOptions = new Mock <CapOptions>().Object; SqlSeverOptions = new SqlServerOptions() { ConnectionString = ConnectionUtil.GetConnectionString() }; DiagnosticProcessorObserver = new DiagnosticProcessorObserver(new Mock <IDispatcher>().Object); InitializeDatabase(); }
public void DatabaseTable_IsExists(string tableName) { using (var connection = ConnectionUtil.CreateConnection()) { var sql = $@" IF OBJECT_ID(N'{tableName}',N'U') IS NOT NULL SELECT 'True' ELSE SELECT 'False'"; var result = connection.QueryFirst <bool>(sql); Assert.True(result); } }
public void DatabaseTable_Received_IsExists() { using (var connection = ConnectionUtil.CreateConnection()) { var sql = @" IF OBJECT_ID(N'[Cap].[Received]',N'U') IS NOT NULL SELECT 'True' ELSE SELECT 'False'"; var result = connection.QueryFirst <bool>(sql); Assert.Equal(true, result); } }
private void InitializeDatabase() { var masterConn = ConnectionUtil.GetMasterConnectionString(); var databaseName = ConnectionUtil.GetDatabaseName(); using (var connection = ConnectionUtil.CreateConnection(masterConn)) { connection.Execute($@" IF NOT EXISTS (SELECT * FROM sysdatabases WHERE name = N'{databaseName}') CREATE DATABASE [{databaseName}];"); } new SqlServerStorage(Logger, CapOptions, SqlSeverOptions, DiagnosticProcessorObserver).InitializeAsync().GetAwaiter().GetResult(); SqlObjectInstalled = true; }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString }); services.AddSingleton <SqlServerStorage>(); _services = services; }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString }); services.AddSingleton <SqlServerStorage>(); services.AddDbContext <TestDbContext>(options => options.UseSqlServer(_connectionString)); _services = services; }
public void Database_IsExists() { var master = ConnectionUtil.GetMasterConnectionString(); using (var connection = ConnectionUtil.CreateConnection(master)) { var databaseName = ConnectionUtil.GetDatabaseName(); var sql = $@" IF EXISTS (SELECT * FROM sysdatabases WHERE name = N'{databaseName}') SELECT 'True' ELSE SELECT 'False'"; var result = connection.QueryFirst <bool>(sql); Assert.Equal(true, result); } }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); ConnectionString = ConnectionUtil.GetConnectionString(); services.AddOptions <CapOptions>(); services.Configure <SqlServerOptions>(x => { x.ConnectionString = ConnectionString; }); services.AddSingleton <SqlServerDataStorage>(); services.AddSingleton <IStorageInitializer, SqlServerStorageInitializer>(); _services = services; }
public async Task FetchNextMessageAsync_Test() { var sql = "INSERT INTO [Cap].[Queue]([MessageId],[MessageType]) VALUES(@MessageId,@MessageType);"; var queue = new CapQueue { MessageId = 3333, MessageType = MessageType.Publish }; using (var connection = ConnectionUtil.CreateConnection()) { connection.Execute(sql, queue); } var fetchedMessage = await _storage.FetchNextMessageAsync(); fetchedMessage.Dispose(); Assert.NotNull(fetchedMessage); Assert.Equal(MessageType.Publish, fetchedMessage.MessageType); Assert.Equal(3333, fetchedMessage.MessageId); }
protected DatabaseTestHost() { Logger = new Mock <ILogger <SqlServerStorage> >().Object; var capOptions = new Mock <IOptions <CapOptions> >(); capOptions.Setup(x => x.Value).Returns(new CapOptions()); CapOptions = capOptions.Object; var options = new Mock <IOptions <SqlServerOptions> >(); options.Setup(x => x.Value).Returns(new SqlServerOptions { ConnectionString = ConnectionUtil.GetConnectionString() }); SqlSeverOptions = options.Object; DiagnosticProcessorObserver = new DiagnosticProcessorObserver(new Mock <IDispatcher>().Object); InitializeDatabase(); }
public async Task GetPublishedMessageAsync_Test() { var sql = "INSERT INTO [Cap].[Published]([Id],[Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) VALUES(@Id,@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; var insertedId = SnowflakeId.Default().NextId(); var publishMessage = new CapPublishedMessage { Id = insertedId, Name = "SqlServerStorageConnectionTest", Content = "", StatusName = StatusName.Scheduled }; using (var connection = ConnectionUtil.CreateConnection()) { await connection.ExecuteAsync(sql, publishMessage); } var message = await _storage.GetPublishedMessageAsync(insertedId); Assert.NotNull(message); Assert.Equal("SqlServerStorageConnectionTest", message.Name); Assert.Equal(StatusName.Scheduled, message.StatusName); }
private void DeleteAllData() { var conn = ConnectionUtil.GetConnectionString(); using (var connection = new SqlConnection(conn)) { var commands = new[] { "DISABLE TRIGGER ALL ON ?", "ALTER TABLE ? NOCHECK CONSTRAINT ALL", "DELETE FROM ?", "ALTER TABLE ? CHECK CONSTRAINT ALL", "ENABLE TRIGGER ALL ON ?" }; foreach (var command in commands) { connection.Execute( "sp_MSforeachtable", new { command1 = command }, commandType: CommandType.StoredProcedure); } } }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = ConnectionUtil.GetConnectionString(); optionsBuilder.UseSqlServer(connectionString); }
public SqlServerStorageTest() { _dbName = ConnectionUtil.GetDatabaseName(); _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString(); }