Пример #1
0
        /// <summary>
        /// Write the list of name to storage
        /// </summary>
        /// <param name="file">file name and path</param>
        /// <param name="names">list of name object</param>
        public static void WriteNamesToStorage(NamesFile file, List <Name> names)
        {
            string namesString;

            //
            //create storage and message object from the factory
            //
            IStorage storage       = StorageFactory.CreatStorage(file);
            IMessage promptMessage = MessageFactory.CreatMessage(Message.MessageType.Prompt);


            //
            //convert list of name object to a string
            //
            namesString = NamesStringConverter.ConvertNamesToString(names);

            //
            //write names string to storage
            //
            storage.WriteData(namesString);

            //
            //give user a message of writing completion at the end
            //
            promptMessage.DisplayMessage("Writing data to " + file.WriteFilePath + " is completed");
        }
        public void NamesToStringConversion_ShouldWork()
        {
            //
            //list of sample name object
            //
            Name name1 = new Name("John", "Smith");
            Name name2 = new Name("Jake Jackson", "Lee");
            Name name3 = new Name("Rob", "Smyth");
            Name name4 = new Name("Angela", "Nash");

            List <Name> names = new List <Name>();

            names.Add(name1);
            names.Add(name2);
            names.Add(name3);
            names.Add(name4);

            //
            //expected names in string
            //

            string expected = "John Smith" + Environment.NewLine +
                              "Jake Jackson Lee" + Environment.NewLine +
                              "Rob Smyth" + Environment.NewLine +
                              "Angela Nash" + Environment.NewLine;

            //
            //actual names in string
            //
            string actual = NamesStringConverter.ConvertNamesToString(names);

            //
            //Assert
            //
            Assert.Equal(expected, actual);
        }