コード例 #1
0
        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);
        }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
ファイル: DatabaseTestHost.cs プロジェクト: yimogit/CAP
        private void DeleteAllData()
        {
            var conn = ConnectionUtil.GetConnectionString();

            using (var connection = ConnectionUtil.CreateConnection(conn))
            {
                connection.Execute($@"
TRUNCATE TABLE cap.published;
TRUNCATE TABLE cap.received;");
            }
        }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
ファイル: DatabaseTestHost.cs プロジェクト: yimogit/CAP
        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};");
            }
        }
コード例 #6
0
        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}];");
            }
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
ファイル: TestHost.cs プロジェクト: yimogit/CAP
        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;
        }
コード例 #15
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);
        }
コード例 #16
0
ファイル: DatabaseTestHost.cs プロジェクト: zxrliuyan/CAP
        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();
        }
コード例 #17
0
        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);
        }
コード例 #18
0
ファイル: DatabaseTestHost.cs プロジェクト: zpc870921/CAP
        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);
                }
            }
        }
コード例 #19
0
ファイル: TestDbContext.cs プロジェクト: zhujinhu21/CAP
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionString = ConnectionUtil.GetConnectionString();

            optionsBuilder.UseSqlServer(connectionString);
        }
コード例 #20
0
 public SqlServerStorageTest()
 {
     _dbName = ConnectionUtil.GetDatabaseName();
     _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString();
 }