public void when_principal_is_valid() { Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity("test")); IPrincipalAccessor principalAccessor = new PrincipalAccessor(); Assert.Equal("test", principalAccessor.Principal.Identity.AuthenticationType); }
static async Task Main() { Console.Title = "Samples.UsernameHeader.Endpoint1"; var endpointConfiguration = new EndpointConfiguration("Samples.UsernameHeader.Endpoint1"); endpointConfiguration.UsePersistence <LearningPersistence>(); endpointConfiguration.UseTransport <LearningTransport>(); #region component-registration-sender var principalAccessor = new PrincipalAccessor(); endpointConfiguration.RegisterComponents( registration: components => { components.RegisterSingleton <IPrincipalAccessor>(principalAccessor); components.ConfigureComponent <AddUserNameToOutgoingHeadersMutator>(DependencyLifecycle.InstancePerCall); }); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); #region send-message async Task SendMessage(int userNumber) { var identity = new GenericIdentity($"FakeUser{userNumber}"); principalAccessor.CurrentPrincipal = new GenericPrincipal(identity, new string[0]); var message = new MyMessage(); await endpointInstance.Send("Samples.UsernameHeader.Endpoint2", message) .ConfigureAwait(false); } await Task.WhenAll(SendMessage(1), SendMessage(2)).ConfigureAwait(false); #endregion Console.WriteLine("Message sent. Press any key to exit"); Console.ReadKey(); await endpointInstance.Stop() .ConfigureAwait(false); }