Tôi có một hành vi lạ trong một thử nghiệm mà tôi muốn kiểm tra rằng một ngoại lệ được ném khi null được truyền vào như một tham số. Khi tôi chạy thử nghiệm tôi nhận được từ NUnit:Hành vi lạ với NUnit, ExpectedException & return return
System.ArgumentNullException was expected
-- Exception doesn't have a stack trace --
thử nghiệm của tôi:
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void Should_not_retrieve_any_fields_when_file_is_null()
{
_creator.CreateFields(null);
}
thực hiện của tôi:
public IEnumerable<ImportField> CreateFields(HttpPostedFileBase file)
{
if (file == null) throw new ArgumentNullException("file");
using (var reader = new StreamReader(file.InputStream))
{
var firstLine = reader.ReadLine();
var columns = firstLine.Split(new[] { ',' });
for (var i = 0; i < columns.Length; i++)
{
yield return new ImportField(columns[i], i);
}
}
}
Có một lời giải thích hợp lý để hành vi này và tôi nên làm của tôi thực hiện khác nhau?
+1 đẹp bắt !! – sll