public async Task Invoke_HasIdentity_DoesNotOverwrite() { // Arrange var data = new Dictionary <string, object?>(StringComparer.OrdinalIgnoreCase) { { "Headers", "{\"Authorization\":\"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0In0.vVkzbkZ6lB3srqYWXVA00ic5eXwy4R8oniHQyok0QWY\"}" } }; var identity = new MarketOperatorIdentity(); ((IMarketOperatorIdentity)identity).AssignId("other"); var mockedFunctionContext = new MockedFunctionContext(); mockedFunctionContext.BindingContext.Setup(x => x.BindingData) .Returns(data); var actorContext = new Mock <IActorContext>(); actorContext.Setup(x => x.CurrentActor).Returns(new Actor(Guid.NewGuid(), "?", "1234", "?")); var target = new JwtAuthenticationMiddleware(identity, actorContext.Object); // Act await target.Invoke(mockedFunctionContext, _ => Task.CompletedTask).ConfigureAwait(false); // Assert Assert.Equal("other", identity.ActorId); }
public async Task Invoke_NullDelegate_ThrowsException() { // Arrange var actorContext = new Mock <IActorContext>(); var identity = new MarketOperatorIdentity(); var target = new JwtAuthenticationMiddleware(identity, actorContext.Object); // Act + Assert await Assert .ThrowsAsync <ArgumentNullException>(() => target.Invoke(new MockedFunctionContext(), null !)) .ConfigureAwait(false); }
public async Task Invoke_ActorContextHasIdentity_AssignsGlnToIdentity() { // Arrange var identity = new MarketOperatorIdentity(); var mockedFunctionContext = new MockedFunctionContext(); var actorContext = new Mock <IActorContext>(); actorContext.Setup(x => x.CurrentActor).Returns(new Actor(Guid.NewGuid(), "?", "1234", "?")); var target = new JwtAuthenticationMiddleware(identity, actorContext.Object); // Act await target.Invoke(mockedFunctionContext, _ => Task.CompletedTask).ConfigureAwait(false); // Assert Assert.Equal("1234", identity.ActorId); }