public void Setup()
        {
            _dbFaker = new SecurityDbFaker();
            _mapper  = new Mapper(new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <AccessRightProfile>();
            }));

            _mock = new Mock <ISecurityData>();

            //success
            _mock.Setup(x => x.DeleteRight(It.Is <int>(right =>
                                                       _dbFaker.AccessRights.Any(l => l.Id == right))))
            .Returns <int>(id =>
            {
                return(Task.FromResult(true));
            });

            //not exists
            _mock.Setup(x => x.DeleteRight(It.Is <int>(right =>
                                                       _dbFaker.AccessRights.All(l => l.Id != right))))
            .Returns <int>(id =>
            {
                throw new SecurityDbException("not exists", ExceptionType.NotFound,
                                              EntityType.Right, new[] { id.ToString() });
            });

            _securityData = new RightsService(_mock.Object, _mapper);
        }
Пример #2
0
 public RoleService(IRoleRepository roleRepository, IRightsService rightsService, IOrganizationRepository organizationRepository, IUnitOfWork uow)
 {
     this._roleRepository         = roleRepository;
     this._rightsService          = rightsService;
     this._organizationRepository = organizationRepository;
     this._uow = uow;
 }
Пример #3
0
 /// <summary>
 /// Constructor for initializing services and cache.
 /// </summary>
 /// <param name="userService">User service to be used</param>
 /// <param name="accountService">Account service to be used</param>
 /// <param name="rightsService">Rights service to be used</param>
 /// <param name="dataService">Data service to be used</param>
 /// <param name="memoryCache">Cache to be used</param>
 public CreateModel(IUserService userService, IAccountService accountService, IRightsService rightsService, IDataService dataService, IMemoryCache memoryCache)
 {
     this.userService    = userService;
     this.accountService = accountService;
     this.rightsService  = rightsService;
     this.dataService    = dataService;
     this.cache          = memoryCache;
 }
Пример #4
0
        public RightsServiceTest()
        {
            IUnitOfWork       uow = new NHUnitOfWork();
            IRightsRepository _rightsRepository = new RightsRepository(uow);

            this._rightsService = new RightsService(_rightsRepository, uow);
            AutoMapperBootStrapper.ConfigureAutoMapper();
        }
Пример #5
0
 public AccountController(
     IUsersService usersService,
     ICookieStorageService cookieStorageService,
     IAuthenticationService authenticationService,
     IUserDeviceService serDeviceService,
     IRightsService rightsService
     )
 {
     this._usersService          = usersService;
     this._cookieStorageService  = cookieStorageService;
     this._authenticationService = authenticationService;
     this._serDeviceService      = serDeviceService;
     this._rightsService         = rightsService;
 }
        public void Setup()
        {
            _dbFaker = new SecurityDbFaker();
            _mapper  = new Mapper(new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <AccessRightProfile>();
                cfg.AddProfile <AccessFunctionProfile>();
                cfg.AddProfile <FeatureProfile>();
                cfg.AddProfile <RoleProfile>();
                cfg.AddProfile <UserRightsProfile>();
            }));

            _mock = new Mock <ISecurityData>();
            //success
            _mock.Setup(x => x.AddRights(It.Is <string[]>(right =>
                                                          !right.Any(l => _dbFaker.AccessRights.Any(k => k.Name == l)))))
            .Returns <string[]>(names =>
            {
                return(Task.FromResult(names.Select((name, i) =>
                                                    new AccessRightDb
                {
                    Name = name,
                    Id = _dbFaker.AccessRights.Max(l => l.Id) + i + 1
                }).ToArray()));
            });

            //existed name
            _mock.Setup(x => x.AddRights(It.Is <string[]>(right =>
                                                          right.Any(l => _dbFaker.AccessRights.Any(k => k.Name == l)))))
            .Returns <string[]>(names =>
            {
                throw new SecurityDbException("existed name", ExceptionType.NameExists,
                                              EntityType.Right, names);
            });

            //unknown error
            _mock.Setup(x => x.AddRights(It.Is <string[]>(right =>
                                                          right.Any(l => l.Equals("Error!")))))
            .Returns <string[]>(names =>
            {
                throw new Exception();
            });

            _securityData = new RightsService(_mock.Object, _mapper);
        }
        public void Setup()
        {
            _dbFaker = new SecurityDbFaker();
            _mapper  = new Mapper(new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <AccessRightProfile>();
                cfg.AddProfile <AccessFunctionProfile>();
                cfg.AddProfile <FeatureProfile>();
                cfg.AddProfile <RoleProfile>();
                cfg.AddProfile <UserRightsProfile>();
            }));

            _mock = new Mock <ISecurityData>();
            _mock.Setup(x => x.GetRights(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns((int i, int p, string m) =>
                     Task.FromResult(new AccessRightsGetResult {
                Rights = _dbFaker.AccessRights.Where(l => string.IsNullOrEmpty(m) || l.Name.Contains(m))
                         .OrderBy(l => l.Name).Skip((p - 1) * i).Take(i)
            }));
            _securityData = new RightsService(_mock.Object, _mapper);
        }
Пример #8
0
        /// <summary>
        /// This method is used to load all available RightsModels for an application from the server.
        /// These models are then converted to the list of SelectListItem that can be used in HTML
        /// selects to pick a rights for user.
        /// </summary>
        /// <param name="rightsService">Rights service to conntect to the server</param>
        /// <param name="token">JWT token to authenticate at the server</param>
        /// <returns>List of SelectListItem</returns>
        public async Task <List <SelectListItem> > FillUserRightsData(IRightsService rightsService, JWTToken token)
        {
            var response = await rightsService.GetAll(token);

            // If server did not return the rights successfully
            if (!response.IsSuccessStatusCode)
            {
                Logger.LogToConsole($"For user with token {token.Value} rights to select did not load successfully from the server.");
                return(new List <SelectListItem>());
            }
            ;
            // Deserialize response
            List <RightsModel> data = JsonConvert.DeserializeObject <List <RightsModel> >(await response.Content.ReadAsStringAsync());

            // Transform it to the select list
            return(data.Select(x =>
                               new SelectListItem
            {
                Value = x.Id.ToString(),
                Text = x.Name
            })
                   .ToList());
        }
Пример #9
0
 //private readonly ILogger _ILogger;
 public RightsController(IRightsService rightsService)
 {
     _rightsService = rightsService;
     //_ILogger = logger;
 }
Пример #10
0
 /// <summary>
 /// Constructor for initializing services and cache.
 /// </summary>
 /// <param name="rightsService">Rights service to be used</param>
 /// <param name="accountService">Account service to be used</param>
 /// <param name="memoryCache">Cache to be used</param>
 public EditModel(IRightsService rightsService, IAccountService accountService, IMemoryCache memoryCache)
 {
     this.rightsService  = rightsService;
     this.accountService = accountService;
     this.cache          = memoryCache;
 }
Пример #11
0
 public RightsController(IRightsService rightsService)
 {
     this._rightsService = rightsService;
 }
Пример #12
0
 public RightsController(IRightsService rightsService, ILogger logger)
 {
     _rightsService = rightsService;
     _ILogger       = logger;
 }
Пример #13
0
 public RoleController(IRoleService roleService, IRightsService rightsService)
 {
     this._roleService   = roleService;
     this._rightsService = rightsService;
 }
Пример #14
0
 public ChooseTripController(IRightsService iserv)
 {
     this.rightsService = iserv;
 }
 public RightsChecker(IRightsService service)
 {
     this.service = service;
 }
Пример #16
0
 public RightsController(IRightsService securityService)
 {
     _securityService = securityService;
 }