How do I make a unit test to test a method that checks request headers?

后端 未结 3 1081
北海茫月
北海茫月 2021-02-05 18:35

I am very, very new to unit testing and am trying to write a test for a pretty simple method:

public class myClass : RequireHttpsAttribute
{
    public override          


        
3条回答
  •  情书的邮戳
    2021-02-05 19:19

    I encountered an issue with the accepted solution using ASP.NET MVC 4. To resolve it I mocked the http context Items attribute otherwise the sut.OnAuthorization was causing an object is undefined exception:

    MockHttpContext.Setup(x => x.Items)
        .Returns(new System.Collections.Generic.Dictionary());
    

提交回复
热议问题