简体   繁体   English

System.Data.Entity.Infrastructure.DbUpdateException问题

[英]System.Data.Entity.Infrastructure.DbUpdateException Issue

I have a test method that tests a task that is suppose to get a task definition (task description) for edit: 我有一个测试方法,可以测试一个任务,该任务假设是要获取要编辑的任务定义(任务描述):

[TestMethod]
public void GetTaskDefinitionsForEdit_HavingTaskDefinitions_ReturnsChecklistTaskDefinitions()
{
    // this.CreateChecklistTaskDefinition(referenceKey: "Xxx123", description: "SomeDescription");
    // this.checklistTaskTestHelper.CreateChecklistTaskDefinition(referenceKey: "Yyy234", description: "SomeOtherDescription");

    this.helper.CreateChecklistTaskDefinition(referenceKey: "Xxx123", description: "SomeDescription");
    this.helper.CreateChecklistTaskDefinition(referenceKey: "Yyy234", description: "SomeOtherDescription");

    this.CompanyDbContext.SaveChanges();

    //var result = this.checklistTaskTestHelper.checklistTaskDefinitionRepository.GetTaskDefinitionsForEdit(ChecklistReferenceType.ReconAccountGroup, "Xxx123");

    var result = this.checklistTaskDefinitionRepository.GetTaskDefinitionsForEdit(ChecklistReferenceType.ReconAccountGroup, "Xxx123");

    Assert.AreEqual(1, result.Count);
    //Assert.AreEqual("Xxx123", result[0].ReferenceKey);
    //Assert.AreEqual("SomeDescription", result[0].Description);
}

I also have an initilize method: 我也有一个初始化方法:

protected override void Initialize()
{
    this.company = this.CreateCompany("Test company");
    this.checklistTaskDefinitionRepository = this.CreateRepository<ChecklistTaskDefinitionRepository>(this.company);
    this.helper = new ChecklistTaskTestHelper(this.checklistTaskDefinitionRepository, this.checklistTaskStatusRepository);
}

And these at the start of the class: 这些是在课程开始时:

private Company company;
private ChecklistTaskDefinitionRepository checklistTaskDefinitionRepository;
private ChecklistTaskStatusRepository checklistTaskStatusRepository;
private ChecklistTaskTestHelper helper;

And as soon as I run the test method, It prints out this: 一旦我运行测试方法,它就会打印出以下内容:

Test method Core.Data.Test.Modules.Checklists.ChecklistTaskDefinitionRepositoryTest.GetTaskDefinitionsForEdit_HavingTaskDefinitions_ReturnsChecklistTaskDefinitions threw exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. 测试方法Core.Data.Test.Modules.Checklists.ChecklistTaskDefinitionRepositoryTest.GetTaskDefinitionsForEdit_HavingTaskDefinitions_ReturnsChecklistTaskDefinitions引发了异常:System.Data.Entity.Infrastructure.DbUpdateException:更新条目时发生错误。

If you debug the test, you can retrieve the inner exception that in this case will give you the reason of the error (fk error, duplicated pk error, column does not exists, table does not exists, database does not exists). 如果调试测试,则可以检索内部异常,在这种情况下,该异常将为您提供错误原因(fk错误,重复的pk错误,列不存在,表不存在,数据库不存在)。

To debug the test inside visual studio, right click on the test and click debug. 要在Visual Studio中调试测试,请右键单击测试,然后单击“调试”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Data.Entity.Infrastructure.DbUpdateException - System.Data.Entity.Infrastructure.DbUpdateException 发生System.Data.Entity.Infrastructure.DbUpdateException - System.Data.Entity.Infrastructure.DbUpdateException occurred MVC EF-System.Data.Entity.Infrastructure.DbUpdateException - MVC EF - System.Data.Entity.Infrastructure.DbUpdateException 如何解决 System.Data.Entity.Infrastructure.DbUpdateException - How to solve System.Data.Entity.Infrastructure.DbUpdateException 递归树方法上的System.Data.Entity.Infrastructure.DbUpdateException - System.Data.Entity.Infrastructure.DbUpdateException on recursive Tree method 将数据添加到数据库(错误:System.Data.Entity.Infrastructure.DbUpdateException) - Adding Data to Database (Error: System.Data.Entity.Infrastructure.DbUpdateException) EntityFramework.dll 中发生“System.Data.Entity.Infrastructure.DbUpdateException” - 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll 如何避免System.Data.Entity.Infrastructure.DbUpdateException - How to avoid System.Data.Entity.Infrastructure.DbUpdateException 发生类型为“ System.Data.Entity.Infrastructure.DbUpdateException”的异常 - An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred 类型为“ System.Data.Entity.Infrastructure.DbUpdateException”的异常 - An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM