gpt4 book ai didi

c# - 单元测试中的元素在完成后仍待处理

转载 作者:行者123 更新时间:2023-12-01 16:04:26 25 4
gpt4 key购买 nike

运行测试后,我在 Resharper 中看到此警告,所有测试均通过。

2018.08.09 11:11:58.524 WARN Element Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests was left pending after its run completion. 2018.08.09 11:11:58.524 WARN Element Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests.Reso was left pending after its run completion.

它们是在测试数据库中设置一些 SQL 的集成测试,然后针对该数据库运行测试。

这是完整的测试类:

namespace Data.Tests.Infra.IntegrationTests
{
using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
using Infrastructure.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public sealed class ResolvedIdentityTests
{
[ClassInitialize]
public static void Initialise(TestContext context)
{
const string sql = @"insert into infra.tblUnresolvedIdentities
(DeviceId, Fqdn, TimeConflictOccured)
values
('85E33FB5-C321-4EF2-994C-C835F136BA0C', 'unr.test.foo', '2018-08-06 12:16:24.183'),
('D3F32F97-2375-47CC-86E7-37C50ABAC85F', 'unr2.test.foo', '2018-08-06 12:16:24.183')

insert into infra.tblOrg ([Name]) values ('rito')
declare @orgId int = (select OrgId from infra.tblOrg where [Name] = 'rito');

insert into infra.tblSite ([SiteName], [OrgId]) values ('rito.site', @OrgId);
declare @siteId int = (select SiteId from infra.tblSite where [SiteName] = 'rito.site');

insert into infra.tblDevice
(DeviceId, [Name], SiteId)
values
('CE810507-C614-4C65-9675-569EEFFDBC9F', 'unr.test.foo', @siteId),
('94FF1C23-0B7E-41CB-A0F8-058CED0465B3', 'blacklisted.test.foo', @siteId)

insert into infra.tblBlacklistedAgents
(DeviceId, Fqdn)
values
('94FF1C23-0B7E-41CB-A0F8-058CED0465B3', 'rit.test.com')";
RunSql(sql);
}

[ClassCleanup]
public static void Cleanup()
{
const string sql = @"delete from infra.tblBlacklistedAgents where DeviceId = '94FF1C23-0B7E-41CB-A0F8-058CED0465B3'
delete from infra.tblUnresolvedIdentities where DeviceId in ('85E33FB5-C321-4EF2-994C-C835F136BA0C', 'D3F32F97-2375-47CC-86E7-37C50ABAC85F')
delete from infra.tblDevice where DeviceID in( 'CE810507-C614-4C65-9675-569EEFFDBC9F', '94FF1C23-0B7E-41CB-A0F8-058CED0465B3')
delete from infra.tblsite where SiteName = 'rito.site'
delete from infra.tblorg where Name = 'rito'
delete from infra.tblResolvedIdentities where ActualDeviceId = 'CE810507-C614-4C65-9675-569EEFFDBC9F'";
RunSql(sql);
}

private static void RunSql(string sql)
{
using (var sqlConnection = new SqlConnection(Configuration.InitConfiguration()["ConnectionString"]))
sqlConnection.Execute(sql);
}

[TestMethod]
public async Task ResolvedIdentityTests_ShouldResolveAnIdentityAndAddRowToResolvedIdentityTable()
{
var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
await infra.ResolveIdentity(erroneousDeviceId: new Guid("85E33FB5-C321-4EF2-994C-C835F136BA0C"), actualDeviceId: new Guid("CE810507-C614-4C65-9675-569EEFFDBC9F"));

// now call GetResolvedIdentity so we can verify it was resolved.
var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("85E33FB5-C321-4EF2-994C-C835F136BA0C"));
Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity.ActualDeviceId, expected: new Guid("CE810507-C614-4C65-9675-569EEFFDBC9F"));
Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity.SiteName, expected: "rito.site");
Assert.IsFalse(resolvedIdentity.ResolvedIdentity.Id == -1);
Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Resolved);
}

[TestMethod]
public async Task GetResolvedIdenity_ShouldResolveToBlacklisted()
{
var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("94FF1C23-0B7E-41CB-A0F8-058CED0465B3"));

Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Blacklisted);
Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity, expected: null);
}

[TestMethod]
public async Task GetResolvedIdenity_ShouldResolveToStillPending()
{
var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("D3F32F97-2375-47CC-86E7-37C50ABAC85F"));

Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Pending);
Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity, expected: null);
}
}
}

我不知道为什么这些测试仍然悬而未决,或者这些警告是否是我应该关心的事情。

这是在Resharper测试运行器中,在MS测试运行器中运行时不显示警告(但也许它不显示警告?)

最佳答案

关于c# - 单元测试中的元素在完成后仍待处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51764422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com