Example #1
0
        public async Task Invoke(HttpContext httpContext, CurrentUserService userService)
        {
            await userService.LoadUser(httpContext.Request.Headers[Header]);

            httpContext.User = userService.GetUser();
            await _next(httpContext);
        }
 public AssignToCurrentUserAction(string listTitle, int listItemId) : base()
 {
     currentUserService            = new CurrentUserService();
     ListItemIdentifiers           = new ListItemIdentifiers();
     ListItemIdentifiers.Id        = listItemId;
     ListItemIdentifiers.ListTitle = listTitle;
 }
Example #3
0
 public GetBasketQueryHandler(AppDbContext context, IMapper mapper, CurrentUserService currentUserService, ILogger <GetBasketQueryHandler> logger)
 {
     _context            = context;
     _mapper             = mapper;
     _currentUserService = currentUserService;
     _logger             = logger;
 }
Example #4
0
 public AddToBasketCommandHandler(AppDbContext context, IMapper mapper, CurrentUserService currentUserService, ILogger <AddToBasketCommandHandler> logger)
 {
     _context            = context;
     _mapper             = mapper;
     _currentUserService = currentUserService;
     _logger             = logger;
 }
Example #5
0
        public async Task GetTeamIdAsync_UserAuthenticated_ReturnsTeamIdOfOne()
        {
            var sut = new CurrentUserService(new FakeAuthenticationStateProvider(true));

            var result = await sut.GetTeamIdAsync();

            result.Should().Be(1);
        }
Example #6
0
        public async Task GetTeamIdAsync_UserNotAuthenticated_ReturnsZero()
        {
            var sut = new CurrentUserService(new FakeAuthenticationStateProvider(false));

            var result = await sut.GetTeamIdAsync();

            result.Should().Be(0);
        }
Example #7
0
        /// <summary>
        /// Setup the test
        /// </summary>
        public CurrentUserUnitTest()
        {
            DbContextOptions <DbAppContext> options      = new DbContextOptions <DbAppContext>();
            Mock <DbAppContext>             dbAppContext = new Mock <DbAppContext>(null, options);
            CurrentUserService _service = new CurrentUserService(null, dbAppContext.Object, null);

            _CurrentUser = new CurrentUserController(_service);
        }
        public MesTableauxViewModel(NavigationManager navigation, CurrentUserService userService, IDataAccess accessData)
        {
            NavigationManager  = navigation;
            currentUserService = userService;
            dataAccess         = accessData;

            GetMesTableaux().GetAwaiter().GetResult();
        }
Example #9
0
 public AuthorsRepository(
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IDbContextResolver contextResolver,
     CurrentUserService currentUser
     ) : base(loggerFactory, jsonApiContext, contextResolver, currentUser)
 {
 }
        public void ShouldNotAuthenticate_WhenUserClaimDoesntExist(Mock <IHttpContextAccessor> contextAccessor)
        {
            // Act
            var sut = new CurrentUserService(contextAccessor.Object);

            // Assert
            sut.UserId.Should().BeEmpty();
            sut.IsAuthenticated.Should().BeFalse();
        }
Example #11
0
 public RequestLogger(
     ILogger <TRequest> logger,
     CurrentUserService currentUserService,
     IdentityService identityService)
 {
     _logger             = logger;
     _currentUserService = currentUserService;
     _identityService    = identityService;
 }
        public void UserId_WhenContextNotPresent_ReturnsSystem()
        {
            var mockCtxAccessor = new Mock <IHttpContextAccessor>();
            var sut             = new CurrentUserService(mockCtxAccessor.Object);

            var result = sut.UserId;

            result.Should().Be("System");
        }
Example #13
0
 public UsersController(
     IJsonApiContext jsonApiContext,
     IResourceService <User> resourceService,
     ILoggerFactory loggerFactory,
     CurrentUserService currentUser
     ) : base(jsonApiContext, resourceService, loggerFactory)
 {
     _currentUser = currentUser;
 }
        public void TestCustomUser()
        {
            CurrentUserService.ResolveUser <CustomUser>();
            var myUser = new CustomUser();

            Assert.Equal(myUser.FriendlyName, CurrentUserService.CurrentUser.FriendlyName);

            CurrentUserService.Reset();
        }
 public SendMailWithTextFromOriginalTicketAction(string listTitle, int listItemId) : base()
 {
     listItemIdentifiers           = new ListItemIdentifiers();
     listItemIdentifiers.Id        = listItemId;
     listItemIdentifiers.ListTitle = listTitle;
     currentUserService            = new CurrentUserService();
     textToSend  = new TicketOriginalText();
     currentUser = currentUserService.GetCurrentUser();
 }
Example #16
0
 public BelongsToUserRepository(
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IDbContextResolver contextResolver,
     CurrentUserService currentUser
     ) : base(loggerFactory, jsonApiContext, contextResolver)
 {
     _currentUser = currentUser;
     _db          = (AppDbContext)contextResolver.GetContext();
 }
Example #17
0
 public RequestPerfObjRelMappinganceBehaviour(
     ILogger <TRequest> logger,
     CurrentUserService currentUserService,
     IdentityService identityService)
 {
     _timer              = new Stopwatch();
     _logger             = logger;
     _currentUserService = currentUserService;
     _identityService    = identityService;
 }
Example #18
0
        public void GivenAnUnauthenticatedContext_ReturnsIsAuthenticatedFalse()
        {
            // Arrange
            var httpContextAccessMock = new Mock <IHttpContextAccessor>();

            // Act
            var result = new CurrentUserService(httpContextAccessMock.Object);

            // Assert
            Assert.IsFalse(result.IsAuthenticated);
        }
Example #19
0
        public async Task <IActionResult> UpdateContractorPersonalDataAsync([FromRoute] int contractorId,
                                                                            [FromBody] UpdateContractorPersonalDataCommand command)
        {
            if (!CurrentUserService.IsUser(contractorId))
            {
                return(BadRequest());
            }

            command.Id = contractorId;
            return(await HandleCommandAsync(command));
        }
        public void UserId_WhenUserNotPresent_ReturnsAnonymous()
        {
            var mockCtxAccessor = new Mock <IHttpContextAccessor>();

            mockCtxAccessor.Setup(x => x.HttpContext)
            .Returns(new DefaultHttpContext());
            var sut = new CurrentUserService(mockCtxAccessor.Object);

            var result = sut.UserId;

            result.Should().Be("Anonymous");
        }
        public async Task <IActionResult> ChangePasswordAsync([FromRoute] int userId,
                                                              [FromBody] ChangePasswordCommand changePasswordCommand)
        {
            if (!CurrentUserService.IsUser(userId))
            {
                return(BadRequest());
            }

            changePasswordCommand.UserId = userId;

            return(await HandleCommandAsync(changePasswordCommand));
        }
 public RecipeService(KitchenMasterDbContext dbContext,
                      RecipeRepository recipeRepository,
                      UserRepository userRepository,
                      CurrentUserService currentUser,
                      IMapper mapper)
     : base(dbContext)
 {
     this._recipeRepository = recipeRepository;
     this._userRepository   = userRepository;
     this._currentUser      = currentUser;
     this._mapper           = mapper;
 }
Example #23
0
        public TableauViewModel(IDataAccess dataAccess, CurrentUserService currentUser,
                                NotificationService notificationSvc, IBlazorDownloadFileService blazorDownloadFileService,
                                NavigationManager navigationManager, IModalService modalSvc)
        {
            DataAccess           = dataAccess;
            CurrentUserService   = currentUser;
            _notificationService = notificationSvc;
            DownloadFileService  = blazorDownloadFileService;

            ModalService      = modalSvc;
            NavigationManager = navigationManager;
        }
 public UserMenuService(KitchenMasterDbContext dbContext,
                        CurrentUserService currentUser,
                        RecipeRepository recipeRepository,
                        MenuHistoryRepository menuHistoryRepository,
                        IMapper mapper)
     : base(dbContext)
 {
     this._dbContext             = dbContext;
     this._currentUser           = currentUser;
     this._recipeRepository      = recipeRepository;
     this._menuHistoryRepository = menuHistoryRepository;
     this._mapper = mapper;
 }
        public async Task <IActionResult> AcceptOrderAsync([FromRoute] int orderId,
                                                           [FromBody] AcceptOrderCommandDto command)
        {
            var acceptOrderCommand = Mapper.Map <AcceptOrderCommand>(command);

            acceptOrderCommand.OrderId = orderId;
            if (!CurrentUserService.IsUser(command.ContractorId))
            {
                return(BadRequest());
            }

            return(await HandleCommandAsync(acceptOrderCommand));
        }
Example #26
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var description = Description;

            foreach (var keyValuePair in _parameters)
            {
                description = description.Replace("{" + keyValuePair.Key + "}", keyValuePair.Value.ToString());
            }

            var logAction = new LogAction(CurrentUserService.GetCurrentUser(), filterContext.ActionDescriptor.ActionName,
                                          filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, description);

            LogManager.LogControllerAction(logAction);
        }
        public UserAuthenticationService(
            IdentityDbService context,
            IdentityService identityService,
            CurrentUserService currentUserService,
//#??must confugured for dep inj
            UserManagerService <IAppUser> userManager,
            SignInManagerService <IAppUser> signInManager)
        {
            _context            = context;
            _identityService    = identityService;
            _userManager        = userManager;
            _signInManager      = signInManager;
            _currentUserService = currentUserService;
        }
        public void SetUp()
        {
            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext();

            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);
            _operativeGatewayMock = new Mock <IOperativesGateway>();

            _groupGatewayMock = new Mock <IGroupsGateway>();
            _classUnderTest   = new CurrentUserService(
                new NullLogger <CurrentUserService>(),
                _groupGatewayMock.Object,
                mockHttpContextAccessor.Object,
                _operativeGatewayMock.Object);
        }
Example #29
0
        public NewTableViewModel(CurrentUserService userService, IDataAccess dataAccess,
                                 NotificationService notification, NavigationManager navigationManager,
                                 IModalService modalSvc)
        {
            TableauModel         = new TableauModelValidation();
            TableauModel.IdTable = Guid.NewGuid();

            NouvelleColonne = new ColonneModel();

            CurrentUserService   = userService;
            DataService          = dataAccess;
            _notificationService = notification;

            ModalService       = modalSvc;
            _navigationManager = navigationManager;
        }
        public async Task UserNotLoggedIn()
        {
            var context = MakeContenxt();

            var service = new CurrentUserService(
                context.HttpContextAccessor,
                context.UsersDao,
                context.BranchesDao,
                context.CarsDao);

            Assert.False(service.IsAuthenticated);
            Assert.Null(await service.GetUserAsync());
            Assert.Null(await service.GetRoleAsync());
            Assert.Null(await service.GetBranchAsync());
            Assert.Null(await service.GetCarAsync());
        }