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);
        }
示例#2
0
        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);
        }
示例#3
0
 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);
     }
 }
示例#4
0
 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));
     }
 }
示例#5
0
        private void DeleteAllData()
        {
            var conn = ConnectionUtil.GetConnectionString();

            using (var connection = ConnectionUtil.CreateConnection(conn))
            {
                connection.Execute($@"
TRUNCATE TABLE ""cap"".""published"";
TRUNCATE TABLE ""cap"".""received"";");
            }
        }
示例#6
0
        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}"";");
            }
        }
示例#7
0
        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;
        }
示例#8
0
        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;
        }
示例#9
0
        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);
        }
示例#10
0
 public SqlServerStorageTest()
 {
     _dbName = ConnectionUtil.GetDatabaseName();
     _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString();
     _dbConnectionString       = ConnectionUtil.GetConnectionString();
 }
示例#11
0
 public SqlServerStorageTest()
 {
     _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString();
     _dbConnectionString       = ConnectionUtil.GetConnectionString();
 }