我已经创建了一个测试用例调用GetChangeSetPerProjectTest,下面是这个测试用例的代码:
public void GetChangeSetPerProjectTest()
{
CommonPHIEditorBL_Accessor target = new CommonPHIEditorBL_Accessor();
target.mCommonPHIEditorDS = new CommonPHIEditorDS();
AddPHIYieldInfoREBI(target.mCommonPHIEditorDS.PHIYieldParm, 2, 2, 2, 2, 11705, 2, 2);
AddPHIYieldInfoREBI(target.mCommonPHIEditorDS.PHIYieldParm, 2, 3, 3, 3, 11705, 3, 3);
target.mCommonPHIEditorDS.PHIYieldParm.Rows[1].AcceptChanges();
target.mCommonPHIEditorDS.PHIYieldParm.Rows[1].SetModified();
//For DATA
AddPHIYieldDataInfoWithItemID(target.mCommonPHIEditorDS.PHIYieldParmData, 2, Convert.ToDateTime("2010-06-20 00:00:00.000"), 2, 2, 2, 2, 11705, 2);
AddPHIYieldDataInfoWithItemID(target.mCommonPHIEditorDS.PHIYieldParmData, 3, Convert.ToDateTime("2010-06-20 00:00:00.000"), 3, 3, 3, 3, 11705, 2); //error happened at here
//For Comment Data
EUPHModelDS.MetricModelCommentDTDataTable newDt = new EUPHModelDS.MetricModelCommentDTDataTable();
AddEUPHModelDSDataSet(newDt, "MetricModelCommentDT", 2, 2, 2);
AddEUPHModelDSDataSet(newDt, "MetricModelCommentDT", 4, 2, 2);
AddEUPHModelDSDataSet(newDt, "MetricModelCommentDT", 3, 3, 3);
target.mCommonPHIEditorDS.Tables.Add(newDt);
int projectID = 2; // TODO: Initialize to an appropriate value
int expected; // TODO: Initialize to an appropriate value
expected = target.mCommonPHIEditorDS.PHIYieldParm.Rows.Count;
CommonPHIEditorDS actual;
actual = target.GetChangeSetPerProject(projectID);
Assert.AreEqual(expected, actual.PHIYieldParm.Rows.Count);
Assert.AreEqual(2, actual.PHIYieldParmData.Rows.Count);
Assert.AreEqual(1, actual.Tables["MetricModelCommentDT"].Rows.Count);
//Assert.Inconclusive("Verify the correctness of this test method.");
}
但是,当我查看第二个数据时出现错误:
AddPHIYieldDataInfoWithItemID(target.mCommonPHIEditorDS.PHIYieldParmData,3,Convert.ToDateTime(“2010-06-20 00:00:00.000”),3,3,3,3,11705,2);
在AddPHIYieldDataInfoWithItemID:
中private void AddPHIYieldDataInfoWithItemID(CommonPHIEditorDS.PHIYieldParmDataDataTable dt, int dataID, DateTime dateKey, int metricID, int inputID, int metricModelInputID, int horizonID, int ItemID, int MetricModelID)
{
CommonPHIEditorDS.PHIYieldParmDataRow newRow = dt.NewPHIYieldParmDataRow();
newRow.DataID = dataID;
newRow.DateKey = dateKey;
newRow.InputID = inputID;
newRow.MetricModelInputID = metricModelInputID;
newRow.ItemID = ItemID;
newRow.HrzDisplay = "Current Quater";
newRow.HorizonID = horizonID;
newRow.Value = 20.7;
newRow.MetricID = metricID;
newRow.MetricModelID = 2;
dt.Rows.Add(newRow);
}
我可以成功浏览第一个数据,但在第二个数据中得到错误说:
ForeignKeyConstraint FK_PHIYieldParm_PHIYieldParmData要求子键值(3,3,3,2,11705)存在于父表中。