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       = "MySqlStorageConnectionTest",
                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("MySqlStorageConnectionTest", message.Name);
            Assert.Equal("mygroup", message.Group);
        }
Exemple #2
0
 public void DatabaseTable_IsExists(string tableName)
 {
     using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
     {
         var sql    = $"SELECT TABLE_NAME FROM `TABLES` WHERE TABLE_SCHEMA='{_dbName}' AND TABLE_NAME = '{tableName}'";
         var result = connection.QueryFirstOrDefault <string>(sql);
         Assert.NotNull(result);
         Assert.Equal(tableName, result);
     }
 }
Exemple #3
0
 public void Database_IsExists()
 {
     using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
     {
         var databaseName = ConnectionUtil.GetDatabaseName();
         var sql          = $@"SELECT SCHEMA_NAME FROM SCHEMATA WHERE SCHEMA_NAME = '{databaseName}'";
         var result       = connection.QueryFirstOrDefault <string>(sql);
         Assert.NotNull(result);
         Assert.True(databaseName.Equals(result, System.StringComparison.CurrentCultureIgnoreCase));
     }
 }
Exemple #4
0
        private void DeleteAllData()
        {
            var conn = ConnectionUtil.GetConnectionString();

            using (var connection = ConnectionUtil.CreateConnection(conn))
            {
                connection.Execute($@"
TRUNCATE TABLE `cap.published`;
TRUNCATE TABLE `cap.received`;");
            }
        }
Exemple #5
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}`;");
            }
        }
Exemple #6
0
        private void CreateServiceCollection()
        {
            var services = new ServiceCollection();

            services.AddOptions();
            services.AddLogging();

            _connectionString = ConnectionUtil.GetConnectionString();
            services.AddSingleton(new MySqlOptions {
                ConnectionString = _connectionString
            });
            services.AddSingleton <MySqlStorage>();

            _services = services;
        }
Exemple #7
0
        private void CreateServiceCollection()
        {
            var services = new ServiceCollection();

            services.AddOptions();
            services.AddLogging();

            _connectionString = ConnectionUtil.GetConnectionString();
            services.AddOptions <CapOptions>();
            services.Configure <MySqlOptions>(x => x.ConnectionString = _connectionString);

            services.AddSingleton <MySqlStorage>();

            _services = services;
        }
Exemple #8
0
        private void CreateServiceCollection()
        {
            var services = new ServiceCollection();

            services.AddOptions();
            services.AddLogging();

            ConnectionString = ConnectionUtil.GetConnectionString();
            services.AddOptions <CapOptions>();
            services.Configure <MySqlOptions>(x =>
            {
                x.ConnectionString = ConnectionString;
            });
            services.AddSingleton <MySqlDataStorage>();
            services.AddSingleton <IStorageInitializer, MySqlStorageInitializer>();
            _services = services;
        }
Exemple #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);
            }
            using (var fetchedMessage = await _storage.FetchNextMessageAsync())
            {
                Assert.NotNull(fetchedMessage);
                Assert.Equal(MessageType.Publish, fetchedMessage.MessageType);
                Assert.Equal(3333, fetchedMessage.MessageId);
            }
        }
Exemple #10
0
        public async Task GetPublishedMessageAsync_Test()
        {
            var sql            = "INSERT INTO `cap.published`(`Name`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`) VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);SELECT @@IDENTITY;";
            var publishMessage = new CapPublishedMessage
            {
                Name       = "MySqlStorageConnectionTest",
                Content    = "",
                StatusName = StatusName.Scheduled
            };
            var insertedId = default(int);

            using (var connection = ConnectionUtil.CreateConnection())
            {
                insertedId = connection.QueryFirst <int>(sql, publishMessage);
            }
            var message = await _storage.GetPublishedMessageAsync(insertedId);

            Assert.NotNull(message);
            Assert.Equal("MySqlStorageConnectionTest", message.Name);
            Assert.Equal(StatusName.Scheduled, message.StatusName);
        }
Exemple #11
0
 public MySqlStorageTest()
 {
     _dbName = ConnectionUtil.GetDatabaseName();
     _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString();
 }