public async Task Process_CompleteWith401Unathorized_WhenTokenValid() { const string testMessageId = "someErrorMessageId"; ITokenValidator fakeTokenValidator = Substitute.For <ITokenValidator>(); fakeTokenValidator .When(instance => instance.Validate(Arg.Any <string>())) .Do(_ => throw new ArgumentException("Test")); var processor = new CbsRequestProcessor(Substitute.For <ISecurityContext>(), Substitute.For <ILoggerProvider>(), fakeTokenValidator); IDictionary <string, object> responseProperties = await TestAmqpHost.ProcessCbsRequestAsync(testMessageId, processor); responseProperties.ShouldBe(new Dictionary <string, object> { ["CorrelationId"] = testMessageId, ["status-code"] = 401 }); }
public async Task Process_LogError_WhenTokenInvalid() { var testException = new ArgumentException("Test"); ILogger fakeLogger = Substitute.For <ILogger>(); ILoggerProvider fakeLoggerProvider = Substitute.For <ILoggerProvider>(); fakeLoggerProvider.CreateLogger(Arg.Any <string>()).Returns(fakeLogger); ITokenValidator fakeTokenValidator = Substitute.For <ITokenValidator>(); fakeTokenValidator .When(instance => instance.Validate(Arg.Any <string>())) .Do(_ => throw testException); var processor = new CbsRequestProcessor(Substitute.For <ISecurityContext>(), fakeLoggerProvider, fakeTokenValidator); await TestAmqpHost.ProcessCbsRequestAsync("abc", processor); fakeLogger.Received(1).Log( LogLevel.Error, Arg.Any <EventId>(), Arg.Is <FormattedLogValues>(f => f.ToString().StartsWith("Failed to validate $cbs request")), testException, Arg.Any <Func <FormattedLogValues, Exception, string> >() ); }