Exemplo n.º 1
0
        public void ImportUserSecurityPrivilegesFunctionPrivilegesTest()
        {
            var userToExport = MDSWrapper.UserSecurityPrincipalsGet(UserToExport);

            Assert.IsTrue(userToExport != null & userToExport.Users.Any(), "No security principals returned! Connection: " + MDSWrapper.Configuration.EndpointAddress);

            var fileName = String.Format(global::Common.Constants.StringFormatUserPrivileges, userToExport.Users.FirstOrDefault().Identifier.Id);

            MDSWrapper.SecurityPrivilegesExport(null, folderToExport, fileName, userToExport.Users.FirstOrDefault());

            //switching to another environment
            var config = ConfigurationManager.AppSettings;

            MDSWrapper.Configuration = new ConfigValue("MDS Local 2", config.Get("Domain"), config.Get("UserName"), config.Get("Password"), new Uri("http://localhost:82/Service/service.svc"), BindingType.WSHttpBinding);
            MDSWrapper.SecurityPrivilegesImport(Path.Combine(folderToExport, fileName), SecurityPrivilegesOptions.FunctionPrivileges, false);

            var importedUser = MDSWrapper.UserSecurityPrincipalsGet(UserToExport).Users.FirstOrDefault();

            var functPriv = importedUser.SecurityPrivilege.FunctionPrivileges;

            foreach (var item in functPriv)
            {
                Trace.WriteLine(String.Format("Function privilege {0} = {1}", item.Function, item.IsAuthorized));
            }
            //checking if the principal exists in the 2nd environment
            Assert.IsTrue(importedUser.Identifier.Name == importedUser.Identifier.Name, "The user identifier does not match the expected result");
            Assert.IsTrue(importedUser.SecurityPrivilege.FunctionPrivileges.Count == 2, "The function privileges were not copied correctly");
            Assert.IsTrue(importedUser.SecurityPrivilege.ModelPrivileges.Count == 0, "The model privileges were not copied correctly");
            Assert.IsTrue(importedUser.SecurityPrivilege.HierarchyMemberPrivileges.Count == 0, "The hierarc privileges were not copied correctly");

            //Deleting the user
            MDSWrapper.SecurityPrincipalsDelete(importedUser);


            Assert.IsTrue(File.Exists(Path.Combine(folderToExport, fileName)));
        }