コード例 #1
0
        public List <Name> ReadData(string fileName)
        {
            List <Name>             listOfNames       = new List <Name>();
            CreateNameObjects       createNameObjects = new CreateNameObjects();
            NameDataValidateService dataValidation    = new NameDataValidateService();

            try
            {
                using (StreamReader streamReader = new StreamReader(fileName))
                {
                    string NameRecord = "";
                    while ((NameRecord = streamReader.ReadLine()) != null)
                    {
                        if (dataValidation.IsValid(NameRecord))
                        {
                            listOfNames.Add(createNameObjects.CreateNameObjectFromString(NameRecord));
                        }
                        else
                        {
                            log.Info("Name record " + NameRecord + " ignored due to invalid format.");
                        }
                    }
                }
            }
            catch (IOException e)
            {
                log.Error(e.Message);
            }

            return(listOfNames);
        }
コード例 #2
0
        public void CreateNameObjectFromStringShouldReturn()
        {
            //Arrange
            string line    = "Sweta Anant Shah";
            Name   actName = new Name
            {
                GivenName = "Sweta Anant",
                LastName  = "Shah"
            };

            //Act
            Name outputName = _createNameObjects.CreateNameObjectFromString(line);

            //Assert
            Assert.Equal(outputName, actName);
        }