Exemplo n.º 1
0
        public DataBaseManager()
        {
            DbContext = new Context();

            User = new UserManager(this);
            Authentication = new AuthenticationManager(this);
            Authorization = new AuthorizationManager(this);
            Container = new ContainerManager(this);
            ContainerPrototype = new ContainerPrototypeManager(this);
            Role = new RoleManager(this);
            RoleType = new RoleTypeManager(this);
            Rule = new RuleManager(this);
            Service = new ServiceManager(this);
            Structure = new StructureManager(this);
            WorkSpaceType = new WorkSpaceTypeManager(this);
        }
Exemplo n.º 2
0
        public void ShouldTestBasicFeaturesWithoutCache()
        {
            DataBaseManager.DropAndCreate();

            DataBaseManager dataBaseManager;
            dataBaseManager = new DataBaseManager();

            #region CREATE_SERVICES

            var serviceManager = new ServiceManager(dataBaseManager);

            var serviceGit = new ServiceView()
                                 {
                                     Name = "Git",
                                     Description = "System Version Control (decentralized)"
                                 };

            serviceManager.Create(serviceGit, new[] {"r", "rw"});

            var serviceSvn = new ServiceView()
                                 {
                                     Name = "SVN",
                                     Description = "System Version Control (Centralized)"
                                 };

            serviceManager.Create(serviceSvn, new[] {"r", "rw"});

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_USERS

            var userManager = new UserManager(dataBaseManager);

            var userFaustino = new UserView()
                                   {
                                       Name = "FaustinoLeiras",
                                       Email = "*****@*****.**",
                                       Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                   };

            userManager.Create(userFaustino);

            var userSamir = new UserView()
                                {
                                    Name = "SamirHafez",
                                    Email = "*****@*****.**",
                                    Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                };

            userManager.Create(userSamir);

            var userRicardo = new UserView()
                                  {
                                      Name = "Ricardo",
                                      Email = "*****@*****.**",
                                      Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                  };

            userManager.Create(userRicardo);

            var userGeada = new UserView()
                                {
                                    Name = "Gueada",
                                    Email = "*****@*****.**",
                                    Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                };

            userManager.Create(userGeada);

            var userFelix = new UserView()
                                {
                                    Name = "Felix",
                                    Email = "*****@*****.**",
                                    Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                };

            userManager.Create(userFelix);

            var userGuedes = new UserView()
                                 {
                                     Name = "Guedes",
                                     Email = "*****@*****.**",
                                     Password = AuthenticationManager.EncryptPassword("12345678Ab")
                                 };

            userManager.Create(userGuedes);

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_STRUCTURE

            var structureManager = new StructureManager(dataBaseManager);

            var structure = new StructureView()
                                {
                                    Name = "AcademicStructure",
                                    Description = "My Academic Structure :)"
                                };

            structureManager.Create(structure, userFelix.Name);

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_WORKSPACE_TYPE

            var workspaceType = new WorkSpaceTypeManager(dataBaseManager);

            var workspacePublic = new WorkSpaceTypeView()
                                      {
                                          Name = "public"
                                      };

            workspaceType.Create(workspacePublic, structure.Id, new[] {serviceGit.Name, serviceSvn.Name});

            var workspacePrivate = new WorkSpaceTypeView()
                                       {
                                           Name = "private"
                                       };

            workspaceType.Create(workspacePrivate, structure.Id, new[] {serviceGit.Name, serviceSvn.Name});

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_CONTAINER_PROTOTYPE

            var containerPrototype = new ContainerPrototypeManager(dataBaseManager);

            var prototypeCourse = new ContainerPrototypeView()
                                      {
                                          Name = "Course"
                                      };

            containerPrototype.Create(prototypeCourse, structure.Id);

            var prototypeClass = new ContainerPrototypeView()
                                     {
                                         Name = "Class"
                                     };

            containerPrototype.Create(prototypeClass, structure.Id, prototypeCourse.Name);

            var prototypeGroup = new ContainerPrototypeView()
                                     {
                                         Name = "Group"
                                     };

            containerPrototype.Create(prototypeGroup, structure.Id, prototypeClass.Name);

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region ADD_WORKSPACE_TYPES_INTO_CONTAINER_PROTOTYPE

            containerPrototype = new ContainerPrototypeManager(dataBaseManager);

            containerPrototype.AddWorkSpaceType(structure.Id, prototypeCourse.Name, workspacePublic.Name);

            containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePublic.Name);
            containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePrivate.Name);

            containerPrototype.AddWorkSpaceType(structure.Id, prototypeGroup.Name, workspacePublic.Name);

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_ROLETYPE

            var roleType = new RoleTypeManager(dataBaseManager);

            var roleTypeTeacher = new RoleTypeView()
                                      {
                                          Name = "teacher"
                                      };

            roleType.Create(roleTypeTeacher, structure.Id);

            var roleTypeDirector = new RoleTypeView()
                                       {
                                           Name = "director"
                                       };

            roleType.Create(roleTypeDirector, structure.Id);

            var roleTypeStudant = new RoleTypeView()
                                      {
                                          Name = "studant"
                                      };

            roleType.Create(roleTypeStudant, structure.Id);

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_RULE

            var rule = new RuleManager(dataBaseManager);

            var ruleReaders = new RuleView()
                                  {
                                      Name = "readers"
                                  };

            rule.Create(ruleReaders, structure.Id, new[]
                                                       {
                                                           new KeyValuePair<string, string>(serviceGit.Name, "r"),
                                                           new KeyValuePair<string, string>(serviceSvn.Name, "r")
                                                       });

            var ruleReadersAndWriters = new RuleView()
                                            {
                                                Name = "ReadersAndWriters"
                                            };

            rule.Create(ruleReadersAndWriters, structure.Id, new[]
                                                                 {
                                                                     new KeyValuePair<string, string>(
                                                                         serviceGit.Name,
                                                                         "rw"),
                                                                     new KeyValuePair<string, string>(
                                                                         serviceSvn.Name,
                                                                         "rw")
                                                                 });

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_ROLE

            var role = new RoleManager(dataBaseManager);

            #region ADD_ROLES_COURSE_WORKSPACE_PUBLIC

            role.Create(
                structure.Id,
                prototypeCourse.Name,
                workspacePublic.Name,
                roleTypeDirector.Name,
                ruleReadersAndWriters.Name
                );

            role.Create(
                structure.Id,
                prototypeCourse.Name,
                workspacePublic.Name,
                roleTypeTeacher.Name,
                ruleReaders.Name
                );

            role.Create(
                structure.Id,
                prototypeCourse.Name,
                workspacePublic.Name,
                roleTypeStudant.Name,
                ruleReaders.Name
                );

            #endregion

            #region ADD_ROLES_CLASS_WORKSPACE_PUBLIC

            role.Create(
                structure.Id,
                prototypeClass.Name,
                workspacePublic.Name,
                roleTypeDirector.Name,
                ruleReaders.Name
                );

            role.Create(
                structure.Id,
                prototypeClass.Name,
                workspacePublic.Name,
                roleTypeTeacher.Name,
                ruleReadersAndWriters.Name
                );

            role.Create(
                structure.Id,
                prototypeClass.Name,
                workspacePublic.Name,
                roleTypeStudant.Name,
                ruleReaders.Name
                );

            #endregion

            #region ADD_ROLES_CLASS_WORKSPACE_PRIVATE

            role.Create(
                structure.Id,
                prototypeClass.Name,
                workspacePrivate.Name,
                roleTypeDirector.Name,
                ruleReaders.Name
                );

            role.Create(
                structure.Id,
                prototypeClass.Name,
                workspacePrivate.Name,
                roleTypeTeacher.Name,
                ruleReadersAndWriters.Name
                );

            #endregion

            #region ADD_ROLES_GROUP_WORKSPACE_PUBLIC

            role.Create(
                structure.Id,
                prototypeGroup.Name,
                workspacePublic.Name,
                roleTypeDirector.Name,
                ruleReaders.Name
                );

            role.Create(
                structure.Id,
                prototypeGroup.Name,
                workspacePublic.Name,
                roleTypeTeacher.Name,
                ruleReadersAndWriters.Name
                );

            role.Create(
                structure.Id,
                prototypeGroup.Name,
                workspacePublic.Name,
                roleTypeStudant.Name,
                ruleReadersAndWriters.Name
                );

            #endregion

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region CREATE_CONTAINERS

            var container = new ContainerManager(dataBaseManager);

            #region CREATE_COURSE_MPD

            var containerMpd = new ContainerView()
                                   {
                                       Name = "MPD",
                                       Description = "Modelo de padoes de desenho"
                                   };

            container.Create(containerMpd, structure.Id, prototypeCourse.Name);

            var containerMpdLi31D = new ContainerView()
                                        {
                                            Name = "LI31D",
                                            Description = "Turma 1 de terceiro semestre diurno"
                                        };

            container.Create(containerMpdLi31D, structure.Id, prototypeClass.Name, containerMpd.Id);

            var containerMpdG1 = new ContainerView()
                                     {
                                         Name = "Grupo1",
                                         Description = "Grupo de MPD"
                                     };

            container.Create(containerMpdG1, structure.Id, prototypeGroup.Name, containerMpdLi31D.Id);

            var containerMpdG2 = new ContainerView()
                                     {
                                         Name = "Grupo2",
                                         Description = "Grupo de MPD"
                                     };

            container.Create(containerMpdG2, structure.Id, prototypeGroup.Name, containerMpdLi31D.Id);

            #endregion

            #region CREATE_COURSE_SD

            var containerSd = new ContainerView()
                                  {
                                      Name = "SD",
                                      Description = "Sistemas distribuidos"
                                  };

            container.Create(containerSd, structure.Id, prototypeCourse.Name);

            var containerSdLi31D = new ContainerView()
                                       {
                                           Name = "LI31D",
                                           Description = "Turma 1 de terceiro semestre diurno"
                                       };

            container.Create(containerSdLi31D, structure.Id, prototypeClass.Name, containerSd.Id);

            var containerSdG1 = new ContainerView()
                                    {
                                        Name = "Grupo1",
                                        Description = "Grupo de SD"
                                    };

            container.Create(containerSdG1, structure.Id, prototypeGroup.Name, containerSdLi31D.Id);

            var containerSdG2 = new ContainerView()
                                    {
                                        Name = "Grupo2",
                                        Description = "Grupo de SD"
                                    };

            container.Create(containerSdG2, structure.Id, prototypeGroup.Name, containerSdLi31D.Id);

            #endregion

            #endregion

            dataBaseManager.Dispose();
            dataBaseManager = new DataBaseManager();

            #region ENROLL_USER

            userManager = new UserManager(dataBaseManager);

            userManager.Enroll(userFelix.Name, structure.Id, containerMpd.Id, roleTypeDirector.Name);
            userManager.Enroll(userGuedes.Name, structure.Id, containerSd.Id, roleTypeDirector.Name);

            userManager.Enroll(userFelix.Name, structure.Id, containerSdLi31D.Id, roleTypeTeacher.Name);
            userManager.Enroll(userGuedes.Name, structure.Id, containerMpdLi31D.Id, roleTypeTeacher.Name);

            userManager.Enroll(userFaustino.Name, structure.Id, containerMpdG1.Id, roleTypeStudant.Name);
            userManager.Enroll(userSamir.Name, structure.Id, containerMpdG1.Id, roleTypeStudant.Name);

            userManager.Enroll(userRicardo.Name, structure.Id, containerMpdG2.Id, roleTypeStudant.Name);
            userManager.Enroll(userGeada.Name, structure.Id, containerMpdG2.Id, roleTypeStudant.Name);

            userManager.Enroll(userFaustino.Name, structure.Id, containerSdG1.Id, roleTypeStudant.Name);
            userManager.Enroll(userRicardo.Name, structure.Id, containerSdG1.Id, roleTypeStudant.Name);

            userManager.Enroll(userGeada.Name, structure.Id, containerSdG2.Id, roleTypeStudant.Name);
            userManager.Enroll(userSamir.Name, structure.Id, containerSdG2.Id, roleTypeStudant.Name);

            #endregion

            dataBaseManager.Dispose();
            using (dataBaseManager = new DataBaseManager())
            {
                AuthorizationTestes aut = new AuthorizationTestes();
                AuthorizationManager authorizationManager = new AuthorizationManager(dataBaseManager);

                authorizationManager.CreateServiceAuthorizationStruct(aut, serviceSvn.Name);
            }
        }