Beispiel #1
0
        public async Task ShouldNotCallGetUserNameAsyncOnceIfUnauthenticated()
        {
            var requestLogger = new LoggingBehavior <CreateDeliveryCommand>(_logger.Object, _currentUserService.Object, _identityService.Object);

            await requestLogger.Process(new CreateDeliveryCommand {
                ZoneId = 1,
                Title  = "title"
            }, new CancellationToken());

            _identityService.Verify(i => i.GetUserNameAsync(null), Times.Never);
        }
Beispiel #2
0
        public async Task ShouldCallGetUserNameAsyncOnceIfAuthenticated()
        {
            _currentUserService.Setup(x => x.UserId).Returns("Administrator");

            var requestLogger = new LoggingBehavior <CreateDeliveryCommand>(_logger.Object, _currentUserService.Object, _identityService.Object);

            await requestLogger.Process(new CreateDeliveryCommand {
                ZoneId = 1,
                Title  = "title"
            }, new CancellationToken());

            _identityService.Verify(i => i.GetUserNameAsync(It.IsAny <string>()), Times.Once);
        }
        public async Task OnLoggingBehavior_WithUnauthenticadUser_CallsGetUserNameAsync()
        {
            //Arrange
            _currentUserService.Setup(x => x.RecoverUserId).Returns(new ServiceResponse <string>()
            {
                Data = "Administrator"
            });
            _identityService.Setup(x => x.GetUserNameAsync(It.IsAny <string>())).ReturnsAsync(new ServiceResponse <string>()
            {
                Data = "Administrator"
            });
            var requestLogger = new LoggingBehavior <CreateAssetCommand>(_logger.Object, _currentUserService.Object, _identityService.Object);

            //Act
            await requestLogger.Process(new CreateAssetCommand(), new CancellationToken());

            //Assert
            _identityService.Verify(i => i.GetUserNameAsync(null), Times.Never);
        }