Unit testing for Server.MapPath

后端 未结 3 1764
暖寄归人
暖寄归人 2020-12-01 13:31

I\'ve a method. which retrieve a document from hard disk. I can\'t test this from unit testing. It always throw an exception invalid null path or something. How to test that

3条回答
  •  天命终不由人
    2020-12-01 13:43

    I was using NSubstitute and I implemented it as below:

     var fakeContext = Substitute.For();
    fakeContext.Server.MapPath(Arg.Any()).ReturnsForAnyArgs("/set-path/");
    

提交回复
热议问题