public void IIA001 () { string[] files = new string[] { "2.IIA001Policy.xml", "2.IIA001Request.xml", "2.IIA001Response.xml" }; Assert.AreEqual( files.Length, 3, "Test incomplete" );FileInfo policyFile = new FileInfo( files[0] ); FileInfo requestFile = new FileInfo( files[1] ); FileInfo ResponseElementFile = new FileInfo( files[2] ); using( FileStream fs = new FileStream( policyFile.FullName, FileMode.Open, FileAccess.Read ) ) using( FileStream fs1 = new FileStream( requestFile.FullName, FileMode.Open, FileAccess.Read ) ) using( FileStream fs2 = new FileStream( ResponseElementFile.FullName, FileMode.Open, FileAccess.Read ) ) { // Load Policy PolicyDocument policyDocument = (PolicyDocument)PolicyLoader.LoadPolicyDocument( fs, XacmlVersion.Version20, DocumentAccess.ReadOnly ); // Load Request ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument( fs1, XacmlVersion.Version20 ); // Load ResponseElement ContextDocumentReadWrite ResponseElementDocument = ContextLoader.LoadContextDocument( fs2, XacmlVersion.Version20 ); EvaluationEngine engine = new EvaluationEngine(); ResponseElement res = engine.Evaluate( policyDocument, (ContextDocument)requestDocument ); NUnit.Framework.Assert.AreEqual( ((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)ResponseElementDocument.Response.Results[0]).Obligations.Count ); NUnit.Framework.Assert.AreEqual( ResponseElementDocument.Response.Results.Count, res.Results.Count ); NUnit.Framework.Assert.IsTrue( ((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)ResponseElementDocument.Response.Results[0]).Decision.ToString(), string.Format( "Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)ResponseElementDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString() ) ); NUnit.Framework.Assert.IsTrue( ((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)ResponseElementDocument.Response.Results[0]).Status.StatusCode.Value, String.Format( "Status incorrect Expected:{0} Returned:{1}", ((ResultElement)ResponseElementDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value ) ); } }
private void menuItem8_Click(object sender, EventArgs e) { if( MessageBox.Show( this,"The policy will be saved. Do you want to proceed?", "Warning", MessageBoxButtons.YesNo ) == DialogResult.Yes ) { //Loads the request openFileDialog.Filter = "Request Files|*.xml|All Files|*.*"; if( openFileDialog.ShowDialog() == DialogResult.OK ) { menuItem9_Click( sender, e ); con.ContextDocumentReadWrite oCon = ContextLoader.LoadContextDocument( openFileDialog.OpenFile(), XacmlVersion.Version11 ); //Gets the policy from the TreeView Stream stream = new FileStream( _path, FileMode.Open ); pol.PolicyDocumentReadWrite oPol = PolicyLoader.LoadPolicyDocument( stream , XacmlVersion.Version20 ); stream.Close(); //Evaluates the request EvaluationEngine engine = new EvaluationEngine(); con.ResponseElement res = engine.Evaluate( (pol.PolicyDocument)oPol, (con.ContextDocument)oCon ); //Creates the xml string path = Path.GetTempFileName(); XmlWriter writer = new XmlTextWriter( path, Encoding.UTF8 ); res.WriteDocument( writer ); writer.Close(); mainPanel.Controls.Clear(); mainPanel.Controls.Add( new XmlViewer( path, ResponseElement.Response ) ); } } }