gpt4 book ai didi

c# - 尝试使用工具 Effort : The type date is not a qualified namespace 运行单元测试时 MVC4 应用程序出错

转载 作者:行者123 更新时间:2023-11-30 17:02:03 26 4
gpt4 key购买 nike

我正在尽我所能在我的 MVC4 项目上创建单元测试。为此,我使用 Entity Framework 单元测试工具 Effort (如 this tutorial 中所述。此工具在内存中创建一个数据库/上下文,可以在其上运行测试。

连接字符串在我的主项目中有效。但是当我在运行以下测试时尝试从我的测试项目中使用它时:

[TestInitialize]
public void Initialize()
{
DbConnection connection = Effort.DbConnectionFactory.CreateTransient();

using (var context = new seashell_brawl_corveeContext(connection))
{
// Add test data to the database here
context.Products.Add(new Product() { ProductId = 1 });
}

//_context
}

测试失败并显示以下结果消息:

Initialization method Project.Tests.Controllers.ShoppingCartTest.Initialize threw exception.  
System.Data.MetadataException: System.Data.MetadataException: Schema specified is not valid.
Errors:

(47,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive
types can be used without qualification.

(57,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive
types can be used without qualification.

(76,6) : error 0040: The Type date is not qualified with a namespace or alias. Only primitive
types can be used without qualification..

堆栈跟踪可以在 this gist 中找到.

有人知道如何解决这个问题吗?我是否正确引用了我的连接字符串?我没有在 Project.Test app.config 文件中引用我的连接字符串。我所有带日期的数据类型都具有以下属性:

[Column(TypeName = "Date")]
[DataType(DataType.DateTime)]

是否应将其更改为其他内容?

我希望有人能在正确的方向上给我提示。

最佳答案

.NET 中没有“日期”类型。有 DateTime 和 DateTimeOffset 类型,但即使 DateTime 对象的 Date 属性也是 DateTIme。

我也不确定 Column 属性的“TypeName”属性是什么。它不在 documentation

此外,您的示例中没有任何地方显示小写 d,显示“日期”,因此我不确定错误中“日期”的来源。

关于c# - 尝试使用工具 Effort : The type date is not a qualified namespace 运行单元测试时 MVC4 应用程序出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20332912/

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