dimanche 28 décembre 2014

Unable to retrieve data in unit testing

I have a question about retrieving data, which is something I am trying to learn and also first time to used it.



Error for test failed: "Test method TestBusinessLogic.MediaDurationBLTest.OpenModelTest threw exception: System.Exception: Unable to retrieve Media Duration Model Another user has already updated the model. Please refresh and try again."



MediaDurationBLTest.cs


This is the main method:



[TestMethod()]
public void OpenModelTest()
{
MediaDurationDS mds = new MediaDurationDS();
PopulateTestDataSet(mds);

MediaDurationBL target = new MediaDurationBL();
TestBusinessLogic.BusinessLogic_MediaDurationBLAccessor accessor = new TestBusinessLogic.BusinessLogic_MediaDurationBLAccessor(target);
//assign accessor to mds
accessor.mMediaDurationDataSet = mds;

int modelID = 5514;

target.OpenModel(modelID);

Assert.AreEqual(20, mds.Tables.Count, "# of tables retrieved are different");

//We are creating copy of ProjectMetricData, check if copyTable and original table are same
//except projectmetrictdata has pf&d and client does not so subtract that.
int pfanddRows = 2;
int projectMetricDataRows = accessor.mMediaDurationDataSet.ProjectMetricData.Rows.Count;
int copiedRows = projectMetricDataRows - pfanddRows;
if (copiedRows < 0)
copiedRows = 0;

Assert.AreEqual(accessor.mMediaDurationDataSet.ClientProjectMetricData.Rows.Count, copiedRows, "project metric data copy not created");

}


This is the inner code of the "target.OpenModel(modelID);", I get the error and straight away jump to "catch (Exception e)"), my data was empty at here "mMediaDurationDataLayer.GetModelDetails(mMediaDurationDataSet, modelID);", how do I solve the error?



public DataSet OpenModel(int modelID)
{
try
{
mMediaDurationDataSet = new MediaDurationDS();
mMediaDurationDataLayer.GetModelDetails(mMediaDurationDataSet, modelID);

//ConvertToLocalTime(mMediaDurationDataSet.Model, "ClientLastUpdateDate");
ConvertToLocalTime(mMediaDurationDataSet.ModelActivity, "ClientLastUpdateDate");

//IF MODEL IS MOR, ACT
CreateProjectForMORModel(modelID);

//COPY PROJECT METRIC DATA TABLE INTO CLIENTPROJECTMETRICDATA
foreach (MediaDurationDS.ProjectMetricDataRow pmdr in mMediaDurationDataSet.ProjectMetricData.Rows)
{
//WE DONT WANT PF&D IN CLIENT TABLE
if (!pmdr.MetricTypeName.Equals(PFANDDPARAMETER))
{
CreateClientProjectMetricDataRow(pmdr, pmdr.ProjectMetricID);
}

}

mMediaDurationDataSet.AcceptChanges();
mMediaDurationDataSet.WriteXml("C:\\MediaDurationTestDataSet.xml");
return mMediaDurationDataSet;
}
catch (Exception e)
{
string errorMessage = "Unable to retrieve Media Duration Model " +Environment.NewLine + e.Message;
throw new Exception(errorMessage);
}
}



public class MediaDurationDL
{
ProjectManagerDL mProjectManagerDL;

public void GetModelDetails(DataSet mediaDurationDataSet, int modelID)
{
Database db = X.XXX.WindowsApplicationTemplate.ApplicationDatabase.DatabaseFactory.CreateDatabase();

string sqlProcedure = "uspMediaDurationGetModel";
DbCommand dbCommand = db.GetStoredProcCommand(sqlProcedure);
UtilityDL.SetCommandTimeout(dbCommand);
db.AddInParameter(dbCommand, "ModelID", DbType.Int32, modelID);

string[] tables = new string[] { "LaborCategory", "ProcessCategory", "Media", "Activity", "Time", "Model", "ModelTime", "ModelActivity",
"Project", "ProjectAccess", "MetricType", "ProjectMetric", "ProjectMetricData" };//, "Metric", "MetricData"};

// RETRIEVE DATA FROM DB AND LOAD INTO DATASET
mediaDurationDataSet.Clear();
//PrintAllErrs(mediaDurationDataSet);
db.LoadDataSet(dbCommand, mediaDurationDataSet, tables);
//PrintAllErrs(mediaDurationDataSet);
}

Aucun commentaire:

Enregistrer un commentaire