Example #1
0
        public async Task CanCreateContact()
        {
            var uniqueSignature = Guid.NewGuid().ToString().Substring(0, 4);
            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestContactUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.First();

            baseContact.Id        = null;
            baseContact.UserId    = $"{TestData.TestPrefix}-{uniqueSignature}-{TestContactUserId}";
            baseContact.FirstName = $"{TestData.TestPrefix}-{uniqueSignature}-first";
            baseContact.LastName += $"{TestData.TestPrefix}-{uniqueSignature}-last";

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new RegistrantQuery
            {
                ContactId = newContactId
            };

            (await contactRepository.QueryContact(newContactQuery)).Items.ShouldHaveSingleItem().Id.ShouldBe(newContactId);
        }
Example #2
0
        public async Task CanCreateContactWithAddressLookupValues()
        {
            var country         = "CAN";
            var province        = "BC";
            var city            = TestData.RandomCommunity;
            var uniqueSignature = Guid.NewGuid().ToString().Substring(0, 4);

            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestContactUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.FirstOrDefault();

            baseContact.ShouldNotBeNull();

            baseContact.Id         = null;
            baseContact.UserId     = TestContactUserId + Guid.NewGuid().ToString("N").Substring(0, 4);
            baseContact.FirstName += "_" + uniqueSignature;
            baseContact.LastName  += "_" + uniqueSignature;
            baseContact.PrimaryAddress.Country       = country;
            baseContact.PrimaryAddress.StateProvince = province;
            baseContact.PrimaryAddress.Community     = city;
            baseContact.MailingAddress.Country       = country;
            baseContact.MailingAddress.StateProvince = province;
            baseContact.MailingAddress.Community     = city;

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new RegistrantQuery
            {
                ContactId = newContactId
            };
            var newQueryResult = await contactRepository.QueryContact(newContactQuery);

            var newContact = newQueryResult.Items.FirstOrDefault();

            newContact.ShouldNotBeNull().Id.ShouldBe(newContactId);

            newContact.PrimaryAddress.Country.ShouldBe(country);
            newContact.PrimaryAddress.StateProvince.ShouldBe(province);
            newContact.PrimaryAddress.Community.ShouldBe(city);

            newContact.MailingAddress.Country.ShouldBe(country);
            newContact.MailingAddress.StateProvince.ShouldBe(province);
            newContact.MailingAddress.Community.ShouldBe(city);
        }
Example #3
0
        public async Task CanCreateContact()
        {
            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.FirstOrDefault();

            baseContact.Id     = null;
            baseContact.UserId = TestUserId + Guid.NewGuid().ToString("N").Substring(0, 4);

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new RegistrantQuery
            {
                ContactId = newContactId
            };
            var newQueryResult = await contactRepository.QueryContact(newContactQuery);

            var newContact = newQueryResult.Items.FirstOrDefault();

            newContact.ShouldNotBeNull().Id.ShouldBe(newContactId);

            /* Delete New Contact */
            DeleteContact deleteCmd = new DeleteContact
            {
                ContactId = newContactId
            };
            var deleteResult = await contactRepository.ManageContact(deleteCmd);

            var deletedContactId = deleteResult.ContactId;

            /* Get Deleted Contact */
            var deletedCaseQuery = new RegistrantQuery
            {
                ContactId = deletedContactId
            };
            var deletedQueryResult = await contactRepository.QueryContact(deletedCaseQuery);

            var deletedContact = (Contact)deletedQueryResult.Items.LastOrDefault();

            deletedContact.ShouldBeNull();
        }
Example #4
0
        public async Task <string> Handle(SubmitEvacuationFileCommand cmd)
        {
            var file = mapper.Map <Resources.Cases.Evacuations.EvacuationFile>(cmd.File);

            var query = new RegistrantQuery();

            //TODO: replace this with an explicit property for userid
            if (Guid.TryParse(file.PrimaryRegistrantId, out var _))
            {
                query.ContactId = file.PrimaryRegistrantId;
            }
            else
            {
                query.UserId = file.PrimaryRegistrantId;
            }

            var contact = (await contactRepository.QueryContact(query)).Items.SingleOrDefault();

            if (contact == null)
            {
                throw new NotFoundException($"Registrant not found '{file.PrimaryRegistrantId}'", file.PrimaryRegistrantId);
            }
            file.PrimaryRegistrantId = contact.Id;

            if (!string.IsNullOrEmpty(file.Id))
            {
                var caseRecord   = (await caseRepository.QueryCase(new Resources.Cases.EvacuationFilesQuery {
                    FileId = file.Id
                })).Items.SingleOrDefault();
                var existingFile = mapper.Map <Resources.Cases.Evacuations.EvacuationFile>(caseRecord);

                if (!string.IsNullOrEmpty(existingFile.TaskId) && !existingFile.TaskId.Equals(file.TaskId, StringComparison.Ordinal))
                {
                    throw new BusinessLogicException($"The ESS Task Number cannot be modified or updated once it's been initially assigned.");
                }
            }

            var caseId = (await caseRepository.ManageCase(new SubmitEvacuationFileNeedsAssessment {
                EvacuationFile = file
            })).Id;

            if (string.IsNullOrEmpty(file.Id) && !string.IsNullOrEmpty(contact.Email))
            {
                //notify registrant of the new file and has email
                await SendEmailNotification(
                    SubmissionTemplateType.NewEvacuationFileSubmission,
                    email : contact.Email,
                    name : $"{contact.LastName}, {contact.FirstName}",
                    tokens : new[] { KeyValuePair.Create("fileNumber", caseId) });
            }

            return(caseId);
        }
Example #5
0
        public async Task CanGetContact()
        {
            var contactQuery = new RegistrantQuery
            {
                UserId = TestContactUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            queryResult.Items.ShouldNotBeEmpty();

            var contact = (Contact)queryResult.Items.First();

            contact.ShouldNotBeNull();
        }
Example #6
0
        public async Task <string> Handle(SubmitEvacuationFileCommand cmd)
        {
            var file = mapper.Map <Resources.Cases.EvacuationFile>(cmd.File);

            var query = new RegistrantQuery();

            if (Guid.TryParse(file.PrimaryRegistrantId, out var _))
            {
                query.ContactId = file.PrimaryRegistrantId;
            }
            else
            {
                query.UserId = file.PrimaryRegistrantId;
            }

            var contact = (await contactRepository.QueryContact(query)).Items.SingleOrDefault();

            if (contact == null)
            {
                throw new Exception($"Registrant not found '{file.PrimaryRegistrantId}'");
            }
            file.PrimaryRegistrantId = contact.Id;

            var caseId = (await caseRepository.ManageCase(new SaveEvacuationFile {
                EvacuationFile = file
            })).Id;

            if (string.IsNullOrEmpty(file.Id) && !string.IsNullOrEmpty(contact.Email))
            {
                //notify registrant of the new file and has email
                await SendEmailNotification(
                    SubmissionTemplateType.NewEvacuationFileSubmission,
                    email : contact.Email,
                    name : $"{contact.LastName}, {contact.FirstName}",
                    tokens : new[] { KeyValuePair.Create("fileNumber", caseId) });
            }

            return(caseId);
        }
Example #7
0
        public async Task CanUpdateContact()
        {
            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestContactUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var contact = queryResult.Items.First();

            var newCommunity = TestData.RandomCommunity;
            var currentCity  = contact.PrimaryAddress.Community;

            contact.PrimaryAddress.Community = currentCity == newCommunity
              ? TestData.RandomCommunity
              : newCommunity;;

            /* Update Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = contact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var updatedContactId = saveResult.ContactId;

            /* Get Updated Contact */
            var updatedContactQuery = new RegistrantQuery
            {
                ContactId = updatedContactId
            };
            var updatedQueryResult = await contactRepository.QueryContact(updatedContactQuery);

            var updatedContact = updatedQueryResult.Items.First();

            updatedContact.PrimaryAddress.Community.ShouldBe(newCommunity);
        }
Example #8
0
        public async Task CanUpdateContact()
        {
            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var contact = queryResult.Items.FirstOrDefault();

            var currentCity = contact.PrimaryAddress.Community;
            var newCity     = currentCity == "406adfaf-9f97-ea11-b813-005056830319"
                ? "226adfaf-9f97-ea11-b813-005056830319"
                : "406adfaf-9f97-ea11-b813-005056830319";

            contact.PrimaryAddress.Community = newCity;

            /* Update Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = contact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var updatedContactId = saveResult.ContactId;

            /* Get Updated Contact */
            var updatedContactQuery = new RegistrantQuery
            {
                ContactId = updatedContactId
            };
            var updatedQueryResult = await contactRepository.QueryContact(updatedContactQuery);

            var updatedContact = updatedQueryResult.Items.FirstOrDefault();

            updatedContact.PrimaryAddress.Community.ShouldBe(newCity);
        }
Example #9
0
        public async Task CanCreateContactWithAddressLookupValues()
        {
            var country  = "CAN";
            var province = "BC";
            var city     = "226adfaf-9f97-ea11-b813-005056830319";

            /* Get Contact */
            var contactQuery = new RegistrantQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.FirstOrDefault();

            baseContact.ShouldNotBeNull();

            baseContact.Id     = null;
            baseContact.UserId = TestUserId + Guid.NewGuid().ToString("N").Substring(0, 4);
            baseContact.PrimaryAddress.Country       = country;
            baseContact.PrimaryAddress.StateProvince = province;
            baseContact.PrimaryAddress.Community     = city;
            baseContact.MailingAddress.Country       = country;
            baseContact.MailingAddress.StateProvince = province;
            baseContact.MailingAddress.Community     = city;

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new RegistrantQuery
            {
                ContactId = newContactId
            };
            var newQueryResult = await contactRepository.QueryContact(newContactQuery);

            var newContact = newQueryResult.Items.FirstOrDefault();

            newContact.ShouldNotBeNull().Id.ShouldBe(newContactId);

            newContact.PrimaryAddress.Country.ShouldBe(country);
            newContact.PrimaryAddress.StateProvince.ShouldBe(province);
            newContact.PrimaryAddress.Community.ShouldBe(city);

            newContact.MailingAddress.Country.ShouldBe(country);
            newContact.MailingAddress.StateProvince.ShouldBe(province);
            newContact.MailingAddress.Community.ShouldBe(city);

            /* Delete New Contact */
            DeleteContact deleteCmd = new DeleteContact
            {
                ContactId = newContactId
            };
            var deleteResult = await contactRepository.ManageContact(deleteCmd);

            var deletedContactId = deleteResult.ContactId;

            /* Get deleted contact */
            var deletedCaseQuery = new RegistrantQuery
            {
                ContactId = deletedContactId
            };
            var deletedQueryResult = await contactRepository.QueryContact(deletedCaseQuery);

            var deletedContact = (Contact)deletedQueryResult.Items.LastOrDefault();

            deletedContact.ShouldBeNull();
        }