public async Task ShouldCallGetUserNameAsyncOnceIfAuthenticated() { _currentUserService.Setup(x => x.UserId).Returns("Administrator"); var performanceBehaviour = new PerformanceBehaviour <CreateCalendarCommand, long>(_logger.Object, _currentUserService.Object); await performanceBehaviour.Handle(new CreateCalendarCommand { }, new CancellationToken(), () => { return(Task.FromResult(1L)); }); _currentUserService.Verify(i => i.UserId, Times.Never); }
public async Task ShouldNotLogWarning() { var requestLogger = new PerformanceBehaviour <CreateArticleCommand, CreateArticleCommandHandler>(_logger.Object, _currentUserService.Object, _identityService.Object); await requestLogger.Handle(new CreateArticleCommand { Id = Guid.NewGuid(), Title = "Article Title", Abstract = "Article Abstract", Image = null, Content = "Article Content" }, new CancellationToken(), _responseShort.Object); _logger.Object.IsSameOrEqualTo(null); }
public async Task DoesPerformanceBehaviourWorksCorrectlyWhenRequestIsSlow() { var fakeStopwatch = new Mock <IStopwatch>(); fakeStopwatch.Setup(x => x.ElapsedMilliseconds).Returns(1000); var loggerFactory = TestLoggerFactory.Create(); var behaviour = new PerformanceBehaviour <SampleRequest, SampleResponse>(fakeStopwatch.Object, loggerFactory.CreateLogger <SampleRequest>()); var request = new SampleRequest { Version = "v2.0", IsWorking = true }; await behaviour.Handle(request, CancellationToken.None, () => Task.FromResult(new SampleResponse { HasWorked = true })); loggerFactory.Sink.LogEntries.Should().ContainSingle(x => x.LogLevel == LogLevel.Warning && x.Message == "eru Long Running Request: SampleRequest (1000 milliseconds) {Version = v2.0, IsWorking = True}"); }
public async Task DoesPerformanceBehaviourWorksCorrectlyWhenRequestIsFast() { var fakeStopwatch = new Mock <IStopwatch>(); fakeStopwatch.Setup(x => x.ElapsedMilliseconds).Returns(100); var loggerFactory = TestLoggerFactory.Create(); var behaviour = new PerformanceBehaviour <SampleRequest, SampleResponse>(fakeStopwatch.Object, loggerFactory.CreateLogger <SampleRequest>()); var request = new SampleRequest { Version = "v2.0", IsWorking = true }; await behaviour.Handle(request, CancellationToken.None, () => Task.FromResult(new SampleResponse { HasWorked = true })); loggerFactory.Sink.LogEntries.Should().BeEmpty(); }
public async Task ShouldNotLogWarning() { var requestLogger = new PerformanceBehaviour <CreateArticleCommand, CreateArticleCommandHandler>(_logger.Object, _currentUserService.Object, _identityService.Object); await requestLogger.Handle(new CreateArticleCommand { Id = Guid.NewGuid(), Title = "Article Title", Abstract = "Article Abstract", Image = null, Content = "Article Content" }, new CancellationToken(), _responseShort.Object); _logger.Verify( l => l.Log( LogLevel.Warning, It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => true), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once ); }