From d140d997d1fed622d36cf11c8bd01efc5d7a1b77 Mon Sep 17 00:00:00 2001 From: Axel Kesseler Date: Sat, 28 Sep 2019 05:16:54 +0200 Subject: [PATCH] Culture support --- README.md | 3 + .../Converters/CapacityConverterTests.cs | 72 +- .../Entities/CapacityEntityTests.cs | 142 ++-- .../Formatters/CapacityFormatterTests.cs | 749 +++++++++--------- .../Properties/AssemblyInfo.cs | 42 +- .../Converters/CapacityConverter.cs | 49 +- .../Entities/CapacityEntity.cs | 32 +- .../Formatters/CapacityFormatter.cs | 52 +- .../Plexdata.CapacityConverter.csproj | 3 + 9 files changed, 661 insertions(+), 483 deletions(-) diff --git a/README.md b/README.md index 0b1f9ae..d6941e6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ + + +

## Plexdata Capacity Converter diff --git a/code/src/Plexdata.CapacityConverter.Tests/Converters/CapacityConverterTests.cs b/code/src/Plexdata.CapacityConverter.Tests/Converters/CapacityConverterTests.cs index e8e914d..f6ba322 100644 --- a/code/src/Plexdata.CapacityConverter.Tests/Converters/CapacityConverterTests.cs +++ b/code/src/Plexdata.CapacityConverter.Tests/Converters/CapacityConverterTests.cs @@ -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)); diff --git a/code/src/Plexdata.CapacityConverter.Tests/Entities/CapacityEntityTests.cs b/code/src/Plexdata.CapacityConverter.Tests/Entities/CapacityEntityTests.cs index 69deabc..1464dbf 100644 --- a/code/src/Plexdata.CapacityConverter.Tests/Entities/CapacityEntityTests.cs +++ b/code/src/Plexdata.CapacityConverter.Tests/Entities/CapacityEntityTests.cs @@ -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); @@ -147,9 +155,9 @@ 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()); @@ -157,15 +165,15 @@ public void Format_UnitInvalid_ResultWithUnitOne(String value, String unit, Stri 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()); @@ -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()); @@ -237,7 +245,7 @@ public void Format_ValueUnitDecimalsCalculateCombinations_ResultAsExpected(Strin private CultureInfo GetCulture() { - return CultureInfo.CurrentCulture; + return CultureInfo.CurrentUICulture; } private NumberFormatInfo GetFormatter() diff --git a/code/src/Plexdata.CapacityConverter.Tests/Formatters/CapacityFormatterTests.cs b/code/src/Plexdata.CapacityConverter.Tests/Formatters/CapacityFormatterTests.cs index 1ab35b7..8ef8c73 100644 --- a/code/src/Plexdata.CapacityConverter.Tests/Formatters/CapacityFormatterTests.cs +++ b/code/src/Plexdata.CapacityConverter.Tests/Formatters/CapacityFormatterTests.cs @@ -38,24 +38,22 @@ namespace Plexdata.CapacityConverter.Tests.Formatters [ExcludeFromCodeCoverage] public class CapacityFormatterTests { - private CapacityFormatter instance; - - [SetUp] - public void Setup() + [Test] + public void CapacityFormatter_DefaultConstruction_ThrowsNothing() { - this.instance = new CapacityFormatter(); + Assert.That(() => new CapacityFormatter(), Throws.Nothing); } [Test] - public void CapacityFormatter_DefaultConstruction_ThrowsNothing() + public void CapacityFormatter_CultureConstruction_ThrowsNothing() { - Assert.That(() => new CapacityFormatter(), Throws.Nothing); + Assert.That(() => new CapacityFormatter(null), Throws.Nothing); } [Test] public void CapacityFormatter_SupportedTypes_SupportedTypesAsExpected() { - List actual = this.instance.Supported.ToList(); + List actual = this.GetInstance().Supported.ToList(); Assert.That(actual.Count, Is.EqualTo(11)); Assert.That(actual[0], Is.EqualTo(typeof(SByte))); @@ -71,6 +69,21 @@ public void CapacityFormatter_SupportedTypes_SupportedTypesAsExpected() Assert.That(actual[10], Is.EqualTo(typeof(Decimal))); } + [Test] + public void CapacityFormatter_DefaultCulture_DefaultCultureIsNull() + { + Assert.That(this.GetInstance().Culture, Is.Null); + } + + [Test] + [TestCase("en-US")] + [TestCase("de-DE")] + [TestCase("fr-FR")] + public void CapacityFormatter_OtherCulture_UsedCultureAsExpected(String culture) + { + Assert.That(this.GetInstance(new CultureInfo(culture)).Culture.Name, Is.EqualTo(culture)); + } + [Test] [TestCase(typeof(IFormatProvider))] [TestCase(typeof(CultureInfo))] @@ -78,468 +91,481 @@ public void CapacityFormatter_SupportedTypes_SupportedTypesAsExpected() [TestCase(typeof(DateTimeFormatInfo))] public void GetFormat_InvalidTypes_ResultIsNull(Type candidate) { - Assert.That(this.instance.GetFormat(candidate), Is.Null); + Assert.That(this.GetInstance().GetFormat(candidate), Is.Null); } [Test] [TestCase(typeof(ICustomFormatter), typeof(CapacityFormatter))] public void GetFormat_ValidTypes_ResultIsExpectedType(Type candidate, Type expected) { - Assert.That(this.instance.GetFormat(candidate), Is.InstanceOf(expected)); + Assert.That(this.GetInstance().GetFormat(candidate), Is.InstanceOf(expected)); } [Test] public void Format_NullValue_ResultIsEmpty() { - Assert.That(this.instance.Format("format", null, this.instance), Is.Empty); + CapacityFormatter instance = this.GetInstance(); + Assert.That(instance.Format("format", null, instance), Is.Empty); } [Test] public void Format_ProviderIsNullValueIsFormattable_ResultAsExpected() { DateTime value = new DateTime(2019, 5, 23, 17, 5, 23); - Assert.That(this.instance.Format("yyyy-MM-dd HH:mm:ss", value, null), Is.EqualTo("2019-05-23 17:05:23")); + Assert.That(this.GetInstance().Format("yyyy-MM-dd HH:mm:ss", value, null), Is.EqualTo("2019-05-23 17:05:23")); } [Test] public void Format_ProviderIsNullValueIsNotFormattable_ResultAsExpected() { String value = "Hello, World!"; - Assert.That(this.instance.Format(null, value, null), Is.EqualTo("Hello, World!")); + Assert.That(this.GetInstance().Format(null, value, null), Is.EqualTo("Hello, World!")); } [Test] public void Format_ProviderIsNumberFormatterValueIsFormattable_ResultAsExpected() { Int32 value = 1234; - Assert.That(this.instance.Format("N", value, NumberFormatInfo.CurrentInfo), Is.EqualTo("1,234.00")); + Assert.That(this.GetInstance().Format("N", value, NumberFormatInfo.CurrentInfo), Is.EqualTo("1,234.00")); } [Test] public void Format_ProviderIsCapacityFormatterValueIsUnsupported_ResultAsExpected() { + CapacityFormatter instance = this.GetInstance(); DateTime value = new DateTime(2019, 5, 23, 17, 5, 23); - Assert.That(this.instance.Format("yyyy-MM-dd HH:mm:ss", value, this.instance), Is.EqualTo("2019-05-23 17:05:23")); + Assert.That(instance.Format("yyyy-MM-dd HH:mm:ss", value, instance), Is.EqualTo("2019-05-23 17:05:23")); } [Test] - [TestCase("Unit", 1234, "1,234 Unit")] - [TestCase("Unit5", 1234, "1,234 Unit")] + [TestCase("Unit", 1234, "1,234\u00A0Unit")] + [TestCase("Unit5", 1234, "1,234\u00A0Unit")] public void Format_ProviderIsCapacityFormatterValueIsSupported_ResultAsExpected(String format, Int32 value, String expected) { - Assert.That(this.instance.Format(format, value, this.instance), Is.EqualTo(expected)); + CapacityFormatter instance = this.GetInstance(); + Assert.That(instance.Format(format, value, instance), Is.EqualTo(expected)); } [Test] - [TestCase("{0}", 0, "0 Bytes")] - [TestCase("{0}", 123, "123 Bytes")] - [TestCase("{0}", 1234, "1 KB")] - [TestCase("{0}", 12345, "12 KB")] - [TestCase("{0}", 123456, "121 KB")] - [TestCase("{0}", 1234567, "1 MB")] - [TestCase("{0}", 12345678, "12 MB")] - [TestCase("{0}", 123456789, "118 MB")] - [TestCase("{0}", 1234567890, "1 GB")] - [TestCase("{0}", 12345678901, "11 GB")] - [TestCase("{0}", 123456789012, "115 GB")] - [TestCase("{0}", 1234567890123, "1 TB")] - [TestCase("{0}", 12345678901234, "11 TB")] - [TestCase("{0}", 123456789012345, "112 TB")] - [TestCase("{0}", 1234567890123456, "1 PB")] - [TestCase("{0}", 12345678901234567, "11 PB")] - [TestCase("{0}", 123456789012345678, "110 PB")] + [TestCase("{0}", 0, "0\u00A0Bytes")] + [TestCase("{0}", 123, "123\u00A0Bytes")] + [TestCase("{0}", 1234, "1\u00A0KB")] + [TestCase("{0}", 12345, "12\u00A0KB")] + [TestCase("{0}", 123456, "121\u00A0KB")] + [TestCase("{0}", 1234567, "1\u00A0MB")] + [TestCase("{0}", 12345678, "12\u00A0MB")] + [TestCase("{0}", 123456789, "118\u00A0MB")] + [TestCase("{0}", 1234567890, "1\u00A0GB")] + [TestCase("{0}", 12345678901, "11\u00A0GB")] + [TestCase("{0}", 123456789012, "115\u00A0GB")] + [TestCase("{0}", 1234567890123, "1\u00A0TB")] + [TestCase("{0}", 12345678901234, "11\u00A0TB")] + [TestCase("{0}", 123456789012345, "112\u00A0TB")] + [TestCase("{0}", 1234567890123456, "1\u00A0PB")] + [TestCase("{0}", 12345678901234567, "11\u00A0PB")] + [TestCase("{0}", 123456789012345678, "110\u00A0PB")] public void Format_DefaultUsageIntegrationTestNoUnitNoDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:3}", 0, "0 Bytes")] - [TestCase("{0:3}", 123, "123 Bytes")] - [TestCase("{0:3}", 1234, "1.205 KB")] - [TestCase("{0:3}", 12345, "12.056 KB")] - [TestCase("{0:3}", 123456, "120.562 KB")] - [TestCase("{0:3}", 1234567, "1.177 MB")] - [TestCase("{0:3}", 12345678, "11.774 MB")] - [TestCase("{0:3}", 123456789, "117.738 MB")] - [TestCase("{0:3}", 1234567890, "1.150 GB")] - [TestCase("{0:3}", 12345678901, "11.498 GB")] - [TestCase("{0:3}", 123456789012, "114.978 GB")] - [TestCase("{0:3}", 1234567890123, "1.123 TB")] - [TestCase("{0:3}", 12345678901234, "11.228 TB")] - [TestCase("{0:3}", 123456789012345, "112.283 TB")] - [TestCase("{0:3}", 1234567890123456, "1.097 PB")] - [TestCase("{0:3}", 12345678901234567, "10.965 PB")] - [TestCase("{0:3}", 123456789012345678, "109.652 PB")] + [TestCase("{0:3}", 0, "0\u00A0Bytes")] + [TestCase("{0:3}", 123, "123\u00A0Bytes")] + [TestCase("{0:3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:3}", 12345, "12.056\u00A0KB")] + [TestCase("{0:3}", 123456, "120.562\u00A0KB")] + [TestCase("{0:3}", 1234567, "1.177\u00A0MB")] + [TestCase("{0:3}", 12345678, "11.774\u00A0MB")] + [TestCase("{0:3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:3}", 1234567890, "1.150\u00A0GB")] + [TestCase("{0:3}", 12345678901, "11.498\u00A0GB")] + [TestCase("{0:3}", 123456789012, "114.978\u00A0GB")] + [TestCase("{0:3}", 1234567890123, "1.123\u00A0TB")] + [TestCase("{0:3}", 12345678901234, "11.228\u00A0TB")] + [TestCase("{0:3}", 123456789012345, "112.283\u00A0TB")] + [TestCase("{0:3}", 1234567890123456, "1.097\u00A0PB")] + [TestCase("{0:3}", 12345678901234567, "10.965\u00A0PB")] + [TestCase("{0:3}", 123456789012345678, "109.652\u00A0PB")] public void Format_DefaultUsageIntegrationTestNoUnitThreeDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:one}", 0, "0 Bytes")] - [TestCase("{0:One}", 0, "0 Bytes")] - [TestCase("{0:ONE}", 0, "0 Bytes")] - [TestCase("{0:one}", 123, "123 Bytes")] - [TestCase("{0:One}", 123, "123 Bytes")] - [TestCase("{0:ONE}", 123, "123 Bytes")] - [TestCase("{0:one}", 1234, "1 KB")] - [TestCase("{0:One}", 1234, "1 KB")] - [TestCase("{0:ONE}", 1234, "1 KB")] - [TestCase("{0:one}", 12345, "12 KB")] - [TestCase("{0:One}", 12345, "12 KB")] - [TestCase("{0:ONE}", 12345, "12 KB")] - [TestCase("{0:one}", 123456, "121 KB")] - [TestCase("{0:One}", 123456, "121 KB")] - [TestCase("{0:ONE}", 123456, "121 KB")] - [TestCase("{0:one}", 1234567, "1 MB")] - [TestCase("{0:One}", 1234567, "1 MB")] - [TestCase("{0:ONE}", 1234567, "1 MB")] - [TestCase("{0:one}", 12345678, "12 MB")] - [TestCase("{0:One}", 12345678, "12 MB")] - [TestCase("{0:ONE}", 12345678, "12 MB")] - [TestCase("{0:one}", 123456789, "118 MB")] - [TestCase("{0:One}", 123456789, "118 MB")] - [TestCase("{0:ONE}", 123456789, "118 MB")] - [TestCase("{0:one}", 1234567890, "1 GB")] - [TestCase("{0:One}", 1234567890, "1 GB")] - [TestCase("{0:ONE}", 1234567890, "1 GB")] - [TestCase("{0:one}", 12345678901, "11 GB")] - [TestCase("{0:One}", 12345678901, "11 GB")] - [TestCase("{0:ONE}", 12345678901, "11 GB")] - [TestCase("{0:one}", 123456789012, "115 GB")] - [TestCase("{0:One}", 123456789012, "115 GB")] - [TestCase("{0:ONE}", 123456789012, "115 GB")] - [TestCase("{0:one}", 1234567890123, "1 TB")] - [TestCase("{0:One}", 1234567890123, "1 TB")] - [TestCase("{0:ONE}", 1234567890123, "1 TB")] - [TestCase("{0:one}", 12345678901234, "11 TB")] - [TestCase("{0:One}", 12345678901234, "11 TB")] - [TestCase("{0:ONE}", 12345678901234, "11 TB")] - [TestCase("{0:one}", 123456789012345, "112 TB")] - [TestCase("{0:One}", 123456789012345, "112 TB")] - [TestCase("{0:ONE}", 123456789012345, "112 TB")] - [TestCase("{0:one}", 1234567890123456, "1 PB")] - [TestCase("{0:One}", 1234567890123456, "1 PB")] - [TestCase("{0:ONE}", 1234567890123456, "1 PB")] - [TestCase("{0:one}", 12345678901234567, "11 PB")] - [TestCase("{0:One}", 12345678901234567, "11 PB")] - [TestCase("{0:ONE}", 12345678901234567, "11 PB")] - [TestCase("{0:one}", 123456789012345678, "110 PB")] - [TestCase("{0:One}", 123456789012345678, "110 PB")] - [TestCase("{0:ONE}", 123456789012345678, "110 PB")] + [TestCase("{0:one}", 0, "0\u00A0Bytes")] + [TestCase("{0:One}", 0, "0\u00A0Bytes")] + [TestCase("{0:ONE}", 0, "0\u00A0Bytes")] + [TestCase("{0:one}", 123, "123\u00A0Bytes")] + [TestCase("{0:One}", 123, "123\u00A0Bytes")] + [TestCase("{0:ONE}", 123, "123\u00A0Bytes")] + [TestCase("{0:one}", 1234, "1\u00A0KB")] + [TestCase("{0:One}", 1234, "1\u00A0KB")] + [TestCase("{0:ONE}", 1234, "1\u00A0KB")] + [TestCase("{0:one}", 12345, "12\u00A0KB")] + [TestCase("{0:One}", 12345, "12\u00A0KB")] + [TestCase("{0:ONE}", 12345, "12\u00A0KB")] + [TestCase("{0:one}", 123456, "121\u00A0KB")] + [TestCase("{0:One}", 123456, "121\u00A0KB")] + [TestCase("{0:ONE}", 123456, "121\u00A0KB")] + [TestCase("{0:one}", 1234567, "1\u00A0MB")] + [TestCase("{0:One}", 1234567, "1\u00A0MB")] + [TestCase("{0:ONE}", 1234567, "1\u00A0MB")] + [TestCase("{0:one}", 12345678, "12\u00A0MB")] + [TestCase("{0:One}", 12345678, "12\u00A0MB")] + [TestCase("{0:ONE}", 12345678, "12\u00A0MB")] + [TestCase("{0:one}", 123456789, "118\u00A0MB")] + [TestCase("{0:One}", 123456789, "118\u00A0MB")] + [TestCase("{0:ONE}", 123456789, "118\u00A0MB")] + [TestCase("{0:one}", 1234567890, "1\u00A0GB")] + [TestCase("{0:One}", 1234567890, "1\u00A0GB")] + [TestCase("{0:ONE}", 1234567890, "1\u00A0GB")] + [TestCase("{0:one}", 12345678901, "11\u00A0GB")] + [TestCase("{0:One}", 12345678901, "11\u00A0GB")] + [TestCase("{0:ONE}", 12345678901, "11\u00A0GB")] + [TestCase("{0:one}", 123456789012, "115\u00A0GB")] + [TestCase("{0:One}", 123456789012, "115\u00A0GB")] + [TestCase("{0:ONE}", 123456789012, "115\u00A0GB")] + [TestCase("{0:one}", 1234567890123, "1\u00A0TB")] + [TestCase("{0:One}", 1234567890123, "1\u00A0TB")] + [TestCase("{0:ONE}", 1234567890123, "1\u00A0TB")] + [TestCase("{0:one}", 12345678901234, "11\u00A0TB")] + [TestCase("{0:One}", 12345678901234, "11\u00A0TB")] + [TestCase("{0:ONE}", 12345678901234, "11\u00A0TB")] + [TestCase("{0:one}", 123456789012345, "112\u00A0TB")] + [TestCase("{0:One}", 123456789012345, "112\u00A0TB")] + [TestCase("{0:ONE}", 123456789012345, "112\u00A0TB")] + [TestCase("{0:one}", 1234567890123456, "1\u00A0PB")] + [TestCase("{0:One}", 1234567890123456, "1\u00A0PB")] + [TestCase("{0:ONE}", 1234567890123456, "1\u00A0PB")] + [TestCase("{0:one}", 12345678901234567, "11\u00A0PB")] + [TestCase("{0:One}", 12345678901234567, "11\u00A0PB")] + [TestCase("{0:ONE}", 12345678901234567, "11\u00A0PB")] + [TestCase("{0:one}", 123456789012345678, "110\u00A0PB")] + [TestCase("{0:One}", 123456789012345678, "110\u00A0PB")] + [TestCase("{0:ONE}", 123456789012345678, "110\u00A0PB")] public void Format_DefaultUsageIntegrationTestUnitOneNoDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:one3}", 0, "0 Bytes")] - [TestCase("{0:One3}", 0, "0 Bytes")] - [TestCase("{0:ONE3}", 0, "0 Bytes")] - [TestCase("{0:one3}", 123, "123 Bytes")] - [TestCase("{0:One3}", 123, "123 Bytes")] - [TestCase("{0:ONE3}", 123, "123 Bytes")] - [TestCase("{0:one3}", 1234, "1.205 KB")] - [TestCase("{0:One3}", 1234, "1.205 KB")] - [TestCase("{0:ONE3}", 1234, "1.205 KB")] - [TestCase("{0:one3}", 12345, "12.056 KB")] - [TestCase("{0:One3}", 12345, "12.056 KB")] - [TestCase("{0:ONE3}", 12345, "12.056 KB")] - [TestCase("{0:one3}", 123456, "120.562 KB")] - [TestCase("{0:One3}", 123456, "120.562 KB")] - [TestCase("{0:ONE3}", 123456, "120.562 KB")] - [TestCase("{0:one3}", 1234567, "1.177 MB")] - [TestCase("{0:One3}", 1234567, "1.177 MB")] - [TestCase("{0:ONE3}", 1234567, "1.177 MB")] - [TestCase("{0:one3}", 12345678, "11.774 MB")] - [TestCase("{0:One3}", 12345678, "11.774 MB")] - [TestCase("{0:ONE3}", 12345678, "11.774 MB")] - [TestCase("{0:one3}", 123456789, "117.738 MB")] - [TestCase("{0:One3}", 123456789, "117.738 MB")] - [TestCase("{0:ONE3}", 123456789, "117.738 MB")] - [TestCase("{0:one3}", 1234567890, "1.150 GB")] - [TestCase("{0:One3}", 1234567890, "1.150 GB")] - [TestCase("{0:ONE3}", 1234567890, "1.150 GB")] - [TestCase("{0:one3}", 12345678901, "11.498 GB")] - [TestCase("{0:One3}", 12345678901, "11.498 GB")] - [TestCase("{0:ONE3}", 12345678901, "11.498 GB")] - [TestCase("{0:one3}", 123456789012, "114.978 GB")] - [TestCase("{0:One3}", 123456789012, "114.978 GB")] - [TestCase("{0:ONE3}", 123456789012, "114.978 GB")] - [TestCase("{0:one3}", 1234567890123, "1.123 TB")] - [TestCase("{0:One3}", 1234567890123, "1.123 TB")] - [TestCase("{0:ONE3}", 1234567890123, "1.123 TB")] - [TestCase("{0:one3}", 12345678901234, "11.228 TB")] - [TestCase("{0:One3}", 12345678901234, "11.228 TB")] - [TestCase("{0:ONE3}", 12345678901234, "11.228 TB")] - [TestCase("{0:one3}", 123456789012345, "112.283 TB")] - [TestCase("{0:One3}", 123456789012345, "112.283 TB")] - [TestCase("{0:ONE3}", 123456789012345, "112.283 TB")] - [TestCase("{0:one3}", 1234567890123456, "1.097 PB")] - [TestCase("{0:One3}", 1234567890123456, "1.097 PB")] - [TestCase("{0:ONE3}", 1234567890123456, "1.097 PB")] - [TestCase("{0:one3}", 12345678901234567, "10.965 PB")] - [TestCase("{0:One3}", 12345678901234567, "10.965 PB")] - [TestCase("{0:ONE3}", 12345678901234567, "10.965 PB")] - [TestCase("{0:one3}", 123456789012345678, "109.652 PB")] - [TestCase("{0:One3}", 123456789012345678, "109.652 PB")] - [TestCase("{0:ONE3}", 123456789012345678, "109.652 PB")] + [TestCase("{0:one3}", 0, "0\u00A0Bytes")] + [TestCase("{0:One3}", 0, "0\u00A0Bytes")] + [TestCase("{0:ONE3}", 0, "0\u00A0Bytes")] + [TestCase("{0:one3}", 123, "123\u00A0Bytes")] + [TestCase("{0:One3}", 123, "123\u00A0Bytes")] + [TestCase("{0:ONE3}", 123, "123\u00A0Bytes")] + [TestCase("{0:one3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:One3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:ONE3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:one3}", 12345, "12.056\u00A0KB")] + [TestCase("{0:One3}", 12345, "12.056\u00A0KB")] + [TestCase("{0:ONE3}", 12345, "12.056\u00A0KB")] + [TestCase("{0:one3}", 123456, "120.562\u00A0KB")] + [TestCase("{0:One3}", 123456, "120.562\u00A0KB")] + [TestCase("{0:ONE3}", 123456, "120.562\u00A0KB")] + [TestCase("{0:one3}", 1234567, "1.177\u00A0MB")] + [TestCase("{0:One3}", 1234567, "1.177\u00A0MB")] + [TestCase("{0:ONE3}", 1234567, "1.177\u00A0MB")] + [TestCase("{0:one3}", 12345678, "11.774\u00A0MB")] + [TestCase("{0:One3}", 12345678, "11.774\u00A0MB")] + [TestCase("{0:ONE3}", 12345678, "11.774\u00A0MB")] + [TestCase("{0:one3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:One3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:ONE3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:one3}", 1234567890, "1.150\u00A0GB")] + [TestCase("{0:One3}", 1234567890, "1.150\u00A0GB")] + [TestCase("{0:ONE3}", 1234567890, "1.150\u00A0GB")] + [TestCase("{0:one3}", 12345678901, "11.498\u00A0GB")] + [TestCase("{0:One3}", 12345678901, "11.498\u00A0GB")] + [TestCase("{0:ONE3}", 12345678901, "11.498\u00A0GB")] + [TestCase("{0:one3}", 123456789012, "114.978\u00A0GB")] + [TestCase("{0:One3}", 123456789012, "114.978\u00A0GB")] + [TestCase("{0:ONE3}", 123456789012, "114.978\u00A0GB")] + [TestCase("{0:one3}", 1234567890123, "1.123\u00A0TB")] + [TestCase("{0:One3}", 1234567890123, "1.123\u00A0TB")] + [TestCase("{0:ONE3}", 1234567890123, "1.123\u00A0TB")] + [TestCase("{0:one3}", 12345678901234, "11.228\u00A0TB")] + [TestCase("{0:One3}", 12345678901234, "11.228\u00A0TB")] + [TestCase("{0:ONE3}", 12345678901234, "11.228\u00A0TB")] + [TestCase("{0:one3}", 123456789012345, "112.283\u00A0TB")] + [TestCase("{0:One3}", 123456789012345, "112.283\u00A0TB")] + [TestCase("{0:ONE3}", 123456789012345, "112.283\u00A0TB")] + [TestCase("{0:one3}", 1234567890123456, "1.097\u00A0PB")] + [TestCase("{0:One3}", 1234567890123456, "1.097\u00A0PB")] + [TestCase("{0:ONE3}", 1234567890123456, "1.097\u00A0PB")] + [TestCase("{0:one3}", 12345678901234567, "10.965\u00A0PB")] + [TestCase("{0:One3}", 12345678901234567, "10.965\u00A0PB")] + [TestCase("{0:ONE3}", 12345678901234567, "10.965\u00A0PB")] + [TestCase("{0:one3}", 123456789012345678, "109.652\u00A0PB")] + [TestCase("{0:One3}", 123456789012345678, "109.652\u00A0PB")] + [TestCase("{0:ONE3}", 123456789012345678, "109.652\u00A0PB")] public void Format_DefaultUsageIntegrationTestUnitOneThreeDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:two}", 0, "0 BiB")] - [TestCase("{0:Two}", 0, "0 BiB")] - [TestCase("{0:TWO}", 0, "0 BiB")] - [TestCase("{0:two}", 123, "123 BiB")] - [TestCase("{0:Two}", 123, "123 BiB")] - [TestCase("{0:TWO}", 123, "123 BiB")] - [TestCase("{0:two}", 1234, "1 KiB")] - [TestCase("{0:Two}", 1234, "1 KiB")] - [TestCase("{0:TWO}", 1234, "1 KiB")] - [TestCase("{0:two}", 12345, "12 KiB")] - [TestCase("{0:Two}", 12345, "12 KiB")] - [TestCase("{0:TWO}", 12345, "12 KiB")] - [TestCase("{0:two}", 123456, "121 KiB")] - [TestCase("{0:Two}", 123456, "121 KiB")] - [TestCase("{0:TWO}", 123456, "121 KiB")] - [TestCase("{0:two}", 1234567, "1 MiB")] - [TestCase("{0:Two}", 1234567, "1 MiB")] - [TestCase("{0:TWO}", 1234567, "1 MiB")] - [TestCase("{0:two}", 12345678, "12 MiB")] - [TestCase("{0:Two}", 12345678, "12 MiB")] - [TestCase("{0:TWO}", 12345678, "12 MiB")] - [TestCase("{0:two}", 123456789, "118 MiB")] - [TestCase("{0:Two}", 123456789, "118 MiB")] - [TestCase("{0:TWO}", 123456789, "118 MiB")] - [TestCase("{0:two}", 1234567890, "1 GiB")] - [TestCase("{0:Two}", 1234567890, "1 GiB")] - [TestCase("{0:TWO}", 1234567890, "1 GiB")] - [TestCase("{0:two}", 12345678901, "11 GiB")] - [TestCase("{0:Two}", 12345678901, "11 GiB")] - [TestCase("{0:TWO}", 12345678901, "11 GiB")] - [TestCase("{0:two}", 123456789012, "115 GiB")] - [TestCase("{0:Two}", 123456789012, "115 GiB")] - [TestCase("{0:TWO}", 123456789012, "115 GiB")] - [TestCase("{0:two}", 1234567890123, "1 TiB")] - [TestCase("{0:Two}", 1234567890123, "1 TiB")] - [TestCase("{0:TWO}", 1234567890123, "1 TiB")] - [TestCase("{0:two}", 12345678901234, "11 TiB")] - [TestCase("{0:Two}", 12345678901234, "11 TiB")] - [TestCase("{0:TWO}", 12345678901234, "11 TiB")] - [TestCase("{0:two}", 123456789012345, "112 TiB")] - [TestCase("{0:Two}", 123456789012345, "112 TiB")] - [TestCase("{0:TWO}", 123456789012345, "112 TiB")] - [TestCase("{0:two}", 1234567890123456, "1 PiB")] - [TestCase("{0:Two}", 1234567890123456, "1 PiB")] - [TestCase("{0:TWO}", 1234567890123456, "1 PiB")] - [TestCase("{0:two}", 12345678901234567, "11 PiB")] - [TestCase("{0:Two}", 12345678901234567, "11 PiB")] - [TestCase("{0:TWO}", 12345678901234567, "11 PiB")] - [TestCase("{0:two}", 123456789012345678, "110 PiB")] - [TestCase("{0:Two}", 123456789012345678, "110 PiB")] - [TestCase("{0:TWO}", 123456789012345678, "110 PiB")] + [TestCase("{0:two}", 0, "0\u00A0BiB")] + [TestCase("{0:Two}", 0, "0\u00A0BiB")] + [TestCase("{0:TWO}", 0, "0\u00A0BiB")] + [TestCase("{0:two}", 123, "123\u00A0BiB")] + [TestCase("{0:Two}", 123, "123\u00A0BiB")] + [TestCase("{0:TWO}", 123, "123\u00A0BiB")] + [TestCase("{0:two}", 1234, "1\u00A0KiB")] + [TestCase("{0:Two}", 1234, "1\u00A0KiB")] + [TestCase("{0:TWO}", 1234, "1\u00A0KiB")] + [TestCase("{0:two}", 12345, "12\u00A0KiB")] + [TestCase("{0:Two}", 12345, "12\u00A0KiB")] + [TestCase("{0:TWO}", 12345, "12\u00A0KiB")] + [TestCase("{0:two}", 123456, "121\u00A0KiB")] + [TestCase("{0:Two}", 123456, "121\u00A0KiB")] + [TestCase("{0:TWO}", 123456, "121\u00A0KiB")] + [TestCase("{0:two}", 1234567, "1\u00A0MiB")] + [TestCase("{0:Two}", 1234567, "1\u00A0MiB")] + [TestCase("{0:TWO}", 1234567, "1\u00A0MiB")] + [TestCase("{0:two}", 12345678, "12\u00A0MiB")] + [TestCase("{0:Two}", 12345678, "12\u00A0MiB")] + [TestCase("{0:TWO}", 12345678, "12\u00A0MiB")] + [TestCase("{0:two}", 123456789, "118\u00A0MiB")] + [TestCase("{0:Two}", 123456789, "118\u00A0MiB")] + [TestCase("{0:TWO}", 123456789, "118\u00A0MiB")] + [TestCase("{0:two}", 1234567890, "1\u00A0GiB")] + [TestCase("{0:Two}", 1234567890, "1\u00A0GiB")] + [TestCase("{0:TWO}", 1234567890, "1\u00A0GiB")] + [TestCase("{0:two}", 12345678901, "11\u00A0GiB")] + [TestCase("{0:Two}", 12345678901, "11\u00A0GiB")] + [TestCase("{0:TWO}", 12345678901, "11\u00A0GiB")] + [TestCase("{0:two}", 123456789012, "115\u00A0GiB")] + [TestCase("{0:Two}", 123456789012, "115\u00A0GiB")] + [TestCase("{0:TWO}", 123456789012, "115\u00A0GiB")] + [TestCase("{0:two}", 1234567890123, "1\u00A0TiB")] + [TestCase("{0:Two}", 1234567890123, "1\u00A0TiB")] + [TestCase("{0:TWO}", 1234567890123, "1\u00A0TiB")] + [TestCase("{0:two}", 12345678901234, "11\u00A0TiB")] + [TestCase("{0:Two}", 12345678901234, "11\u00A0TiB")] + [TestCase("{0:TWO}", 12345678901234, "11\u00A0TiB")] + [TestCase("{0:two}", 123456789012345, "112\u00A0TiB")] + [TestCase("{0:Two}", 123456789012345, "112\u00A0TiB")] + [TestCase("{0:TWO}", 123456789012345, "112\u00A0TiB")] + [TestCase("{0:two}", 1234567890123456, "1\u00A0PiB")] + [TestCase("{0:Two}", 1234567890123456, "1\u00A0PiB")] + [TestCase("{0:TWO}", 1234567890123456, "1\u00A0PiB")] + [TestCase("{0:two}", 12345678901234567, "11\u00A0PiB")] + [TestCase("{0:Two}", 12345678901234567, "11\u00A0PiB")] + [TestCase("{0:TWO}", 12345678901234567, "11\u00A0PiB")] + [TestCase("{0:two}", 123456789012345678, "110\u00A0PiB")] + [TestCase("{0:Two}", 123456789012345678, "110\u00A0PiB")] + [TestCase("{0:TWO}", 123456789012345678, "110\u00A0PiB")] public void Format_DefaultUsageIntegrationTestUnitTwoNoDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:two3}", 0, "0 BiB")] - [TestCase("{0:Two3}", 0, "0 BiB")] - [TestCase("{0:TWO3}", 0, "0 BiB")] - [TestCase("{0:two3}", 123, "123 BiB")] - [TestCase("{0:Two3}", 123, "123 BiB")] - [TestCase("{0:TWO3}", 123, "123 BiB")] - [TestCase("{0:two3}", 1234, "1.205 KiB")] - [TestCase("{0:Two3}", 1234, "1.205 KiB")] - [TestCase("{0:TWO3}", 1234, "1.205 KiB")] - [TestCase("{0:two3}", 12345, "12.056 KiB")] - [TestCase("{0:Two3}", 12345, "12.056 KiB")] - [TestCase("{0:TWO3}", 12345, "12.056 KiB")] - [TestCase("{0:two3}", 123456, "120.562 KiB")] - [TestCase("{0:Two3}", 123456, "120.562 KiB")] - [TestCase("{0:TWO3}", 123456, "120.562 KiB")] - [TestCase("{0:two3}", 1234567, "1.177 MiB")] - [TestCase("{0:Two3}", 1234567, "1.177 MiB")] - [TestCase("{0:TWO3}", 1234567, "1.177 MiB")] - [TestCase("{0:two3}", 12345678, "11.774 MiB")] - [TestCase("{0:Two3}", 12345678, "11.774 MiB")] - [TestCase("{0:TWO3}", 12345678, "11.774 MiB")] - [TestCase("{0:two3}", 123456789, "117.738 MiB")] - [TestCase("{0:Two3}", 123456789, "117.738 MiB")] - [TestCase("{0:TWO3}", 123456789, "117.738 MiB")] - [TestCase("{0:two3}", 1234567890, "1.150 GiB")] - [TestCase("{0:Two3}", 1234567890, "1.150 GiB")] - [TestCase("{0:TWO3}", 1234567890, "1.150 GiB")] - [TestCase("{0:two3}", 12345678901, "11.498 GiB")] - [TestCase("{0:Two3}", 12345678901, "11.498 GiB")] - [TestCase("{0:TWO3}", 12345678901, "11.498 GiB")] - [TestCase("{0:two3}", 123456789012, "114.978 GiB")] - [TestCase("{0:Two3}", 123456789012, "114.978 GiB")] - [TestCase("{0:TWO3}", 123456789012, "114.978 GiB")] - [TestCase("{0:two3}", 1234567890123, "1.123 TiB")] - [TestCase("{0:Two3}", 1234567890123, "1.123 TiB")] - [TestCase("{0:TWO3}", 1234567890123, "1.123 TiB")] - [TestCase("{0:two3}", 12345678901234, "11.228 TiB")] - [TestCase("{0:Two3}", 12345678901234, "11.228 TiB")] - [TestCase("{0:TWO3}", 12345678901234, "11.228 TiB")] - [TestCase("{0:two3}", 123456789012345, "112.283 TiB")] - [TestCase("{0:Two3}", 123456789012345, "112.283 TiB")] - [TestCase("{0:TWO3}", 123456789012345, "112.283 TiB")] - [TestCase("{0:two3}", 1234567890123456, "1.097 PiB")] - [TestCase("{0:Two3}", 1234567890123456, "1.097 PiB")] - [TestCase("{0:TWO3}", 1234567890123456, "1.097 PiB")] - [TestCase("{0:two3}", 12345678901234567, "10.965 PiB")] - [TestCase("{0:Two3}", 12345678901234567, "10.965 PiB")] - [TestCase("{0:TWO3}", 12345678901234567, "10.965 PiB")] - [TestCase("{0:two3}", 123456789012345678, "109.652 PiB")] - [TestCase("{0:Two3}", 123456789012345678, "109.652 PiB")] - [TestCase("{0:TWO3}", 123456789012345678, "109.652 PiB")] + [TestCase("{0:two3}", 0, "0\u00A0BiB")] + [TestCase("{0:Two3}", 0, "0\u00A0BiB")] + [TestCase("{0:TWO3}", 0, "0\u00A0BiB")] + [TestCase("{0:two3}", 123, "123\u00A0BiB")] + [TestCase("{0:Two3}", 123, "123\u00A0BiB")] + [TestCase("{0:TWO3}", 123, "123\u00A0BiB")] + [TestCase("{0:two3}", 1234, "1.205\u00A0KiB")] + [TestCase("{0:Two3}", 1234, "1.205\u00A0KiB")] + [TestCase("{0:TWO3}", 1234, "1.205\u00A0KiB")] + [TestCase("{0:two3}", 12345, "12.056\u00A0KiB")] + [TestCase("{0:Two3}", 12345, "12.056\u00A0KiB")] + [TestCase("{0:TWO3}", 12345, "12.056\u00A0KiB")] + [TestCase("{0:two3}", 123456, "120.562\u00A0KiB")] + [TestCase("{0:Two3}", 123456, "120.562\u00A0KiB")] + [TestCase("{0:TWO3}", 123456, "120.562\u00A0KiB")] + [TestCase("{0:two3}", 1234567, "1.177\u00A0MiB")] + [TestCase("{0:Two3}", 1234567, "1.177\u00A0MiB")] + [TestCase("{0:TWO3}", 1234567, "1.177\u00A0MiB")] + [TestCase("{0:two3}", 12345678, "11.774\u00A0MiB")] + [TestCase("{0:Two3}", 12345678, "11.774\u00A0MiB")] + [TestCase("{0:TWO3}", 12345678, "11.774\u00A0MiB")] + [TestCase("{0:two3}", 123456789, "117.738\u00A0MiB")] + [TestCase("{0:Two3}", 123456789, "117.738\u00A0MiB")] + [TestCase("{0:TWO3}", 123456789, "117.738\u00A0MiB")] + [TestCase("{0:two3}", 1234567890, "1.150\u00A0GiB")] + [TestCase("{0:Two3}", 1234567890, "1.150\u00A0GiB")] + [TestCase("{0:TWO3}", 1234567890, "1.150\u00A0GiB")] + [TestCase("{0:two3}", 12345678901, "11.498\u00A0GiB")] + [TestCase("{0:Two3}", 12345678901, "11.498\u00A0GiB")] + [TestCase("{0:TWO3}", 12345678901, "11.498\u00A0GiB")] + [TestCase("{0:two3}", 123456789012, "114.978\u00A0GiB")] + [TestCase("{0:Two3}", 123456789012, "114.978\u00A0GiB")] + [TestCase("{0:TWO3}", 123456789012, "114.978\u00A0GiB")] + [TestCase("{0:two3}", 1234567890123, "1.123\u00A0TiB")] + [TestCase("{0:Two3}", 1234567890123, "1.123\u00A0TiB")] + [TestCase("{0:TWO3}", 1234567890123, "1.123\u00A0TiB")] + [TestCase("{0:two3}", 12345678901234, "11.228\u00A0TiB")] + [TestCase("{0:Two3}", 12345678901234, "11.228\u00A0TiB")] + [TestCase("{0:TWO3}", 12345678901234, "11.228\u00A0TiB")] + [TestCase("{0:two3}", 123456789012345, "112.283\u00A0TiB")] + [TestCase("{0:Two3}", 123456789012345, "112.283\u00A0TiB")] + [TestCase("{0:TWO3}", 123456789012345, "112.283\u00A0TiB")] + [TestCase("{0:two3}", 1234567890123456, "1.097\u00A0PiB")] + [TestCase("{0:Two3}", 1234567890123456, "1.097\u00A0PiB")] + [TestCase("{0:TWO3}", 1234567890123456, "1.097\u00A0PiB")] + [TestCase("{0:two3}", 12345678901234567, "10.965\u00A0PiB")] + [TestCase("{0:Two3}", 12345678901234567, "10.965\u00A0PiB")] + [TestCase("{0:TWO3}", 12345678901234567, "10.965\u00A0PiB")] + [TestCase("{0:two3}", 123456789012345678, "109.652\u00A0PiB")] + [TestCase("{0:Two3}", 123456789012345678, "109.652\u00A0PiB")] + [TestCase("{0:TWO3}", 123456789012345678, "109.652\u00A0PiB")] public void Format_DefaultUsageIntegrationTestUnitTwoThreeDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:bytes}", 0, "0 Bytes")] - [TestCase("{0:Bytes}", 0, "0 Bytes")] - [TestCase("{0:BYTES}", 0, "0 Bytes")] - [TestCase("{0:bytes}", 1234, "1,234 Bytes")] - [TestCase("{0:Bytes}", 1234, "1,234 Bytes")] - [TestCase("{0:BYTES}", 1234, "1,234 Bytes")] - [TestCase("{0:kb}", 1234, "1 KB")] - [TestCase("{0:Kb}", 1234, "1 KB")] - [TestCase("{0:KB}", 1234, "1 KB")] - [TestCase("{0:mb}", 123456789, "118 MB")] - [TestCase("{0:Mb}", 123456789, "118 MB")] - [TestCase("{0:MB}", 123456789, "118 MB")] - [TestCase("{0:gb}", 12345678912, "11 GB")] - [TestCase("{0:Gb}", 12345678912, "11 GB")] - [TestCase("{0:GB}", 12345678912, "11 GB")] - [TestCase("{0:tb}", 12345678912345, "11 TB")] - [TestCase("{0:Tb}", 12345678912345, "11 TB")] - [TestCase("{0:TB}", 12345678912345, "11 TB")] - [TestCase("{0:pb}", 123456789123456789, "110 PB")] - [TestCase("{0:Pb}", 123456789123456789, "110 PB")] - [TestCase("{0:PB}", 123456789123456789, "110 PB")] + [TestCase("{0:bytes}", 0, "0\u00A0Bytes")] + [TestCase("{0:Bytes}", 0, "0\u00A0Bytes")] + [TestCase("{0:BYTES}", 0, "0\u00A0Bytes")] + [TestCase("{0:bytes}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:Bytes}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:BYTES}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:kb}", 1234, "1\u00A0KB")] + [TestCase("{0:Kb}", 1234, "1\u00A0KB")] + [TestCase("{0:KB}", 1234, "1\u00A0KB")] + [TestCase("{0:mb}", 123456789, "118\u00A0MB")] + [TestCase("{0:Mb}", 123456789, "118\u00A0MB")] + [TestCase("{0:MB}", 123456789, "118\u00A0MB")] + [TestCase("{0:gb}", 12345678912, "11\u00A0GB")] + [TestCase("{0:Gb}", 12345678912, "11\u00A0GB")] + [TestCase("{0:GB}", 12345678912, "11\u00A0GB")] + [TestCase("{0:tb}", 12345678912345, "11\u00A0TB")] + [TestCase("{0:Tb}", 12345678912345, "11\u00A0TB")] + [TestCase("{0:TB}", 12345678912345, "11\u00A0TB")] + [TestCase("{0:pb}", 123456789123456789, "110\u00A0PB")] + [TestCase("{0:Pb}", 123456789123456789, "110\u00A0PB")] + [TestCase("{0:PB}", 123456789123456789, "110\u00A0PB")] public void Format_StandardUsageIntegrationTestUnitOne_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:bib}", 0, "0 BiB")] - [TestCase("{0:BiB}", 0, "0 BiB")] - [TestCase("{0:BIB}", 0, "0 BiB")] - [TestCase("{0:bib}", 1234, "1,234 BiB")] - [TestCase("{0:BiB}", 1234, "1,234 BiB")] - [TestCase("{0:BIB}", 1234, "1,234 BiB")] - [TestCase("{0:kib}", 1234, "1 KiB")] - [TestCase("{0:KiB}", 1234, "1 KiB")] - [TestCase("{0:KIB}", 1234, "1 KiB")] - [TestCase("{0:mib}", 123456789, "118 MiB")] - [TestCase("{0:MiB}", 123456789, "118 MiB")] - [TestCase("{0:MIB}", 123456789, "118 MiB")] - [TestCase("{0:gib}", 12345678912, "11 GiB")] - [TestCase("{0:GiB}", 12345678912, "11 GiB")] - [TestCase("{0:GIB}", 12345678912, "11 GiB")] - [TestCase("{0:tib}", 12345678912345, "11 TiB")] - [TestCase("{0:TiB}", 12345678912345, "11 TiB")] - [TestCase("{0:TIB}", 12345678912345, "11 TiB")] - [TestCase("{0:pib}", 123456789123456789, "110 PiB")] - [TestCase("{0:PiB}", 123456789123456789, "110 PiB")] - [TestCase("{0:PIB}", 123456789123456789, "110 PiB")] + [TestCase("{0:bib}", 0, "0\u00A0BiB")] + [TestCase("{0:BiB}", 0, "0\u00A0BiB")] + [TestCase("{0:BIB}", 0, "0\u00A0BiB")] + [TestCase("{0:bib}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:BiB}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:BIB}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:kib}", 1234, "1\u00A0KiB")] + [TestCase("{0:KiB}", 1234, "1\u00A0KiB")] + [TestCase("{0:KIB}", 1234, "1\u00A0KiB")] + [TestCase("{0:mib}", 123456789, "118\u00A0MiB")] + [TestCase("{0:MiB}", 123456789, "118\u00A0MiB")] + [TestCase("{0:MIB}", 123456789, "118\u00A0MiB")] + [TestCase("{0:gib}", 12345678912, "11\u00A0GiB")] + [TestCase("{0:GiB}", 12345678912, "11\u00A0GiB")] + [TestCase("{0:GIB}", 12345678912, "11\u00A0GiB")] + [TestCase("{0:tib}", 12345678912345, "11\u00A0TiB")] + [TestCase("{0:TiB}", 12345678912345, "11\u00A0TiB")] + [TestCase("{0:TIB}", 12345678912345, "11\u00A0TiB")] + [TestCase("{0:pib}", 123456789123456789, "110\u00A0PiB")] + [TestCase("{0:PiB}", 123456789123456789, "110\u00A0PiB")] + [TestCase("{0:PIB}", 123456789123456789, "110\u00A0PiB")] public void Format_StandardUsageIntegrationTestUnitTwo_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:bytes3}", 0, "0 Bytes")] - [TestCase("{0:Bytes3}", 0, "0 Bytes")] - [TestCase("{0:BYTES3}", 0, "0 Bytes")] - [TestCase("{0:bytes3}", 1234, "1,234 Bytes")] - [TestCase("{0:Bytes3}", 1234, "1,234 Bytes")] - [TestCase("{0:BYTES3}", 1234, "1,234 Bytes")] - [TestCase("{0:kb3}", 1234, "1.205 KB")] - [TestCase("{0:Kb3}", 1234, "1.205 KB")] - [TestCase("{0:KB3}", 1234, "1.205 KB")] - [TestCase("{0:mb3}", 123456789, "117.738 MB")] - [TestCase("{0:Mb3}", 123456789, "117.738 MB")] - [TestCase("{0:MB3}", 123456789, "117.738 MB")] - [TestCase("{0:gb3}", 12345678912, "11.498 GB")] - [TestCase("{0:Gb3}", 12345678912, "11.498 GB")] - [TestCase("{0:GB3}", 12345678912, "11.498 GB")] - [TestCase("{0:tb3}", 12345678912345, "11.228 TB")] - [TestCase("{0:Tb3}", 12345678912345, "11.228 TB")] - [TestCase("{0:TB3}", 12345678912345, "11.228 TB")] - [TestCase("{0:pb3}", 123456789123456789, "109.652 PB")] - [TestCase("{0:Pb3}", 123456789123456789, "109.652 PB")] - [TestCase("{0:PB3}", 123456789123456789, "109.652 PB")] + [TestCase("{0:bytes3}", 0, "0\u00A0Bytes")] + [TestCase("{0:Bytes3}", 0, "0\u00A0Bytes")] + [TestCase("{0:BYTES3}", 0, "0\u00A0Bytes")] + [TestCase("{0:bytes3}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:Bytes3}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:BYTES3}", 1234, "1,234\u00A0Bytes")] + [TestCase("{0:kb3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:Kb3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:KB3}", 1234, "1.205\u00A0KB")] + [TestCase("{0:mb3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:Mb3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:MB3}", 123456789, "117.738\u00A0MB")] + [TestCase("{0:gb3}", 12345678912, "11.498\u00A0GB")] + [TestCase("{0:Gb3}", 12345678912, "11.498\u00A0GB")] + [TestCase("{0:GB3}", 12345678912, "11.498\u00A0GB")] + [TestCase("{0:tb3}", 12345678912345, "11.228\u00A0TB")] + [TestCase("{0:Tb3}", 12345678912345, "11.228\u00A0TB")] + [TestCase("{0:TB3}", 12345678912345, "11.228\u00A0TB")] + [TestCase("{0:pb3}", 123456789123456789, "109.652\u00A0PB")] + [TestCase("{0:Pb3}", 123456789123456789, "109.652\u00A0PB")] + [TestCase("{0:PB3}", 123456789123456789, "109.652\u00A0PB")] public void Format_StandardUsageIntegrationTestUnitOnePlusDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:bib4}", 0, "0 BiB")] - [TestCase("{0:BiB4}", 0, "0 BiB")] - [TestCase("{0:BIB4}", 0, "0 BiB")] - [TestCase("{0:bib4}", 1234, "1,234 BiB")] - [TestCase("{0:BiB4}", 1234, "1,234 BiB")] - [TestCase("{0:BIB4}", 1234, "1,234 BiB")] - [TestCase("{0:kib4}", 1234, "1.2051 KiB")] - [TestCase("{0:KiB4}", 1234, "1.2051 KiB")] - [TestCase("{0:KIB4}", 1234, "1.2051 KiB")] - [TestCase("{0:mib4}", 123456789, "117.7376 MiB")] - [TestCase("{0:MiB4}", 123456789, "117.7376 MiB")] - [TestCase("{0:MIB4}", 123456789, "117.7376 MiB")] - [TestCase("{0:gib4}", 12345678912, "11.4978 GiB")] - [TestCase("{0:GiB4}", 12345678912, "11.4978 GiB")] - [TestCase("{0:GIB4}", 12345678912, "11.4978 GiB")] - [TestCase("{0:tib4}", 12345678912345, "11.2283 TiB")] - [TestCase("{0:TiB4}", 12345678912345, "11.2283 TiB")] - [TestCase("{0:TIB4}", 12345678912345, "11.2283 TiB")] - [TestCase("{0:pib4}", 123456789123456789, "109.6517 PiB")] - [TestCase("{0:PiB4}", 123456789123456789, "109.6517 PiB")] - [TestCase("{0:PIB4}", 123456789123456789, "109.6517 PiB")] + [TestCase("{0:bib4}", 0, "0\u00A0BiB")] + [TestCase("{0:BiB4}", 0, "0\u00A0BiB")] + [TestCase("{0:BIB4}", 0, "0\u00A0BiB")] + [TestCase("{0:bib4}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:BiB4}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:BIB4}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:kib4}", 1234, "1.2051\u00A0KiB")] + [TestCase("{0:KiB4}", 1234, "1.2051\u00A0KiB")] + [TestCase("{0:KIB4}", 1234, "1.2051\u00A0KiB")] + [TestCase("{0:mib4}", 123456789, "117.7376\u00A0MiB")] + [TestCase("{0:MiB4}", 123456789, "117.7376\u00A0MiB")] + [TestCase("{0:MIB4}", 123456789, "117.7376\u00A0MiB")] + [TestCase("{0:gib4}", 12345678912, "11.4978\u00A0GiB")] + [TestCase("{0:GiB4}", 12345678912, "11.4978\u00A0GiB")] + [TestCase("{0:GIB4}", 12345678912, "11.4978\u00A0GiB")] + [TestCase("{0:tib4}", 12345678912345, "11.2283\u00A0TiB")] + [TestCase("{0:TiB4}", 12345678912345, "11.2283\u00A0TiB")] + [TestCase("{0:TIB4}", 12345678912345, "11.2283\u00A0TiB")] + [TestCase("{0:pib4}", 123456789123456789, "109.6517\u00A0PiB")] + [TestCase("{0:PiB4}", 123456789123456789, "109.6517\u00A0PiB")] + [TestCase("{0:PIB4}", 123456789123456789, "109.6517\u00A0PiB")] public void Format_StandardUsageIntegrationTestUnitTwoPlusDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] - [TestCase("{0:bib0}", 0, "0 BiB")] - [TestCase("{0:bib0}", 1234, "1,234 BiB")] - [TestCase("{0:kib0}", 1234, "1 KiB")] - [TestCase("{0:mib0}", 123456789, "118 MiB")] - [TestCase("{0:gib0}", 12345678912, "11 GiB")] - [TestCase("{0:tib0}", 12345678912345, "11 TiB")] - [TestCase("{0:pib0}", 123456789123456789, "110 PiB")] + [TestCase("{0:bib0}", 0, "0\u00A0BiB")] + [TestCase("{0:bib0}", 1234, "1,234\u00A0BiB")] + [TestCase("{0:kib0}", 1234, "1\u00A0KiB")] + [TestCase("{0:mib0}", 123456789, "118\u00A0MiB")] + [TestCase("{0:gib0}", 12345678912, "11\u00A0GiB")] + [TestCase("{0:tib0}", 12345678912345, "11\u00A0TiB")] + [TestCase("{0:pib0}", 123456789123456789, "110\u00A0PiB")] public void Format_StandardUsageIntegrationTestUnitTwoAndZeroDigits_ResultAsExpected(String format, Object value, String expected) { - String actual = String.Format(this.instance, format, value); + String actual = String.Format(this.GetInstance(), format, value); + Assert.That(actual, Is.EqualTo(expected)); + } + + [Test] + [TestCase("en-US", "{0:MB3}", 123456789123456789, "117,737,568,973.023\u00A0MB")] + [TestCase("de-DE", "{0:MB3}", 123456789123456789, "117.737.568.973,023\u00A0MB")] + [TestCase("fr-FR", "{0:MB3}", 123456789123456789, "117\u00A0737\u00A0568\u00A0973,023\u00A0MB")] + public void Format_CultureDependentFormatting_ResultAsExpected(String culture, String format, Object value, String expected) + { + String actual = String.Format(this.GetInstance(new CultureInfo(culture)), format, value); Assert.That(actual, Is.EqualTo(expected)); } [Test] public void Examples_RecommendedUsage_ResultsInOutput() { - CapacityFormatter formatter = new CapacityFormatter(); + CapacityFormatter formatter = this.GetInstance(); Debug.WriteLine("Auto-format, auto-unit-selection, zero decimal digits."); Debug.WriteLine(String.Format(formatter, "{0}", 0)); @@ -695,5 +721,10 @@ public void Examples_RecommendedUsage_ResultsInOutput() Assert.That(true); } + + private CapacityFormatter GetInstance(CultureInfo culture = null) + { + return new CapacityFormatter(culture); + } } } diff --git a/code/src/Plexdata.CapacityConverter.Tests/Properties/AssemblyInfo.cs b/code/src/Plexdata.CapacityConverter.Tests/Properties/AssemblyInfo.cs index c4898f2..59305ad 100644 --- a/code/src/Plexdata.CapacityConverter.Tests/Properties/AssemblyInfo.cs +++ b/code/src/Plexdata.CapacityConverter.Tests/Properties/AssemblyInfo.cs @@ -1,4 +1,28 @@ -using System.Reflection; +/* + * MIT License + * + * Copyright (c) 2019 plexdata.de + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -6,11 +30,15 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Plexdata.CapacityConverter.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyDescription("The NUnit test environment for the Plexdata.CapacityConverter library.")] +#if DEBUG +[assembly: AssemblyConfiguration("DEBUG")] +#else +[assembly: AssemblyConfiguration("RELEASE")] +#endif +[assembly: AssemblyCompany("plexdata.de")] [assembly: AssemblyProduct("Plexdata.CapacityConverter.Tests")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCopyright("Copyright © 2019 - plexdata.de")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +60,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0")] +[assembly: AssemblyFileVersion("1.0.0")] diff --git a/code/src/Plexdata.CapacityConverter/Converters/CapacityConverter.cs b/code/src/Plexdata.CapacityConverter/Converters/CapacityConverter.cs index eb4c2e5..bc624e9 100644 --- a/code/src/Plexdata.CapacityConverter/Converters/CapacityConverter.cs +++ b/code/src/Plexdata.CapacityConverter/Converters/CapacityConverter.cs @@ -25,6 +25,7 @@ using Plexdata.Converters.Entities; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace Plexdata.Converters @@ -74,9 +75,9 @@ static CapacityConverter() /// Gets the default capacity entity. /// /// - /// This property returns the default capacity entity. This default capacity - /// is intended to be as fallback. This fallback is actually the last entry - /// all supported . + /// This property returns the default capacity entity. The default capacity is + /// intended to be used as fallback. This fallback is actually the last entry + /// of all supported . /// /// /// The default capacity used as fallback. @@ -242,7 +243,39 @@ public static String Convert(Decimal value, String unit) /// /// /// + /// public static String Convert(Decimal value, String unit, Int32 decimals) + { + return CapacityConverter.Convert(value, unit, decimals, null); + } + + /// + /// Converts provided value into its string representation. + /// + /// + /// This method converts provided value into its string representation + /// by finding the best fitting capacity entity and using it to format + /// provided value afterwards. + /// + /// + /// The value to be converted. + /// + /// + /// The unit to get a capacity entity for. + /// + /// + /// The number of decimal digits used for calculation. + /// + /// + /// The culture to be used for conversion. + /// + /// + /// The string representation of converted value. + /// + /// + /// + /// + public static String Convert(Decimal value, String unit, Int32 decimals, CultureInfo culture) { if (!String.IsNullOrWhiteSpace(unit)) { @@ -250,25 +283,25 @@ public static String Convert(Decimal value, String unit, Int32 decimals) if (unit.Equals("one", StringComparison.InvariantCultureIgnoreCase)) { CapacityEntity entity = CapacityConverter.Find(value); - return entity.Format(value, entity.Unit1, decimals); + return entity.Format(value, entity.Unit1, decimals, culture); } // Special case: Prefere unit two. if (unit.Equals("two", StringComparison.InvariantCultureIgnoreCase)) { CapacityEntity entity = CapacityConverter.Find(value); - return entity.Format(value, entity.Unit2, decimals); + return entity.Format(value, entity.Unit2, decimals, culture); } - return CapacityConverter.Find(unit).Format(value, unit, decimals); + return CapacityConverter.Find(unit).Format(value, unit, decimals, culture); } if (decimals > 0) { - return CapacityConverter.Convert(value, decimals); + return CapacityConverter.Find(value).Format(value, decimals, culture); } - return CapacityConverter.Convert(value); + return CapacityConverter.Find(value).Format(value, culture); } #endregion diff --git a/code/src/Plexdata.CapacityConverter/Entities/CapacityEntity.cs b/code/src/Plexdata.CapacityConverter/Entities/CapacityEntity.cs index f5b92f0..acb741a 100644 --- a/code/src/Plexdata.CapacityConverter/Entities/CapacityEntity.cs +++ b/code/src/Plexdata.CapacityConverter/Entities/CapacityEntity.cs @@ -197,6 +197,7 @@ public Decimal Calculate(Decimal value, Int32 decimals) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value) { return this.Format(value, this.GetUnit(), this.GetDecimals(), this.GetCalculate(), this.GetFormatter()); @@ -217,6 +218,7 @@ public String Format(Decimal value) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit) { return this.Format(value, unit, this.GetDecimals(), this.GetCalculate(), this.GetFormatter()); @@ -237,6 +239,7 @@ public String Format(Decimal value, String unit) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals) { return this.Format(value, this.GetUnit(), decimals, this.GetCalculate(), this.GetFormatter()); @@ -260,6 +263,7 @@ public String Format(Decimal value, Int32 decimals) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Int32 decimals) { return this.Format(value, this.GetUnit(unit), decimals, this.GetCalculate(), this.GetFormatter()); @@ -280,6 +284,7 @@ public String Format(Decimal value, String unit, Int32 decimals) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Boolean calculate) { return this.Format(value, this.GetUnit(), this.GetDecimals(), calculate, this.GetFormatter()); @@ -303,6 +308,7 @@ public String Format(Decimal value, Boolean calculate) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Boolean calculate) { return this.Format(value, unit, this.GetDecimals(), calculate, this.GetFormatter()); @@ -326,6 +332,7 @@ public String Format(Decimal value, String unit, Boolean calculate) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals, Boolean calculate) { return this.Format(value, this.GetUnit(), decimals, calculate, this.GetFormatter()); @@ -352,6 +359,7 @@ public String Format(Decimal value, Int32 decimals, Boolean calculate) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Int32 decimals, Boolean calculate) { return this.Format(value, unit, decimals, calculate, this.GetFormatter()); @@ -372,6 +380,7 @@ public String Format(Decimal value, String unit, Int32 decimals, Boolean calcula /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, CultureInfo culture) { return this.Format(value, this.GetUnit(), this.GetDecimals(), this.GetCalculate(), this.GetFormatter(culture)); @@ -395,6 +404,7 @@ public String Format(Decimal value, CultureInfo culture) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, CultureInfo culture) { return this.Format(value, unit, this.GetDecimals(), this.GetCalculate(), this.GetFormatter(culture)); @@ -418,6 +428,7 @@ public String Format(Decimal value, String unit, CultureInfo culture) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals, CultureInfo culture) { return this.Format(value, this.GetUnit(), decimals, this.GetCalculate(), this.GetFormatter(culture)); @@ -444,6 +455,7 @@ public String Format(Decimal value, Int32 decimals, CultureInfo culture) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Int32 decimals, CultureInfo culture) { return this.Format(value, unit, decimals, this.GetCalculate(), this.GetFormatter(culture)); @@ -467,6 +479,7 @@ public String Format(Decimal value, String unit, Int32 decimals, CultureInfo cul /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Boolean calculate, CultureInfo culture) { return this.Format(value, this.GetUnit(), this.GetDecimals(), calculate, this.GetFormatter(culture)); @@ -493,6 +506,7 @@ public String Format(Decimal value, Boolean calculate, CultureInfo culture) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Boolean calculate, CultureInfo culture) { return this.Format(value, unit, this.GetDecimals(), calculate, this.GetFormatter(culture)); @@ -519,6 +533,7 @@ public String Format(Decimal value, String unit, Boolean calculate, CultureInfo /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals, Boolean calculate, CultureInfo culture) { return this.Format(value, this.GetUnit(), decimals, calculate, this.GetFormatter(culture)); @@ -548,6 +563,7 @@ public String Format(Decimal value, Int32 decimals, Boolean calculate, CultureIn /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Int32 decimals, Boolean calculate, CultureInfo culture) { return this.Format(value, unit, decimals, calculate, this.GetFormatter(culture)); @@ -568,6 +584,7 @@ public String Format(Decimal value, String unit, Int32 decimals, Boolean calcula /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, NumberFormatInfo formatter) { return this.Format(value, this.GetUnit(), this.GetDecimals(), this.GetCalculate(), formatter); @@ -591,6 +608,7 @@ public String Format(Decimal value, NumberFormatInfo formatter) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, NumberFormatInfo formatter) { return this.Format(value, unit, this.GetDecimals(), this.GetCalculate(), formatter); @@ -614,6 +632,7 @@ public String Format(Decimal value, String unit, NumberFormatInfo formatter) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals, NumberFormatInfo formatter) { return this.Format(value, this.GetUnit(), decimals, this.GetCalculate(), formatter); @@ -640,6 +659,7 @@ public String Format(Decimal value, Int32 decimals, NumberFormatInfo formatter) /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Int32 decimals, NumberFormatInfo formatter) { return this.Format(value, unit, decimals, this.GetCalculate(), formatter); @@ -663,6 +683,7 @@ public String Format(Decimal value, String unit, Int32 decimals, NumberFormatInf /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Boolean calculate, NumberFormatInfo formatter) { return this.Format(value, this.GetUnit(), this.GetDecimals(), calculate, formatter); @@ -689,6 +710,7 @@ public String Format(Decimal value, Boolean calculate, NumberFormatInfo formatte /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, String unit, Boolean calculate, NumberFormatInfo formatter) { return this.Format(value, unit, this.GetDecimals(), calculate, formatter); @@ -715,6 +737,7 @@ public String Format(Decimal value, String unit, Boolean calculate, NumberFormat /// /// The string representation of formatted value. /// + /// public String Format(Decimal value, Int32 decimals, Boolean calculate, NumberFormatInfo formatter) { return this.Format(value, this.GetUnit(), decimals, calculate, formatter); @@ -724,7 +747,9 @@ public String Format(Decimal value, Int32 decimals, Boolean calculate, NumberFor /// Formats provided value according to current settings. /// /// - /// This method formats provided value according to current settings. + /// This method formats provided value according to current settings. Keep in + /// mind, resulting number and unit are concatenated by the 'NO-BREAK SPACE' + /// Unicode character (U+00A0). /// /// /// The value to be formatted. @@ -760,7 +785,8 @@ public String Format(Decimal value, String unit, Int32 decimals, Boolean calcula value = calculate ? this.Calculate(value, decimals) : value; - String format = $"{{0:N}} {this.GetUnit(unit)}"; + // Concatenate number and unit by the 'NO-BREAK SPACE' Unicode character. + String format = $"{{0:N}}\u00A0{this.GetUnit(unit)}"; return String.Format(formatter, format, value); } @@ -888,7 +914,7 @@ private CultureInfo GetCulture() /// /// /// This method returns the default number formatter, which is based on - /// default culture.. + /// default culture. /// /// /// The default number formatter. diff --git a/code/src/Plexdata.CapacityConverter/Formatters/CapacityFormatter.cs b/code/src/Plexdata.CapacityConverter/Formatters/CapacityFormatter.cs index 6249102..663d914 100644 --- a/code/src/Plexdata.CapacityConverter/Formatters/CapacityFormatter.cs +++ b/code/src/Plexdata.CapacityConverter/Formatters/CapacityFormatter.cs @@ -58,9 +58,25 @@ public class CapacityFormatter : IFormatProvider, ICustomFormatter /// Default constructor. /// /// - /// The default constructor just initializes its properties. + /// The default constructor just initializes its properties with default values. /// public CapacityFormatter() + : this(null) + { + } + + /// + /// Parameterized constructor. + /// + /// + /// The parameterized constructor initializes its properties. Keep in mind, current + /// UI culture is used if parameter is null. + /// + /// + /// The culture to be used or null if current UI culture is wanted. + /// + /// + public CapacityFormatter(CultureInfo culture) : base() { this.Supported = new List() @@ -77,6 +93,8 @@ public CapacityFormatter() typeof(Double), typeof(Decimal), }; + + this.Culture = culture; } #endregion @@ -96,6 +114,18 @@ public CapacityFormatter() /// public IEnumerable Supported { get; private set; } + /// + /// Gets the used culture. + /// + /// + /// This getter returns the used culture. Keep in mind, this culture might be + /// null. In such a case, current UI culture is used instead. + /// + /// + /// The used culture or null. + /// + public CultureInfo Culture { get; private set; } + #endregion #region Public methods @@ -153,13 +183,13 @@ public String Format(String format, Object value, IFormatProvider provider) { if (value is IFormattable) { - return (value as IFormattable).ToString(format, provider ?? CultureInfo.CurrentUICulture); + return (value as IFormattable).ToString(format, provider ?? this.GetCulture()); } return value.ToString(); } - return CapacityConverter.Convert(Convert.ToDecimal(value), this.GetUnit(format), this.GetDecimals(format)); + return CapacityConverter.Convert(Convert.ToDecimal(value), this.GetUnit(format), this.GetDecimals(format), this.GetCulture()); } #endregion @@ -224,6 +254,22 @@ private Int32 GetDecimals(String format) return 0; } + /// + /// Determines the used culture. + /// + /// + /// This method determines the culture to be used. Either this culture + /// is set by the constructor or it is the current UI culture. + /// + /// + /// The culture to be used. + /// + /// + private CultureInfo GetCulture() + { + return this.Culture ?? CultureInfo.CurrentUICulture; + } + #endregion } } diff --git a/code/src/Plexdata.CapacityConverter/Plexdata.CapacityConverter.csproj b/code/src/Plexdata.CapacityConverter/Plexdata.CapacityConverter.csproj index c230fa2..acfa3d7 100644 --- a/code/src/Plexdata.CapacityConverter/Plexdata.CapacityConverter.csproj +++ b/code/src/Plexdata.CapacityConverter/Plexdata.CapacityConverter.csproj @@ -13,6 +13,9 @@ This library provides classes as well as interfaces to be used to convert numbers into their capacity representation. convert format number capacity converter formatter parser Initial draft. + 1.0.0 + 1.0.0 + 1.0.0