1
我已經使用了一個快樂的測試來創建一個方法,現在我正在對它使用一個空測試。如何測試失敗的moq
我需要改變測試方法中的斷言,但我不知道如何去做。我做了一些搜索,但我似乎只能在主要方法中找到快樂路徑測試或返回。有一種方法可以做到不excecuting或由具有該方法返回的變量(一個布爾在這種情況下)
方法
public void Upload(Data.RPADataEntity RPADataEntity)
{
if (RPADataEntity != null)
{
//Give RPA the first status and then insert it into the database it.
RPADataEntity.RPAStatusID = Convert.ToInt32(Enum.RPAStatusEnum.RPAStatus.FileInputDataUploaded);
_IRPADataLayer.InsertRpaData(RPADataEntity);
}
}
的測試方法的唯一方式一起訂量和測試
[TestMethod]
public void TestUploadRPAEntityNull()
{
//Arange
var fileinputtest = new FileInput();
RPADataEntity RPADataEntity = null;
//Act
fileinputtest.Upload(RPADataEntity);
//Assert
_mockRepository.Verify(x => x.InsertRpaData(RPADataEntity));
}
簡單而有效。 – Andy 2010-11-01 11:02:28