Преглед на файлове

update for test.

master
yangxiaodong преди 7 години
родител
ревизия
cf5708e7a5
променени са 2 файла, в които са добавени 165 реда и са изтрити 165 реда
  1. +121
    -121
      test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs
  2. +44
    -44
      test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs

+ 121
- 121
test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageConnectionTest.cs Целия файл

@@ -1,135 +1,135 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Models;
using Xunit;
//using System;
//using System.Collections.Generic;
//using System.Text;
//using System.Threading.Tasks;
//using Dapper;
//using DotNetCore.CAP.Infrastructure;
//using DotNetCore.CAP.Models;
//using Xunit;

namespace DotNetCore.CAP.SqlServer.Test
{
public class SqlServerStorageConnectionTest : DatabaseTestHost
{
private SqlServerStorageConnection _storage;
//namespace DotNetCore.CAP.SqlServer.Test
//{
// public class SqlServerStorageConnectionTest : DatabaseTestHost
// {
// private SqlServerStorageConnection _storage;

public SqlServerStorageConnectionTest()
{
var options = GetService<SqlServerOptions>();
_storage = new SqlServerStorageConnection(options);
}
// public SqlServerStorageConnectionTest()
// {
// var options = GetService<SqlServerOptions>();
// _storage = new SqlServerStorageConnection(options);
// }

[Fact]
public async Task GetPublishedMessageAsync_Test()
{
var sql = "INSERT INTO [Cap].[Published]([Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) OUTPUT INSERTED.Id VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
var publishMessage = new CapPublishedMessage
{
Name = "SqlServerStorageConnectionTest",
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("SqlServerStorageConnectionTest", message.Name);
Assert.Equal(StatusName.Scheduled, message.StatusName);
}
// [Fact]
// public async Task GetPublishedMessageAsync_Test()
// {
// var sql = "INSERT INTO [Cap].[Published]([Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) OUTPUT INSERTED.Id VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
// var publishMessage = new CapPublishedMessage
// {
// Name = "SqlServerStorageConnectionTest",
// 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("SqlServerStorageConnectionTest", message.Name);
// 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<int>(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<int>(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);
// }

}
}
// }
//}

+ 44
- 44
test/DotNetCore.CAP.SqlServer.Test/SqlServerStorageTest.cs Целия файл

@@ -5,37 +5,37 @@ namespace DotNetCore.CAP.SqlServer.Test
{
public class SqlServerStorageTest : DatabaseTestHost
{
[Fact]
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);
}
}
// [Fact]
// 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);
// }
// }

[Fact]
public void DatabaseTable_Published_IsExists()
{
using (var connection = ConnectionUtil.CreateConnection())
{
var sql = @"
IF OBJECT_ID(N'[Cap].[Published]',N'U') IS NOT NULL
SELECT 'True'
ELSE
SELECT 'False'";
var result = connection.QueryFirst<bool>(sql);
Assert.Equal(true, result);
}
}
// [Fact]
// public void DatabaseTable_Published_IsExists()
// {
// using (var connection = ConnectionUtil.CreateConnection())
// {
// var sql = @"
//IF OBJECT_ID(N'[Cap].[Published]',N'U') IS NOT NULL
//SELECT 'True'
//ELSE
//SELECT 'False'";
// var result = connection.QueryFirst<bool>(sql);
// Assert.Equal(true, result);
// }
// }

[Fact]
public void DatabaseTable_Queue_IsExists()
@@ -52,19 +52,19 @@ SELECT 'False'";
}
}

[Fact]
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);
}
}
// [Fact]
// 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);
// }
// }
}
}

Зареждане…
Отказ
Запис