diff --git a/appveyor.yml b/appveyor.yml index 4185499..05802e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,7 +4,7 @@ environment: BUILDING_ON_PLATFORM: win BuildEnvironment: appveyor Cap_SqlServer_ConnectionStringTemplate: Server=(local)\SQL2014;Database={0};User ID=sa;Password=Password12! - Cap_MySql_ConnectionStringTemplate: Server=localhost;Database={0};Uid=root;Pwd=Password12! + Cap_MySql_ConnectionStringTemplate: Server=localhost;Database={0};Uid=root;Pwd=Password12!;Allow User Variables=True Cap_PostgreSql_ConnectionStringTemplate: Server=localhost;Database={0};UserId=postgres;Password=Password12! services: - mssql2014 diff --git a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs index ae559e5..f803e26 100644 --- a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs +++ b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs @@ -10,7 +10,7 @@ namespace Sample.RabbitMQ.MySql { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySql("Server=localhost;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;"); + optionsBuilder.UseMySql("Server=localhost;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;Allow User Variables=True"); //optionsBuilder.UseMySql("Server=192.168.2.206;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;"); } } diff --git a/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs b/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs index cd42410..7059515 100644 --- a/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs +++ b/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs @@ -41,8 +41,8 @@ namespace DotNetCore.CAP.MySql public Task FetchNextMessageAsync() { var sql = $@" -SELECT @MessageId:=`MessageId` as MessageId, @MessageType:=`MessageType` as MessageType FROM `{_prefix}.queue` LIMIT 1; -DELETE FROM `{_prefix}.queue` where `MessageId` = @MessageId AND `MessageType`=@MessageType;"; +SELECT @MId:=`MessageId` as MessageId, @MType:=`MessageType` as MessageType FROM `{_prefix}.queue` LIMIT 1; +DELETE FROM `{_prefix}.queue` where `MessageId` = @MId AND `MessageType`=@MType;"; return FetchNextMessageCoreAsync(sql); } diff --git a/test/DotNetCore.CAP.MySql.Test/ConnectionUtil.cs b/test/DotNetCore.CAP.MySql.Test/ConnectionUtil.cs index eafee54..9d79882 100644 --- a/test/DotNetCore.CAP.MySql.Test/ConnectionUtil.cs +++ b/test/DotNetCore.CAP.MySql.Test/ConnectionUtil.cs @@ -12,7 +12,7 @@ namespace DotNetCore.CAP.MySql.Test private const string DefaultDatabaseName = @"DotNetCore.CAP.MySql.Test"; private const string DefaultConnectionStringTemplate = - @"Server=localhost;Database={0};Uid=root;Pwd=123123;"; + @"Server=localhost;Database={0};Uid=root;Pwd=123123;Allow User Variables=True;"; public static string GetDatabaseName() { diff --git a/test/DotNetCore.CAP.MySql.Test/MySqlStorageConnectionTest.cs b/test/DotNetCore.CAP.MySql.Test/MySqlStorageConnectionTest.cs index a9e56d5..fd8f99d 100644 --- a/test/DotNetCore.CAP.MySql.Test/MySqlStorageConnectionTest.cs +++ b/test/DotNetCore.CAP.MySql.Test/MySqlStorageConnectionTest.cs @@ -52,11 +52,12 @@ namespace DotNetCore.CAP.MySql.Test { 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); + using (var fetchedMessage = await _storage.FetchNextMessageAsync()) + { + Assert.NotNull(fetchedMessage); + Assert.Equal(MessageType.Publish, fetchedMessage.MessageType); + Assert.Equal(3333, fetchedMessage.MessageId); + } } [Fact] diff --git a/test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs b/test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs index a105ae2..de07787 100644 --- a/test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs +++ b/test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs @@ -48,7 +48,7 @@ namespace DotNetCore.CAP.Test [Theory] [InlineData(nameof(Sample.ThrowException))] [InlineData(nameof(Sample.AsyncMethod))] - public async void InvokeMethodTest(string methodName) + public void InvokeMethodTest(string methodName) { var methodInfo = typeof(Sample).GetRuntimeMethods() .Single(x => x.Name == methodName); @@ -64,10 +64,10 @@ namespace DotNetCore.CAP.Test var invoker = consumerInvokerFactory.CreateInvoker(context); - await Assert.ThrowsAsync(typeof(Exception), async () => + Assert.Throws(() => { - await invoker.InvokeAsync(); - }); + invoker.InvokeAsync().GetAwaiter().GetResult(); + }); } } } \ No newline at end of file diff --git a/test/DotNetCore.CAP.Test/OperateResultTest.cs b/test/DotNetCore.CAP.Test/OperateResultTest.cs index 62cedae..5788f19 100644 --- a/test/DotNetCore.CAP.Test/OperateResultTest.cs +++ b/test/DotNetCore.CAP.Test/OperateResultTest.cs @@ -11,7 +11,7 @@ namespace DotNetCore.CAP.Test var result = new OperateResult(); Assert.False(result.Succeeded); - Assert.Equal(0, result.Errors.Count()); + Assert.Empty(result.Errors); } [Fact] @@ -20,7 +20,7 @@ namespace DotNetCore.CAP.Test var result = OperateResult.Failed(); Assert.False(result.Succeeded); - Assert.Equal(0, result.Errors.Count()); + Assert.Empty(result.Errors); } } } \ No newline at end of file