public void TestClear()
        {
            //Arrange
            var fileCabinet = new FileCabinetService();
            var expected    = new List <Record>();

            //Act
            fileCabinet.Create("firstName", "lastName", "dateOfBirth");
            fileCabinet.Clear();
            var result = fileCabinet.GetRecords().ToList();

            //Assert
            CollectionAssert.AreEqual(expected, result);
        }
        public void TestCreate(string firstName, string lastName, string dateOfBirth)
        {
            //Arrange
            var fileCabinet = new FileCabinetService();
            var expected    = new List <Record>
            {
                new Record {
                    FirstName = firstName, LastName = lastName, DateOfBirth = dateOfBirth
                }
            };

            //Act
            fileCabinet.Create(firstName, lastName, dateOfBirth);
            var result = fileCabinet.GetRecords().ToList();

            //Assert
            CollectionAssert.AreEqual(expected, result);
        }
        public void TestUpdate()
        {
            //Arrange
            var fileCabinet = new FileCabinetService();
            var expected    = new List <Record>
            {
                new Record {
                    FirstName = "first", LastName = "last", DateOfBirth = "date"
                }
            };

            //Act
            fileCabinet.Create("firstName", "lastName", "dateOfBirth");
            fileCabinet.Update(0, "first", "last", "date");
            var result = fileCabinet.GetRecords().ToList();

            //Assert
            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Creates a list of records from memory and send to console
        /// </summary>
        private static void ListRecords(string[] commands)
        {
            var counter = 1;

            var outputType = new List <int>();

            while (commands.Length > counter)
            {
                var currentCommand = commands[counter++];
                if (currentCommand == "id")
                {
                    outputType.Add(1);
                }
                else if (currentCommand == "firstname")
                {
                    outputType.Add(2);
                }
                else if (currentCommand == "lastname")
                {
                    outputType.Add(3);
                }
                else if (currentCommand == "dateofbirth")
                {
                    outputType.Add(4);
                }
            }

            var result = CabinetService.GetRecords().ToList();

            if (outputType.Count < 1)
            {
                WriteToConsoleListRecords(result);
                return;
            }

            counter = 1;

            foreach (var record in result)
            {
                foreach (var i in outputType)
                {
                    if (i == 1)
                    {
                        Console.Write($"#{counter} ");
                    }
                    else if (i == 2)
                    {
                        Console.Write($"{record.FirstName} ");
                    }
                    else if (i == 3)
                    {
                        Console.Write($"{record.LastName} ");
                    }
                    else if (i == 4)
                    {
                        Console.Write($"{record.DateOfBirth} ");
                    }
                }
                Console.WriteLine();
                counter++;
            }
        }