public void IIA001() { string[] files = new string[] { "2.IIA001Policy.xml" }; string tempFile = Path.GetTempFileName(); XmlTextWriter tw = new XmlTextWriter(tempFile, System.Text.Encoding.ASCII); tw.Namespaces = true; tw.Formatting = Formatting.Indented; FileInfo policyFile = new FileInfo(Consts.Path + files[0]); using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read)) { // Load Policy PolicyDocumentReadWrite policyDocument = PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadWrite); if (policyDocument.Policy == null) { policyDocument.PolicySet.Description = "UnitTest!!"; } else { policyDocument.Policy.Description = "UnitTest!!"; } policyDocument.WriteDocument(tw); tw.Close(); using (FileStream fs1 = new FileStream(tempFile, FileMode.Open, FileAccess.Read)) { PolicyDocument newPd = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs1, XacmlVersion.Version20, DocumentAccess.ReadOnly); if (newPd.Policy == null) { Assert.AreEqual(newPd.PolicySet.Description, policyDocument.PolicySet.Description); } else { Assert.AreEqual(newPd.Policy.Description, policyDocument.Policy.Description); } } } }
/// <summary> /// Creates a new policy document /// </summary> /// <param name="sender">The mainTree control.</param> /// <param name="args">The arguements for the event.</param> private void CreatePolicyDocument(object sender, EventArgs args) { // Create a new policydocument var newPolicyDoc = new PolicyDocumentReadWrite(XacmlVersion.Version11); //TODO: check version newPolicyDoc.Namespaces.Add(string.Empty, Consts.Schema1.Namespaces.Policy); newPolicyDoc.Namespaces.Add("xsi", Consts.Schema1.Namespaces.Xsi); var newNode = new TreeNodes.PolicyDocument(newPolicyDoc); _mainTree.Nodes.Add(newNode); _docType = DocumentType.Policy; newNode.NodeFont = new Font(_mainTree.Font, FontStyle.Bold); _menuItemOpenPolicy.Enabled = false; _menuItemOpenRequest.Enabled = false; _menuItemSaveAs.Enabled = true; _menuItemSave.Enabled = true; _menuItemRunRequest.Enabled = true; _menuItemRunPolicy.Enabled = false; }