Moq.Mock Ausnahme mit Aufruf fehlgeschlagen mit gespielter strenge Verhalten

Ich bin neu Moq-framework und ich habe geschrieben eine test-Methode, aber ich bekomme die folgende Fehlermeldung. Ich konnte nicht finden, wo ich verpasst habe.

Kann jemand bitte lassen Sie mich wissen, wie kann ich das korrigieren die folgende Fehlermeldung?


Eine Ausnahme des Typs 'Moq.MockException' ist in Moq.dll aber war
nicht behandelt werden, in Benutzer-code

Zusätzliche Informationen: IResponseMessage.ReadContentAsString()
Aufruf fehlgeschlagen mit mock-Verhalten Streng.

Alle Aufrufe auf die mock-muss über eine entsprechende setup.

Execp.cs

public Execp(IResponseMessage msg)  
{

    this.StatusCode = msg.StatusCode;//*getting exception here while running **method 1***
    this.ReadContentAsString = msg.ReadContentAsString();//*getting exception here while running **method 2***


}

Meinem test-Methoden

Methode 1

[TestMethod()]        
public void TestFail()
{

    int employeeId = 0;

    DataModel.Employee.Get.Employee employee= new DataModel.Employee.Get.Employee();
    string url = string.Format("api/1/somename/{0}", employeeId);

    restClient
        .Setup(x => x.Get(url))
        .Returns(responseMessage.Object);

    responseMessage.SetupGet(x => x.IsSuccessStatusCode).Returns(false);

    var client = new account(clientFactory.Object, serverUri, moqLogged.Object);
    var result = client.GetEmployee(employeeId);
    Assert.AreEqual(result, null);

    client.Dispose();
    moqFactory.VerifyAll();
}

Methode 2

[TestMethod()]
public void TestBadRequest()
{

   var httpStatusCode = System.Net.HttpStatusCode.BadRequest;

    string employeeName = "Test Name";
    int teamLeaderId= 1;
    string url = string.Format("api/1/somename/{0}/teammember", teamLeaderId);
    DataModel.Group.Post.TeamMember employee= new DataModel.Group.Post.teamMember();

    UserResponse userResponse = new UserResponse();

    restClient
        .Setup(x => x.PostAsJson(url, It.IsAny<DataModel.Employee.Post.TeamMember>()))
        .Returns(responseMessage.Object);

    responseMessage.SetupGet(x => x.IsSuccessStatusCode).Returns(false);
    responseMessage.SetupGet(x => x.StatusCode).Returns(httpStatusCode);

    var client = new AcronisAccountManagementClient(clientFactory.Object, serverUri, moqLogged.Object);

    var result = client.CreateEmployee(employee, teamLeaderId);
    Assert.AreEqual(result.statusCode, httpStatusCode);

    client.Dispose();
    moqFactory.VerifyAll();
}
InformationsquelleAutor crony | 2016-07-26
Schreibe einen Kommentar