Skip to content

Commit

Permalink
Culture support
Browse files Browse the repository at this point in the history
  • Loading branch information
akesseler committed Sep 28, 2019
1 parent d7fd47c commit d140d99
Show file tree
Hide file tree
Showing 9 changed files with 661 additions and 483 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<a href="https://github.com/akesseler/Plexdata.CapacityConverter/wiki" alt="wiki">
<img src="https://img.shields.io/badge/wiki-docs-orange.svg" />
</a>
<a href="https://akesseler.github.io/Plexdata.CapacityConverter" alt="help">
<img src="https://img.shields.io/badge/help-docs-orange.svg" />
</a>
</p>

## Plexdata Capacity Converter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,54 +142,54 @@ public void Find_BydValueValidation_ValueFitsValue(String value, String expected
}

[Test]
[TestCase("10000000000000000000000000", "8 YB")]
[TestCase("10000000000000000000000", "8 ZB")]
[TestCase("10000000000000000000", "9 EB")]
[TestCase("10000000000000000", "9 PB")]
[TestCase("10000000000000", "9 TB")]
[TestCase("10000000000", "9 GB")]
[TestCase("10000000", "10 MB")]
[TestCase("10000", "10 KB")]
[TestCase("100", "100 Bytes")]
[TestCase("0", "0 Bytes")]
[TestCase("10000000000000000000000000", "8\u00A0YB")]
[TestCase("10000000000000000000000", "8\u00A0ZB")]
[TestCase("10000000000000000000", "9\u00A0EB")]
[TestCase("10000000000000000", "9\u00A0PB")]
[TestCase("10000000000000", "9\u00A0TB")]
[TestCase("10000000000", "9\u00A0GB")]
[TestCase("10000000", "10\u00A0MB")]
[TestCase("10000", "10\u00A0KB")]
[TestCase("100", "100\u00A0Bytes")]
[TestCase("0", "0\u00A0Bytes")]
public void Convert_ByValue_ResultAsExpected(String value, String expected)
{
Assert.That(Examinee.Convert(Convert.ToDecimal(value)), Is.EqualTo(expected));
}

[Test]
[TestCase("10000000000000000000000000", "YB", "8.27 YB")]
[TestCase("10000000000000000000000", "ZB", "8.47 ZB")]
[TestCase("10000000000000000000", "EB", "8.67 EB")]
[TestCase("10000000000000000", "PB", "8.88 PB")]
[TestCase("10000000000000", "TB", "9.09 TB")]
[TestCase("10000000000", "GB", "9.31 GB")]
[TestCase("10000000", "MB", "9.54 MB")]
[TestCase("10000", "KB", "9.77 KB")]
[TestCase("100", "Bytes", "100 Bytes")]
[TestCase("100", "Other", "100 Other")]
[TestCase("123456789", "Other", "123,456,789 Other")]
[TestCase("0", "Bytes", "0 Bytes")]
[TestCase("0", "Other", "0 Other")]
[TestCase("10000000000000000000000000", "YB", "8.27\u00A0YB")]
[TestCase("10000000000000000000000", "ZB", "8.47\u00A0ZB")]
[TestCase("10000000000000000000", "EB", "8.67\u00A0EB")]
[TestCase("10000000000000000", "PB", "8.88\u00A0PB")]
[TestCase("10000000000000", "TB", "9.09\u00A0TB")]
[TestCase("10000000000", "GB", "9.31\u00A0GB")]
[TestCase("10000000", "MB", "9.54\u00A0MB")]
[TestCase("10000", "KB", "9.77\u00A0KB")]
[TestCase("100", "Bytes", "100\u00A0Bytes")]
[TestCase("100", "Other", "100\u00A0Other")]
[TestCase("123456789", "Other", "123,456,789\u00A0Other")]
[TestCase("0", "Bytes", "0\u00A0Bytes")]
[TestCase("0", "Other", "0\u00A0Other")]
public void Convert_ByValueUnit_ResultAsExpected(String value, String unit, String expected)
{
Assert.That(Examinee.Convert(Convert.ToDecimal(value), unit), Is.EqualTo(expected));
}

[Test]
[TestCase("10000000000000000000000000", "YB", 3, "8.272 YB")]
[TestCase("10000000000000000000000", "ZB", 3, "8.470 ZB")]
[TestCase("10000000000000000000", "EB", 3, "8.674 EB")]
[TestCase("10000000000000000", "PB", 3, "8.882 PB")]
[TestCase("10000000000000", "TB", 3, "9.095 TB")]
[TestCase("10000000000", "GB", 3, "9.313 GB")]
[TestCase("10000000", "MB", 3, "9.537 MB")]
[TestCase("10000", "KB", 3, "9.766 KB")]
[TestCase("100", "Bytes", 3, "100 Bytes")]
[TestCase("100", "Other", 3, "100 Other")]
[TestCase("123456789", "Other", 3, "123,456,789 Other")]
[TestCase("0", "Bytes", 3, "0 Bytes")]
[TestCase("0", "Other", 3, "0 Other")]
[TestCase("10000000000000000000000000", "YB", 3, "8.272\u00A0YB")]
[TestCase("10000000000000000000000", "ZB", 3, "8.470\u00A0ZB")]
[TestCase("10000000000000000000", "EB", 3, "8.674\u00A0EB")]
[TestCase("10000000000000000", "PB", 3, "8.882\u00A0PB")]
[TestCase("10000000000000", "TB", 3, "9.095\u00A0TB")]
[TestCase("10000000000", "GB", 3, "9.313\u00A0GB")]
[TestCase("10000000", "MB", 3, "9.537\u00A0MB")]
[TestCase("10000", "KB", 3, "9.766\u00A0KB")]
[TestCase("100", "Bytes", 3, "100\u00A0Bytes")]
[TestCase("100", "Other", 3, "100\u00A0Other")]
[TestCase("123456789", "Other", 3, "123,456,789\u00A0Other")]
[TestCase("0", "Bytes", 3, "0\u00A0Bytes")]
[TestCase("0", "Other", 3, "0\u00A0Other")]
public void Convert_ByValueUnitDecimals_ResultAsExpected(String value, String unit, Int32 decimals, String expected)
{
Assert.That(Examinee.Convert(Convert.ToDecimal(value), unit, decimals), Is.EqualTo(expected));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public void Format_AllCalls_ThrowsNothing()
Assert.That(() => this.GetInstance().Format(150, "unit", false), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, 5, false), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", 5, false), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, 5, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", 5, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, false, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", false, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, 5, false, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", 5, false, (CultureInfo)null), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, this.GetCulture()), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, "unit", this.GetCulture()), Throws.Nothing);
Assert.That(() => this.GetInstance().Format(150, 5, this.GetCulture()), Throws.Nothing);
Expand All @@ -147,25 +155,25 @@ public void Format_NumberFormatInfoIsNull_ThrowsArgumentNullException()
}

[Test]
[TestCase("150", null, "150 Unit1")]
[TestCase("150", "", "150 Unit1")]
[TestCase("150", " ", "150 Unit1")]
[TestCase("150", null, "150\u00A0Unit1")]
[TestCase("150", "", "150\u00A0Unit1")]
[TestCase("150", " ", "150\u00A0Unit1")]
public void Format_UnitInvalid_ResultWithUnitOne(String value, String unit, String expected)
{
String actual = this.GetInstance().Format(Convert.ToDecimal(value), unit, 0, false, this.GetFormatter());

Assert.That(actual, Is.EqualTo(expected));
}

[TestCase("150", " Other ", 0, "150 Other")]
[TestCase("150", " other ", 0, "150 other")]
[TestCase("150", " OTHER ", 0, "150 OTHER")]
[TestCase("150", " Other ", 2, "150.00 Other")]
[TestCase("150", " other ", 2, "150.00 other")]
[TestCase("150", " OTHER ", 2, "150.00 OTHER")]
[TestCase("150", " Other ", 4, "150.0000 Other")]
[TestCase("150", " other ", 4, "150.0000 other")]
[TestCase("150", " OTHER ", 4, "150.0000 OTHER")]
[TestCase("150", " Other ", 0, "150\u00A0Other")]
[TestCase("150", " other ", 0, "150\u00A0other")]
[TestCase("150", " OTHER ", 0, "150\u00A0OTHER")]
[TestCase("150", " Other ", 2, "150.00\u00A0Other")]
[TestCase("150", " other ", 2, "150.00\u00A0other")]
[TestCase("150", " OTHER ", 2, "150.00\u00A0OTHER")]
[TestCase("150", " Other ", 4, "150.0000\u00A0Other")]
[TestCase("150", " other ", 4, "150.0000\u00A0other")]
[TestCase("150", " OTHER ", 4, "150.0000\u00A0OTHER")]
public void Format_OtherUnitWithSpaces_ResultAsExpected(String value, String unit, Int32 decimals, String expected)
{
String actual = this.GetInstance().Format(Convert.ToDecimal(value), unit, decimals, false, this.GetFormatter());
Expand All @@ -174,60 +182,60 @@ public void Format_OtherUnitWithSpaces_ResultAsExpected(String value, String uni
}

[Test]
[TestCase("150", "Unit1", 0, false, "150 Unit1")]
[TestCase("150", "unit1", 0, false, "150 Unit1")]
[TestCase("150", "UNIT1", 0, false, "150 Unit1")]
[TestCase("150", "Unit2", 0, false, "150 Unit2")]
[TestCase("150", "unit2", 0, false, "150 Unit2")]
[TestCase("150", "UNIT2", 0, false, "150 Unit2")]
[TestCase("150", "Other", 0, false, "150 Other")]
[TestCase("150", "other", 0, false, "150 other")]
[TestCase("150", "OTHER", 0, false, "150 OTHER")]
[TestCase("150", "Unit1", 2, false, "150.00 Unit1")]
[TestCase("150", "unit1", 2, false, "150.00 Unit1")]
[TestCase("150", "UNIT1", 2, false, "150.00 Unit1")]
[TestCase("150", "Unit2", 2, false, "150.00 Unit2")]
[TestCase("150", "unit2", 2, false, "150.00 Unit2")]
[TestCase("150", "UNIT2", 2, false, "150.00 Unit2")]
[TestCase("150", "Other", 2, false, "150.00 Other")]
[TestCase("150", "other", 2, false, "150.00 other")]
[TestCase("150", "OTHER", 2, false, "150.00 OTHER")]
[TestCase("150", "Unit1", 5, false, "150.00000 Unit1")]
[TestCase("150", "unit1", 5, false, "150.00000 Unit1")]
[TestCase("150", "UNIT1", 5, false, "150.00000 Unit1")]
[TestCase("150", "Unit2", 5, false, "150.00000 Unit2")]
[TestCase("150", "unit2", 5, false, "150.00000 Unit2")]
[TestCase("150", "UNIT2", 5, false, "150.00000 Unit2")]
[TestCase("150", "Other", 5, false, "150.00000 Other")]
[TestCase("150", "other", 5, false, "150.00000 other")]
[TestCase("150", "OTHER", 5, false, "150.00000 OTHER")]
[TestCase("150", "Unit1", 0, true, "4 Unit1")]
[TestCase("150", "unit1", 0, true, "4 Unit1")]
[TestCase("150", "UNIT1", 0, true, "4 Unit1")]
[TestCase("150", "Unit2", 0, true, "4 Unit2")]
[TestCase("150", "unit2", 0, true, "4 Unit2")]
[TestCase("150", "UNIT2", 0, true, "4 Unit2")]
[TestCase("150", "Other", 0, true, "4 Other")]
[TestCase("150", "other", 0, true, "4 other")]
[TestCase("150", "OTHER", 0, true, "4 OTHER")]
[TestCase("150", "Unit1", 2, true, "3.57 Unit1")]
[TestCase("150", "unit1", 2, true, "3.57 Unit1")]
[TestCase("150", "UNIT1", 2, true, "3.57 Unit1")]
[TestCase("150", "Unit2", 2, true, "3.57 Unit2")]
[TestCase("150", "unit2", 2, true, "3.57 Unit2")]
[TestCase("150", "UNIT2", 2, true, "3.57 Unit2")]
[TestCase("150", "Other", 2, true, "3.57 Other")]
[TestCase("150", "other", 2, true, "3.57 other")]
[TestCase("150", "OTHER", 2, true, "3.57 OTHER")]
[TestCase("150", "Unit1", 5, true, "3.57143 Unit1")]
[TestCase("150", "unit1", 5, true, "3.57143 Unit1")]
[TestCase("150", "UNIT1", 5, true, "3.57143 Unit1")]
[TestCase("150", "Unit2", 5, true, "3.57143 Unit2")]
[TestCase("150", "unit2", 5, true, "3.57143 Unit2")]
[TestCase("150", "UNIT2", 5, true, "3.57143 Unit2")]
[TestCase("150", "Other", 5, true, "3.57143 Other")]
[TestCase("150", "other", 5, true, "3.57143 other")]
[TestCase("150", "OTHER", 5, true, "3.57143 OTHER")]
[TestCase("150", "Unit1", 0, false, "150\u00A0Unit1")]
[TestCase("150", "unit1", 0, false, "150\u00A0Unit1")]
[TestCase("150", "UNIT1", 0, false, "150\u00A0Unit1")]
[TestCase("150", "Unit2", 0, false, "150\u00A0Unit2")]
[TestCase("150", "unit2", 0, false, "150\u00A0Unit2")]
[TestCase("150", "UNIT2", 0, false, "150\u00A0Unit2")]
[TestCase("150", "Other", 0, false, "150\u00A0Other")]
[TestCase("150", "other", 0, false, "150\u00A0other")]
[TestCase("150", "OTHER", 0, false, "150\u00A0OTHER")]
[TestCase("150", "Unit1", 2, false, "150.00\u00A0Unit1")]
[TestCase("150", "unit1", 2, false, "150.00\u00A0Unit1")]
[TestCase("150", "UNIT1", 2, false, "150.00\u00A0Unit1")]
[TestCase("150", "Unit2", 2, false, "150.00\u00A0Unit2")]
[TestCase("150", "unit2", 2, false, "150.00\u00A0Unit2")]
[TestCase("150", "UNIT2", 2, false, "150.00\u00A0Unit2")]
[TestCase("150", "Other", 2, false, "150.00\u00A0Other")]
[TestCase("150", "other", 2, false, "150.00\u00A0other")]
[TestCase("150", "OTHER", 2, false, "150.00\u00A0OTHER")]
[TestCase("150", "Unit1", 5, false, "150.00000\u00A0Unit1")]
[TestCase("150", "unit1", 5, false, "150.00000\u00A0Unit1")]
[TestCase("150", "UNIT1", 5, false, "150.00000\u00A0Unit1")]
[TestCase("150", "Unit2", 5, false, "150.00000\u00A0Unit2")]
[TestCase("150", "unit2", 5, false, "150.00000\u00A0Unit2")]
[TestCase("150", "UNIT2", 5, false, "150.00000\u00A0Unit2")]
[TestCase("150", "Other", 5, false, "150.00000\u00A0Other")]
[TestCase("150", "other", 5, false, "150.00000\u00A0other")]
[TestCase("150", "OTHER", 5, false, "150.00000\u00A0OTHER")]
[TestCase("150", "Unit1", 0, true, "4\u00A0Unit1")]
[TestCase("150", "unit1", 0, true, "4\u00A0Unit1")]
[TestCase("150", "UNIT1", 0, true, "4\u00A0Unit1")]
[TestCase("150", "Unit2", 0, true, "4\u00A0Unit2")]
[TestCase("150", "unit2", 0, true, "4\u00A0Unit2")]
[TestCase("150", "UNIT2", 0, true, "4\u00A0Unit2")]
[TestCase("150", "Other", 0, true, "4\u00A0Other")]
[TestCase("150", "other", 0, true, "4\u00A0other")]
[TestCase("150", "OTHER", 0, true, "4\u00A0OTHER")]
[TestCase("150", "Unit1", 2, true, "3.57\u00A0Unit1")]
[TestCase("150", "unit1", 2, true, "3.57\u00A0Unit1")]
[TestCase("150", "UNIT1", 2, true, "3.57\u00A0Unit1")]
[TestCase("150", "Unit2", 2, true, "3.57\u00A0Unit2")]
[TestCase("150", "unit2", 2, true, "3.57\u00A0Unit2")]
[TestCase("150", "UNIT2", 2, true, "3.57\u00A0Unit2")]
[TestCase("150", "Other", 2, true, "3.57\u00A0Other")]
[TestCase("150", "other", 2, true, "3.57\u00A0other")]
[TestCase("150", "OTHER", 2, true, "3.57\u00A0OTHER")]
[TestCase("150", "Unit1", 5, true, "3.57143\u00A0Unit1")]
[TestCase("150", "unit1", 5, true, "3.57143\u00A0Unit1")]
[TestCase("150", "UNIT1", 5, true, "3.57143\u00A0Unit1")]
[TestCase("150", "Unit2", 5, true, "3.57143\u00A0Unit2")]
[TestCase("150", "unit2", 5, true, "3.57143\u00A0Unit2")]
[TestCase("150", "UNIT2", 5, true, "3.57143\u00A0Unit2")]
[TestCase("150", "Other", 5, true, "3.57143\u00A0Other")]
[TestCase("150", "other", 5, true, "3.57143\u00A0other")]
[TestCase("150", "OTHER", 5, true, "3.57143\u00A0OTHER")]
public void Format_ValueUnitDecimalsCalculateCombinations_ResultAsExpected(String value, String unit, Int32 decimals, Boolean calculate, String expected)
{
String actual = this.GetInstance().Format(Convert.ToDecimal(value), unit, decimals, calculate, this.GetFormatter());
Expand All @@ -237,7 +245,7 @@ public void Format_ValueUnitDecimalsCalculateCombinations_ResultAsExpected(Strin

private CultureInfo GetCulture()
{
return CultureInfo.CurrentCulture;
return CultureInfo.CurrentUICulture;
}

private NumberFormatInfo GetFormatter()
Expand Down
Loading

0 comments on commit d140d99

Please sign in to comment.