public async Task GetReceivedMessageAsync_Test() { var sql = $@" INSERT INTO ""cap"".""received""(""Id"",""Name"",""Group"",""Content"",""Retries"",""Added"",""ExpiresAt"",""StatusName"") VALUES(@Id,@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; var insertedId = SnowflakeId.Default().NextId(); var receivedMessage = new CapReceivedMessage { Id = insertedId, Name = "PostgreSqlStorageConnectionTest", Content = "", Group = "mygroup", StatusName = StatusName.Scheduled }; using (var connection = ConnectionUtil.CreateConnection()) { await connection.ExecuteAsync(sql, receivedMessage); } var message = await _storage.GetReceivedMessageAsync(insertedId); Assert.NotNull(message); Assert.Equal(StatusName.Scheduled, message.StatusName); Assert.Equal("PostgreSqlStorageConnectionTest", message.Name); Assert.Equal("mygroup", message.Group); }
public async Task GetReceivedMessageAsync_Test() { var sql = $@" INSERT INTO ""cap"".""received""(""Name"",""Group"",""Content"",""Retries"",""Added"",""ExpiresAt"",""StatusName"") VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName) RETURNING ""Id"";"; var receivedMessage = new CapReceivedMessage { Name = "PostgreSqlStorageConnectionTest", 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("PostgreSqlStorageConnectionTest", message.Name); Assert.Equal("mygroup", message.Group); }
public void DatabaseTable_IsExists(string tableName) { using (var connection = ConnectionUtil.CreateConnection(_dbConnectionString)) { var sql = $"SELECT to_regclass('{tableName}') is not null;"; var result = connection.QueryFirstOrDefault <bool>(sql); Assert.True(result); } }
public void Database_IsExists() { using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString)) { var databaseName = ConnectionUtil.GetDatabaseName(); var sql = $@"select * from pg_database where datname = '{databaseName}'"; var result = connection.QueryFirstOrDefault <string>(sql); Assert.NotNull(result); Assert.True(databaseName.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"";"); } }
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 CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddSingleton(new PostgreSqlOptions { ConnectionString = _connectionString }); services.AddSingleton <PostgreSqlStorage>(); _services = services; }
private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); _connectionString = ConnectionUtil.GetConnectionString(); services.AddOptions <CapOptions>(); services.Configure <PostgreSqlOptions>(x => x.ConnectionString = _connectionString); services.AddSingleton <PostgreSqlStorage>(); _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); }
public SqlServerStorageTest() { _dbName = ConnectionUtil.GetDatabaseName(); _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString(); _dbConnectionString = ConnectionUtil.GetConnectionString(); }
public SqlServerStorageTest() { _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString(); _dbConnectionString = ConnectionUtil.GetConnectionString(); }