Exemplo n.º 1
0
        public void ToSting_1Row()
        {
            const string expectedString = "A,1";
            var table1 = new Table(expectedString);
            var result = table1.ToString();

            Assert.That(result, Is.EqualTo(expectedString));
        }
Exemplo n.º 2
0
        public void MapValuesFrom_OneValueFound()
        {
            var table1 = new Table("A,1");
            var table2 = new Table("A");

            table2.MapValuesFrom(table1);

            Assert.That(table2.Rows.First().Value, Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public void MapValuesFrom_MultipleKeys_FirstValueMapped()
        {
            var table1 = new Table("A,1\nA,2");
            var table2 = new Table("A");

            table2.MapValuesFrom(table1);

            Assert.That(table2.Rows.First().Value, Is.EqualTo(1));
        }
Exemplo n.º 4
0
        public void MapValuesFrom_2ValuesFound()
        {
            var table1 = new Table("A,1\nB,2");
            var table2 = new Table("A\nB");

            table2.MapValuesFrom(table1);

            Assert.That(table2.Rows[0].Value, Is.EqualTo(1));
            Assert.That(table2.Rows[1].Value, Is.EqualTo(2));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Maps the Values from provided value by the Keys.
        /// </summary>
        /// <param name="sourseTable">Sourse table.</param>
        public void MapValuesFrom(Table sourseTable)
        {
            try
            {

                Rows.ForEach(
                    x => x.Value = sourseTable.Rows.First(
                        y => y.Key.Equals(x.Key)).Value);
            }
            catch (InvalidOperationException)
            {
                throw new ApplicationException("Key not found in source Table");
            }
        }
Exemplo n.º 6
0
        public void MapValuesFromError_KeyNotFound()
        {
            var table1 = new Table("A,1");
            var table2 = new Table("B");
            const string message = "Key not found in source Table";

            try
            {
                table2.MapValuesFrom(table1);
            }
            catch (ApplicationException ex)
            {
                Assert.That(ex.Message, Is.EqualTo(message));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Run the instance of application.
        /// </summary>
        public void Run()
        {
            try
            {
                if (_file1 == null && _file2 == null)
                    GetFilesFromArgumets();
                var table1 = new Table(FileHandler.ReadFile(_file1));
                var table2 = new Table(FileHandler.ReadFile(_file2));
                table2.MapValuesFrom(table1);
                FileHandler.WriteFile(_file2, table2.ToString());

            }
            catch (ApplicationException ex)
            {
                Console.Write(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected error occured: {0}", ex);
                return;
            }
            Console.Write("Values were successfully mapped from <{0}> to <{1}>", _file1, _file2);
        }
Exemplo n.º 8
0
 public void Constructor_2RowTable()
 {
     var table = new Table("A,1\nB,2");
     Assert.That(table.Rows.Count, Is.EqualTo(2));
 }
Exemplo n.º 9
0
 public void Constructor_1RowTable()
 {
     var table = new Table("A,1");
     Assert.That(table.Rows.Count, Is.EqualTo(1));
 }