Exemplo n.º 1
0
 public RoleObject(Role role)
 {
    this.Id = role.Id;
    this.Name = role.Name;
    this.Description = role.Description;
    
    if (role.Permissions != null)
    {
       this.Permissions = new List<PermissionObject>();
       foreach (var p in role.Permissions)
       {
          this.Permissions.Add(new PermissionObject(p));
       }
    }
 }
Exemplo n.º 2
0
 private bool RoleHasPermission(Role r, Privileges privilege)
 {
     return SecurityUtil.ExistOnCurrentWorkstation(privilege) &&
         (from p in r.Permissions where p.Name == privilege.ToString() select p).Count() > 0;
 }
Exemplo n.º 3
0
 internal bool UserHasRole(User user, Role role)
 {
     return (from r in user.Roles where r.Id == role.Id select r).Count() > 0;
 }
Exemplo n.º 4
0
 public void RemoveRoleFromUser(Role role, User user)
 {
     var userRole = user.Roles.Where(_ => _.Id == role.Id).FirstOrDefault();
     if(userRole != null)
     {
         user.Roles.Remove(userRole);
         ModifiableView.IsModified = true;
     }
 }
Exemplo n.º 5
0
 public void AddRoleToUser(Role role, User user)
 {
     var userRole = user.Roles.Where(_ => _.Id == role.Id).FirstOrDefault();
     if(userRole == null)
     {
         user.Roles.Add(role);
         ModifiableView.IsModified = true;
     }
 }
Exemplo n.º 6
0
 public void AddPermissionToRole(Role role, Permission p)
 {
     var rolePerm = role.Permissions.Where(_ => _.Id == p.Id).FirstOrDefault();
     if(rolePerm == null)
     {
         role.Permissions.Add(p);
         ModifiableView.IsModified = true;
     }
 }
Exemplo n.º 7
0
        public void RemovePermissionFromRole(Role role, Permission p)
        {
            var rolePerm = role.Permissions.Where(_ => _.Id == p.Id).FirstOrDefault();
            if(rolePerm != null)
            {
                role.Permissions.Remove(rolePerm);
                ModifiableView.IsModified = true;
            }

        }
Exemplo n.º 8
0
 public bool RoleHasPermission(Role role, Permission perm)
 {
     return (from p in role.Permissions where p.Id == perm.Id select p).Count() > 0;
 }
        public void TestSaveSettings()
        {
            var notify = new Mock<IUserNotify>();

            var repoPipeSize = new Mock<IMillPipeSizeTypeRepository>();
            var repoPipeTests = new Mock<IPipeTestRepository>();
            var repoWelders = new Mock<IWelderRepository>();
            var repoInspectors = new Mock<IInspectorRepository>();
            var repoManufacturers = new Mock<IPlateManufacturerRepository>();
            var repoProjectSetting = new Mock<IProjectRepository>();
            var repoUsers = new Mock<IUserRepository>();
            var repoRoles = new Mock<IRoleRepository>();
            var repoPerms = new Mock<IPermissionRepository>();
            var repoCategory = new Mock<ICategoryRepository>();
            var repoJointOperation = new Mock<IJointOperationRepository>();
            var repoCertificateType = new Mock<ICertificateTypeRepository>();
            var repoComponentType = new Mock<IComponentTypeRepository>();
            var repoSeamType = new Mock<ISeamTypeRepository>();

            var testProjectSetting = new Project() { IsNative = true};
            var testSizeType = new PipeMillSizeType() 
            { 
                IsNative = true, 
                Project = testProjectSetting,
                Diameter = 10,
                Thickness = 5,
                SeamType = new SeamType(),
                Length = 20,
            };
            foreach (PipeTest t in testSizeType.PipeTests)
            {
                t.Code = "Code";
                t.Name = "Name";
                t.ControlType = PipeTestControlType.Monitor;
                t.ResultType = PipeTestResultType.Boolean;
            }
            var testWelder = new Welder() { Certificate = new Certificate() { ExpirationDate = DateTime.Now} };
            var testManufacturer = new PlateManufacturer() { IsNative = true, Project = testProjectSetting};
            var testInspector = new Inspector();
            var testUser = new User();
            var testRole = new Role();
            var testPerm = new Permission() { Name = "CreateJoint" };
            var modifiableView = new Mock<IModifiable>();
            var jointOperations = new JointOperation();
            var ctx = new Mock<ISecurityContext>();

            repoPipeSize.Setup(_ => _.GetAll()).Returns(new List<PipeMillSizeType>() { testSizeType });
            repoWelders.Setup(_ => _.GetAll()).Returns(new List<Welder>() { testWelder });
            repoManufacturers.Setup(_ => _.GetAll()).Returns(new List<PlateManufacturer>() { testManufacturer });
            repoProjectSetting.Setup(_ => _.GetSingle()).Returns(testProjectSetting);
            repoInspectors.Setup(_ => _.GetAll()).Returns(new List<Inspector>() { testInspector });
            repoUsers.Setup(_ => _.GetAll()).Returns(new List<User>() { testUser });
            repoRoles.Setup(_ => _.GetAll()).Returns(new List<Role>() { testRole });
            repoPerms.Setup(_ => _.GetAll()).Returns(new List<Permission>() { testPerm });
            repoJointOperation.Setup(_ => _.GetAll()).Returns(new List<JointOperation>() { jointOperations });
            repoCategory.Setup(x => x.GetAll()).Returns(new List<Category>() { new Category() });
            repoCertificateType.Setup(x => x.GetAll()).Returns(new List<InspectorCertificateType>() { new InspectorCertificateType() });
            repoComponentType.Setup(x => x.GetAll()).Returns(new List<ComponentType>() { new ComponentType() });


            Mock<ISettingsRepositories> settingsRepos = new Mock<ISettingsRepositories>();
            settingsRepos.SetupGet(_ => _.PipeSizeTypeRepo).Returns(repoPipeSize.Object);
            settingsRepos.SetupGet(_ => _.PipeTestRepo).Returns(repoPipeTests.Object);
            settingsRepos.SetupGet(_ => _.WelderRepo).Returns(repoWelders.Object);
            settingsRepos.SetupGet(_ => _.PlateManufacturerRepo).Returns(repoManufacturers.Object);
            settingsRepos.SetupGet(_ => _.ProjectRepo).Returns(repoProjectSetting.Object);
            settingsRepos.SetupGet(_ => _.InspectorRepo).Returns(repoInspectors.Object);
            settingsRepos.SetupGet(_ => _.UserRepo).Returns(repoUsers.Object);
            settingsRepos.SetupGet(_ => _.RoleRepo).Returns(repoRoles.Object);
            settingsRepos.SetupGet(_ => _.PermissionRepo).Returns(repoPerms.Object);
            settingsRepos.SetupGet(_ => _.JointRepo).Returns(repoJointOperation.Object);
            settingsRepos.SetupGet(x => x.СategoryRepo).Returns(repoCategory.Object);
            settingsRepos.SetupGet(x => x.CertificateTypeRepo).Returns(repoCertificateType.Object);
            settingsRepos.SetupGet(x => x.ComponentTypeRepo).Returns(repoComponentType.Object);
            settingsRepos.SetupGet(x => x.SeamTypeRepo).Returns(repoSeamType.Object);

            var viewModel = new SettingsViewModel(settingsRepos.Object, notify.Object, ctx.Object);
            viewModel.ModifiableView = modifiableView.Object;
            viewModel.LoadData();
            viewModel.ModifiableView = modifiableView.Object;
            var validatable = new Mock<IValidatable>();
            validatable.Setup(x => x.Validate()).Returns(true);
            viewModel.validatableView = validatable.Object;

            var command = new SaveSettingsCommand(viewModel, settingsRepos.Object, notify.Object, ctx.Object);

            command.Execute();

            settingsRepos.Verify(_ => _.BeginTransaction(), Times.Once());
            repoPipeSize.Verify(_ => _.SaveOrUpdate(testSizeType), Times.Once());
            settingsRepos.Verify(_ => _.Commit(), Times.Once());
            repoPipeSize.Verify(_ => _.Evict(testSizeType), Times.Once());
            repoWelders.Verify(_ => _.SaveOrUpdate(testWelder), Times.Once());
            repoWelders.Verify(_ => _.Evict(testWelder), Times.Once());
            repoManufacturers.Verify(_ => _.SaveOrUpdate(testManufacturer), Times.Once());
            repoManufacturers.Verify(_ => _.Evict(testManufacturer), Times.Once());
            repoProjectSetting.Verify(_ => _.SaveOrUpdate(testProjectSetting), Times.Once());
            repoProjectSetting.Verify(_ => _.Evict(testProjectSetting), Times.Once());
            repoInspectors.Verify(_ => _.SaveOrUpdate(testInspector), Times.Once());
            repoInspectors.Verify(_ => _.Evict(testInspector), Times.Once());
            repoUsers.Verify(_ => _.SaveOrUpdate(testUser), Times.Once());
            repoUsers.Verify(_ => _.Evict(testUser), Times.Once());
            repoRoles.Verify(_ => _.SaveOrUpdate(testRole), Times.Once());
            repoRoles.Verify(_ => _.Evict(testRole), Times.Once());
        }