Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2a8d2d5
Two new styles added
edzcodes Oct 27, 2018
62cd511
Changing date format tests to use all cultures without hard-coding
Nov 4, 2018
79c956c
Supressing problematic test for now
tdwright Nov 6, 2018
c8d3d63
Merge branch 'develop' into develop
tdwright Nov 6, 2018
15da83e
Merge branch 'develop' into NewStyle
tdwright Nov 6, 2018
ae7cfa2
Date in tests is formatted using culture and regardless of culture
Nov 8, 2018
3cdc377
Merge pull request #59 from zumo-sk/develop
tdwright Nov 8, 2018
a9d7a74
First attempt to make stretch styles for tables
zumo-sk Nov 11, 2018
f379b87
Small refactorings, 3 styles working
zumo-sk Nov 17, 2018
34b0e64
Merge branch 'develop' into NewStyle
tdwright Nov 17, 2018
9bedf65
Removed deprecated members of the Style class
tdwright Nov 21, 2018
7902996
Merge branch 'develop' of https://github.com/tdwright/contabs into de…
tdwright Nov 21, 2018
290a408
First pass at an attribute system (no tests yet!)
tdwright Nov 21, 2018
cae3721
Demo program to show the attribute system in action
tdwright Nov 21, 2018
b0f4a87
Added the Empty style where the separator is a single whitespace
wargamer Nov 22, 2018
c8fab77
Renamed Empty style to Whitespace
wargamer Nov 22, 2018
495506d
Also renamed unit test
wargamer Nov 22, 2018
2ea451e
Merge pull request #66 from wargamer/feature/empty-style
tdwright Nov 23, 2018
93d7e8f
Merge branch 'develop' of github.com:tdwright/contabs into develop
tdwright Nov 23, 2018
a63bd99
Added unit tests for the 3 new column attributes
tdwright Nov 23, 2018
bfdd513
Updated all NuGet packages
tdwright Nov 23, 2018
9a47c06
Does NUnit + Autofixture require 32 bit? https://github.com/nunit/nun…
tdwright Nov 23, 2018
da113e6
Try specifying which assembly contains our tests
tdwright Nov 24, 2018
2ac16a7
Updated version of NUnit console runner in appveyor config
tdwright Nov 24, 2018
5dbf8dc
Added an attribute to set column format strings
tdwright Nov 24, 2018
6765ca4
Merge branch 'develop' into NewStyle
tdwright Nov 27, 2018
59a517c
All long string behaviors implemented
zumo-sk Dec 2, 2018
b66db99
Simplified style declarations, added XML comments, and added tests
tdwright Dec 15, 2018
f2ef307
Merge branch 'ErsinDagli-NewStyle' into develop
tdwright Dec 15, 2018
bc41944
Implemented a range of suggestions made by ReSharper (thanks JetBrains!)
tdwright Dec 15, 2018
5ae7d71
UnicodeDoubleWalled and UnicodeDoubleFloored Added.
oisinmcl Dec 17, 2018
6fc1f88
Playing with retargeting to .Net Standard 2.0
Dec 18, 2018
4320620
Merge pull request #67 from oisinmcl/develop
tdwright Dec 18, 2018
9ddd817
Updated package info for preview release
tdwright Dec 19, 2018
ce1e462
Merge branch 'develop' into dev/netstandard2.0
tdwright Dec 19, 2018
df5a99c
Added tests, aligned demo programs, fixed format abbreviation from pr…
zumo-sk Dec 26, 2018
5d54d4e
Setting display width to internal, not to be changed by users
zumo-sk Dec 26, 2018
ef5c849
Package metadata for the .net standard 2.0 preview
tdwright Jan 15, 2019
98590d3
Adding support for CanvasWidth = 0 and setting it to default, adding …
zumo-sk Feb 9, 2019
410c750
Adding forgotten summary
zumo-sk Feb 9, 2019
20df5bb
Merge conflicts fixed, fixed culture dependant decimal separator bug …
zumo-sk Feb 9, 2019
c92441f
Merge pull request #70 from zumo-sk/develop
tdwright Feb 19, 2019
7ddf787
Tiny stylistic change to suit the temperament of this particular auto…
tdwright Feb 19, 2019
9ca6478
Updated package metadata for second preview of v2.0.0
tdwright Feb 19, 2019
696af58
Merge branch 'develop' into dev/netstandard2.0
tdwright Apr 17, 2022
f94fd94
Merge pull request #69 from tdwright/dev/netstandard2.0
tdwright Apr 17, 2022
015c726
Added demo app for targetting .NET 5
tdwright Apr 17, 2022
c4b2f58
Updated Appveyor image to support .NET 5 builds
tdwright Apr 17, 2022
7551efe
Merge pull request #74 from tdwright/dev/net5-demo
tdwright Apr 17, 2022
0ba4b04
Basic implementation of a flexible bar chart method
tdwright Apr 18, 2022
374bf45
Added XML documentation for the new method
tdwright Apr 18, 2022
855709d
Improved generic type constraints, with link to source
tdwright Apr 18, 2022
7d6cc0d
Merge pull request #76 from tdwright/dev/barcharts
tdwright Apr 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,4 @@ TestResult.xml
# NDepend
*.ndproj
/NDependOut
.vscode/
179 changes: 179 additions & 0 deletions ConTabs.Tests/BarChartTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
using ConTabs.TestData;
using NUnit.Framework;
using Shouldly;
using System;

namespace ConTabs.Tests
{
[TestFixture]
public class BarChartTests
{
[Test]
public void GenerateBarChart_ResultsInNewColumnAdded()
{
// Arrange
var data = DataProvider.ListOfMinimalData();
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"]);

// Assert
table.Columns.Count.ShouldBe(3);
}

[Test]
public void GenerateBarChart_ResultsInStringColumnAdded()
{
// Arrange
var data = DataProvider.ListOfMinimalData();
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"]);

// Assert
table.Columns[2].SourceType.ShouldBe(typeof(string));
}

[Test]
public void GenerateBarChart_WithDefaultParams_BarsAreExpectedSize()
{
// Arrange
var data = DataProvider.ListOfMinimalData(3); // IntB = 3, 9, 27
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"]); // Max = 27, default width = 25, unit scale = 25/27 = 0.92592...

// Assert
table.Columns[2].Values[0].ShouldBe("###"); // 0.92592 * 3 = 2.77 = 3
table.Columns[2].Values[1].ShouldBe("########"); // 0.92592 * 9 = 8.33 = 8
table.Columns[2].Values[2].ShouldBe("#########################"); // 0.92592 * 27 = 25.00 = 25
}

[Test]
public void GenerateBarChart_MaxWidthCanBeSpecified()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], maxLength: 3);

// Assert
table.Columns[2].Values[0].ShouldBe("###");
}

[Test]
public void GenerateBarChart_ForSingleValues_ResultsInFullWidthBar()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], maxLength: 10);

// Assert
table.Columns[2].Values[0].ShouldBe("##########"); // count = 10 = maxLength
}

[Test]
public void GenerateBarChart_UnitCharCanBeChanged()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], maxLength:3, unitChar: '>');

// Assert
table.Columns[2].Values[0].ShouldBe(">>>");
}

[Test]
public void GenerateBarChart_ScaleCanBeSpecified()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], unitSize: 3);

// Assert
table.Columns[2].Values[0].ShouldBe("#"); // one unit of size 3, for a value of 3
}

[Test]
public void GenerateBarChart_WhenBothScaleAndMaxWidthAreSpecified_ScaleTakesPrecedence()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], unitSize: 3, maxLength: 9);

// Assert
table.Columns[2].Values[0].ShouldBe("#"); // one unit of size 3, for a value of 3, rather than 100% of maxLength
}

[Test]
public void GenerateBarChart_WhenBothScaleAndMaxWidthAreSpecified_NeverExceedsMax()
{
// Arrange
var data = DataProvider.ListOfMinimalData(3); // single row, IntB = 3
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], unitSize: 3, maxLength: 5);

// Assert
table.Columns[2].Values[0].ShouldBe("#");
table.Columns[2].Values[1].ShouldBe("###");
table.Columns[2].Values[2].ShouldBe("#####"); // capped at 5 instead of value 27 / scale 3 = 9 units
}

[Test]
public void GenerateBarChart_NegativeValuesGetHandledGracefully()
{
// Arrange
var data = DataProvider.ListOfMinimalData(1); // single row, IntB = 3
data[0].IntB = -1;
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"]);

// Assert
table.Columns[2].Values[0].ShouldBe("");
}

[Test]
public void GenerateBarChart_ConformanceTest()
{
// Arrange
var data = DataProvider.ListOfMinimalData(3); // IntB = 3, 9, 27
var table = Table.Create(data);

// Act
table.Columns.AddBarChart<int>("Chart", table.Columns["IntB"], maxLength: 10, unitChar: '=');

// Assert
string expected = "";
expected += "+------+------+------------+" + Environment.NewLine;
expected += "| IntA | IntB | Chart |" + Environment.NewLine;
expected += "+------+------+------------+" + Environment.NewLine;
expected += "| 1 | 3 | = |" + Environment.NewLine;
expected += "| 2 | 9 | === |" + Environment.NewLine;
expected += "| 3 | 27 | ========== |" + Environment.NewLine;
expected += "+------+------+------------+";

table.ToString().ShouldBe(expected);
}
}
}
93 changes: 93 additions & 0 deletions ConTabs.Tests/ColumnAttributeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using AutoFixture.NUnit3;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;
using System.Linq;
using ConTabs.Attributes;
using System.Threading;
using System.Globalization;

namespace ConTabs.Tests
{
[TestFixture]
public class ColumnAttributeTests
{
[Test, AutoData]
public void ConTabsColumnHideAttributeShouldResultInColumnBeingHidden(List<ClassWithOneHiddenColumn> data)
{
// act
var table = Table.Create(data);

// assert
table.Columns.Count(c => c.Hide).ShouldBe(1);
table.Columns.Count(c => !c.Hide).ShouldBe(1);
}

[Test, AutoData]
public void ConTabsColumnPositionAttributeShouldResultInColumnBeingMoved(List<ClassWithReorderedColumns> data)
{
// act
var table = Table.Create(data);

// assert
table.Columns[0].ColumnName.ShouldBe("ColumnB");
table.Columns[1].ColumnName.ShouldBe("ColumnA");
}

[Test, AutoData]
public void ConTabsColumnNameAttributeShouldResultInColumnBeingRenamed(List<ClassWithRenamedColumns> data)
{
// act
var table = Table.Create(data);

// assert
table.Columns[1].ColumnName.ShouldBe("ColumnX");
}

[Test, AutoData]
public void ConTabsColumnFormatStringAttributeShouldResultInFormatBeingApplied(List<ClassWithFormattedColumns> data)
{
// arrange
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

// act
var table = Table.Create(data);

// assert
table.Columns[1].StringValForCol(79.11d).ShouldBe("079.110");
}
}


public class ClassWithOneHiddenColumn
{
public int ColumnA { get; set; }

[ConTabsColumnHide]
public int ColumnB { get; set; }
}

public class ClassWithReorderedColumns
{
public int ColumnA { get; set; }

[ConTabsColumnPosition(0)]
public int ColumnB { get; set; }
}

public class ClassWithRenamedColumns
{
public int ColumnA { get; set; }

[ConTabsColumnName("ColumnX")]
public int ColumnB { get; set; }
}

public class ClassWithFormattedColumns
{
public int ColumnA { get; set; }

[ConTabsColumnFormatString("000.000")]
public double ColumnB { get; set; }
}
}
8 changes: 4 additions & 4 deletions ConTabs.Tests/ColumnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void MaxWidthWithNullValuesReturnsColumnNameLength()
var column = new Column(typeof(string), "StringColumn");

//Act
var result = column.MaxWidth;
var result = TableStretchStyles.DoNothing.CalculateOptimalWidth(column, 0);

//Assert
result.ShouldBe(12);
Expand All @@ -41,7 +41,7 @@ public void MaxWidthWithZeroValuesReturnsColumnNameLength()
column.Values = new List<object>();

//Act
var result = column.MaxWidth;
var result = TableStretchStyles.DoNothing.CalculateOptimalWidth(column, 0);

//Assert
result.ShouldBe(12);
Expand All @@ -57,7 +57,7 @@ public void MaxWidthWithLongStringBehaviourReturnsLongStringBehaviourWidth()
column.LongStringBehaviour.Width = 15;

//Act
var result = column.MaxWidth;
var result = TableStretchStyles.DoNothing.CalculateOptimalWidth(column, 0);

//Assert
result.ShouldBe(15);
Expand All @@ -71,7 +71,7 @@ public void MaxWidthWithValuesReturnsLengthOfLongestValue()
column.Values = new List<object>() { "one", "two", "three", "four" };

//Act
var result = column.MaxWidth;
var result = TableStretchStyles.DoNothing.CalculateOptimalWidth(column, 0);

//Assert
result.ShouldBe(5);
Expand Down
30 changes: 23 additions & 7 deletions ConTabs.Tests/ConTabs.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConTabs.Tests</RootNamespace>
<AssemblyName>ConTabs.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
Expand Down Expand Up @@ -39,16 +40,29 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="AutoFixture, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
<HintPath>..\packages\AutoFixture.4.5.0\lib\net452\AutoFixture.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=2.8.3.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.8.3\lib\net451\Shouldly.dll</HintPath>
<Reference Include="AutoFixture.NUnit3, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
<HintPath>..\packages\AutoFixture.NUnit3.4.5.0\lib\net452\AutoFixture.NUnit3.dll</HintPath>
</Reference>
<Reference Include="Fare, Version=2.1.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
<HintPath>..\packages\Fare.2.1.1\lib\net35\Fare.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=3.0.2.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.3.0.2\lib\net451\Shouldly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="BarChartTests.cs" />
<Compile Include="ColumnAttributeTests.cs" />
<Compile Include="ConformanceTests.cs" />
<Compile Include="FormatTests.cs" />
<Compile Include="AlignmentTests.cs" />
Expand All @@ -62,6 +76,7 @@
<Compile Include="UsageTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand All @@ -80,6 +95,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>
Loading