我有一個測試是假設得到一個任務定義(任務描述)的編輯任務的測試方法:System.Data.Entity.Infrastructure.DbUpdateException問題
[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);
}
我也有一個用來初始化方法:
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:更新條目中出現了錯誤。
環境DbContext變量極易出錯。以前做了哪些更改,哪些對象位於ChangeTracker中,這兩種方法做了什麼以及內部異常是什麼? – DevilSuichiro