Пример #1
0
        public UnitTestBase()
        {
            orgAdminUIService = crm.GetAdminService(new MockupServiceSettings(true, false, MockupServiceSettings.Role.UI));
            orgGodService     = crm.GetAdminService(new MockupServiceSettings(false, true, MockupServiceSettings.Role.SDK));
            orgAdminService   = crm.GetAdminService();
            if (crmRealData != null)
            {
                orgRealDataService = crmRealData.GetAdminService();
            }

            //create an admin user for our impersonating user plugin to run as
            var adminId = Guid.Parse("84a23551-017a-44fa-9cc1-08ee14bb97e8");
            var admin   = new Entity("systemuser");

            admin.Id = adminId;
            admin["internalemailaddress"] = "*****@*****.**";
            admin["businessunitid"]       = crm.RootBusinessUnit;
            admin["islicensed"]           = true;

            // crm.CreateUser

            var adminRole = crm.GetSecurityRole("System Administrator");
            var adminUser = crm.CreateUser(orgAdminService, admin, new Guid[] { adminRole.RoleId });

            InitialiseAccessTeamConfiguration();
        }
Пример #2
0
        public UnitTestBase(XrmMockupFixture fixture)
        {
            crm = fixture.crm;
            crm.ResetEnvironment();
            orgAdminUIService = crm.GetAdminService(new MockupServiceSettings(true, false, MockupServiceSettings.Role.UI));
            orgGodService     = crm.GetAdminService(new MockupServiceSettings(false, true, MockupServiceSettings.Role.SDK));
            orgAdminService   = crm.GetAdminService();
            if (fixture.crmRealData != null)
            {
                orgRealDataService = fixture.crmRealData.GetAdminService();
            }

            //create an admin user to run our impersonating user plugins as
            var adminUser = new Entity("systemuser")
            {
                Id = Guid.Parse("3b961284-cd7a-4fa3-af7e-89802e88dd5c")
            };

            adminUser["businessunitid"]       = crm.RootBusinessUnit;
            adminUser["internalemailaddress"] = "*****@*****.**";
            adminUser["islicensed"]           = true;

            adminUser = crm.CreateUser(orgAdminService, adminUser, SecurityRoles.SystemAdministrator);

            InitialiseAccessTeamConfiguration();
        }
Пример #3
0
        public UnitTestBaseNoReset(XrmMockupFixture fixture)
        {
            crm = fixture.crm;
            orgAdminUIService = crm.GetAdminService(new MockupServiceSettings(true, false, MockupServiceSettings.Role.UI));
            orgGodService     = crm.GetAdminService(new MockupServiceSettings(false, true, MockupServiceSettings.Role.SDK));
            orgAdminService   = crm.GetAdminService();
            if (fixture.crmRealData != null)
            {
                orgRealDataService = fixture.crmRealData.GetAdminService();
            }

            //create an admin user to run our impersonating user plugins as

            var userQuery = new QueryExpression("systemuser");

            userQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, Guid.Parse("3b961284-cd7a-4fa3-af7e-89802e88dd5c"));
            var users = orgAdminService.RetrieveMultiple(userQuery);

            if (users.Entities.SingleOrDefault() == null)
            {
                var adminUser = new Entity("systemuser")
                {
                    Id = Guid.Parse("3b961284-cd7a-4fa3-af7e-89802e88dd5c")
                };
                adminUser["businessunitid"] = crm.RootBusinessUnit;
                adminUser = crm.CreateUser(orgAdminService, adminUser, SecurityRoles.SystemAdministrator);
            }
        }
Пример #4
0
        private void InitialiseAccessTeamConfiguration()
        {
            //create a new security role with basic level only on all contact privileges
            var accessTeamTestRole = crm.CloneSecurityRole("Salesperson");

            accessTeamTestRole.Name = "AccessTeamTest";
            var contactPriv = accessTeamTestRole.Privileges["contact"];
            var newPriv     = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>();

            foreach (var priv in contactPriv)
            {
                var newP = priv.Value.Clone();
                newP.PrivilegeDepth = PrivilegeDepth.Basic;
                newPriv.Add(priv.Key, newP);
            }
            accessTeamTestRole.Privileges.Remove("contact");
            accessTeamTestRole.Privileges.Add("contact", newPriv);

            var accountPriv = accessTeamTestRole.Privileges["account"];

            newPriv = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>();
            foreach (var priv in accountPriv)
            {
                var newP = priv.Value.Clone();
                newP.PrivilegeDepth = PrivilegeDepth.Basic;
                newPriv.Add(priv.Key, newP);
            }
            accessTeamTestRole.Privileges.Remove("account");
            accessTeamTestRole.Privileges.Add("account", newPriv);
            crm.AddSecurityRole(accessTeamTestRole);

            //create a new security role without share priv on contact
            var accessTeamTestRole2 = crm.CloneSecurityRole("Salesperson");

            accessTeamTestRole2.Name = "AccessTeamTestNoShare";
            var contactPriv2 = accessTeamTestRole.Privileges["contact"];
            var newPriv2     = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>();

            foreach (var priv in contactPriv.Where(x => x.Value.AccessRight != AccessRights.ShareAccess))
            {
                var newP = priv.Value.Clone();
                newP.PrivilegeDepth = PrivilegeDepth.Basic;
                newPriv2.Add(priv.Key, newP);
            }
            accessTeamTestRole2.Privileges.Remove("contact");
            accessTeamTestRole2.Privileges.Add("contact", newPriv2);
            crm.AddSecurityRole(accessTeamTestRole2);

            //create a new security role without write priv on contact
            var accessTeamTestRole3 = crm.CloneSecurityRole("Salesperson");

            accessTeamTestRole3.Name = "AccessTeamTestNoWrite";
            var contactPriv3 = accessTeamTestRole.Privileges["contact"];
            var newPriv3     = new Dictionary <AccessRights, DG.Tools.XrmMockup.RolePrivilege>();

            foreach (var priv in contactPriv.Where(x => x.Value.AccessRight != AccessRights.WriteAccess))
            {
                var newP = priv.Value.Clone();
                newP.PrivilegeDepth = PrivilegeDepth.Basic;
                newPriv3.Add(priv.Key, newP);
            }
            accessTeamTestRole3.Privileges.Remove("contact");
            accessTeamTestRole3.Privileges.Add("contact", newPriv3);
            crm.AddSecurityRole(accessTeamTestRole3);

            //create some users with the new role
            var user = new Entity("systemuser");

            user["internalemailaddress"] = "*****@*****.**";
            user["businessunitid"]       = crm.RootBusinessUnit;
            user["islicensed"]           = true;
            testUser1        = crm.CreateUser(orgAdminService, user, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId });
            testUser1Service = crm.CreateOrganizationService(testUser1.Id);

            var user2 = new Entity("systemuser");

            user2["internalemailaddress"] = "*****@*****.**";
            user2["businessunitid"]       = crm.RootBusinessUnit;
            user2["islicensed"]           = true;
            testUser2        = crm.CreateUser(orgAdminService, user2, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId });
            testUser2Service = crm.CreateOrganizationService(testUser2.Id);

            var user3 = new Entity("systemuser");

            user3["internalemailaddress"] = "*****@*****.**";
            user3["businessunitid"]       = crm.RootBusinessUnit;
            user3["islicensed"]           = true;
            testUser3        = crm.CreateUser(orgAdminService, user3, new Guid[] { crm.GetSecurityRole("AccessTeamTest").RoleId });
            testUser3Service = crm.CreateOrganizationService(testUser3.Id);

            var user4 = new Entity("systemuser");

            user4["internalemailaddress"] = "*****@*****.**";
            user4["businessunitid"]       = crm.RootBusinessUnit;
            user4["islicensed"]           = true;
            testUser4        = crm.CreateUser(orgAdminService, user4, new Guid[] { crm.GetSecurityRole("AccessTeamTestNoShare").RoleId });
            testUser4Service = crm.CreateOrganizationService(testUser4.Id);

            var user5 = new Entity("systemuser");

            user5["internalemailaddress"] = "*****@*****.**";
            user5["businessunitid"]       = crm.RootBusinessUnit;
            user5["islicensed"]           = true;
            testUser5 = crm.CreateUser(orgAdminService, user5, new Guid[] { crm.GetSecurityRole("AccessTeamTestNoWrite").RoleId });

            //create some access team templates
            CreateAccessTeamTemplate("TestWriteContact", 2, AccessRights.WriteAccess);
            CreateAccessTeamTemplate("TestReadContact", 2, AccessRights.ReadAccess);
            CreateAccessTeamTemplate("TestDeleteContact", 2, AccessRights.DeleteAccess);
            CreateAccessTeamTemplate("TestAppendContact", 2, AccessRights.AppendAccess);
            CreateAccessTeamTemplate("TestAssignContact", 2, AccessRights.AssignAccess);
            CreateAccessTeamTemplate("TestShareContact", 2, AccessRights.ShareAccess);
            CreateAccessTeamTemplate("TestAppendToAccount", 1, AccessRights.AppendToAccess);
            CreateAccessTeamTemplate("TestMultipleContact", 2, AccessRights.WriteAccess, AccessRights.ReadAccess, AccessRights.DeleteAccess);
        }