public void Delete()
        {
            string id;

            using (var repository = LocalRepository.New())
            {
                var doc = new BestStartGrantBuilder("form123").With(f => f.ApplicantDetails, new ApplicantDetails {
                    FirstName = "some data"
                }).Value();
                id = doc.Id;
                repository.Insert(doc);
            }

            using (var repository = LocalRepository.New(deleteAllDocuments: false))
            {
                var doc = repository.Load <BestStartGrant>(id);
                repository.Delete(doc);
            }

            using (var repository = LocalRepository.New(deleteAllDocuments: false))
            {
                var count =
                    repository.Query <BestStartGrant>()
                    .ToList()
                    .Count;

                count.Should().Be(0);
            }
        }
        public void Update()
        {
            string id;

            using (var repository = LocalRepository.New())
            {
                var doc = new BestStartGrantBuilder("form123").With(f => f.ApplicantDetails, new ApplicantDetails {
                    FirstName = "some data"
                }).Value();
                id = doc.Id;
                repository.Insert(doc);
            }

            using (var repository = LocalRepository.New(deleteAllDocuments: false))
            {
                var doc = repository.Load <BestStartGrant>(id);
                doc.ApplicantDetails.FirstName = "updated value";
                repository.Update(doc);
            }

            using (var repository = LocalRepository.New(deleteAllDocuments: false))
            {
                var doc = repository.Load <BestStartGrant>(id);
                doc.ApplicantDetails.FirstName.Should().Be("updated value");
            }
        }
Example #3
0
        public void Execute_RemovesFile()
        {
            var existingForm = new BestStartGrantBuilder("form123").Insert();

            var cmdA = new AddEvidenceFile
            {
                FormId   = "form123",
                Filename = "test.pdf",
                Content  = Encoding.ASCII.GetBytes("evidence file"),
            };

            cmdA.Execute();

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

            updatedForm.Evidence.Files.Count.Should().Be(1);

            var cloudName = updatedForm.Evidence.Files[0].CloudName;

            var cmdR = new RemoveEvidenceFile
            {
                FormId    = "form123",
                CloudName = cloudName,
            };

            cmdR.Execute();

            updatedForm = Repository.Load <BestStartGrant>("form123");
            updatedForm.Evidence.Files.Count.Should().Be(0);
        }
        public void Insert_Fails_IsValidationContextHasErrors()
        {
            using (var repository = LocalRepository.New())
            {
                var doc = new BestStartGrantBuilder("form123").Value();

                DomainRegistry.ValidationContext = new ValidationContext(false);
                Assert.Throws <DomainException>(() => repository.Insert(doc));
            }
        }
        public void Find_OnlyReturnLatest()
        {
            var userId        = "*****@*****.**";
            var existingForm1 = new BestStartGrantBuilder("form1").WithCompletedSections().With(f => f.UserId, userId).With(f => f.Completed, new DateTime(2008, 07, 06)).Insert();
            var existingForm2 = new BestStartGrantBuilder("form2").WithCompletedSections().With(f => f.UserId, userId).With(f => f.Completed, new DateTime(2009, 07, 06)).Insert();
            var existingForm3 = new BestStartGrantBuilder("form3").WithCompletedSections().With(f => f.UserId, userId).With(f => f.Completed, new DateTime(2007, 07, 06)).Insert();

            var query = new FindLatestApplication
            {
                UserId = userId,
            };

            var detail = query.Find();

            detail.Should().NotBeNull();
            detail.Id.Should().Be(existingForm2.Id);
        }
        public void Find_OnlyReturnsCompleted()
        {
            var userId = "*****@*****.**";

            var existingForm1 = new BestStartGrantBuilder("form1")
                                .WithCompletedSections(markAsCompleted: false)
                                .With(f => f.UserId, userId)
                                .With(f => f.Declaration, null)
                                .Insert();

            var query = new FindLatestApplication
            {
                UserId = userId,
            };

            var detail = query.Find();

            detail.Should().BeNull();
        }
Example #7
0
        public void Execute_StoresConsent()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .Insert();

            existingForm.Consent.Should().BeNull("no data stored before executing command");

            var cmd = new AddConsent
            {
                FormId  = "form123",
                Consent = ConsentBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.Consent.Should().NotBeNull();
            updatedForm.Consent.AgreedToConsent.Should().Be(cmd.Consent.AgreedToConsent);
        }
Example #8
0
        public void Execute_StoresBenefitsDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .Insert();

            existingForm.GuardianPartnerBenefits.Should().BeNull("no data stored before executing command");

            var cmd = new AddGuardianPartnerBenefits
            {
                FormId = "form123",
                GuardianPartnerBenefits = BenefitsBuilder.NewWithBenefit(),
            };

            cmd.Execute();

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

            updatedForm.GuardianPartnerBenefits.Should().NotBeNull();
            updatedForm.GuardianPartnerBenefits.HasIncomeSupport.Should().Be(cmd.GuardianPartnerBenefits.HasIncomeSupport);
        }
Example #9
0
        public void Execute_StoresApplicantDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .Insert();

            existingForm.ApplicantDetails.Should().BeNull("no data stored before executing command");

            var cmd = new AddApplicantDetails
            {
                FormId           = "form123",
                ApplicantDetails = ApplicantDetailsBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.ApplicantDetails.Should().NotBeNull();
            updatedForm.ApplicantDetails.FirstName.Should().Be(cmd.ApplicantDetails.FirstName);
        }
        public void Execute_StoresDeclaration()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .Insert();

            existingForm.Declaration.Should().BeNull("no data stored before executing command");

            var cmd = new AddDeclaration
            {
                FormId      = "form123",
                Declaration = DeclarationBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.Declaration.Should().NotBeNull();
            updatedForm.Declaration.AgreedToLegalStatement.Should().BeTrue();
        }
Example #11
0
        public void Execute_StoresExpectedDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid())
                               .Insert();

            existingForm.ExpectedChildren.Should().BeNull("no data stored before executing command");

            var cmd = new AddExpectedChildren
            {
                FormId           = "form123",
                ExpectedChildren = ExpectedChildrenBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.ExpectedChildren.Should().NotBeNull();
            updatedForm.ExpectedChildren.ExpectancyDate.Should().Be(cmd.ExpectedChildren.ExpectancyDate);
        }
Example #12
0
        public void Execute_StoresGuardianPartnerDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .With(f => f.GuardianPartnerDetails, RelationDetailsBuilder.NewValid())
                               .Insert();

            existingForm.GuardianPartnerDetails.Address.Line1.Should().NotBeNull();

            var cmd = new AddGuardianPartnerDetails
            {
                FormId = "form123",
                GuardianPartnerDetails = RelationDetailsBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.GuardianPartnerDetails.Should().NotBeNull();
            updatedForm.GuardianPartnerDetails.Address.Line1.Should().Be(cmd.GuardianPartnerDetails.Address.Line1);
        }
        public void Find_PopulatesDetail()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .WithCompletedSections()
                               .Insert();

            var query = new FindBsgSection
            {
                FormId  = "form123",
                Section = Sections.ExistingChildren,
            };

            var detail = query.Find();

            var expectedDetail = new BsgDetail {
                PreviousSection = Sections.ExpectedChildren
            };

            BestStartGrantBuilder.CopySectionsFrom(existingForm, expectedDetail);

            detail.ShouldBeEquivalentTo(expectedDetail);
        }
Example #14
0
        public void Execute_StoresEvidence()
        {
            var existingForm = new BestStartGrantBuilder("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 <BestStartGrant>("form123");

            updatedForm.Evidence.SendingByPost.Should().Be(cmd.Evidence.SendingByPost);
            updatedForm.Evidence.Files.Count.Should().Be(2, "files should not be overwritten");
        }
        public void Execute_StoresHealthProfessionalDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid())
                               .With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid())
                               .With(f => f.ExistingChildren, ExistingChildrenBuilder.NewValid())
                               .Insert();

            existingForm.HealthProfessional.Should().BeNull("no data stored before executing command");

            var cmd = new AddHealthProfessional
            {
                FormId             = "form123",
                HealthProfessional = HealthProfessionalBuilder.NewValid(),
            };

            cmd.Execute();

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

            updatedForm.HealthProfessional.Should().NotBeNull();
            updatedForm.HealthProfessional.Pin.Should().Be(cmd.HealthProfessional.Pin);
        }
        public void AddIdentity_StoresBsgDetail()
        {
            var existingForm = new BestStartGrantBuilder("existing_form")
                               .WithCompletedSections()
                               .With(f => f.UserId, "*****@*****.**")
                               .Insert(f =>
            {
                f.ApplicantDetails.Title                = "tst_title";
                f.ApplicantDetails.FirstName            = "tst_fn";
                f.ApplicantDetails.OtherNames           = "tst_on";
                f.ApplicantDetails.SurnameOrFamilyName  = "tst_sn";
                f.ApplicantDetails.CurrentAddress.Line1 = "al1";
                f.ApplicantDetails.MobilePhoneNumber    = "123";
                f.ApplicantDetails.PhoneNumer           = "234";
                f.ApplicantDetails.EmailAddress         = "[email protected]";

                f.PaymentDetails.HasBankAccount = true;
                f.PaymentDetails.AccountNumber  = "12345";
                f.PaymentDetails.SortCode       = "12-34-56";
            });

            var coc = new ChangeOfCircsBuilder("form").Insert();

            coc.AddIdentity("*****@*****.**");

            coc.ExistingApplicantDetails.Title.Should().Be("tst_title");
            coc.ExistingApplicantDetails.FullName.Should().Be("tst_fn tst_on tst_sn");
            coc.ExistingApplicantDetails.Address.Line1.Should().Be("al1");
            coc.ExistingApplicantDetails.MobilePhoneNumber.Should().Be("123");
            coc.ExistingApplicantDetails.HomePhoneNumer.Should().Be("234");
            coc.ExistingApplicantDetails.EmailAddress.Should().Be("[email protected]");

            coc.ExistingPaymentDetails.HasBankAccount.Should().BeTrue();
            coc.ExistingPaymentDetails.AccountNumber.Should().BeNull();
            coc.ExistingPaymentDetails.SortCode.Should().BeNull();
        }
Example #17
0
        public void UpdateDataToMakeConsistent()
        {
            DomainRegistry.ValidationContext = new ValidationContext(true);

            using (var repo = LocalRepository.New(deleteAllDocuments: false))
                foreach (var doc in repo.Query <BestStartGrant>().ToList())
                {
                    var changed = false;

                    if (doc.UserId != doc.ApplicantDetails?.EmailAddress)
                    {
                        Builder.Modify(doc).With(d => d.UserId, doc.ApplicantDetails?.EmailAddress);
                        Console.WriteLine("Changing {0} UserId={1}", doc.Id, doc.ApplicantDetails?.EmailAddress);
                        changed = true;
                    }

                    if (doc.Started == DateTime.MinValue)
                    {
                        // this is not currently reached, as the default constructor will set Started
                        Builder.Modify(doc).With(f => f.Started, DateTime.UtcNow);
                        Console.WriteLine("Changing {0} Started={1}", doc.Id, DateTime.UtcNow);
                        changed = true;
                    }

                    if (doc.ExpectedChildren != null)
                    {
                        if (doc.ExpectedChildren.IsBabyExpected == null)
                        {
                            doc.ExpectedChildren.IsBabyExpected = doc.ExpectedChildren.ExpectancyDate != null;
                            Console.WriteLine("Changing {0} IsBabyExpected={1}", doc.Id, doc.ExpectedChildren.IsBabyExpected);
                            changed = true;
                        }

                        if (doc.ExpectedChildren.ExpectedBabyCount != null && doc.ExpectedChildren.IsMoreThan1BabyExpected == null)
                        {
                            doc.ExpectedChildren.IsMoreThan1BabyExpected = doc.ExpectedChildren.ExpectedBabyCount > 1;
                            Console.WriteLine("Changing {0} IsMoreThan1BabyExpected={1}", doc.Id, doc.ExpectedChildren.IsMoreThan1BabyExpected);
                            changed = true;
                        }

                        if (doc.ExpectedChildren.ExpectedBabyCount.HasValue && doc.ExpectedChildren.ExpectedBabyCount < 2)
                        {
                            doc.ExpectedChildren.ExpectedBabyCount = null;
                            Console.WriteLine("Changing {0} ExpectedBabyCount=null", doc.Id);
                            changed = true;
                        }
                    }

                    if (doc.PaymentDetails != null)
                    {
                        if (doc.PaymentDetails.HasBankAccount == null)
                        {
                            doc.PaymentDetails.HasBankAccount = !string.IsNullOrWhiteSpace(doc.PaymentDetails.AccountNumber);
                            Console.WriteLine("Changing {0} HasBankAccount={1}", doc.Id, doc.PaymentDetails.HasBankAccount);
                            changed = true;
                        }
                    }

                    if (doc.Declaration?.AgreedToLegalStatement == true && !doc.Completed.HasValue)
                    {
                        Builder.Modify(doc).With(f => f.Completed, DateTime.UtcNow);
                        Console.WriteLine("Changing {0} Completed={1}", doc.Id, DateTime.UtcNow);
                        changed = true;
                    }

                    if (changed)
                    {
                        repo.Update(doc);
                    }

                    var checkDoc = repo.Load <BestStartGrant>(doc.Id);
                    BestStartGrantBuilder.VerifyConsistent(checkDoc);
                }
        }
Example #18
0
        public void CompleteApplication()
        {
            var     userId = "*****@*****.**";
            BsgForm bsg    = null;

            Db(r =>
            {
                bsg =
                    new BestStartGrantBuilder("existingForm")
                    .PreviousApplicationFor(userId)
                    .Insert(f =>
                {
                    f.ApplicantDetails.FirstName = "st_fn";
                });
            });

            App.GoTo(FormUI.Controllers.Home.HomeActions.Index());
            App.VerifyCanSeeText("Tell us if something has changed");
            App.Submit();

            FillInConsent();
            App.Submit();

            FillInIdentity(userId);
            App.VerifyCanSeeText("confirm who you are");
            App.Submit();

            FillInOptions();
            App.Submit();

            FillInApplicantDetails(bsg);
            App.Submit();

            var expectancyDate = DateTime.UtcNow.Date.AddDays(100);

            FillInExpectedChildren(expectancyDate);
            App.Submit();

            FillInHealthProfessional();
            App.Submit();

            FillInPaymentDetails(bsg);
            App.Submit();

            var filename = FillInEvidence();

            App.ClickButton("");

            FillInDeclaration();
            App.Submit();

            App.VerifyCanSeeText("Thank you");

            Db(r =>
            {
                var doc = r.Query <ChangeOfCircs>().ToList().Single();

                VerifyConsent(doc);
                VerifyIdentity(doc, userId);
                VerifyOptions(doc);
                VerifyApplicantDetails(doc);
                VerifyExpectedChildren(doc, expectancyDate);
                VerifyHealthProfessional(doc);
                VerifyPaymentDetails(doc);
                VerifyEvidence(doc, filename);
                VerifyDeclaration(doc);
            });
        }