public PolicyPublished Deserialise(XElement policyPublished)
        {
            if (policyPublished.Name != "policy_published")
            {
                throw new ArgumentException("Root element must be policy_published");
            }

            string domain = policyPublished.Single("domain").Value;

            if (!_domainValidator.IsValidDomain(domain))
            {
                throw new ArgumentException("Invalid domain");
            }

            //nullable this deviates from spec
            Alignment adkimCandidate;
            Alignment?adkim = Enum.TryParse(policyPublished.SingleOrDefault("adkim")?.Value, true, out adkimCandidate) ? adkimCandidate : (Alignment?)null;

            //nullable this deviates from spec
            Alignment aspfCandidate;
            Alignment?aspf = Enum.TryParse(policyPublished.SingleOrDefault("aspf")?.Value, true, out aspfCandidate) ? aspfCandidate : (Alignment?)null;

            Disposition p = (Disposition)Enum.Parse(typeof(Disposition), policyPublished.Single("p").Value, true);

            //nullable this deviates from spec
            Disposition spCandidate;
            Disposition?sp = Enum.TryParse(policyPublished.SingleOrDefault("sp")?.Value, true, out spCandidate) ? spCandidate : (Disposition?)null;

            //nullable this deviates from spec
            int pctCandidate;
            int?pct = int.TryParse(policyPublished.SingleOrDefault("pct")?.Value, out pctCandidate) ? pctCandidate : (int?)null;

            return(new PolicyPublished(domain, adkim, aspf, p, sp, pct));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetWelcomeSearchResult(DomainsRequest request)
        {
            if (!_domainValidator.IsValidDomain(request.Search))
            {
                return(BadRequest(new ErrorResponse("Please enter a valid domain.")));
            }

            WelcomeSearchResult result = await _domainStatusListDao.GetWelcomeSearchResult(request.Search);

            bool isPublicSectorOrg = _publicDomainValidator.IsValidPublicDomain(request.Search);

            return(new ObjectResult(new WelcomeSearchResponse(result, isPublicSectorOrg)));
        }
Ejemplo n.º 3
0
        public void PolicyPublishedMustExist()
        {
            XElement xElement = XElement.Parse(PolicyPublishedDeserialiserTestsResources.NoPolicyPublished);

            A.CallTo(() => _domainValidator.IsValidDomain(A <string> ._)).Returns(true);
            Assert.Throws <ArgumentException>(() => _policyPublishedDeserialiser.Deserialise(xElement));
        }