private void AddCookieToHttpContext(MockHttpContextCookies mock, IDataProtectionProvider eProvider, bool keepOwnPermissions = false) { var data = new ImpersonationData("differentUserId", "*****@*****.**", keepOwnPermissions); mock.RequestCookies["UserImpersonation"] = eProvider.CreateProtector(_cookieEncryptPurpose).Protect(data.GetPackImpersonationData()); }
private static ITestParameterBuilder GetOrCreateImpersonationDataTestParameter(IPatternScope scope) { ITestParameterBuilder parameterBuilder = scope.TestBuilder.GetParameter(ImpersonationDataParameterName); if (parameterBuilder == null) { // Add a new test parameter for some ImpersonationData. // This makes the test data-driven. ITestDataContextBuilder parameterDataContextBuilder = scope.TestDataContextBuilder.CreateChild(); parameterBuilder = scope.TestBuilder.CreateParameter(ImpersonationDataParameterName, null, parameterDataContextBuilder); // When the ImpersonationData is bound to the parameter before the initialization phase // of the test, add it to the test instance state so we can access it later. parameterBuilder.TestParameterActions.BindTestParameterChain.After((state, obj) => { var data = (ImpersonationData)obj; state.Data.SetValue(ImpersonationDataKey, data); state.AddNameSuffix(data.GetChildTestSuffix()); }); scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around((state, inner) => { ImpersonationData data = state.Data.GetValue(ImpersonationDataKey); using (new Impersonation(data.UserName, data.Domain ?? String.Empty, data.Password)) { return(inner(state)); } }); } return(parameterBuilder); }
private static void EnlistImpersonationData(ITestParameterBuilder parameterBuilder, ImpersonationData data) { DataSource dataSource = parameterBuilder.TestDataContextBuilder.DefineDataSource(""); dataSource.AddDataSet(new ValueSequenceDataSet(new[] { data }, null, false)); }