Example #1
0
        private void StubUsersRepositories()
        {
            A.CallTo(() => EntityRepository.LoadAsync <User>(ManagerOfProductAssemblyShop.Id)).Returns(ManagerOfProductAssemblyShop);
            A.CallTo(() => EntityRepository.GetAsync <User>(ManagerOfProductAssemblyShop.Id)).Returns(ManagerOfProductAssemblyShop);

            A.CallTo(() => EntityRepository.LoadAsync <User>(UserToArchive.Id)).Returns(UserToArchive);
            A.CallTo(() => EntityRepository.GetAsync <User>(UserToArchive.Id)).Returns(UserToArchive);

            A.CallTo(() => EntityRepository.LoadAsync <User>(UserWithPermissions.Id)).Returns(UserWithPermissions);
            A.CallTo(() => EntityRepository.GetAsync <User>(UserWithPermissions.Id)).Returns(UserWithPermissions);

            A.CallTo(() => EntityRepository.LoadAsync <User>(GlobalAdmin.Id)).Returns(GlobalAdmin);
            A.CallTo(() => EntityRepository.GetAsync <User>(GlobalAdmin.Id)).Returns(GlobalAdmin);

            A.CallTo(() => EntityRepository.LoadAsync <DomainResource>(ProduceInventoryItemHandler.Id)).Returns(ProduceInventoryItemHandler);
            A.CallTo(() => EntityRepository.GetAsync <DomainResource>(ProduceInventoryItemHandler.Id)).Returns(ProduceInventoryItemHandler);

            A.CallTo(() => PermissionRepo.Find(ManagerOfProductAssemblyShop, ProduceInventoryItemHandler))
            .Returns(default(Permission));
            A.CallTo(() => PermissionRepo.Find(UserWithPermissions, ProduceInventoryItemHandler))
            .Returns(UserWithPermissionsOnProduceInventoryItemHandler);
            A.CallTo(() => PermissionRepo.Find(GlobalAdmin, ProduceInventoryItemHandler))
            .Returns(GlobalAdminOnProduceInventoryItemHandler);

            A.CallTo(() => PermissionRepo.GetAsync(GlobalAdminOnProduceInventoryItemHandler.Id))
            .Returns(GlobalAdminOnProduceInventoryItemHandler);
            A.CallTo(() => PermissionRepo.GetAsync(UserWithPermissionsOnProduceInventoryItemHandler.Id))
            .Returns(UserWithPermissionsOnProduceInventoryItemHandler);

            A.CallTo(() => EntityRepository.GetAsync <Permission>(GlobalAdminOnProduceInventoryItemHandler.Id))
            .Returns(GlobalAdminOnProduceInventoryItemHandler);
            A.CallTo(() => EntityRepository.GetAsync <Permission>(UserWithPermissionsOnProduceInventoryItemHandler.Id))
            .Returns(UserWithPermissionsOnProduceInventoryItemHandler);
        }
        public void InitialiseSuccessfully()
        {
            var path           = Path.Combine(TestRootDir, PermissionsMissingTestJson);
            var permissionRepo = new PermissionRepo(TestRootDir, PermissionsMissingTestJson);
            var status         = permissionRepo.Initialise();

            status.Should().BeOfType <Success>();
            File.Exists(path).Should().BeTrue();
            var fileContent       = File.ReadAllText(path);
            var deserializeObject = JsonConvert.DeserializeObject <Dictionary <UserRole, List <Permission> > >(fileContent);

            deserializeObject.Should().ContainKeys(UserRole.Administrator, UserRole.Developer, UserRole.Guest, UserRole.ProductOwner);
        }
        public RequestHandlerFactory(IConfiguration configuration)
        {
            _handler = new Lazy <RequestHandler>(() =>
            {
                var rootPath        = configuration.GetValue <string>("App:DataRootPath");
                var userRepo        = new UserRepo(rootPath, "users.json");
                var backlogRepo     = new BacklogRepo(rootPath);
                var permissionsRepo = new PermissionRepo(rootPath, "permissions.json");

                if (userRepo.Initialise() is Failure ||
                    backlogRepo.Initialise() is Failure ||
                    permissionsRepo.Initialise() is Failure)
                {
                    throw new FailedRepositoryCreationException();
                }

                return(new RequestHandler(backlogRepo, new TotalOrder(), userRepo, new Security(), permissionsRepo));
            });
        }
Example #4
0
 public static bool LoginUser(string username, string password)
 {
     try
     {
         _User = new UserRepo().FindByCredentials(username, password);
         _UserPermissionses = new List <UserPermissions>();
         if (_User != null)
         {
             if (!_User.IsAdmin)
             {
                 _UserPermissionses = new UserPermissionRepo().GetUserPermissions(_User.Id);
             }
             else
             {
                 // when user is admin, we should fill all permissions for him in userpermissions list
                 var allperms = new PermissionRepo().GetAll();
                 foreach (Permission item in allperms)
                 {
                     _UserPermissionses.Add(new UserPermissions()
                     {
                         UserID = _User.Id, PermKey = item.PermKey
                     });
                 }
             }
             LoadModules();
             return(true);
         }
         else
         {
             // login failed
             return(false);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
Example #5
0
 internal UserModule()
 {
     userRepo           = new UserRepo();
     userPermissionRepo = new UserPermissionRepo();
     permissionRepo     = new PermissionRepo();
 }
Example #6
0
 public void Setup()
 {
     Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
     _permissionRepo = new PermissionRepo(TestRootDir, PermissionsTestJson);
 }