0

I want test this method. Not exactly this because it does not make sense to test this, but this is simple version of what I need.

public bool Test()
{
    var authenticationScheme = Context.GetCurrentAuthenticationScheme();
    return authenticationScheme == "google";
}

GetCurrentAuthenticationScheme is extension method.

public static string GetCurrentAuthenticationScheme(this HttpContext context)
{

    var protector = context.ApplicationServices
                           .GetDataProtector(nameof(CookieStateHandlerExtensions));
    return protector.Unprotect(context.Request
                                      .Cookies[CURRENTAUTHENTICATIONSCHEMECOOKIE]
                                      .FirstOrDefault());
}

GetDataProtector is also extension method from "Microsoft.AspNet.DataProtection"
Unprotect is extension method from same namespace.

My question is how to mock this(using Moq) so that GetCurrentAuthenticationScheme() return string I want?

Old Fox
  • 8,629
  • 4
  • 34
  • 52
Raskolnikov
  • 3,791
  • 9
  • 43
  • 88
  • Yes, but does not help me in my case. Because I still don't know how to write test. How to return what I want from GetCurrentAuthenticationScheme? – Raskolnikov Oct 07 '15 at 08:06
  • If you use `HttpContext.Current`, then you can initialize it manually in your test method... BTW it looks like a code which you'd better test through as integration test instead of UT... – Old Fox Oct 07 '15 at 08:11

0 Answers0