Ich verwende microsoft.visualstudio.testtools 10.0 und EntityFramework 6.0C# DataDriven Einheit Test wirft Fehler bei Verwendung von LINQ
- Ich habe die Methode "validateAlreadyEnroll", die eine Linq-Abfrage ausführt.
- Ich habe einen Komponententest "testAlreadyEnroll", der "validateAlreadyEnroll" aufruft
- testAlreadyEnroll schlägt fehl oder ist erfolgreich, wenn ich die linq-Abfrage kommentiere, andernfalls stürzt es ab.
- Es wird die app.config, die die Datensätze Test Driven
Ist dies ein Problem mit Versionen? Bitte helfen Sie.
Main-Methode:
public static bool validateAlreadyEnroll(int sectionid, int personid, ref string extramessage, ref validationResult vr)
{
int n = (from e in db.Enrollments where e.SectionID == sectionid && e.EnrolledPersonID == personid select e).ToList().Count();
if(n == 0){
return false;
}
var statusid2 = db.Database.SqlQuery<resultStatusID>("select top 1 EnrollmentStatusID from Enrollment where SectionID = " + sectionid + " and EnrolledPersonID = " + personid + " order by EnrollmentID desc").ToList();
if (statusid2[0].EnrollmentStatusID == CANCELREQUEST) {
return false;
}
return true;
}
Einheit Test:
[TestMethod]
[DataSource("DataSource3")]
[DeploymentItem("Regi.Service.Tests\\tests.xlsx")]
public void testAlreadyEnroll()
{
int n;
int sectionid;
if (Int32.TryParse(TestContext.DataRow["sectionid"].ToString(), out n))
{
sectionid = Int32.Parse(TestContext.DataRow["sectionid"].ToString());
}
else
{
sectionid = 0;
}
int personid;
if (Int32.TryParse(TestContext.DataRow["personid"].ToString(), out n))
{
personid = Int32.Parse(TestContext.DataRow["personid"].ToString());
}
else
{
personid = 0;
}
bool answer = Helper.validateAlreadyEnroll(sectionid, personid, ref msg, ref vr);
bool result = Convert.ToBoolean(TestContext.DataRow["result"].ToString());
Assert.AreEqual(answer, result, "Failure");
}
Bitte schreiben Sie die spezifische Fehlermeldung und Stack-Trace. Das würde uns Hinweise geben, was das Problem sein könnte. – Kevin
Ich habe den Fehler als Bild hinzugefügt, da ich nicht kopieren und einfügen konnte (ist eine Menge), danke Kevin! Ich habe völlig vergessen, es hinzuzufügen. –
Zu welcher Datenbank soll sich Ihr Kontext verbinden? Ich sehe nur eine ExcelConnection in den Verbindungszeichenfolgen. –