public static EvaluationEngine Create(XmlReader reader, IXacmlPolicyRepository ch)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            EvaluationEngine engine;

            if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml10Constants.Namespaces.Policy))
            {
                Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml10Constants.Namespaces.Policy))
            {
                Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicySet(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml20Constants.Namespaces.Policy))
            {
                Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml20Constants.Namespaces.Policy))
            {
                Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicySet(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml30Constants.Namespaces.Policy))
            {
                Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer();
                engine = new EvaluationEngine30(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml30Constants.Namespaces.Policy))
            {
                Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer();
                engine = new EvaluationEngine30(serializer.ReadPolicySet(reader));
            }
            else
            {
                throw new XmlException("Unknown XML");
            }

            engine.ch = ch;
            return(engine);
        }
        public static EvaluationEngine Create(XmlReader reader, IXacmlPolicyRepository ch) {
            Contract.Requires<ArgumentNullException>(reader != null);

            EvaluationEngine engine;

            if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml10Constants.Namespaces.Policy)) {
                Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml10Constants.Namespaces.Policy)) {
                Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicySet(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml20Constants.Namespaces.Policy)) {
                Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml20Constants.Namespaces.Policy)) {
                Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer();
                engine = new EvaluationEngine(serializer.ReadPolicySet(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml30Constants.Namespaces.Policy)) {
                Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer();
                engine = new EvaluationEngine30(serializer.ReadPolicy(reader));
            }
            else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml30Constants.Namespaces.Policy)) {
                Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer();
                engine = new EvaluationEngine30(serializer.ReadPolicySet(reader));
            }
            else {
                throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XmlException("Unknown XML"));
            }

            engine.ch = ch;
            return engine;
        }
        public void ConfirmanceTestsIIE_20(XmlDocument policy, XmlDocument request, XmlDocument response, XmlDocument aPolicy, XmlDocument aPolicySet)
        {
            var serialize = new Xacml20ProtocolSerializer();
            XacmlContextRequest  requestData;
            XacmlContextResponse responseData;

            XacmlPolicy    aPolicyData;
            XacmlPolicySet aPolicySetData;

            using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) {
                requestData = serialize.ReadContextRequest(reader);
            }

            using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) {
                responseData = serialize.ReadContextResponse(reader);
            }

            using (XmlReader reader = XmlReader.Create(new StringReader(aPolicy.OuterXml))) {
                aPolicyData = serialize.ReadPolicy(reader);
            }

            using (XmlReader reader = XmlReader.Create(new StringReader(aPolicySet.OuterXml))) {
                aPolicySetData = serialize.ReadPolicySet(reader);
            }

            var policyRepositoryMock = Substitute.For <IXacmlPolicyRepository>();

            policyRepositoryMock.RequestPolicy(Arg.Is(aPolicyData.PolicyId)).Returns(aPolicyData);
            policyRepositoryMock.RequestPolicySet(Arg.Is(aPolicySetData.PolicySetId)).Returns(aPolicySetData);

            EvaluationEngine engine = EvaluationEngineFactory.Create(policy, policyRepositoryMock);

            XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request);

            XacmlResponseAssert(responseData, evaluatedResponse);
        }