我有一个测试方法,用于测试一个任务,该任务假定为编辑获取任务定义(任务描述):
[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);
}
我也有一个initilize方法:
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);
}
这些在课程开始时:
private Company company;
private ChecklistTaskDefinitionRepository checklistTaskDefinitionRepository;
private ChecklistTaskStatusRepository checklistTaskStatusRepository;
private ChecklistTaskTestHelper helper;
一旦我运行测试方法,就打印出来:
测试方法Core.Data.Test.Modules.Checklists.ChecklistTaskDefinitionRepositoryTest.GetTaskDefinitionsForEdit_HavingTaskDefinitions_ReturnsChecklistTaskDefinitions抛出异常: System.Data.Entity.Infrastructure.DbUpdateException:更新条目时发生错误。
答案 0 :(得分:0)
如果你调试测试,你可以检索内部异常,在这种情况下会给你错误的原因(fk错误,重复的pk错误,列不存在,表不存在,数据库不存在)
要在visual studio中调试测试,请右键单击测试并单击debug。