public Task Invoke(HttpContext httpContext, IRequestScope requestScope) { var token = httpContext.Request?.Headers["Authorization"]; var endpoint = httpContext.Features?.Get <IEndpointFeature>()?.Endpoint; var allowAnonymous = endpoint?.Metadata?.GetMetadata <IAllowAnonymous>(); if (allowAnonymous != null) { return(_next(httpContext)); } if (!token.HasValue || !token.Value.Any()) { return(_next(httpContext)); } var userId = httpContext.User.GetValue("userId"); if (userId.HasValue()) { requestScope.SetUserId(Guid.Parse(userId)); } return(_next(httpContext)); }
public FavoriteBookApplicationServiceTest() : base() { CreateScope(); _userRepository = GetIntanceScope <IUserRepository>(); _favoriteBookRepository = GetIntanceScope <IFavoriteBookRepository>(); _unitOfWork = GetIntanceScope <IUnitOfWork>(); _requestScope = GetIntanceScope <IRequestScope>(); _favoriteBookApplicationService = GetIntanceScope <IFavoriteBookApplicationService>(); CreateUser(); _requestScope.SetUserId(currentUser.Id); }
public void UserApplicationService_Add_without_permission() { var currentUser = new UserBuilder().WithProfile(ProfileType.Standard).Builder(); _userRepository.Add(currentUser); _unitOfWork.Commit(); _requestScope.SetUserId(currentUser.Id); var model = new UserModel { Name = "test", Email = "*****@*****.**", Password = "******", Profile = (short)ProfileType.Standard }; _userApplicationService.Add(model); var result = _userRepository.Get(new Filter()); result.totalItems.Should().Be(1); result.entities.Should().HaveCount(1); DomainNotificationHandler.HasNotifications().Should().BeTrue(); DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.StandardProfileUserDoesNotHavePermission); }