From 6f917898f36a7396934e3615ca9adb6ae1fb5899 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 19 Jul 2017 19:41:46 +0800 Subject: [PATCH] update tests. --- .../SqlServerStorageConnectionTest.cs | 169 +++++++++--------- .../SqlServerStorageTest.cs | 1 + 2 files changed, 85 insertions(+), 85 deletions(-) diff --git a/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs b/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs index 003cd6f..bd0bab4 100644 --- a/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs +++ b/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using Dapper; using DotNetCore.CAP.Infrastructure; @@ -9,14 +7,15 @@ using Xunit; namespace DotNetCore.CAP.SqlServer.Test { + [Collection("sqlserver")] public class SqlServerStorageConnectionTest : DatabaseTestHost { private SqlServerStorageConnection _storage; - + public SqlServerStorageConnectionTest() { var options = GetService(); - _storage = new SqlServerStorageConnection(options); + _storage = new SqlServerStorageConnection(options); } [Fact] @@ -40,96 +39,96 @@ namespace DotNetCore.CAP.SqlServer.Test Assert.Equal(StatusName.Scheduled, message.StatusName); } -// [Fact] -// 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); -// } + [Fact] + 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); + } -// [Fact] -// public async Task StoreReceivedMessageAsync_Test() -// { -// var receivedMessage = new CapReceivedMessage -// { -// Name = "SqlServerStorageConnectionTest", -// Content = "", -// Group = "mygroup", -// StatusName = StatusName.Scheduled -// }; + [Fact] + public async Task StoreReceivedMessageAsync_Test() + { + var receivedMessage = new CapReceivedMessage + { + Name = "SqlServerStorageConnectionTest", + Content = "", + Group = "mygroup", + StatusName = StatusName.Scheduled + }; -// Exception exception = null; -// try -// { -// await _storage.StoreReceivedMessageAsync(receivedMessage); -// } -// catch (Exception ex) -// { -// exception = ex; -// } -// Assert.Null(exception); -// } + Exception exception = null; + try + { + await _storage.StoreReceivedMessageAsync(receivedMessage); + } + catch (Exception ex) + { + exception = ex; + } + Assert.Null(exception); + } -// [Fact] -// public async Task GetReceivedMessageAsync_Test() -// { + [Fact] + 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(sql, receivedMessage); -// } + 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(sql, receivedMessage); + } -// var message = await _storage.GetReceivedMessageAsync(insertedId); + 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); -// } + Assert.NotNull(message); + Assert.Equal(StatusName.Scheduled, message.StatusName); + Assert.Equal("SqlServerStorageConnectionTest", message.Name); + Assert.Equal("mygroup", message.Group); + } -// [Fact] -// public async Task GetNextReceviedMessageToBeEnqueuedAsync_Test() -// { -// var receivedMessage = new CapReceivedMessage -// { -// Name = "SqlServerStorageConnectionTest", -// Content = "", -// Group = "mygroup", -// StatusName = StatusName.Scheduled -// }; -// await _storage.StoreReceivedMessageAsync(receivedMessage); + [Fact] + public async Task GetNextReceviedMessageToBeEnqueuedAsync_Test() + { + var receivedMessage = new CapReceivedMessage + { + Name = "SqlServerStorageConnectionTest", + Content = "", + Group = "mygroup", + StatusName = StatusName.Scheduled + }; + await _storage.StoreReceivedMessageAsync(receivedMessage); -// var message = await _storage.GetNextReceviedMessageToBeEnqueuedAsync(); + var message = await _storage.GetNextReceviedMessageToBeEnqueuedAsync(); -// Assert.NotNull(message); -// Assert.Equal(StatusName.Scheduled, message.StatusName); -// Assert.Equal("SqlServerStorageConnectionTest", message.Name); -// Assert.Equal("mygroup", message.Group); -// } + Assert.NotNull(message); + Assert.Equal(StatusName.Scheduled, message.StatusName); + Assert.Equal("SqlServerStorageConnectionTest", message.Name); + Assert.Equal("mygroup", message.Group); + } } } diff --git a/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs b/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs index 5ca727b..38fb6c1 100644 --- a/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs +++ b/test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs @@ -3,6 +3,7 @@ using Dapper; namespace DotNetCore.CAP.SqlServer.Test { + [Collection("sqlserver")] public class SqlServerStorageTest : DatabaseTestHost { [Fact]