init
This commit is contained in:
74
DouyinApi.Tests/Service_Test/BlogArticleService_Should.cs
Normal file
74
DouyinApi.Tests/Service_Test/BlogArticleService_Should.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using DouyinApi.IServices;
|
||||
using DouyinApi.Model.Models;
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
|
||||
namespace DouyinApi.Tests
|
||||
{
|
||||
public class BlogArticleService_Should
|
||||
{
|
||||
|
||||
private IBlogArticleServices blogArticleServices;
|
||||
DI_Test dI_Test = new DI_Test();
|
||||
|
||||
|
||||
public BlogArticleService_Should()
|
||||
{
|
||||
//mockBlogRep.Setup(r => r.Query());
|
||||
|
||||
var container = dI_Test.DICollections();
|
||||
|
||||
blogArticleServices = container.Resolve<IBlogArticleServices>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void BlogArticleServices_Test()
|
||||
{
|
||||
Assert.NotNull(blogArticleServices);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blogs_Test()
|
||||
{
|
||||
var data = await blogArticleServices.GetBlogs();
|
||||
|
||||
Assert.True(data.Any());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Add_Blog_Test()
|
||||
{
|
||||
BlogArticle blogArticle = new BlogArticle()
|
||||
{
|
||||
bCreateTime = DateTime.Now,
|
||||
bUpdateTime = DateTime.Now,
|
||||
btitle = "xuint test title",
|
||||
bcontent = "xuint test content",
|
||||
bsubmitter = "xuint test submitter",
|
||||
};
|
||||
|
||||
var BId = await blogArticleServices.Add(blogArticle);
|
||||
|
||||
Assert.True(BId > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Delete_Blog_Test()
|
||||
{
|
||||
Add_Blog_Test();
|
||||
|
||||
var deleteModel = (await blogArticleServices.Query(d => d.btitle == "xuint test title")).FirstOrDefault();
|
||||
|
||||
Assert.NotNull(deleteModel);
|
||||
|
||||
var IsDel = await blogArticleServices.Delete(deleteModel);
|
||||
|
||||
Assert.True(IsDel);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
DouyinApi.Tests/Service_Test/DbTest.cs
Normal file
39
DouyinApi.Tests/Service_Test/DbTest.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace DouyinApi.Tests;
|
||||
|
||||
public class DbTest(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
[Fact]
|
||||
public void Test_CreateDataBase()
|
||||
{
|
||||
string connectionString = "Database=master;TrustServerCertificate=true;Persist Security Info=False;Trusted_Connection=True;server=(local)";
|
||||
string connectionString2 = "Database=DouyinApi;TrustServerCertificate=true;Persist Security Info=False;Trusted_Connection=True;server=(local)";
|
||||
|
||||
// 创建数据库
|
||||
using (SqlConnection masterConnection = new SqlConnection(connectionString))
|
||||
{
|
||||
masterConnection.Open();
|
||||
string createDbQuery = $"CREATE DATABASE [DouyinApi];";
|
||||
using (SqlCommand command = new SqlCommand(createDbQuery, masterConnection))
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
testOutputHelper.WriteLine("Database created successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
// 连接到新创建的数据库
|
||||
using (SqlConnection newDbConnection = new SqlConnection(connectionString2))
|
||||
{
|
||||
newDbConnection.Open();
|
||||
string testQuery = "SELECT 1;";
|
||||
using (SqlCommand command = new SqlCommand(testQuery, newDbConnection))
|
||||
{
|
||||
int result = (int)command.ExecuteScalar()!;
|
||||
testOutputHelper.WriteLine("Connection to new database successful, test query result: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user