protected static BsgDetail NewBsgDetail(string formId, int childCount = 2)
        {
            var detail = new BsgDetail
            {
                Id = formId,

                Consent                 = ConsentBuilder.NewValid(),
                ApplicantDetails        = ApplicantDetailsBuilder.NewValid(),
                ExpectedChildren        = ExpectedChildrenBuilder.NewValid(),
                ExistingChildren        = ExistingChildrenBuilder.NewValid(childCount),
                ApplicantBenefits       = BenefitsBuilder.NewWithBenefit(),
                PartnerBenefits         = BenefitsBuilder.NewWithBenefit(),
                GuardianBenefits        = BenefitsBuilder.NewWithBenefit(),
                GuardianPartnerBenefits = BenefitsBuilder.NewWithBenefit(),
                PartnerDetails          = RelationDetailsBuilder.NewValid("partner"),
                GuardianDetails         = RelationDetailsBuilder.NewValid("guardian"),
                GuardianPartnerDetails  = RelationDetailsBuilder.NewValid("guardian partner"),
                HealthProfessional      = HealthProfessionalBuilder.NewValid(),
                PaymentDetails          = PaymentDetailsBuilder.NewValid(),
                Evidence                = EvidenceBuilder.NewValid(),
                Declaration             = DeclarationBuilder.NewValid(),
            };

            return(detail);
        }
 private NextSection AddEvidence(NextSection current, Action <Evidence> mutator = null)
 {
     current.Section.Should().Be(Sections.Evidence);
     return(NextSection(current.Section, () => new AddEvidence {
         FormId = current.Id, Evidence = EvidenceBuilder.NewValid(mutator)
     }.Execute()));
 }
예제 #3
0
        public BestStartGrantBuilder WithCompletedSections(bool markAsCompleted = true)
        {
            With(f => f.Consent, ConsentBuilder.NewValid());
            With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid());
            With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid());
            With(f => f.ExistingChildren, ExistingChildrenBuilder.NewValid());
            With(f => f.ApplicantBenefits, BenefitsBuilder.NewWithBenefit());
            With(f => f.PartnerBenefits, BenefitsBuilder.NewWithBenefit());
            With(f => f.GuardianBenefits, BenefitsBuilder.NewWithBenefit());
            With(f => f.GuardianPartnerBenefits, BenefitsBuilder.NewWithBenefit());
            With(f => f.PartnerDetails, RelationDetailsBuilder.NewValid("partner"));
            With(f => f.GuardianDetails, RelationDetailsBuilder.NewValid("guardian"));
            With(f => f.GuardianPartnerDetails, RelationDetailsBuilder.NewValid("guardian partner"));
            With(f => f.HealthProfessional, HealthProfessionalBuilder.NewValid());
            With(f => f.PaymentDetails, PaymentDetailsBuilder.NewValid());
            With(f => f.Evidence, EvidenceBuilder.NewValid());
            With(f => f.Declaration, DeclarationBuilder.NewValid());

            With(f => f.Started, DomainRegistry.NowUtc() - TimeSpan.FromHours(24));
            With(f => f.Completed, DomainRegistry.NowUtc());
            With(f => f.UserId, _instance.ApplicantDetails?.EmailAddress);
            VerifyConsistent(_instance);

            if (!markAsCompleted)
            {
                With(f => f.Completed, null);
            }

            return(this);
        }
예제 #4
0
        public ChangeOfCircsBuilder WithCompletedSections(bool markAsCompleted = true, bool excludeOptionalSections = false)
        {
            With(f => f.Consent, ConsentBuilder.NewValid());
            With(f => f.UserId, "*****@*****.**");
            With(f => f.ExistingApplicantDetails, ApplicantDetailsBuilder.NewValid(ad => ad.Address = AddressBuilder.NewValid("existing")));
            With(f => f.ExistingPaymentDetails, PaymentDetailsBuilder.NewValid());
            With(f => f.Options, OptionsBuilder.NewValid());

            if (!excludeOptionalSections)
            {
                With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid());
                With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid());
                With(f => f.HealthProfessional, HealthProfessionalBuilder.NewValid());
                With(f => f.PaymentDetails, PaymentDetailsBuilder.NewValid());
            }

            With(f => f.Evidence, EvidenceBuilder.NewValid());
            With(f => f.Declaration, DeclarationBuilder.NewValid());

            With(f => f.Started, DomainRegistry.NowUtc() - TimeSpan.FromHours(24));
            With(f => f.Completed, DomainRegistry.NowUtc());
            VerifyConsistent(_instance);

            if (!markAsCompleted)
            {
                With(f => f.Completed, null);
            }

            return(this);
        }
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary<string, object> GetContextClaims(string aspectName)
        {
            using (new Tracer(aspectName))
            {
                if (_contextEngineClient == null)
                {
                    // Apparently an exception occurred in the class constructor; it should have logged the exception already.
                    throw new DxaException("Context Engine Client was not initialized. Check the log file for errors.");
                }

                // TODO: Not really nice to use HttpContext at this level.
                HttpContext httpContext = HttpContext.Current;
                if (httpContext == null)
                {
                    throw new DxaException("Cannot obtain HttpContext.");
                }
                HttpRequest httpRequest = httpContext.Request;
                HttpCookie contextCookie = httpRequest.Cookies["context"];

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", httpRequest.UserAgent);
                    if (contextCookie != null && !string.IsNullOrEmpty(contextCookie.Value))
                    {
                        evidenceBuilder.With("cookie", string.Format("{0}={1}", contextCookie.Name, contextCookie.Value));
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    contextMap = _contextEngineClient.Resolve(evidence);
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.", ex);
                }

                IDictionary<string, object> result = new Dictionary<string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return result;
            }
        }
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName)
        {
            using (new Tracer(aspectName))
            {
                if (_contextEngineClient == null)
                {
                    // Apparently an exception occurred in the class constructor; it should have logged the exception already.
                    throw new DxaException("Context Engine Client was not initialized. Check the log file for errors.");
                }

                // TODO: Not really nice to use HttpContext at this level.
                HttpContext httpContext = HttpContext.Current;
                if (httpContext == null)
                {
                    throw new DxaException("Cannot obtain HttpContext.");
                }
                HttpRequest httpRequest   = httpContext.Request;
                HttpCookie  contextCookie = httpRequest.Cookies["context"];

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", httpRequest.UserAgent);
                    if (contextCookie != null && !string.IsNullOrEmpty(contextCookie.Value))
                    {
                        evidenceBuilder.With("cookie", string.Format("{0}={1}", contextCookie.Name, contextCookie.Value));
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    contextMap = _contextEngineClient.Resolve(evidence);
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.", ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
예제 #7
0
        protected static CocDetail NewCocDetail(string formId)
        {
            var detail = new CocDetail
            {
                Id = formId,

                Consent            = ConsentBuilder.NewValid(),
                Identity           = "*****@*****.**",
                Options            = OptionsBuilder.NewValid(),
                ApplicantDetails   = ApplicantDetailsBuilder.NewValid(),
                ExpectedChildren   = ExpectedChildrenBuilder.NewValid(),
                HealthProfessional = HealthProfessionalBuilder.NewValid(),
                PaymentDetails     = PaymentDetailsBuilder.NewValid(),
                Evidence           = EvidenceBuilder.NewValid(),
                Declaration        = DeclarationBuilder.NewValid(),
            };

            return(detail);
        }
        public void Execute_StoresEvidence()
        {
            var existingForm = new ChangeOfCircsBuilder("form123")
                               .With(f => f.Evidence, EvidenceBuilder.NewValid(e => e.SendingByPost = false))
                               .Insert(f => f.Evidence.AddFiles(f, 2));

            existingForm.Evidence.SendingByPost.Should().BeFalse("not set before executing command");
            existingForm.Evidence.Files.Count.Should().Be(2, "should have existing uploaded files");

            var cmd = new AddEvidence
            {
                FormId   = "form123",
                Evidence = EvidenceBuilder.NewValid(),
            };

            cmd.Execute();

            var updatedForm = Repository.Load <ChangeOfCircs>("form123");

            updatedForm.Evidence.SendingByPost.Should().Be(cmd.Evidence.SendingByPost);
            updatedForm.Evidence.Files.Count.Should().Be(2, "files should not be overwritten");
        }
예제 #9
0
 protected void EvidenceShouldBeValid(ChangeOfCircs form, Action <Evidence> mutator)
 {
     Builder.Modify(form).With(f => f.Evidence, null);
     ShouldBeValid(() => form.AddEvidence(EvidenceBuilder.NewValid(mutator)));
 }
예제 #10
0
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName, Localization localization)
        {
            using (new Tracer(aspectName))
            {
                var contextEngineClient = ODataContextEngineInstance.Instance;
                if (contextEngineClient == null)
                {
                    return(new Dictionary <string, object>());
                }

                string      userAgent          = null;
                string      contextCookieValue = null;
                HttpContext httpContext        = HttpContext.Current;
                // TODO: Not really nice to use HttpContext at this level.
                if (httpContext != null)
                {
                    userAgent = httpContext.Request.UserAgent;
                    HttpCookie contextCookie = httpContext.Request.Cookies["context"];
                    if (contextCookie != null)
                    {
                        contextCookieValue = contextCookie.Value;
                    }
                }
                if (string.IsNullOrEmpty(userAgent))
                {
                    userAgent = DefaultUserAgent;
                }

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", userAgent);
                    if (_usePublicationEvidence)
                    {
                        evidenceBuilder.WithPublicationId(Convert.ToInt32(localization.Id));
                        // TODO: What about URI scheme?
                    }
                    if (!string.IsNullOrEmpty(contextCookieValue))
                    {
                        evidenceBuilder.With("cookie", $"context={contextCookieValue}");
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    lock (_lock)
                    {
                        contextMap = contextEngineClient.Resolve(evidence);
                    }
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.",
                                           ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
예제 #11
0
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName, Localization localization)
        {
            using (new Tracer(aspectName))
            {
                if (_contextEngineClient == null)
                {
                    // Apparently an exception occurred in the class constructor; it should have logged the exception already.
                    throw new DxaException("Context Engine Client was not initialized. Check the log file for errors.");
                }

                string      userAgent          = null;
                string      contextCookieValue = null;
                HttpContext httpContext        = HttpContext.Current; // TODO: Not really nice to use HttpContext at this level.
                if (httpContext != null)
                {
                    userAgent = httpContext.Request.UserAgent;
                    HttpCookie contextCookie = httpContext.Request.Cookies["context"];
                    if (contextCookie != null)
                    {
                        contextCookieValue = contextCookie.Value;
                    }
                }
                if (string.IsNullOrEmpty(userAgent))
                {
                    userAgent = DefaultUserAgent;
                }

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", userAgent);
                    if (_usePublicationEvidence)
                    {
                        evidenceBuilder.WithPublicationId(Convert.ToInt32(localization.Id)); // TODO: What about URI scheme?
                    }
                    if (!string.IsNullOrEmpty(contextCookieValue))
                    {
                        evidenceBuilder.With("cookie", string.Format("context={0}", contextCookieValue));
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    contextMap = _contextEngineClient.Resolve(evidence);
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.", ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
 protected void EvidenceShouldBeValid(BestStartGrant form, Action <Evidence> mutator)
 {
     Builder.Modify(form).With(f => f.Evidence, null);
     ShouldBeValid(() => form.AddEvidence(EvidenceBuilder.NewValid(mutator)));
 }