public void ImpersonationServiceSupportsWindowsPrincipalImpersonation()
        {
            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            Thread.CurrentPrincipal = principal;

            string currentUser          = Thread.CurrentPrincipal.Identity.Name;
            string impersonatedUsername = "******";

            WindowsAuthenticationService authService =
                mockContainer.Services.AddNew <WindowsAuthenticationService, IAuthenticationService>();

            authService.Identity = impersonatedUsername;

            IImpersonationService impersonator =
                mockContainer.Services.AddNew <WindowsImpersonationService, IImpersonationService>();

            using (IImpersonationContext context = impersonator.Impersonate())
            {
                Assert.IsTrue(Thread.CurrentPrincipal.Identity.IsAuthenticated);
                Assert.AreEqual(impersonatedUsername, Thread.CurrentPrincipal.Identity.Name);
            }

            Assert.IsTrue(Thread.CurrentPrincipal.Identity.IsAuthenticated);
            Assert.AreEqual(currentUser, Thread.CurrentPrincipal.Identity.Name);
        }
 public WindowsImpersonationService(
     [ServiceDependency] IAuthenticationService authService)
 {
     _authService = authService as WindowsAuthenticationService;
 }