コード例 #1
0
        public void CreateOtherPersonList_ShouldMapCustomFormFieldToOtherPersonList_When8thFieldPopulated()
        {
            // Arrange
            var config = new OtherPeopleConfigurationModel
            {
                DateOfBirth = "PREFIX_DOB",
                FirstName   = "ANOTHER_PREFIX_FIRSTNAME",
                Gender      = "PREFIX_EXAMPLE_GENDER",
                LastName    = "PREFIX_EXAMPLE_LASTNAME"
            };

            var model = new List <CustomField>
            {
                new CustomField($"{config.Gender}1", "test"),
                new CustomField($"{config.LastName}1", "last name test"),
                new CustomField($"{config.Gender}8", "test 2"),
                new CustomField($"{config.LastName}8", "last name test 2")
            };

            // Act
            var result = _caseService.CreateOtherPersonList(config, model);

            // Assert
            Assert.Equal(model[0].Value, result[0].Gender);
            Assert.Equal(model[1].Value, result[0].LastName);
            Assert.Equal(model[2].Value, result[1].Gender);
            Assert.Equal(model[3].Value, result[1].LastName);

            Assert.Equal(2, result.Count);
        }
コード例 #2
0
        public void CreateOtherPersonList_ShouldReturnCorrectAddress(string address, string expectedLine1, string expectedLine2, string expectedTown)
        {
            // Arrange
            var config = new OtherPeopleConfigurationModel
            {
                DateOfBirth = "PREFIX_DOB",
                FirstName   = "ANOTHER_PREFIX_FIRSTNAME",
                Gender      = "PREFIX_EXAMPLE_GENDER",
                LastName    = "PREFIX_EXAMPLE_LASTNAME",
                Address     = "over16address1"
            };

            var model = new List <CustomField>
            {
                new CustomField($"{config.Address}1", address)
            };

            // Act
            var result = _caseService.CreateOtherPersonList(config, model, 1);

            // Assert
            Assert.Equal(result[0].Address.AddressLine1, expectedLine1);
            Assert.Equal(result[0].Address.AddressLine2, expectedLine2);
            Assert.Equal(result[0].Address.Town, expectedTown);
        }
コード例 #3
0
        public void CreateOtherPersonList_ShouldMapCustomFormFieldToOtherPersonList()
        {
            // Arrange
            var config = new OtherPeopleConfigurationModel
            {
                DateOfBirth = "PREFIX_DOB",
                FirstName   = "ANOTHER_PREFIX_FIRSTNAME",
                Gender      = "PREFIX_EXAMPLE_GENDER",
                LastName    = "PREFIX_EXAMPLE_LASTNAME"
            };

            var model = new List <CustomField>
            {
                new CustomField($"{config.DateOfBirth}1", "01/02/1996"),
                new CustomField($"{config.FirstName}1", "firstname1"),
                new CustomField($"{config.DateOfBirth}2", "01/02/1996"),
                new CustomField($"{config.FirstName}2", "firstname2"),
                new CustomField($"{config.DateOfBirth}3", "01/02/1996"),
                new CustomField($"{config.FirstName}3", "firstname3")
            };

            // Act
            var result = _caseService.CreateOtherPersonList(config, model);

            // Assert
            Assert.Equal(model[0].Value, result[0].DateOfBirth.GetValueOrDefault().ToString("dd/MM/yyyy"));
            Assert.Equal(model[1].Value, result[0].FirstName);
            Assert.Equal(model[2].Value, result[1].DateOfBirth.GetValueOrDefault().ToString("dd/MM/yyyy"));
            Assert.Equal(model[3].Value, result[1].FirstName);
            Assert.Equal(model[4].Value, result[2].DateOfBirth.GetValueOrDefault().ToString("dd/MM/yyyy"));
            Assert.Equal(model[5].Value, result[2].FirstName);

            Assert.Equal(3, result.Count);
        }
コード例 #4
0
        public FormFieldBuilder CreateOtherPersonBuilder(OtherPeopleConfigurationModel config, List <OtherPerson> otherPeople, int capacity = 8)
        {
            var builder = new FormFieldBuilder();

            for (var i = 0; i < otherPeople?.Count; i++)
            {
                var nameSuffix = i + 1;

                builder
                .AddField($"{config.FirstName}{nameSuffix}", otherPeople[i].FirstName ?? string.Empty)
                .AddField($"{config.DateOfBirth}{nameSuffix}", otherPeople[i].DateOfBirth?.ToString("dd/MM/yyyy") ?? string.Empty)
                .AddField($"{config.Gender}{nameSuffix}", otherPeople[i].Gender ?? string.Empty)
                .AddField($"{config.LastName}{nameSuffix}", otherPeople[i].LastName ?? string.Empty);

                if (!string.IsNullOrEmpty(config.RelationshipToYou))
                {
                    builder.AddField($"{config.RelationshipToYou}{nameSuffix}", otherPeople[i].RelationshipToYou ?? string.Empty);
                }

                if (!string.IsNullOrEmpty(config.Address) && !string.IsNullOrEmpty(config.Postcode))
                {
                    if (otherPeople[i].Address == null)
                    {
                        otherPeople[i].Address = new Model.Address();
                    }
                    builder
                    .AddField($"{config.Address}{nameSuffix}", otherPeople[i].Address.AddressLine1 + "|" + otherPeople[i].Address.AddressLine2 + "|" + otherPeople[i].Address.Town)
                    .AddField($"{config.Postcode}{nameSuffix}", otherPeople[i].Address.Postcode ?? string.Empty);
                }
            }

            for (var i = otherPeople?.Count; i < capacity; i++)
            {
                var nameSuffix = i + 1;

                builder
                .AddField($"{config.FirstName}{nameSuffix}", string.Empty)
                .AddField($"{config.DateOfBirth}{nameSuffix}", string.Empty)
                .AddField($"{config.Gender}{nameSuffix}", string.Empty)
                .AddField($"{config.LastName}{nameSuffix}", string.Empty);

                if (!string.IsNullOrEmpty(config.RelationshipToYou))
                {
                    builder.AddField($"{config.RelationshipToYou}{nameSuffix}", string.Empty);
                }

                if (!string.IsNullOrEmpty(config.Address) && !string.IsNullOrEmpty(config.Postcode))
                {
                    builder
                    .AddField($"{config.Address}{nameSuffix}", string.Empty)
                    .AddField($"{config.Postcode}{nameSuffix}", string.Empty);
                }
            }

            return(builder);
        }
コード例 #5
0
        public List <OtherPerson> CreateOtherPersonList(OtherPeopleConfigurationModel config, List <CustomField> formFields, int capacity = 8)
        {
            var otherPersonList = new List <OtherPerson>();

            for (var i = 0; i < capacity; i++)
            {
                otherPersonList.Add(new OtherPerson
                {
                    Address = new Model.Address()
                });
            }

            formFields.ForEach(field =>
            {
                if (string.IsNullOrEmpty(field.Name))
                {
                    return;
                }

                int.TryParse(field.Name[field.Name.Length - 1].ToString(), out var index);

                index--;

                if (index < 0)
                {
                    return;
                }

                if (field.Name.Contains(config.DateOfBirth))
                {
                    otherPersonList[index].DateOfBirth = DateTime.Parse(field.Value);
                }

                if (field.Name.Contains(config.FirstName))
                {
                    otherPersonList[index].FirstName = field.Value;
                }

                if (field.Name.Contains(config.LastName))
                {
                    otherPersonList[index].LastName = field.Value;
                }

                if (field.Name.Contains(config.Gender))
                {
                    otherPersonList[index].Gender = field.Value;
                }

                if (!string.IsNullOrEmpty(config.RelationshipToYou) && field.Name.Contains(config.RelationshipToYou))
                {
                    otherPersonList[index].RelationshipToYou = field.Value;
                }

                if (!string.IsNullOrEmpty(config.Address) && field.Name.Contains(config.Address))
                {
                    var address = field.Value.Split("|");

                    switch (address.Length)
                    {
                    case 0:
                        otherPersonList[index].Address.AddressLine1 = string.Empty;
                        otherPersonList[index].Address.AddressLine2 = string.Empty;
                        otherPersonList[index].Address.Town         = string.Empty;
                        break;

                    case 1:
                        otherPersonList[index].Address.AddressLine1 = address[0];
                        break;

                    case 2:
                        otherPersonList[index].Address.AddressLine1 = address[0];
                        otherPersonList[index].Address.Town         = address[1];
                        break;

                    default:
                        otherPersonList[index].Address.AddressLine1 = address[0];
                        otherPersonList[index].Address.AddressLine2 = address[1];
                        otherPersonList[index].Address.Town         = address[2];
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(config.Postcode) && field.Name.Contains(config.Postcode))
                {
                    otherPersonList[index].Address.Postcode = field.Value;
                }
            });

            return(otherPersonList.Where(person =>
                                         person.Gender != null ||
                                         person.LastName != null ||
                                         person.FirstName != null ||
                                         person.DateOfBirth != null ||
                                         person.RelationshipToYou != null ||
                                         person.Address?.AddressLine1 != null ||
                                         person.Address?.AddressLine2 != null ||
                                         person.Address?.Town != null ||
                                         person.Address?.Postcode != null).
                   ToList());
        }