Пример #1
0
        public void TestPrintValidTable()
        {
            var items = new[]
            {
                new MyFormatItem {
                    Name = "Bob", Age = 21
                },
                new MyFormatItem {
                    Name = "Alice", Age = 5
                }
            };

            var tableFormatter = new TableFormater <MyFormatItem>()
                                 .AddColumn("Name", i => i.Name, c => c)
                                 .AddColumn("Age", i => i.Age, c => c.ToString("D"));

            var result = tableFormatter.CreateTable(items);

            var expectedTable = new StringBuilder()
                                .AppendLine("| Name  | Age |")
                                .AppendLine("| Bob   | 21  |")
                                .Append("| Alice | 5   |");

            Assert.AreEqual(expectedTable.ToString(), result);
        }
Пример #2
0
		public void TestAddColumnWithValidSelectors()
		{
			var tableFormatter = new TableFormater<MyFormatItem>();

			tableFormatter.AddColumn("BadColumn", i => "Hello", i => i);

			Assert.AreEqual(1, tableFormatter.ColumnCount);
		}
Пример #3
0
        public void TestAddColumnWithValidSelectors()
        {
            var tableFormatter = new TableFormater <MyFormatItem>();

            tableFormatter.AddColumn("BadColumn", i => "Hello", i => i);

            Assert.AreEqual(1, tableFormatter.ColumnCount);
        }
Пример #4
0
        public void TestPrintTableWithNoRowsReturnsJustHeaders()
        {
            var tableFormatter = new TableFormater <MyFormatItem>()
                                 .AddColumn("Name", i => i.Name, c => c)
                                 .AddColumn("Age", i => i.Age, c => c.ToString("D"));

            var result = tableFormatter.CreateTable(new List <MyFormatItem>(0));

            Assert.AreEqual("| Name | Age |", result);
        }
Пример #5
0
        public void TestPrintTableWithRowExclusionEnableReturnsNullIfNoRowsExist()
        {
            var tableFormatter = new TableFormater <MyFormatItem>()
                                 .ExcludePrintingIfNoRows()
                                 .AddColumn("Name", i => i.Name, c => c)
                                 .AddColumn("Age", i => i.Age, c => c.ToString("D"));

            var result = tableFormatter.CreateTable(new List <MyFormatItem>(0));

            Assert.IsNull(result);
        }
Пример #6
0
		public void TestAddColumnWithNullValueSelectorThrowsException()
		{
			var tableFormatter = new TableFormater<MyFormatItem>();

			try
			{
				tableFormatter.AddColumn("BadColumn", i => "Hello", null);
			}
			catch (ArgumentNullException ex)
			{
				Assert.AreEqual("valueSelector", ex.ParamName);
				throw;
			}
		}
Пример #7
0
        /// <summary>
        /// Gets the comparison table.
        /// </summary>
        /// <returns>The formatted comparison table.</returns>
        internal string GetComparisonTable()
        {
            var tableFormatter = new TableFormater <ValidationItemResult>();

            foreach (var itemValidation in this.validations)
            {
                tableFormatter.AddColumn(
                    itemValidation.ToString(),
                    i => i.PropertyResults.First(p => p.Validation == itemValidation),
                    f => f.FieldExists ? f.ActualValue : "<NOT FOUND>");
            }

            return(tableFormatter.CreateTable(this.CheckedItems));
        }
Пример #8
0
		/// <summary>
		/// Gets the comparison table.
		/// </summary>
		/// <returns>The formatted comparison table.</returns>
		internal string GetComparisonTable()
		{
			var tableFormatter = new TableFormater<ValidationItemResult>();

			foreach (var itemValidation in this.validations)
			{
				tableFormatter.AddColumn(
					itemValidation.ToString(),
					i => i.PropertyResults.First(p => p.Validation == itemValidation),
					f => f.FieldExists ? f.ActualValue : "<NOT FOUND>");
			}

			return tableFormatter.CreateTable(this.CheckedItems);
		}
Пример #9
0
        public void TestAddColumnWithNullValueSelectorThrowsException()
        {
            var tableFormatter = new TableFormater <MyFormatItem>();

            try
            {
                tableFormatter.AddColumn("BadColumn", i => "Hello", null);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("valueSelector", ex.ParamName);
                throw;
            }
        }
Пример #10
0
        /// <summary>
        /// Gets the comparison table displayed by rule.
        /// </summary>
        /// <returns>The formatted table.</returns>
        internal string GetComparisonTableByRule()
        {
            if (this.CheckedItems.Count != 1)
            {
                throw new InvalidOperationException("Only one checked item can exist to process items by rule.");
            }


            var properties     = this.CheckedItems.First().PropertyResults;
            var tableFormatter = new TableFormater <ValidationItemResult.PropertyResult>()
                                 .AddColumn("Field", p => p, p => p.Validation.RawFieldName, CheckFieldExists)
                                 .AddColumn("Rule", p => p.Validation.RawComparisonType, p => p)
                                 .AddColumn("Value", p => p, p => p.Validation.RawComparisonValue, CheckFieldValue);

            return(tableFormatter.CreateTable(properties));
        }
Пример #11
0
		/// <summary>
		/// Gets the comparison table displayed by rule.
		/// </summary>
		/// <returns>The formatted table.</returns>
		internal string GetComparisonTableByRule()
		{
			if (this.CheckedItems.Count != 1)
			{
				throw new InvalidOperationException("Only one checked item can exist to process items by rule.");
			}


			var properties = this.CheckedItems.First().PropertyResults;
			var tableFormatter = new TableFormater<ValidationItemResult.PropertyResult>()
										.AddColumn("Field", p => p, p => p.Validation.RawFieldName, CheckFieldExists)
										.AddColumn("Rule", p => p.Validation.RawComparisonType, p => p)
										.AddColumn("Value", p => p, p => p.Validation.RawComparisonValue, CheckFieldValue);

			return tableFormatter.CreateTable(properties);
		}
Пример #12
0
        public void TestAddColumnWithNullCellSelectorThrowsException()
        {
            var tableFormatter = new TableFormater <MyFormatItem>();

            Assert.Throws <ArgumentNullException>(() =>
            {
                try
                {
                    tableFormatter.AddColumn <string>("BadColumn", null, null);
                }
                catch (ArgumentNullException ex)
                {
                    Assert.AreEqual("cellSelector", ex.ParamName);
                    throw;
                }
            });
        }
Пример #13
0
		public void TestPrintValidTable()
		{
			var items = new[]
			            {
				            new MyFormatItem { Name = "Bob", Age = 21 },
							new MyFormatItem { Name = "Alice", Age = 5 }
			            };

			var tableFormatter = new TableFormater<MyFormatItem>()
										.AddColumn("Name", i => i.Name, c => c)
										.AddColumn("Age", i => i.Age, c => c.ToString("D"));

			var result = tableFormatter.CreateTable(items);

			var expectedTable = new StringBuilder()
										.AppendLine("| Name  | Age |")
										.AppendLine("| Bob   | 21  |")
										    .Append("| Alice | 5   |");

			Assert.AreEqual(expectedTable.ToString(), result);
		}
Пример #14
0
		public void TestPrintTableWithNoRowsReturnsJustHeaders()
		{
			var tableFormatter = new TableFormater<MyFormatItem>()
										.AddColumn("Name", i => i.Name, c => c)
										.AddColumn("Age", i => i.Age, c => c.ToString("D"));

			var result = tableFormatter.CreateTable(new List<MyFormatItem>(0));

			Assert.AreEqual("| Name | Age |", result);
		}
Пример #15
0
		public void TestPrintTableWithRowExclusionEnableReturnsNullIfNoRowsExist()
		{
			var tableFormatter = new TableFormater<MyFormatItem>()
										.ExcludePrintingIfNoRows()
										.AddColumn("Name", i => i.Name, c => c)
										.AddColumn("Age", i => i.Age, c => c.ToString("D"));

			var result = tableFormatter.CreateTable(new List<MyFormatItem>(0));

			Assert.IsNull(result);
		}