diff --git a/specs/Qowaiv.Specs/Cast_specs.cs b/specs/Qowaiv.Specs/Cast_specs.cs index 07892450d..62369153f 100644 --- a/specs/Qowaiv.Specs/Cast_specs.cs +++ b/specs/Qowaiv.Specs/Cast_specs.cs @@ -1,41 +1,35 @@ -using NUnit.Framework; -using Qowaiv; -using Qowaiv.Financial; -using Qowaiv.TestTools; +namespace Cast_specs; -namespace Cast_specs +public class Invalid { - public class Invalid - { - [TestCase(double.MaxValue)] - [TestCase(double.MinValue)] - [TestCase(double.NaN)] - [TestCase(double.NegativeInfinity)] - [TestCase(double.PositiveInfinity)] - public void double_to_Percentage(double num) => QAssert.InvalidCast(() => (Percentage)num); + [TestCase(double.MaxValue)] + [TestCase(double.MinValue)] + [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] + public void double_to_Percentage(double num) => QAssert.InvalidCast(() => (Percentage)num); - [TestCase(double.MaxValue)] - [TestCase(double.MinValue)] - [TestCase(double.NaN)] - [TestCase(double.NegativeInfinity)] - [TestCase(double.PositiveInfinity)] - public void double_to_Amount(double num) => QAssert.InvalidCast(() => (Amount)num); + [TestCase(double.MaxValue)] + [TestCase(double.MinValue)] + [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] + public void double_to_Amount(double num) => QAssert.InvalidCast(() => (Amount)num); - [TestCase(int.MaxValue)] - [TestCase(1_000_000_000)] - public void int_to_HouseNumber(int num) => QAssert.InvalidCast(() => (HouseNumber)num); + [TestCase(int.MaxValue)] + [TestCase(1_000_000_000)] + public void int_to_HouseNumber(int num) => QAssert.InvalidCast(() => (HouseNumber)num); - [TestCase(int.MaxValue)] - [TestCase(1_000_000)] - [TestCase(-1)] - [TestCase(13)] - public void int_to_Month(int num) => QAssert.InvalidCast(() => (Month)num); + [TestCase(int.MaxValue)] + [TestCase(1_000_000)] + [TestCase(-1)] + [TestCase(13)] + public void int_to_Month(int num) => QAssert.InvalidCast(() => (Month)num); - [TestCase(int.MaxValue)] - [TestCase(1_000_000)] - [TestCase(-1)] - [TestCase(10_000)] - public void int_to_Year(int num) => QAssert.InvalidCast(() => (Year)num); - } + [TestCase(int.MaxValue)] + [TestCase(1_000_000)] + [TestCase(-1)] + [TestCase(10_000)] + public void int_to_Year(int num) => QAssert.InvalidCast(() => (Year)num); } diff --git a/specs/Qowaiv.Specs/Debug_specs.cs b/specs/Qowaiv.Specs/Debug_specs.cs index c5f2bfa13..f8a4c2bce 100644 --- a/specs/Qowaiv.Specs/Debug_specs.cs +++ b/specs/Qowaiv.Specs/Debug_specs.cs @@ -1,85 +1,74 @@ -using FluentAssertions; -using NUnit.Framework; -using Qowaiv.Formatting; -using Qowaiv.Globalization; -using Qowaiv.Json; -using Qowaiv.Text; -using System; -using System.Diagnostics; -using System.Globalization; +namespace Debug_specs; -namespace Debug_specs +public class Type_is { - public class Type_is - { - [TestCase(typeof(CultureInfoScope))] - [TestCase(typeof(FormattingArguments))] - [TestCase(typeof(PostalCodeCountryInfo))] - [TestCase(typeof(WildcardPattern))] - public void decorated_with_DebuggerDisplay_attribute(Type svoType) - => svoType.Should().BeDecoratedWith(); - } + [TestCase(typeof(CultureInfoScope))] + [TestCase(typeof(FormattingArguments))] + [TestCase(typeof(PostalCodeCountryInfo))] + [TestCase(typeof(WildcardPattern))] + public void decorated_with_DebuggerDisplay_attribute(Type svoType) + => svoType.Should().BeDecoratedWith(); +} - public class Debugger_displays +public class Debugger_displays +{ + [Test] + public void Open_API_data() { - [Test] - public void Open_API_data() - { - var attribute = new OpenApiDataTypeAttribute( - description: "Year", - example: "1983", - type: "integer", - format: "0000", - nullable: true, - pattern: "^[0-9]{4}$"); + var attribute = new OpenApiDataTypeAttribute( + description: "Year", + example: "1983", + type: "integer", + format: "0000", + nullable: true, + pattern: "^[0-9]{4}$"); - attribute.Should().HaveDebuggerDisplay("{ type: integer, desc: Year, example: 1983, format: 0000, pattern: ^[0-9]{4}$, nullable: true }"); - } + attribute.Should().HaveDebuggerDisplay("{ type: integer, desc: Year, example: 1983, format: 0000, pattern: ^[0-9]{4}$, nullable: true }"); + } - [Test] - public void empty_postal_code_country_data_for_empty_country() - => PostalCodeCountryInfo.GetInstance(Country.Empty) - .Should().HaveDebuggerDisplay("Postal code[], none"); + [Test] + public void empty_postal_code_country_data_for_empty_country() + => PostalCodeCountryInfo.GetInstance(Country.Empty) + .Should().HaveDebuggerDisplay("Postal code[], none"); - [Test] - public void postal_code_pattern_and_county_for_county_with_postal_codes() - => PostalCodeCountryInfo.GetInstance(Country.BE) - .Should().HaveDebuggerDisplay("Postal code[BE], Pattern: ^[1-9][0-9]{3}$"); + [Test] + public void postal_code_pattern_and_county_for_county_with_postal_codes() + => PostalCodeCountryInfo.GetInstance(Country.BE) + .Should().HaveDebuggerDisplay("Postal code[BE], Pattern: ^[1-9][0-9]{3}$"); - [Test] - public void postal_code_value_and_county_for_county_with_one_postal_code() - => PostalCodeCountryInfo.GetInstance(Country.VA) - .Should().HaveDebuggerDisplay("Postal code[VA], Value: 00120"); + [Test] + public void postal_code_value_and_county_for_county_with_one_postal_code() + => PostalCodeCountryInfo.GetInstance(Country.VA) + .Should().HaveDebuggerDisplay("Postal code[VA], Value: 00120"); - [Test] - public void current_and_previous_cultures_for_culture_info_scope() + [Test] + public void current_and_previous_cultures_for_culture_info_scope() + { + using (new CultureInfoScope("en-NL", "en-US")) { - using (new CultureInfoScope("en-NL", "en-US")) - { - using var scope = new CultureInfoScope("es-ES", "fr-FR"); - scope.Should().HaveDebuggerDisplay("CultureInfoScope: [es-ES/fr-FR], Previous: [en-NL/en-US]"); - } + using var scope = new CultureInfoScope("es-ES", "fr-FR"); + scope.Should().HaveDebuggerDisplay("CultureInfoScope: [es-ES/fr-FR], Previous: [en-NL/en-US]"); } - - [Test] - public void formatting_arguments_without_pattern_if_not_specified() - => ((object)new FormattingArgumentsCollection(new CultureInfo("en-GB"))) - .Should().HaveDebuggerDisplay("FormattingArgumentsCollection: 'en-GB', Items: 0"); + } + [Test] + public void formatting_arguments_without_pattern_if_not_specified() + => ((object)new FormattingArgumentsCollection(new CultureInfo("en-GB"))) + .Should().HaveDebuggerDisplay("FormattingArgumentsCollection: 'en-GB', Items: 0"); - [Test] - public void formatting_arguments_with_pattern_if_specified() - => new FormattingArguments("yyyy-MM-dd", new CultureInfo("en-GB")) - .Should().HaveDebuggerDisplay("Format: 'yyyy-MM-dd', Provider: en-GB"); - [Test] - public void wildcard_pattern() - => new WildcardPattern("t?st*") - .Should().HaveDebuggerDisplay("{t?st*}"); + [Test] + public void formatting_arguments_with_pattern_if_specified() + => new FormattingArguments("yyyy-MM-dd", new CultureInfo("en-GB")) + .Should().HaveDebuggerDisplay("Format: 'yyyy-MM-dd', Provider: en-GB"); - [Test] - public void wildcard_pattern_with_options_if_not_default() - => new WildcardPattern("t?st*", WildcardPatternOptions.SingleOrTrailing, StringComparison.Ordinal) - .Should().HaveDebuggerDisplay("{t?st*}, SingleOrTrailing, Ordinal"); - } + [Test] + public void wildcard_pattern() + => new WildcardPattern("t?st*") + .Should().HaveDebuggerDisplay("{t?st*}"); + + [Test] + public void wildcard_pattern_with_options_if_not_default() + => new WildcardPattern("t?st*", WildcardPatternOptions.SingleOrTrailing, StringComparison.Ordinal) + .Should().HaveDebuggerDisplay("{t?st*}, SingleOrTrailing, Ordinal"); } diff --git a/specs/Qowaiv.Specs/Extensions/Enumerable_specs.cs b/specs/Qowaiv.Specs/Extensions/Enumerable_specs.cs index 133d57554..668b7f5e1 100644 --- a/specs/Qowaiv.Specs/Extensions/Enumerable_specs.cs +++ b/specs/Qowaiv.Specs/Extensions/Enumerable_specs.cs @@ -1,17 +1,11 @@ -using FluentAssertions; -using NUnit.Framework; -using Qowaiv.Statistics; -using System.Linq; +namespace Extensions.Enumerable_specs; -namespace Extensions.Enumerable_specs +public class Average { - public class Average + [Test] + public void Elo() { - [Test] - public void Elo() - { - var elos = new Elo[] { 1400, 1600 }; - elos.Average().Should().Be(1500.Elo()); - } + var elos = new Elo[] { 1400, 1600 }; + elos.Average().Should().Be(1500.Elo()); } } diff --git a/specs/Qowaiv.Specs/MonthSpan_specs.cs b/specs/Qowaiv.Specs/MonthSpan_specs.cs index cacf04db5..a9b20414d 100644 --- a/specs/Qowaiv.Specs/MonthSpan_specs.cs +++ b/specs/Qowaiv.Specs/MonthSpan_specs.cs @@ -1,6 +1,4 @@ -using NUnit.Framework.Interfaces; - -namespace MonthSpan_specs; +namespace MonthSpan_specs; public class Is_equal_by_value { diff --git a/specs/Qowaiv.Specs/Reflection/QowaivType_specs.cs b/specs/Qowaiv.Specs/Reflection/QowaivType_specs.cs index 6027f1513..a7e2804ed 100644 --- a/specs/Qowaiv.Specs/Reflection/QowaivType_specs.cs +++ b/specs/Qowaiv.Specs/Reflection/QowaivType_specs.cs @@ -1,99 +1,94 @@ -using NUnit.Framework; -using Qowaiv; -using Qowaiv.Financial; -using Qowaiv.Reflection; -using System; +using Qowaiv.Reflection; using System.Numerics; -namespace Reflection.QowaivType_specs +namespace Reflection.QowaivType_specs; + +public class NullOrDefault { - public class NullOrDefault - { - [Test] - public void Is_true_for_null() - => Assert.That(QowaivType.IsNullOrDefaultValue(null), Is.True); + [Test] + public void Is_true_for_null() + => Assert.That(QowaivType.IsNullOrDefaultValue(null), Is.True); - [Test] - public void Is_true_for_default_primitive() - => Assert.That(QowaivType.IsNullOrDefaultValue(0), Is.True); + [Test] + public void Is_true_for_default_primitive() + => Assert.That(QowaivType.IsNullOrDefaultValue(0), Is.True); - [Test] - public void Is_false_for_object() - => Assert.That(QowaivType.IsNullOrDefaultValue(new object()), Is.False); + [Test] + public void Is_false_for_object() + => Assert.That(QowaivType.IsNullOrDefaultValue(new object()), Is.False); - [Test] - public void Is_false_for_non_default_primitive() - => Assert.That(QowaivType.IsNullOrDefaultValue(17), Is.False); - } + [Test] + public void Is_false_for_non_default_primitive() + => Assert.That(QowaivType.IsNullOrDefaultValue(17), Is.False); +} - public class IsNullable - { - [TestCase(typeof(string))] - [TestCase(typeof(int))] - public void False_for_not_nullable(Type type) - => Assert.That(QowaivType.IsNullable(type), Is.False); +public class IsNullable +{ + [TestCase(typeof(string))] + [TestCase(typeof(int))] + public void False_for_not_nullable(Type type) + => Assert.That(QowaivType.IsNullable(type), Is.False); - [Test] - public void True_for_nullable() - => Assert.That(QowaivType.IsNullable(typeof(int?)), Is.True); - } + [Test] + public void True_for_nullable() + => Assert.That(QowaivType.IsNullable(typeof(int?)), Is.True); +} - public class NotNullableType - { - [TestCase(typeof(string))] - [TestCase(typeof(int))] - public void Returns_type_for_non_nullable(Type type) - => Assert.That(QowaivType.GetNotNullableType(type), Is.EqualTo(type)); +public class NotNullableType +{ + [TestCase(typeof(string))] + [TestCase(typeof(int))] + public void Returns_type_for_non_nullable(Type type) + => Assert.That(QowaivType.GetNotNullableType(type), Is.EqualTo(type)); - [Test] - public void Returns_underlying_type_for_nullable() - => Assert.That(QowaivType.GetNotNullableType(typeof(int?)), Is.EqualTo(typeof(int))); - } + [Test] + public void Returns_underlying_type_for_nullable() + => Assert.That(QowaivType.GetNotNullableType(typeof(int?)), Is.EqualTo(typeof(int))); +} - public class IsNumeric - { - [TestCase(typeof(byte))] - [TestCase(typeof(sbyte))] - [TestCase(typeof(short))] - [TestCase(typeof(ushort))] - [TestCase(typeof(int))] - [TestCase(typeof(uint))] - [TestCase(typeof(long))] - [TestCase(typeof(ulong))] - [TestCase(typeof(float))] - [TestCase(typeof(double))] - [TestCase(typeof(decimal))] - public void Is_true_for_primitive_numerics(Type type) - => Assert.That(QowaivType.IsNumeric(type), Is.True); +public class IsNumeric +{ + [TestCase(typeof(byte))] + [TestCase(typeof(sbyte))] + [TestCase(typeof(short))] + [TestCase(typeof(ushort))] + [TestCase(typeof(int))] + [TestCase(typeof(uint))] + [TestCase(typeof(long))] + [TestCase(typeof(ulong))] + [TestCase(typeof(float))] + [TestCase(typeof(double))] + [TestCase(typeof(decimal))] + public void Is_true_for_primitive_numerics(Type type) + => Assert.That(QowaivType.IsNumeric(type), Is.True); - [TestCase(typeof(object))] - [TestCase(typeof(string))] - [TestCase(typeof(char))] - [TestCase(typeof(bool))] - [TestCase(typeof(Guid))] - [TestCase(typeof(Amount))] - [TestCase(typeof(BigInteger))] - public void Is_false_for_all_other_types(Type type) - => Assert.That(QowaivType.IsNumeric(type), Is.False); - } - public class IsDate - { - [TestCase(typeof(DateTime))] - [TestCase(typeof(DateTimeOffset))] - [TestCase(typeof(LocalDateTime))] - [TestCase(typeof(Date))] - [TestCase(typeof(WeekDate))] - public void Is_true_for_DateTime_and_Qowaiv_DateTypes(Type type) - => Assert.That(QowaivType.IsDate(type), Is.True); + [TestCase(typeof(object))] + [TestCase(typeof(string))] + [TestCase(typeof(char))] + [TestCase(typeof(bool))] + [TestCase(typeof(Guid))] + [TestCase(typeof(Amount))] + [TestCase(typeof(BigInteger))] + public void Is_false_for_all_other_types(Type type) + => Assert.That(QowaivType.IsNumeric(type), Is.False); +} +public class IsDate +{ + [TestCase(typeof(DateTime))] + [TestCase(typeof(DateTimeOffset))] + [TestCase(typeof(LocalDateTime))] + [TestCase(typeof(Date))] + [TestCase(typeof(WeekDate))] + public void Is_true_for_DateTime_and_Qowaiv_DateTypes(Type type) + => Assert.That(QowaivType.IsDate(type), Is.True); - [TestCase(typeof(object))] - [TestCase(typeof(string))] - [TestCase(typeof(char))] - [TestCase(typeof(bool))] - [TestCase(typeof(Guid))] - [TestCase(typeof(Amount))] - [TestCase(typeof(BigInteger))] - public void Is_false_for_all_other_types(Type type) - => Assert.That(QowaivType.IsDate(type), Is.False); - } + [TestCase(typeof(object))] + [TestCase(typeof(string))] + [TestCase(typeof(char))] + [TestCase(typeof(bool))] + [TestCase(typeof(Guid))] + [TestCase(typeof(Amount))] + [TestCase(typeof(BigInteger))] + public void Is_false_for_all_other_types(Type type) + => Assert.That(QowaivType.IsDate(type), Is.False); } diff --git a/specs/Qowaiv.Specs/TestTools/QAssert.cs b/specs/Qowaiv.Specs/TestTools/QAssert.cs index 47ae19798..7f78e6785 100644 --- a/specs/Qowaiv.Specs/TestTools/QAssert.cs +++ b/specs/Qowaiv.Specs/TestTools/QAssert.cs @@ -1,17 +1,12 @@ -using NUnit.Framework; -using System; -using System.Diagnostics; +namespace Qowaiv.TestTools; -namespace Qowaiv.TestTools +public static class QAssert { - public static class QAssert + /// A cast can not be applied unless you assign it, therefore a . + [DebuggerStepThrough] + public static void InvalidCast(Func cast) { - /// A cast can not be applied unless you assign it, therefore a . - [DebuggerStepThrough] - public static void InvalidCast(Func cast) - { - var x = Assert.Catch(() => cast()); - StringAssert.IsMatch($"Cast from .+ to {typeof(TSvo)} is not valid.", x.Message); - } + var x = Assert.Catch(() => cast()); + StringAssert.IsMatch($"Cast from .+ to {typeof(TSvo)} is not valid.", x.Message); } } diff --git a/specs/Qowaiv.Specs/Text/Base32_specs.cs b/specs/Qowaiv.Specs/Text/Base32_specs.cs index 8dfa9a972..d55f780c2 100644 --- a/specs/Qowaiv.Specs/Text/Base32_specs.cs +++ b/specs/Qowaiv.Specs/Text/Base32_specs.cs @@ -1,119 +1,111 @@ -using NUnit.Framework; -using Qowaiv.TestTools.Globalization; -using Qowaiv.Text; -using System; -using System.Globalization; -using System.Linq; +namespace Text.Base32_specs; -namespace Text.Base32_specs +public class ToString { - public class ToString + [Test] + public void Null_StringEmpty() { - [Test] - public void Null_StringEmpty() - { - Assert.AreEqual(string.Empty, Base32.ToString(null)); - } + Assert.AreEqual(string.Empty, Base32.ToString(null)); + } - [Test] - public void EmptyArray_StringEmpty() - { - Assert.AreEqual(string.Empty, Array.Empty()); - } + [Test] + public void EmptyArray_StringEmpty() + { + Assert.AreEqual(string.Empty, Array.Empty()); + } - [TestCase("BQ", 12)] - [TestCase("BQRA", 12, 34)] - [TestCase("QOWAI", 131, 172, 4)] - [TestCase("BQRDQTQ", 12, 34, 56, 78)] - [TestCase("BQRDQTS2", 12, 34, 56, 78, 90)] - [TestCase("BQRDQTS2N4", 12, 34, 56, 78, 90, 111)] - [TestCase("BQRDQTS2N55Q", 12, 34, 56, 78, 90, 111, 123)] - [TestCase("BQRDQTS2N55YM", 12, 34, 56, 78, 90, 111, 123, 134)] - [TestCase("BQRDQTS2N55YNEI", 12, 34, 56, 78, 90, 111, 123, 134, 145)] - [TestCase("BQRDQTS2N55YNEM4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156)] - [TestCase("BQRDQTS2N55YNEM4U4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167)] - [TestCase("BQRDQTS2N55YNEM4U6ZA", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167, 178)] - [TestCase("THEQUICKBROWNFOXJUMBSOVERTHELAZYDOG2345674", 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255)] - public void bytes(string expected, params int[] data) - { - var bytes = data.Select(v => (byte)v).ToArray(); + [TestCase("BQ", 12)] + [TestCase("BQRA", 12, 34)] + [TestCase("QOWAI", 131, 172, 4)] + [TestCase("BQRDQTQ", 12, 34, 56, 78)] + [TestCase("BQRDQTS2", 12, 34, 56, 78, 90)] + [TestCase("BQRDQTS2N4", 12, 34, 56, 78, 90, 111)] + [TestCase("BQRDQTS2N55Q", 12, 34, 56, 78, 90, 111, 123)] + [TestCase("BQRDQTS2N55YM", 12, 34, 56, 78, 90, 111, 123, 134)] + [TestCase("BQRDQTS2N55YNEI", 12, 34, 56, 78, 90, 111, 123, 134, 145)] + [TestCase("BQRDQTS2N55YNEM4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156)] + [TestCase("BQRDQTS2N55YNEM4U4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167)] + [TestCase("BQRDQTS2N55YNEM4U6ZA", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167, 178)] + [TestCase("THEQUICKBROWNFOXJUMBSOVERTHELAZYDOG2345674", 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255)] + public void bytes(string expected, params int[] data) + { + var bytes = data.Select(v => (byte)v).ToArray(); - var actualString = Base32.ToString(bytes); - Assert.AreEqual(expected, actualString); - } + var actualString = Base32.ToString(bytes); + Assert.AreEqual(expected, actualString); + } - [Test] - public void LowerCase() - { - var bytes = new byte[] { 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255 }; - var str = Base32.ToString(bytes, true); - Assert.AreEqual("thequickbrownfoxjumbsoverthelazydog2345674", str); - } + [Test] + public void LowerCase() + { + var bytes = new byte[] { 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255 }; + var str = Base32.ToString(bytes, true); + Assert.AreEqual("thequickbrownfoxjumbsoverthelazydog2345674", str); } +} - public class TryGetBytes_from +public class TryGetBytes_from +{ + [TestCase("BQ", 12)] + [TestCase("BQRA", 12, 34)] + [TestCase("QOWAI", 131, 172, 4)] + [TestCase("BQRDQTQ", 12, 34, 56, 78)] + [TestCase("BQRDQTS2", 12, 34, 56, 78, 90)] + [TestCase("BQRDQTS2N4", 12, 34, 56, 78, 90, 111)] + [TestCase("BQRDQTS2N55Q", 12, 34, 56, 78, 90, 111, 123)] + [TestCase("BQRDQTS2N55YM", 12, 34, 56, 78, 90, 111, 123, 134)] + [TestCase("BQRDQTS2N55YNEI", 12, 34, 56, 78, 90, 111, 123, 134, 145)] + [TestCase("BQRDQTS2N55YNEM4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156)] + [TestCase("BQRDQTS2N55YNEM4U4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167)] + [TestCase("BQRDQTS2N55YNEM4U6ZA", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167, 178)] + [TestCase("THEQUICKBROWNFOXJUMBSOVERTHELAZYDOG2345674", 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255)] + public void String_returns(string str, params int[] expected) { - [TestCase("BQ", 12)] - [TestCase("BQRA", 12, 34)] - [TestCase("QOWAI", 131, 172, 4)] - [TestCase("BQRDQTQ", 12, 34, 56, 78)] - [TestCase("BQRDQTS2", 12, 34, 56, 78, 90)] - [TestCase("BQRDQTS2N4", 12, 34, 56, 78, 90, 111)] - [TestCase("BQRDQTS2N55Q", 12, 34, 56, 78, 90, 111, 123)] - [TestCase("BQRDQTS2N55YM", 12, 34, 56, 78, 90, 111, 123, 134)] - [TestCase("BQRDQTS2N55YNEI", 12, 34, 56, 78, 90, 111, 123, 134, 145)] - [TestCase("BQRDQTS2N55YNEM4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156)] - [TestCase("BQRDQTS2N55YNEM4U4", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167)] - [TestCase("BQRDQTS2N55YNEM4U6ZA", 12, 34, 56, 78, 90, 111, 123, 134, 145, 156, 167, 178)] - [TestCase("THEQUICKBROWNFOXJUMBSOVERTHELAZYDOG2345674", 153, 201, 010, 032, 074, 012, 093, 102, 149, 215, 077, 024, 025, 058, 164, 140, 206, 069, 131, 056, 027, 141, 173, 243, 190, 255)] - public void String_returns(string str, params int[] expected) - { - var bytes = expected.Select(v => (byte)v).ToArray(); - Assert.IsTrue(Base32.TryGetBytes(str, out byte[] actualBytes)); - CollectionAssert.AreEqual(bytes, actualBytes); - } + var bytes = expected.Select(v => (byte)v).ToArray(); + Assert.IsTrue(Base32.TryGetBytes(str, out byte[] actualBytes)); + CollectionAssert.AreEqual(bytes, actualBytes); + } - [Test] - public void Not_support_chars_returns_false_with_EmptyArray() - { - Assert.IsFalse(Base32.TryGetBytes("ABC}", out byte[] bytes)); - Assert.AreEqual(Array.Empty(), bytes); - } + [Test] + public void Not_support_chars_returns_false_with_EmptyArray() + { + Assert.IsFalse(Base32.TryGetBytes("ABC}", out byte[] bytes)); + Assert.AreEqual(Array.Empty(), bytes); } - public class GetBytes +} +public class GetBytes +{ + [Test] + public void Null__returns_EmptyArray() { - [Test] - public void Null__returns_EmptyArray() - { - CollectionAssert.AreEqual(Array.Empty(), Base32.GetBytes(null)); - } + CollectionAssert.AreEqual(Array.Empty(), Base32.GetBytes(null)); + } - [Test] - public void StringEmpty_returns_EmptyArray() - { - CollectionAssert.AreEqual(Array.Empty(), Base32.GetBytes(string.Empty)); - } + [Test] + public void StringEmpty_returns_EmptyArray() + { + CollectionAssert.AreEqual(Array.Empty(), Base32.GetBytes(string.Empty)); + } - [Test] - public void LowerCase_equals_UpperCase() - { - var str = "thequickbrownfoxjumbsoverthelazydog2345674"; - var lowercase = Base32.GetBytes(str); - var uppercase = Base32.GetBytes(str.ToUpperInvariant()); - Assert.AreEqual(uppercase, lowercase); - } + [Test] + public void LowerCase_equals_UpperCase() + { + var str = "thequickbrownfoxjumbsoverthelazydog2345674"; + var lowercase = Base32.GetBytes(str); + var uppercase = Base32.GetBytes(str.ToUpperInvariant()); + Assert.AreEqual(uppercase, lowercase); + } - [Test] - public void Throws_on_invalid_input() + [Test] + public void Throws_on_invalid_input() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) + var act = Assert.Catch(() => { - var act = Assert.Catch(() => - { - Base32.GetBytes("Q0waiv"); - }); - Assert.AreEqual("Not a valid Base32 string", act.Message); - } + Base32.GetBytes("Q0waiv"); + }); + Assert.AreEqual("Not a valid Base32 string", act.Message); } } } diff --git a/specs/Qowaiv.Specs/Text/Base64_specs.cs b/specs/Qowaiv.Specs/Text/Base64_specs.cs index 148421bbd..1db90e618 100644 --- a/specs/Qowaiv.Specs/Text/Base64_specs.cs +++ b/specs/Qowaiv.Specs/Text/Base64_specs.cs @@ -1,67 +1,61 @@ -using NUnit.Framework; -using Qowaiv.Text; -using System; -using System.Linq; +namespace Text.Base64_specs; -namespace Text.Base64_specs +public class ToString { - public class ToString + [Test] + public void Null_StringEmpty() { - [Test] - public void Null_StringEmpty() - { - Assert.AreEqual(string.Empty, Base64.ToString(null)); - } + Assert.AreEqual(string.Empty, Base64.ToString(null)); + } - [Test] - public void EmptyArray_StringEmpty() - { - Assert.AreEqual(string.Empty, Array.Empty()); - } + [Test] + public void EmptyArray_StringEmpty() + { + Assert.AreEqual(string.Empty, Array.Empty()); + } - [TestCase("Aao=", 1, 170)] - [TestCase("Cxct", 11, 23, 45)] - [TestCase("Qowaig==", 66, 140, 26, 138)] - public void bytes(string expected, params int[] data) - { - var bytes = data.Select(v => (byte)v).ToArray(); + [TestCase("Aao=", 1, 170)] + [TestCase("Cxct", 11, 23, 45)] + [TestCase("Qowaig==", 66, 140, 26, 138)] + public void bytes(string expected, params int[] data) + { + var bytes = data.Select(v => (byte)v).ToArray(); - var actualString = Base64.ToString(bytes); - Assert.AreEqual(expected, actualString); - } + var actualString = Base64.ToString(bytes); + Assert.AreEqual(expected, actualString); } +} - public class TryGetBytes_from +public class TryGetBytes_from +{ + [Test] + public void Null__returns_EmptyArray() { - [Test] - public void Null__returns_EmptyArray() - { - Assert.IsTrue(Base64.TryGetBytes(null, out var bytes)); - CollectionAssert.AreEqual(Array.Empty(), bytes); - } + Assert.IsTrue(Base64.TryGetBytes(null, out var bytes)); + CollectionAssert.AreEqual(Array.Empty(), bytes); + } - [Test] - public void StringEmpty_returns_EmptyArray() - { - Assert.IsTrue(Base64.TryGetBytes(string.Empty, out var bytes)); - CollectionAssert.AreEqual(Array.Empty(), bytes); - } + [Test] + public void StringEmpty_returns_EmptyArray() + { + Assert.IsTrue(Base64.TryGetBytes(string.Empty, out var bytes)); + CollectionAssert.AreEqual(Array.Empty(), bytes); + } - [TestCase("Aap=", 1, 170)] - [TestCase("Cxct", 11, 23, 45)] - [TestCase("Qowaiv==", 66, 140, 26, 138)] - public void String_returns(string str, params int[] expected) - { - var bytes = expected.Select(v => (byte)v).ToArray(); - Assert.IsTrue(Base64.TryGetBytes(str, out byte[] actualBytes)); - CollectionAssert.AreEqual(bytes, actualBytes); - } + [TestCase("Aap=", 1, 170)] + [TestCase("Cxct", 11, 23, 45)] + [TestCase("Qowaiv==", 66, 140, 26, 138)] + public void String_returns(string str, params int[] expected) + { + var bytes = expected.Select(v => (byte)v).ToArray(); + Assert.IsTrue(Base64.TryGetBytes(str, out byte[] actualBytes)); + CollectionAssert.AreEqual(bytes, actualBytes); + } - [Test] - public void Not_support_chars_returns_false_with_EmptyArray() - { - Assert.IsFalse(Base64.TryGetBytes("ABC}", out byte[] bytes)); - Assert.AreEqual(Array.Empty(), bytes); - } + [Test] + public void Not_support_chars_returns_false_with_EmptyArray() + { + Assert.IsFalse(Base64.TryGetBytes("ABC}", out byte[] bytes)); + Assert.AreEqual(Array.Empty(), bytes); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/DecimalRoundTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/DecimalRoundTest.cs index e7bb6ec0d..72fc94b6a 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/DecimalRoundTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/DecimalRoundTest.cs @@ -1,164 +1,159 @@ -using NUnit.Framework; -using System.Globalization; -using System; +namespace Qowaiv.UnitTests; -namespace Qowaiv.UnitTests +public class DecimalRoundTest { - public class DecimalRoundTest + [Test] + public void Round_RemainderZero_NoChange() { - [Test] - public void Round_RemainderZero_NoChange() - { - // initializes a decimal with scale of 4, instead of 0. - var value = decimal.Parse("1000.0000", CultureInfo.InvariantCulture); - var rounded = value.Round(-2); - Assert.AreEqual(1000m, rounded); - } - - [Test] - public void Round_Positive_ShouldRoundToEven() - { - var rounded = 24.5m.Round(); - Assert.AreEqual(24m, rounded); - } - [Test] - public void Round_Negative_ShouldRoundToEven() - { - var rounded = -24.5m.Round(); - Assert.AreEqual(-24m, rounded); - } - - [Test] - public void Round_ALotOf3s_WithoutIssues() - { - var value = 9_876_543_210m + 1m / 3m; - var rounded = value.Round(-9); - var expected = 10_000_000_000m; + // initializes a decimal with scale of 4, instead of 0. + var value = decimal.Parse("1000.0000", CultureInfo.InvariantCulture); + var rounded = value.Round(-2); + Assert.AreEqual(1000m, rounded); + } - Assert.AreEqual(expected, rounded); - } + [Test] + public void Round_Positive_ShouldRoundToEven() + { + var rounded = 24.5m.Round(); + Assert.AreEqual(24m, rounded); + } + [Test] + public void Round_Negative_ShouldRoundToEven() + { + var rounded = -24.5m.Round(); + Assert.AreEqual(-24m, rounded); + } + [Test] + public void Round_ALotOf3s_WithoutIssues() + { + var value = 9_876_543_210m + 1m / 3m; + var rounded = value.Round(-9); + var expected = 10_000_000_000m; - [Test] - public void RoundToMultiple_PositiveWithMultipleOf_ShouldRoundToEven() - { - var rounded = 24.5m.RoundToMultiple(1m); - Assert.AreEqual(24m, rounded); - } - [Test] - public void RoundToMultiple_NegativeWithMultipleOf_ShouldRoundToEven() - { - var rounded = -26.5m.RoundToMultiple(1m); - Assert.AreEqual(-26m, rounded); - } + Assert.AreEqual(expected, rounded); + } - [TestCase(150.0, 125.0, 50, DecimalRounding.AwayFromZero)] - [TestCase(125.0, 123.0, 5, DecimalRounding.AwayFromZero)] - [TestCase(123.25, 123.3085, 0.25, DecimalRounding.AwayFromZero)] - [TestCase(666, 666, 3, DecimalRounding.AwayFromZero)] - public void Round_MultipleOf(decimal exp, decimal value, decimal factor, DecimalRounding mode) - { - var act = value.RoundToMultiple(factor, mode); - Assert.AreEqual(exp, act); - } + [Test] + public void RoundToMultiple_PositiveWithMultipleOf_ShouldRoundToEven() + { + var rounded = 24.5m.RoundToMultiple(1m); + Assert.AreEqual(24m, rounded); + } + [Test] + public void RoundToMultiple_NegativeWithMultipleOf_ShouldRoundToEven() + { + var rounded = -26.5m.RoundToMultiple(1m); + Assert.AreEqual(-26m, rounded); + } - /// Use strings as doubles lack precision. - [TestCase("123456789.1234567890", +10)] - [TestCase("123456789.123456789", +9)] - [TestCase("123456789.12345679", +8)] - [TestCase("123456789.1234568", +7)] - [TestCase("123456789.123457", +6)] - [TestCase("123456789.12346", +5)] - [TestCase("123456789.1235", +4)] - [TestCase("123456789.123", +3)] - [TestCase("123456789.12", +2)] - [TestCase("123456789.1", +1)] - [TestCase("123456789", +0)] - [TestCase("123456790", -1)] - [TestCase("123456800", -2)] - [TestCase("123457000", -3)] - [TestCase("123460000", -4)] - [TestCase("123500000", -5)] - [TestCase("123000000", -6)] - [TestCase("120000000", -7)] - [TestCase("100000000", -8)] - [TestCase(0, -9)] - public void Round_Digits(decimal exp, int digits) - { - var act = 123456789.123456789m.Round(digits, DecimalRounding.AwayFromZero); - Assert.AreEqual(exp, act); - } - // Halfway/nearest rounding - [TestCase(-26, -25.5, DecimalRounding.AwayFromZero)] - [TestCase(+26, +25.5, DecimalRounding.AwayFromZero)] - [TestCase(-25, -25.5, DecimalRounding.TowardsZero)] - [TestCase(+25, +25.5, DecimalRounding.TowardsZero)] - [TestCase(+26, +25.5, DecimalRounding.ToEven)] - [TestCase(+24, +24.5, DecimalRounding.ToEven)] - [TestCase(+25, +25.5, DecimalRounding.ToOdd)] - [TestCase(+25, +24.5, DecimalRounding.ToOdd)] - [TestCase(-25, -25.5, DecimalRounding.Up)] - [TestCase(+26, +25.5, DecimalRounding.Up)] - [TestCase(-26, -25.5, DecimalRounding.Down)] - [TestCase(+25, +25.5, DecimalRounding.Down)] - // Direct rounding - [TestCase(-26, -25.1, DecimalRounding.DirectAwayFromZero)] - [TestCase(+26, +25.1, DecimalRounding.DirectAwayFromZero)] - [TestCase(-25, -25.1, DecimalRounding.DirectTowardsZero)] - [TestCase(+25, +25.1, DecimalRounding.DirectTowardsZero)] - [TestCase(-25, -25.1, DecimalRounding.Ceiling)] - [TestCase(+26, +25.1, DecimalRounding.Ceiling)] - [TestCase(-26, -25.1, DecimalRounding.Floor)] - [TestCase(+25, +25.1, DecimalRounding.Floor)] - [TestCase(-25, -25.1, DecimalRounding.Truncate)] - [TestCase(+25, +25.1, DecimalRounding.Truncate)] - public void Round_NearestAndDirect(decimal exp, decimal value, DecimalRounding mode) - { - var act = value.Round(0, mode); - Assert.AreEqual(exp, act); - } + [TestCase(150.0, 125.0, 50, DecimalRounding.AwayFromZero)] + [TestCase(125.0, 123.0, 5, DecimalRounding.AwayFromZero)] + [TestCase(123.25, 123.3085, 0.25, DecimalRounding.AwayFromZero)] + [TestCase(666, 666, 3, DecimalRounding.AwayFromZero)] + public void Round_MultipleOf(decimal exp, decimal value, decimal factor, DecimalRounding mode) + { + var act = value.RoundToMultiple(factor, mode); + Assert.AreEqual(exp, act); + } - [Test] - public void Round_RandomTieBreaking() - { - var value = 17.5m; + /// Use strings as doubles lack precision. + [TestCase("123456789.1234567890", +10)] + [TestCase("123456789.123456789", +9)] + [TestCase("123456789.12345679", +8)] + [TestCase("123456789.1234568", +7)] + [TestCase("123456789.123457", +6)] + [TestCase("123456789.12346", +5)] + [TestCase("123456789.1235", +4)] + [TestCase("123456789.123", +3)] + [TestCase("123456789.12", +2)] + [TestCase("123456789.1", +1)] + [TestCase("123456789", +0)] + [TestCase("123456790", -1)] + [TestCase("123456800", -2)] + [TestCase("123457000", -3)] + [TestCase("123460000", -4)] + [TestCase("123500000", -5)] + [TestCase("123000000", -6)] + [TestCase("120000000", -7)] + [TestCase("100000000", -8)] + [TestCase(0, -9)] + public void Round_Digits(decimal exp, int digits) + { + var act = 123456789.123456789m.Round(digits, DecimalRounding.AwayFromZero); + Assert.AreEqual(exp, act); + } - var runs = 100_000; - var sum = 0m; + // Halfway/nearest rounding + [TestCase(-26, -25.5, DecimalRounding.AwayFromZero)] + [TestCase(+26, +25.5, DecimalRounding.AwayFromZero)] + [TestCase(-25, -25.5, DecimalRounding.TowardsZero)] + [TestCase(+25, +25.5, DecimalRounding.TowardsZero)] + [TestCase(+26, +25.5, DecimalRounding.ToEven)] + [TestCase(+24, +24.5, DecimalRounding.ToEven)] + [TestCase(+25, +25.5, DecimalRounding.ToOdd)] + [TestCase(+25, +24.5, DecimalRounding.ToOdd)] + [TestCase(-25, -25.5, DecimalRounding.Up)] + [TestCase(+26, +25.5, DecimalRounding.Up)] + [TestCase(-26, -25.5, DecimalRounding.Down)] + [TestCase(+25, +25.5, DecimalRounding.Down)] + // Direct rounding + [TestCase(-26, -25.1, DecimalRounding.DirectAwayFromZero)] + [TestCase(+26, +25.1, DecimalRounding.DirectAwayFromZero)] + [TestCase(-25, -25.1, DecimalRounding.DirectTowardsZero)] + [TestCase(+25, +25.1, DecimalRounding.DirectTowardsZero)] + [TestCase(-25, -25.1, DecimalRounding.Ceiling)] + [TestCase(+26, +25.1, DecimalRounding.Ceiling)] + [TestCase(-26, -25.1, DecimalRounding.Floor)] + [TestCase(+25, +25.1, DecimalRounding.Floor)] + [TestCase(-25, -25.1, DecimalRounding.Truncate)] + [TestCase(+25, +25.1, DecimalRounding.Truncate)] + public void Round_NearestAndDirect(decimal exp, decimal value, DecimalRounding mode) + { + var act = value.Round(0, mode); + Assert.AreEqual(exp, act); + } - for(var i = 0; i < runs; i++) - { - var rounded = value.Round(0, DecimalRounding.RandomTieBreaking); - Assert.IsTrue(rounded == 17 || rounded == 18); - sum += rounded; - } + [Test] + public void Round_RandomTieBreaking() + { + var value = 17.5m; - var avg = sum / runs; + var runs = 100_000; + var sum = 0m; - Assert.That(avg, Is.EqualTo(value).Within(0.05m)); + for(var i = 0; i < runs; i++) + { + var rounded = value.Round(0, DecimalRounding.RandomTieBreaking); + Assert.IsTrue(rounded == 17 || rounded == 18); + sum += rounded; } - [TestCase(17.1)] - [TestCase(17.3)] - [TestCase(17.6)] - [TestCase(17.8)] - public void Round_StochasticRounding(decimal value) - { - var runs = 10_000; - var sum = 0m; + var avg = sum / runs; - for (var i = 0; i < runs; i++) - { - var rounded = value.Round(0, DecimalRounding.StochasticRounding); - Assert.IsTrue(rounded == 17 || rounded == 18); - sum += rounded; - } + Assert.That(avg, Is.EqualTo(value).Within(0.05m)); + } - var avg = sum / runs; + [TestCase(17.1)] + [TestCase(17.3)] + [TestCase(17.6)] + [TestCase(17.8)] + public void Round_StochasticRounding(decimal value) + { + var runs = 10_000; + var sum = 0m; - Assert.That(avg, Is.EqualTo(value).Within(0.05m)); + for (var i = 0; i < runs; i++) + { + var rounded = value.Round(0, DecimalRounding.StochasticRounding); + Assert.IsTrue(rounded == 17 || rounded == 18); + sum += rounded; } + + var avg = sum / runs; + + Assert.That(avg, Is.EqualTo(value).Within(0.05m)); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Financial/AmountTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Financial/AmountTest.cs index 844e816e6..fd38e0192 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Financial/AmountTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Financial/AmountTest.cs @@ -1,860 +1,847 @@ -using FluentAssertions; -using NUnit.Framework; -using Qowaiv.Globalization; -using Qowaiv.TestTools; -using Qowaiv.TestTools.Globalization; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using System.Xml.Serialization; - -namespace Qowaiv.Financial.UnitTests +namespace Qowaiv.Financial.UnitTests; + +/// Tests the Amount SVO. +public class AmountTest { - /// Tests the Amount SVO. - public class AmountTest - { - /// The test instance for most tests. - public static readonly Amount TestStruct = (Amount)42.17m; + /// The test instance for most tests. + public static readonly Amount TestStruct = (Amount)42.17m; - public static NumberFormatInfo GetCustomNumberFormatInfo() + public static NumberFormatInfo GetCustomNumberFormatInfo() + { + var info = new NumberFormatInfo { - var info = new NumberFormatInfo - { - CurrencyGroupSeparator = "#", - CurrencyDecimalSeparator = "*", - }; - return info; - } + CurrencyGroupSeparator = "#", + CurrencyDecimalSeparator = "*", + }; + return info; + } - #region Amount const tests + #region Amount const tests - /// Amount.Zero should be equal to the default of Amount. - [Test] - public void Zero_None_EqualsDefault() - { - Assert.AreEqual(default(Amount), Amount.Zero); - } + /// Amount.Zero should be equal to the default of Amount. + [Test] + public void Zero_None_EqualsDefault() + { + Assert.AreEqual(default(Amount), Amount.Zero); + } - #endregion + #endregion - #region TryParse tests + #region TryParse tests - /// TryParse null should be valid. - [Test] - public void TryParse_Null_IsInvalid() - { - string str = null; - Assert.IsFalse(Amount.TryParse(str, out _)); - } + /// TryParse null should be valid. + [Test] + public void TryParse_Null_IsInvalid() + { + string str = null; + Assert.IsFalse(Amount.TryParse(str, out _)); + } - /// TryParse string.Empty should be valid. - [Test] - public void TryParse_StringEmpty_IsInvalid() - { - string str = string.Empty; - Assert.IsFalse(Amount.TryParse(str, out _)); - } + /// TryParse string.Empty should be valid. + [Test] + public void TryParse_StringEmpty_IsInvalid() + { + string str = string.Empty; + Assert.IsFalse(Amount.TryParse(str, out _)); + } - /// TryParse with specified string value should be valid. - [Test] - public void TryParse_StringValue_IsValid() + /// TryParse with specified string value should be valid. + [Test] + public void TryParse_StringValue_IsValid() + { + using (CultureInfoScope.NewInvariant()) { - using (CultureInfoScope.NewInvariant()) - { - string str = "14.1804"; - Assert.IsTrue(Amount.TryParse(str, out Amount val), "Valid"); - Assert.AreEqual(str, val.ToString(), "Value"); - } - } - - [Test] - public void Parse_InvalidInput_ThrowsFormatException() - { - using (TestCultures.En_GB.Scoped()) - { - Assert.Catch - (() => - { - Amount.Parse("InvalidInput"); - }, - "Not a valid amount"); - } + string str = "14.1804"; + Assert.IsTrue(Amount.TryParse(str, out Amount val), "Valid"); + Assert.AreEqual(str, val.ToString(), "Value"); } + } - [Test] - public void TryParse_TestStructInput_AreEqual() + [Test] + public void Parse_InvalidInput_ThrowsFormatException() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) + Assert.Catch + (() => { - var exp = TestStruct; - var act = Amount.TryParse(exp.ToString()); - - Assert.AreEqual(exp, act); - } + Amount.Parse("InvalidInput"); + }, + "Not a valid amount"); } + } - [Test] - public void from_invalid_as_null_with_TryParse() - => Amount.TryParse("invalid input").Should().BeNull(); - - [Test] - public void Parse_CustomFormatProvider_ValidParsing() + [Test] + public void TryParse_TestStructInput_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - Amount act = Amount.Parse("5#123*34", GetCustomNumberFormatInfo()); - Amount exp = (Amount)5123.34; + var exp = TestStruct; + var act = Amount.TryParse(exp.ToString()); Assert.AreEqual(exp, act); } + } - #endregion + [Test] + public void from_invalid_as_null_with_TryParse() + => Amount.TryParse("invalid input").Should().BeNull(); - #region (XML) (De)serialization tests + [Test] + public void Parse_CustomFormatProvider_ValidParsing() + { + Amount act = Amount.Parse("5#123*34", GetCustomNumberFormatInfo()); + Amount exp = (Amount)5123.34; - [Test] - public void GetObjectData_SerializationInfo_AreEqual() - { - ISerializable obj = TestStruct; - var info = new SerializationInfo(typeof(Amount), new FormatterConverter()); - obj.GetObjectData(info, default); + Assert.AreEqual(exp, act); + } - Assert.AreEqual(42.17m, info.GetDecimal("Value")); - } + #endregion - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp, act); - } - [Test] - public void DataContractSerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp, act); - } + #region (XML) (De)serialization tests - [Test] - public void XmlSerialize_TestStruct_AreEqual() - { - var act = Serialize.Xml(TestStruct); - var exp = "42.17"; - Assert.AreEqual(exp, act); - } + [Test] + public void GetObjectData_SerializationInfo_AreEqual() + { + ISerializable obj = TestStruct; + var info = new SerializationInfo(typeof(Amount), new FormatterConverter()); + obj.GetObjectData(info, default); - [Test] - public void XmlDeserialize_XmlString_AreEqual() - { - var act =Deserialize.Xml("42.17"); - Assert.AreEqual(TestStruct, act); - } + Assert.AreEqual(42.17m, info.GetDecimal("Value")); + } + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp, act); + } + [Test] + public void DataContractSerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp, act); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_AmountSerializeObject_AreEqual() - { - var input = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void XmlSerializeDeserialize_AmountSerializeObject_AreEqual() - { - var input = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void DataContractSerializeDeserialize_AmountSerializeObject_AreEqual() - { - var input = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new AmountSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void XmlSerialize_TestStruct_AreEqual() + { + var act = Serialize.Xml(TestStruct); + var exp = "42.17"; + Assert.AreEqual(exp, act); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_Default_AreEqual() - { - var input = new AmountSerializeObject - { - Id = 17, - Obj = default, - Date = new DateTime(1970, 02, 14), - }; - var exp = new AmountSerializeObject - { - Id = 17, - Obj = default, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void XmlSerializeDeserialize_Empty_AreEqual() - { - var input = new AmountSerializeObject - { - Id = 17, - Obj = Amount.Zero, - Date = new DateTime(1970, 02, 14), - }; - var exp = new AmountSerializeObject - { - Id = 17, - Obj = Amount.Zero, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void XmlDeserialize_XmlString_AreEqual() + { + var act =Deserialize.Xml("42.17"); + Assert.AreEqual(TestStruct, act); + } - [Test] - public void GetSchema_None_IsNull() - { - IXmlSerializable obj = TestStruct; - Assert.IsNull(obj.GetSchema()); - } - #endregion + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_AmountSerializeObject_AreEqual() + { + var input = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void XmlSerializeDeserialize_AmountSerializeObject_AreEqual() + { + var input = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void DataContractSerializeDeserialize_AmountSerializeObject_AreEqual() + { + var input = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new AmountSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - #region IFormattable / ToString tests + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_Default_AreEqual() + { + var input = new AmountSerializeObject + { + Id = 17, + Obj = default, + Date = new DateTime(1970, 02, 14), + }; + var exp = new AmountSerializeObject + { + Id = 17, + Obj = default, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void XmlSerializeDeserialize_Empty_AreEqual() + { + var input = new AmountSerializeObject + { + Id = 17, + Obj = Amount.Zero, + Date = new DateTime(1970, 02, 14), + }; + var exp = new AmountSerializeObject + { + Id = 17, + Obj = Amount.Zero, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void ToString_CustomFormatter_SupportsCustomFormatting() - { - var act = TestStruct.ToString("#.0", FormatProvider.CustomFormatter); - var exp = "Unit Test Formatter, value: '42.2', format: '#.0'"; + [Test] + public void GetSchema_None_IsNull() + { + IXmlSerializable obj = TestStruct; + Assert.IsNull(obj.GetSchema()); + } - Assert.AreEqual(exp, act); - } - [Test] - public void ToString_TestStruct_ComplexPattern() - { - var act = TestStruct.ToString(string.Empty, CultureInfo.InvariantCulture); - var exp = "42.17"; - Assert.AreEqual(exp, act); - } + #endregion - [Test] - public void ToString_ValueDutchBelgium_AreEqual() - { - using (TestCultures.Nl_BE.Scoped()) - { - var act = Amount.Parse("1600,1").ToString(); - var exp = "1600,1"; - Assert.AreEqual(exp, act); - } - } + #region IFormattable / ToString tests - [Test] - public void ToString_ValueEnglishGreatBritain_AreEqual() - { - using (TestCultures.En_GB.Scoped()) - { - var act = Amount.Parse("1600.1").ToString(); - var exp = "1600.1"; - Assert.AreEqual(exp, act); - } - } + [Test] + public void ToString_CustomFormatter_SupportsCustomFormatting() + { + var act = TestStruct.ToString("#.0", FormatProvider.CustomFormatter); + var exp = "Unit Test Formatter, value: '42.2', format: '#.0'"; - [Test] - public void ToString_FormatValueDutchBelgium_AreEqual() - { - using (TestCultures.Nl_BE.Scoped()) - { - var act = Amount.Parse("800").ToString("0000"); - var exp = "0800"; - Assert.AreEqual(exp, act); - } - } + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_TestStruct_ComplexPattern() + { + var act = TestStruct.ToString(string.Empty, CultureInfo.InvariantCulture); + var exp = "42.17"; + Assert.AreEqual(exp, act); + } - [Test] - public void ToString_FormatValueEnglishGreatBritain_AreEqual() + [Test] + public void ToString_ValueDutchBelgium_AreEqual() + { + using (TestCultures.Nl_BE.Scoped()) { - using (TestCultures.En_GB.Scoped()) - { - var act = Amount.Parse("800").ToString("0000"); - var exp = "0800"; - Assert.AreEqual(exp, act); - } + var act = Amount.Parse("1600,1").ToString(); + var exp = "1600,1"; + Assert.AreEqual(exp, act); } + } - [Test] - public void ToString_FormatValueSpanishEcuador_AreEqual() + [Test] + public void ToString_ValueEnglishGreatBritain_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - var act = Amount.Parse("1700").ToString("00000.0", new CultureInfo("es-EC")); - var exp = "01700,0"; + var act = Amount.Parse("1600.1").ToString(); + var exp = "1600.1"; Assert.AreEqual(exp, act); } + } - [Test] - public void ToString_FormatCurrencyFrFr_170Comma42Euro() + [Test] + public void ToString_FormatValueDutchBelgium_AreEqual() + { + using (TestCultures.Nl_BE.Scoped()) { - Amount amount = (Amount)170.42; - var act = amount.ToString("C", new CultureInfo("fr-FR")); - var exp = "170,42 €"; + var act = Amount.Parse("800").ToString("0000"); + var exp = "0800"; Assert.AreEqual(exp, act); } + } - - [Test] - public void ToString_CustomFormatProvider_Formatted() + [Test] + public void ToString_FormatValueEnglishGreatBritain_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - Amount amount = (Amount)12345678.235m; - var act = amount.ToString("#,##0.0000", GetCustomNumberFormatInfo()); - var exp = "12#345#678*2350"; + var act = Amount.Parse("800").ToString("0000"); + var exp = "0800"; Assert.AreEqual(exp, act); } - - #endregion + } - #region IEquatable tests + [Test] + public void ToString_FormatValueSpanishEcuador_AreEqual() + { + var act = Amount.Parse("1700").ToString("00000.0", new CultureInfo("es-EC")); + var exp = "01700,0"; + Assert.AreEqual(exp, act); + } - /// GetHash should not fail for Amount.Zero. - [Test] - public void GetHash_Zero_Hash() - { - Assert.AreEqual(0, Amount.Zero.GetHashCode()); - } + [Test] + public void ToString_FormatCurrencyFrFr_170Comma42Euro() + { + Amount amount = (Amount)170.42; + var act = amount.ToString("C", new CultureInfo("fr-FR")); + var exp = "170,42 €"; + Assert.AreEqual(exp, act); + } - /// GetHash should not fail for the test struct. - [Test] - public void GetHash_SameValue_SameHash() - { - var hash0 = ((Amount)451).GetHashCode(); - var hash1 = ((Amount)451).GetHashCode(); - Assert.AreEqual(hash1, hash0); - } - [Test] - public void Equals_EmptyEmpty_IsTrue() - { - Assert.IsTrue(Amount.Zero.Equals(Amount.Zero)); - } + [Test] + public void ToString_CustomFormatProvider_Formatted() + { + Amount amount = (Amount)12345678.235m; + var act = amount.ToString("#,##0.0000", GetCustomNumberFormatInfo()); + var exp = "12#345#678*2350"; + Assert.AreEqual(exp, act); + } + + #endregion - [Test] - public void Equals_FormattedAndUnformatted_IsTrue() - { - using (TestCultures.En_US.Scoped()) - { - var l = Amount.Parse("$ 1,451.070"); - var r = Amount.Parse("1451.07"); + #region IEquatable tests - Assert.IsTrue(l.Equals(r)); - } - } + /// GetHash should not fail for Amount.Zero. + [Test] + public void GetHash_Zero_Hash() + { + Assert.AreEqual(0, Amount.Zero.GetHashCode()); + } - [Test] - public void Equals_TestStructTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals(TestStruct)); - } + /// GetHash should not fail for the test struct. + [Test] + public void GetHash_SameValue_SameHash() + { + var hash0 = ((Amount)451).GetHashCode(); + var hash1 = ((Amount)451).GetHashCode(); + Assert.AreEqual(hash1, hash0); + } - [Test] - public void Equals_TestStructEmpty_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(Amount.Zero)); - } + [Test] + public void Equals_EmptyEmpty_IsTrue() + { + Assert.IsTrue(Amount.Zero.Equals(Amount.Zero)); + } - [Test] - public void Equals_EmptyTestStruct_IsFalse() + [Test] + public void Equals_FormattedAndUnformatted_IsTrue() + { + using (TestCultures.En_US.Scoped()) { - Assert.IsFalse(Amount.Zero.Equals(TestStruct)); - } + var l = Amount.Parse("$ 1,451.070"); + var r = Amount.Parse("1451.07"); - [Test] - public void Equals_TestStructObjectTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals((object)TestStruct)); + Assert.IsTrue(l.Equals(r)); } + } - [Test] - public void Equals_TestStructNull_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(null)); - } + [Test] + public void Equals_TestStructTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals(TestStruct)); + } - [Test] - public void Equals_TestStructObject_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(new object())); - } + [Test] + public void Equals_TestStructEmpty_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(Amount.Zero)); + } - [Test] - public void OperatorIs_TestStructTestStruct_IsTrue() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsTrue(l == r); - } + [Test] + public void Equals_EmptyTestStruct_IsFalse() + { + Assert.IsFalse(Amount.Zero.Equals(TestStruct)); + } - [Test] - public void OperatorIsNot_TestStructTestStruct_IsFalse() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsFalse(l != r); - } + [Test] + public void Equals_TestStructObjectTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals((object)TestStruct)); + } - #endregion + [Test] + public void Equals_TestStructNull_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(null)); + } - #region IComparable tests + [Test] + public void Equals_TestStructObject_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(new object())); + } - /// Orders a list of Amounts ascending. - [Test] - public void OrderBy_Amount_AreEqual() - { - Amount item0 = (Amount)0.23; - Amount item1 = (Amount)1.24; - Amount item2 = (Amount)2.27; - Amount item3 = (Amount)1300; + [Test] + public void OperatorIs_TestStructTestStruct_IsTrue() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsTrue(l == r); + } - var inp = new List { Amount.Zero, item3, item2, item0, item1, Amount.Zero }; - var exp = new List { Amount.Zero, Amount.Zero, item0, item1, item2, item3 }; - var act = inp.OrderBy(item => item).ToList(); + [Test] + public void OperatorIsNot_TestStructTestStruct_IsFalse() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsFalse(l != r); + } - CollectionAssert.AreEqual(exp, act); - } + #endregion - /// Orders a list of Amounts descending. - [Test] - public void OrderByDescending_Amount_AreEqual() - { - Amount item0 = (Amount)0.23; - Amount item1 = (Amount)1.24; - Amount item2 = (Amount)2.27; - Amount item3 = (Amount)1300; + #region IComparable tests - var inp = new List { Amount.Zero, item3, item2, item0, item1, Amount.Zero }; - var exp = new List { item3, item2, item1, item0, Amount.Zero, Amount.Zero }; - var act = inp.OrderByDescending(item => item).ToList(); + /// Orders a list of Amounts ascending. + [Test] + public void OrderBy_Amount_AreEqual() + { + Amount item0 = (Amount)0.23; + Amount item1 = (Amount)1.24; + Amount item2 = (Amount)2.27; + Amount item3 = (Amount)1300; - CollectionAssert.AreEqual(exp, act); - } + var inp = new List { Amount.Zero, item3, item2, item0, item1, Amount.Zero }; + var exp = new List { Amount.Zero, Amount.Zero, item0, item1, item2, item3 }; + var act = inp.OrderBy(item => item).ToList(); - /// Compare with a to object casted instance should be fine. - [Test] - public void CompareTo_ObjectTestStruct_0() - { - object other = TestStruct; + CollectionAssert.AreEqual(exp, act); + } - var exp = 0; - var act = TestStruct.CompareTo(other); + /// Orders a list of Amounts descending. + [Test] + public void OrderByDescending_Amount_AreEqual() + { + Amount item0 = (Amount)0.23; + Amount item1 = (Amount)1.24; + Amount item2 = (Amount)2.27; + Amount item3 = (Amount)1300; - Assert.AreEqual(exp, act); - } + var inp = new List { Amount.Zero, item3, item2, item0, item1, Amount.Zero }; + var exp = new List { item3, item2, item1, item0, Amount.Zero, Amount.Zero }; + var act = inp.OrderByDescending(item => item).ToList(); - /// Compare with null should return 1. - [Test] - public void CompareTo_null_1() - { - object @null = null; - Assert.AreEqual(1, TestStruct.CompareTo(@null)); - } + CollectionAssert.AreEqual(exp, act); + } - /// Compare with a random object should throw an exception. - [Test] - public void CompareTo_newObject_ThrowsArgumentException() - { - Func compare = () => TestStruct.CompareTo(new object()); - compare.Should().Throw(); - } + /// Compare with a to object casted instance should be fine. + [Test] + public void CompareTo_ObjectTestStruct_0() + { + object other = TestStruct; - [Test] - public void LessThan_17LT19_IsTrue() - { - Amount l = (Amount)17; - Amount r = (Amount)19; + var exp = 0; + var act = TestStruct.CompareTo(other); - Assert.IsTrue(l < r); - } - [Test] - public void GreaterThan_21LT19_IsTrue() - { - Amount l = (Amount)21; - Amount r = (Amount)19; + Assert.AreEqual(exp, act); + } - Assert.IsTrue(l > r); - } + /// Compare with null should return 1. + [Test] + public void CompareTo_null_1() + { + object @null = null; + Assert.AreEqual(1, TestStruct.CompareTo(@null)); + } - [Test] - public void LessThanOrEqual_17LT19_IsTrue() - { - Amount l = (Amount)17; - Amount r = (Amount)19; + /// Compare with a random object should throw an exception. + [Test] + public void CompareTo_newObject_ThrowsArgumentException() + { + Func compare = () => TestStruct.CompareTo(new object()); + compare.Should().Throw(); + } - Assert.IsTrue(l <= r); - } - [Test] - public void GreaterThanOrEqual_21LT19_IsTrue() - { - Amount l = (Amount)21; - Amount r = (Amount)19; + [Test] + public void LessThan_17LT19_IsTrue() + { + Amount l = (Amount)17; + Amount r = (Amount)19; - Assert.IsTrue(l >= r); - } + Assert.IsTrue(l < r); + } + [Test] + public void GreaterThan_21LT19_IsTrue() + { + Amount l = (Amount)21; + Amount r = (Amount)19; - [Test] - public void LessThanOrEqual_17LT17_IsTrue() - { - Amount l = (Amount)17; - Amount r = (Amount)17; + Assert.IsTrue(l > r); + } - Assert.IsTrue(l <= r); - } - [Test] - public void GreaterThanOrEqual_21LT21_IsTrue() - { - Amount l = (Amount)21; - Amount r = (Amount)21; + [Test] + public void LessThanOrEqual_17LT19_IsTrue() + { + Amount l = (Amount)17; + Amount r = (Amount)19; - Assert.IsTrue(l >= r); - } - #endregion + Assert.IsTrue(l <= r); + } + [Test] + public void GreaterThanOrEqual_21LT19_IsTrue() + { + Amount l = (Amount)21; + Amount r = (Amount)19; - [TestCase(-1, -1000)] - [TestCase(0, 0)] - [TestCase(+1, 1600)] - public void Sign(int expected, Amount value) - { - var actual = value.Sign(); - Assert.AreEqual(expected, actual); - } + Assert.IsTrue(l >= r); + } - [TestCase(1234.01, -1234.01)] - [TestCase(1234.01, +1234.01)] - public void Abs(Amount expected, Amount value) - { - var abs = value.Abs(); - Assert.AreEqual(expected, abs); - } + [Test] + public void LessThanOrEqual_17LT17_IsTrue() + { + Amount l = (Amount)17; + Amount r = (Amount)17; - [TestCase(-1234.01)] - [TestCase(+1234.01)] - public void Plus(Amount expected) - { - var plus = +expected; - Assert.AreEqual(expected, plus); - } + Assert.IsTrue(l <= r); + } + [Test] + public void GreaterThanOrEqual_21LT21_IsTrue() + { + Amount l = (Amount)21; + Amount r = (Amount)21; - [TestCase(+1234.01, -1234.01)] - [TestCase(-1234.01, +1234.01)] - public void Negate(Amount expected, Amount value) - { - var negated = -value; - Assert.AreEqual(expected, negated); - } + Assert.IsTrue(l >= r); + } + #endregion - [Test] - public void Decrement_EqualsTestStruct() - { - Amount amount = (Amount)43.17; - amount--; - Assert.AreEqual(TestStruct, amount); - } + [TestCase(-1, -1000)] + [TestCase(0, 0)] + [TestCase(+1, 1600)] + public void Sign(int expected, Amount value) + { + var actual = value.Sign(); + Assert.AreEqual(expected, actual); + } - [Test] - public void Increment_EqualsTestStruct() - { - Amount amount = (Amount)41.17; - amount++; - Assert.AreEqual(TestStruct, amount); - } + [TestCase(1234.01, -1234.01)] + [TestCase(1234.01, +1234.01)] + public void Abs(Amount expected, Amount value) + { + var abs = value.Abs(); + Assert.AreEqual(expected, abs); + } - [Test] - public void Add_SomeAmount_Added() - { - Amount amount = (Amount)40.10; - Amount other = (Amount)2.07; - Assert.AreEqual(TestStruct, amount + other); - } + [TestCase(-1234.01)] + [TestCase(+1234.01)] + public void Plus(Amount expected) + { + var plus = +expected; + Assert.AreEqual(expected, plus); + } - [Test] - public void Add_SomePercentage_Added() - { - Amount amount = (Amount)40.00; - var p = 10.Percent(); - Assert.AreEqual((Amount)44.00, amount + p); - } + [TestCase(+1234.01, -1234.01)] + [TestCase(-1234.01, +1234.01)] + public void Negate(Amount expected, Amount value) + { + var negated = -value; + Assert.AreEqual(expected, negated); + } - [Test] - public void Subtract_SomeAmount_Subtracted() - { - Amount amount = (Amount)43.20; - Amount other = (Amount)1.03; - Assert.AreEqual(TestStruct, amount - other); - } + [Test] + public void Decrement_EqualsTestStruct() + { + Amount amount = (Amount)43.17; + amount--; + Assert.AreEqual(TestStruct, amount); + } - [Test] - public void Subtract_SomePercentage_Subtracted() - { - Amount amount = (Amount)40.00; - var p = 25.Percent(); - Assert.AreEqual((Amount)30.00, amount - p); - } + [Test] + public void Increment_EqualsTestStruct() + { + Amount amount = (Amount)41.17; + amount++; + Assert.AreEqual(TestStruct, amount); + } - [Test] - public void Multiply_Percentage() - { - Amount amount = (Amount)100.40m; - var p = 50.Percent(); - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount * p); - } + [Test] + public void Add_SomeAmount_Added() + { + Amount amount = (Amount)40.10; + Amount other = (Amount)2.07; + Assert.AreEqual(TestStruct, amount + other); + } - [Test] - public void Multiply_Float() - { - Amount amount = (Amount)100.40m; - float p = 0.5F; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount * p); - } + [Test] + public void Add_SomePercentage_Added() + { + Amount amount = (Amount)40.00; + var p = 10.Percent(); + Assert.AreEqual((Amount)44.00, amount + p); + } - [Test] - public void Multiply_Double() - { - Amount amount = (Amount)100.40m; - double p = 0.5; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount * p); - } + [Test] + public void Subtract_SomeAmount_Subtracted() + { + Amount amount = (Amount)43.20; + Amount other = (Amount)1.03; + Assert.AreEqual(TestStruct, amount - other); + } - [Test] - public void Multiply_Decimal() - { - Amount amount = (Amount)100.40m; - var p = 0.5m; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount * p); - } + [Test] + public void Subtract_SomePercentage_Subtracted() + { + Amount amount = (Amount)40.00; + var p = 25.Percent(); + Assert.AreEqual((Amount)30.00, amount - p); + } - [Test] - public void Multiply_Short() - { - Amount amount = (Amount)100.40m; - short f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Percentage() + { + Amount amount = (Amount)100.40m; + var p = 50.Percent(); + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount * p); + } - [Test] - public void Multiply_Int() - { - Amount amount = (Amount)100.40m; - int f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Float() + { + Amount amount = (Amount)100.40m; + float p = 0.5F; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount * p); + } - [Test] - public void Multiply_Long() - { - Amount amount = (Amount)100.40m; - long f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Double() + { + Amount amount = (Amount)100.40m; + double p = 0.5; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount * p); + } - [Test] - public void Multiply_UShort() - { - Amount amount = (Amount)100.40m; - ushort f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Decimal() + { + Amount amount = (Amount)100.40m; + var p = 0.5m; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount * p); + } - [Test] - public void Multiply_UInt() - { - Amount amount = (Amount)100.40m; - uint f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Short() + { + Amount amount = (Amount)100.40m; + short f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Multiply_ULong() - { - Amount amount = (Amount)100.40m; - ulong f = 2; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount * f); - } + [Test] + public void Multiply_Int() + { + Amount amount = (Amount)100.40m; + int f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Divide_Percentage() - { - Amount amount = (Amount)100.40m; - var p = 50.Percent(); - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount / p); - } + [Test] + public void Multiply_Long() + { + Amount amount = (Amount)100.40m; + long f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Divide_Float() - { - Amount amount = (Amount)100.40m; - float p = 0.5F; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount / p); - } + [Test] + public void Multiply_UShort() + { + Amount amount = (Amount)100.40m; + ushort f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Divide_Double() - { - Amount amount = (Amount)100.40m; - double p = 0.5; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount / p); - } + [Test] + public void Multiply_UInt() + { + Amount amount = (Amount)100.40m; + uint f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Divide_Decimal() - { - Amount amount = (Amount)100.40m; - var p = 0.5m; - Amount expected = (Amount)200.80m; - Assert.AreEqual(expected, amount / p); - } + [Test] + public void Multiply_ULong() + { + Amount amount = (Amount)100.40m; + ulong f = 2; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount * f); + } - [Test] - public void Divide_Short() - { - Amount amount = (Amount)100.40m; - short f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Percentage() + { + Amount amount = (Amount)100.40m; + var p = 50.Percent(); + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount / p); + } - [Test] - public void Divide_Int() - { - Amount amount = (Amount)100.40m; - int f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Float() + { + Amount amount = (Amount)100.40m; + float p = 0.5F; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount / p); + } - [Test] - public void Divide_Long() - { - Amount amount = (Amount)100.40m; - long f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Double() + { + Amount amount = (Amount)100.40m; + double p = 0.5; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount / p); + } - [Test] - public void Divide_UShort() - { - Amount amount = (Amount)100.40m; - ushort f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Decimal() + { + Amount amount = (Amount)100.40m; + var p = 0.5m; + Amount expected = (Amount)200.80m; + Assert.AreEqual(expected, amount / p); + } - [Test] - public void Divide_UInt() - { - Amount amount = (Amount)100.40m; - uint f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Short() + { + Amount amount = (Amount)100.40m; + short f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } - [Test] - public void Divide_ULong() - { - Amount amount = (Amount)100.40m; - ulong f = 2; - Amount expected = (Amount)50.20m; - Assert.AreEqual(expected, amount / f); - } + [Test] + public void Divide_Int() + { + Amount amount = (Amount)100.40m; + int f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } - [Test] - public void Round_NoDigits() - { - var amount = (Amount)123.4567m; - var rounded = amount.Round(); - Assert.AreEqual((Amount)123m, rounded); - } + [Test] + public void Divide_Long() + { + Amount amount = (Amount)100.40m; + long f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } - [Test] - public void Round_1Digit() - { - var amount = (Amount)123.4567m; - var rounded = amount.Round(1); - Assert.AreEqual((Amount)123.5m , rounded); - } + [Test] + public void Divide_UShort() + { + Amount amount = (Amount)100.40m; + ushort f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } - [Test] - public void RoundToMultiple_0d25() - { - var amount = (Amount)123.6567m; - var rounded = amount.RoundToMultiple(0.25m); - Assert.AreEqual((Amount)123.75m, rounded); - } + [Test] + public void Divide_UInt() + { + Amount amount = (Amount)100.40m; + uint f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } + + [Test] + public void Divide_ULong() + { + Amount amount = (Amount)100.40m; + ulong f = 2; + Amount expected = (Amount)50.20m; + Assert.AreEqual(expected, amount / f); + } + + [Test] + public void Round_NoDigits() + { + var amount = (Amount)123.4567m; + var rounded = amount.Round(); + Assert.AreEqual((Amount)123m, rounded); } - [Serializable] - public class AmountSerializeObject + [Test] + public void Round_1Digit() { - public int Id { get; set; } - public Amount Obj { get; set; } - public DateTime Date { get; set; } + var amount = (Amount)123.4567m; + var rounded = amount.Round(1); + Assert.AreEqual((Amount)123.5m , rounded); } + + [Test] + public void RoundToMultiple_0d25() + { + var amount = (Amount)123.6567m; + var rounded = amount.RoundToMultiple(0.25m); + Assert.AreEqual((Amount)123.75m, rounded); + } +} + +[Serializable] +public class AmountSerializeObject +{ + public int Id { get; set; } + public Amount Obj { get; set; } + public DateTime Date { get; set; } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Formatting/FormattingArgumentsTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Formatting/FormattingArgumentsTest.cs index 4edeb06e6..8ea743d79 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Formatting/FormattingArgumentsTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Formatting/FormattingArgumentsTest.cs @@ -1,235 +1,225 @@ -using NUnit.Framework; -using Qowaiv.Formatting; -using Qowaiv.Globalization; -using Qowaiv.TestTools; -using Qowaiv.TestTools.Globalization; -using System; -using System.Globalization; -using System.Runtime.Serialization; - -namespace Qowaiv.UnitTests.Formatting +namespace Qowaiv.UnitTests.Formatting; + +/// Tests the formatting arguments SVO. +public class FormattingArgumentsTest { - /// Tests the formatting arguments SVO. - public class FormattingArgumentsTest + /// The test instance for most tests. + public static readonly FormattingArguments TestStruct = new("0.000", new CultureInfo("fr-BE")); + + [Test] + public void ToString_IFormattableNull_IsNull() { - /// The test instance for most tests. - public static readonly FormattingArguments TestStruct = new("0.000", new CultureInfo("fr-BE")); + IFormattable formatter = null; + string act = TestStruct.ToString(formatter); + string exp = null; - [Test] - public void ToString_IFormattableNull_IsNull() - { - IFormattable formatter = null; - string act = TestStruct.ToString(formatter); - string exp = null; + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_ObjectNull_IsNull() + { + string act = TestStruct.ToString((object)null); + string exp = null; - Assert.AreEqual(exp, act); - } - [Test] - public void ToString_ObjectNull_IsNull() - { - string act = TestStruct.ToString((object)null); - string exp = null; + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_TypeInt32_SystemInt32() + { + string act = TestStruct.ToString((object)typeof(int)); + string exp = "System.Int32"; - Assert.AreEqual(exp, act); - } - [Test] - public void ToString_TypeInt32_SystemInt32() - { - string act = TestStruct.ToString((object)typeof(int)); - string exp = "System.Int32"; + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_7_7Comma000() + { + string act = TestStruct.ToString((object)7); + string exp = "7,000"; - Assert.AreEqual(exp, act); - } - [Test] - public void ToString_7_7Comma000() + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_7_7Dot000() + { + using (TestCultures.En_GB.Scoped()) { - string act = TestStruct.ToString((object)7); - string exp = "7,000"; + string act = new FormattingArguments("0.000").ToString((object)7); + string exp = "7.000"; Assert.AreEqual(exp, act); } - [Test] - public void ToString_7_7Dot000() - { - using (TestCultures.En_GB.Scoped()) - { - string act = new FormattingArguments("0.000").ToString((object)7); - string exp = "7.000"; - - Assert.AreEqual(exp, act); - } - } + } - #region formatting arguments const tests + #region formatting arguments const tests - /// FormattableArguments.None should be equal to the default of formatting arguments. - [Test] - public void None_None_EqualsDefault() - { - Assert.AreEqual(default(FormattingArguments), FormattingArguments.None); - } + /// FormattableArguments.None should be equal to the default of formatting arguments. + [Test] + public void None_None_EqualsDefault() + { + Assert.AreEqual(default(FormattingArguments), FormattingArguments.None); + } - #endregion + #endregion - #region (De)serialization tests + #region (De)serialization tests - [Test] - public void GetObjectData_SerializationInfo_AreEqual() - { - ISerializable obj = TestStruct; - var info = new SerializationInfo(typeof(FormattingArguments), new System.Runtime.Serialization.FormatterConverter()); - obj.GetObjectData(info, default); + [Test] + public void GetObjectData_SerializationInfo_AreEqual() + { + ISerializable obj = TestStruct; + var info = new SerializationInfo(typeof(FormattingArguments), new System.Runtime.Serialization.FormatterConverter()); + obj.GetObjectData(info, default); - Assert.AreEqual("0.000", info.GetString("Format")); - Assert.AreEqual(new CultureInfo("fr-BE"), info.GetValue("FormatProvider", typeof(IFormatProvider))); - } + Assert.AreEqual("0.000", info.GetString("Format")); + Assert.AreEqual(new CultureInfo("fr-BE"), info.GetValue("FormatProvider", typeof(IFormatProvider))); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_Default_AreEqual() - { - var input = new FormattableArgumentsSerializeObject - { - Id = 17, - Obj = default, - Date = new DateTime(1970, 02, 14), - }; - var exp = new FormattableArgumentsSerializeObject - { - Id = 17, - Obj = default, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void XmlSerializeDeserialize_Empty_AreEqual() - { - var input = new FormattableArgumentsSerializeObject - { - Id = 17, - Obj = FormattingArguments.None, - Date = new DateTime(1970, 02, 14), - }; - var exp = new FormattableArgumentsSerializeObject - { - Id = 17, - Obj = FormattingArguments.None, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_Default_AreEqual() + { + var input = new FormattableArgumentsSerializeObject + { + Id = 17, + Obj = default, + Date = new DateTime(1970, 02, 14), + }; + var exp = new FormattableArgumentsSerializeObject + { + Id = 17, + Obj = default, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void XmlSerializeDeserialize_Empty_AreEqual() + { + var input = new FormattableArgumentsSerializeObject + { + Id = 17, + Obj = FormattingArguments.None, + Date = new DateTime(1970, 02, 14), + }; + var exp = new FormattableArgumentsSerializeObject + { + Id = 17, + Obj = FormattingArguments.None, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + - #endregion + #endregion - #region IEquatable tests + #region IEquatable tests - /// GetHash should not fail for FormattableArguments.Empty. - [Test] - public void GetHash_Empty_0() - { - Assert.AreEqual(0, FormattingArguments.None.GetHashCode()); - } + /// GetHash should not fail for FormattableArguments.Empty. + [Test] + public void GetHash_Empty_0() + { + Assert.AreEqual(0, FormattingArguments.None.GetHashCode()); + } - /// GetHash should not fail for the test struct. - [Test] - public void GetHash_TestStruct_NotZero() - { - Assert.NotZero(TestStruct.GetHashCode()); - } + /// GetHash should not fail for the test struct. + [Test] + public void GetHash_TestStruct_NotZero() + { + Assert.NotZero(TestStruct.GetHashCode()); + } - [Test] - public void Equals_EmptyEmpty_IsTrue() - { - Assert.IsTrue(FormattingArguments.None.Equals(default)); - } + [Test] + public void Equals_EmptyEmpty_IsTrue() + { + Assert.IsTrue(FormattingArguments.None.Equals(default)); + } - [Test] - public void Equals_TestStructTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals(new FormattingArguments("0.000", new CultureInfo("fr-BE")))); - } + [Test] + public void Equals_TestStructTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals(new FormattingArguments("0.000", new CultureInfo("fr-BE")))); + } - [Test] - public void Equals_TestStructEmpty_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(FormattingArguments.None)); - } + [Test] + public void Equals_TestStructEmpty_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(FormattingArguments.None)); + } - [Test] - public void Equals_EmptyTestStruct_IsFalse() - { - Assert.IsFalse(FormattingArguments.None.Equals(TestStruct)); - } + [Test] + public void Equals_EmptyTestStruct_IsFalse() + { + Assert.IsFalse(FormattingArguments.None.Equals(TestStruct)); + } - [Test] - public void Equals_TestStructObjectTestStruct_IsTrue() - { - object obj = TestStruct; - Assert.IsTrue(TestStruct.Equals(obj)); - } + [Test] + public void Equals_TestStructObjectTestStruct_IsTrue() + { + object obj = TestStruct; + Assert.IsTrue(TestStruct.Equals(obj)); + } - [Test] - public void Equals_TestStructNull_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(null)); - } + [Test] + public void Equals_TestStructNull_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(null)); + } - [Test] - public void Equals_TestStructObject_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(new object())); - } + [Test] + public void Equals_TestStructObject_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(new object())); + } - [Test] - public void OperatorIs_TestStructTestStruct_IsTrue() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsTrue(l == r); - } + [Test] + public void OperatorIs_TestStructTestStruct_IsTrue() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsTrue(l == r); + } - [Test] - public void OperatorIsNot_TestStructTestStruct_IsFalse() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsFalse(l != r); - } + [Test] + public void OperatorIsNot_TestStructTestStruct_IsFalse() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsFalse(l != r); + } - #endregion + #endregion - #region Properties + #region Properties - [Test] - public void Format_DefaultValue_StringNull() - { - var exp = Nil.String; - var act = FormattingArguments.None.Format; - Assert.AreEqual(exp, act); - } - [Test] - public void Format_TestStruct_FormatString() - { - var exp = "0.000"; - var act = TestStruct.Format; - Assert.AreEqual(exp, act); - } - #endregion + [Test] + public void Format_DefaultValue_StringNull() + { + var exp = Nil.String; + var act = FormattingArguments.None.Format; + Assert.AreEqual(exp, act); } - - [Serializable] - public class FormattableArgumentsSerializeObject + [Test] + public void Format_TestStruct_FormatString() { - public int Id { get; set; } - public FormattingArguments Obj { get; set; } - public DateTime Date { get; set; } + var exp = "0.000"; + var act = TestStruct.Format; + Assert.AreEqual(exp, act); } + #endregion +} + +[Serializable] +public class FormattableArgumentsSerializeObject +{ + public int Id { get; set; } + public FormattingArguments Obj { get; set; } + public DateTime Date { get; set; } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CountryToCurrencyTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CountryToCurrencyTest.cs index f76f3aa11..cfabddea7 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CountryToCurrencyTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CountryToCurrencyTest.cs @@ -1,27 +1,20 @@ -using NUnit.Framework; -using Qowaiv.Financial; -using Qowaiv.Globalization; -using System.Collections.Generic; -using System.Linq; +namespace Qowaiv.UnitTests.Globalization; -namespace Qowaiv.UnitTests.Globalization +public class CountryToCurrencyTest { - public class CountryToCurrencyTest - { - private static readonly Country[] CountriesWithoutCurrency = new[] { Country.AQ }; - private static IEnumerable GetCountriesWithCurrency() => Country.All.Where(c => !CountriesWithoutCurrency.Contains(c)); + private static readonly Country[] CountriesWithoutCurrency = new[] { Country.AQ }; + private static IEnumerable GetCountriesWithCurrency() => Country.All.Where(c => !CountriesWithoutCurrency.Contains(c)); - [TestCaseSource(nameof(GetCountriesWithCurrency))] - public void GetCurrency_ExistOnStartDate(Country country) - { - Assert.AreNotEqual(Currency.Empty, country.GetCurrency(country.StartDate), "{0} ({0:f}) on {1:yyyy-MM-dd}", country, country.StartDate); - } + [TestCaseSource(nameof(GetCountriesWithCurrency))] + public void GetCurrency_ExistOnStartDate(Country country) + { + Assert.AreNotEqual(Currency.Empty, country.GetCurrency(country.StartDate), "{0} ({0:f}) on {1:yyyy-MM-dd}", country, country.StartDate); + } - [TestCaseSource(nameof(GetCountriesWithCurrency))] - public void GetCurrency_ExistOnEndDate(Country country) - { - var test = country.EndDate ?? Clock.Today(); - Assert.AreNotEqual(Currency.Empty, country.GetCurrency(test), "{0} ({0:f}) on {1:yyyy-MM-dd}", country, test); - } + [TestCaseSource(nameof(GetCountriesWithCurrency))] + public void GetCurrency_ExistOnEndDate(Country country) + { + var test = country.EndDate ?? Clock.Today(); + Assert.AreNotEqual(Currency.Empty, country.GetCurrency(test), "{0} ({0:f}) on {1:yyyy-MM-dd}", country, test); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CultureInfoScopeTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CultureInfoScopeTest.cs index 33345e48b..69c211e1e 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CultureInfoScopeTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Globalization/CultureInfoScopeTest.cs @@ -1,41 +1,36 @@ -using NUnit.Framework; -using Qowaiv.Globalization; -using System.Globalization; +namespace Qowaiv.UnitTests.Globalization; -namespace Qowaiv.UnitTests.Globalization +public class CultureInfoScopeTest { - public class CultureInfoScopeTest + [Test] + public void Scoped_Ctor() { - [Test] - public void Scoped_Ctor() - { - var current = CultureInfo.CurrentCulture; - var currentUI = CultureInfo.CurrentUICulture; - - using (new CultureInfoScope("es-ES", "fr-FR")) - { - Assert.AreEqual("es-ES", CultureInfo.CurrentCulture.Name); - Assert.AreEqual("fr-FR", CultureInfo.CurrentUICulture.Name); - } + var current = CultureInfo.CurrentCulture; + var currentUI = CultureInfo.CurrentUICulture; - Assert.AreEqual(current, CultureInfo.CurrentCulture); - Assert.AreEqual(currentUI, CultureInfo.CurrentUICulture); + using (new CultureInfoScope("es-ES", "fr-FR")) + { + Assert.AreEqual("es-ES", CultureInfo.CurrentCulture.Name); + Assert.AreEqual("fr-FR", CultureInfo.CurrentUICulture.Name); } - [Test] - public void Scoped_ExtensionMethod() - { - var current = CultureInfo.CurrentCulture; - var currentUI = CultureInfo.CurrentUICulture; + Assert.AreEqual(current, CultureInfo.CurrentCulture); + Assert.AreEqual(currentUI, CultureInfo.CurrentUICulture); + } - using (new CultureInfo("es-ES").Scoped()) - { - Assert.AreEqual("es-ES", CultureInfo.CurrentCulture.Name); - Assert.AreEqual("es-ES", CultureInfo.CurrentUICulture.Name); - } + [Test] + public void Scoped_ExtensionMethod() + { + var current = CultureInfo.CurrentCulture; + var currentUI = CultureInfo.CurrentUICulture; - Assert.AreEqual(current, CultureInfo.CurrentCulture); - Assert.AreEqual(currentUI, CultureInfo.CurrentUICulture); + using (new CultureInfo("es-ES").Scoped()) + { + Assert.AreEqual("es-ES", CultureInfo.CurrentCulture.Name); + Assert.AreEqual("es-ES", CultureInfo.CurrentUICulture.Name); } + + Assert.AreEqual(current, CultureInfo.CurrentCulture); + Assert.AreEqual(currentUI, CultureInfo.CurrentUICulture); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/IFormattableExtensionsTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/IFormattableExtensionsTest.cs index a1b23e55e..5bf216880 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/IFormattableExtensionsTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/IFormattableExtensionsTest.cs @@ -1,78 +1,70 @@ -using NUnit.Framework; -using Qowaiv.Formatting; -using Qowaiv.Globalization; -using Qowaiv.TestTools.Globalization; -using System; -using System.Globalization; +namespace Qowaiv.UnitTests; -namespace Qowaiv.UnitTests +[TestFixture] +public class FormattableExtensionsTest { - [TestFixture] - public class FormattableExtensionsTest + [Test] + public void ToString_NullWithFormat_FormattedString() { - [Test] - public void ToString_NullWithFormat_FormattedString() - { - IFormattable formattable = null; - string act = formattable.ToString(new FormattingArguments("0.000", new CultureInfo("es-ES"))); - Assert.IsNull(act); - } + IFormattable formattable = null; + string act = formattable.ToString(new FormattingArguments("0.000", new CultureInfo("es-ES"))); + Assert.IsNull(act); + } - [Test] - public void ToString_DecimalWithFormat_FormattedString() - { - var act = (123.45m).ToString(new FormattingArguments("0.000", new CultureInfo("es-ES"))); - var exp = "123,450"; + [Test] + public void ToString_DecimalWithFormat_FormattedString() + { + var act = (123.45m).ToString(new FormattingArguments("0.000", new CultureInfo("es-ES"))); + var exp = "123,450"; - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); + } - [Test] - public void ToString_NullWithFormatCollection_FormattedString() - { - IFormattable formattable = null; - string act = formattable.ToString(new FormattingArgumentsCollection()); - string exp = null; + [Test] + public void ToString_NullWithFormatCollection_FormattedString() + { + IFormattable formattable = null; + string act = formattable.ToString(new FormattingArgumentsCollection()); + string exp = null; - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); + } - [Test] - public void ToString_NullWithNullCollection_FormattedString() - { - IFormattable formattable = null; - string act = formattable.ToString((FormattingArgumentsCollection)null); - string exp = null; + [Test] + public void ToString_NullWithNullCollection_FormattedString() + { + IFormattable formattable = null; + string act = formattable.ToString((FormattingArgumentsCollection)null); + string exp = null; - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); + } - [Test] - public void ToString_DecimalWithFormatCollection_FormattedString() + [Test] + public void ToString_DecimalWithFormatCollection_FormattedString() + { + using (TestCultures.Es_EC.Scoped()) { - using (TestCultures.Es_EC.Scoped()) - { - var collection = new FormattingArgumentsCollection(); - collection.Add(typeof(decimal), "0.000"); - var act = (123.45m).ToString(collection); - var exp = "123,450"; + var collection = new FormattingArgumentsCollection(); + collection.Add(typeof(decimal), "0.000"); + var act = (123.45m).ToString(collection); + var exp = "123,450"; - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); } + } - [Test] - public void ToString_DecimalWithNullCollection_FormattedString() + [Test] + public void ToString_DecimalWithNullCollection_FormattedString() + { + using (TestCultures.Es_EC.Scoped()) { - using (TestCultures.Es_EC.Scoped()) - { - var collection = (FormattingArgumentsCollection)null; + var collection = (FormattingArgumentsCollection)null; - var act = (123.45m).ToString(collection); - var exp = "123,45"; + var act = (123.45m).ToString(collection); + var exp = "123,45"; - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); } } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Identifiers/IdCastTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Identifiers/IdCastTest.cs index f3a8f660c..b9219ad7a 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Identifiers/IdCastTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Identifiers/IdCastTest.cs @@ -1,127 +1,122 @@ -using NUnit.Framework; -using Qowaiv.Identifiers; -using System; +namespace Qowaiv.UnitTests.Identifiers; -namespace Qowaiv.UnitTests.Identifiers +public class IdCastTest { - public class IdCastTest + [Test] + public void CreateString_Null_IsEmpty() { - [Test] - public void CreateString_Null_IsEmpty() - { - var fromNull = Id.Create(null); - Assert.IsTrue(fromNull.IsEmpty()); - } - - [Test] - public void CreateGuid_Null_IsEmpty() - { - var fromNull = Id.Create(null); - Assert.IsTrue(fromNull.IsEmpty()); - } - - [Test] - public void CreateInt64_Null_IsEmpty() - { - var fromNull = Id.Create(null); - Assert.IsTrue(fromNull.IsEmpty()); - } - - [Test] - public void Create_StringForInt64_Throws() - { - var x = Assert.Catch(() => Id.Create("NaN")); - Assert.AreEqual("Cast from string to Qowaiv.Identifiers.Id is not valid.", x.Message); - } - - [Test] - public void Create_Int64ForGuid_Throws() - { - var x = Assert.Catch(() => Id.Create(13245L)); - Assert.AreEqual("Cast from long to Qowaiv.Identifiers.Id is not valid.", x.Message); - } - - [Test] - public void FromJson_NegativeValue_Throws() - { - var x = Assert.Catch(() => Id.FromJson(-1)); - Assert.AreEqual("Cast from long to Qowaiv.Identifiers.Id is not valid.", x.Message); - } - - [Test] - public void Cast_FromGuidToGuid_Successfull() - { - var guid = Guid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); - var casted = (Id)guid; - var expected = Id.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); - Assert.AreEqual(expected, casted); - } - - [Test] - public void Cast_FromGuidToString_Successfull() - { - var guid = Guid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); - var casted = (Id)guid; - var expected = Id.Parse("ad38ecd4-020f-475c-9318-dff2067da1d4"); - Assert.AreEqual(expected, casted); - } - - [Test] - public void Cast_FromInt64ToInt64_Successfull() - { - var number = 12345L; - var casted = (Id)number; - var expected = Id.Create(12345L); - Assert.AreEqual(expected, casted); - } - - [Test] - public void Cast_FromStringToInt64_Successfull() - { - var number = "12345"; - var casted = (Id)number; - var expected = Id.Create(12345L); - Assert.AreEqual(expected, casted); - } - - [Test] - public void Cast_FromInt64ToString_Successfull() - { - var number = 12345L; - var casted = (Id)number; - var expected = Id.Parse("12345"); - Assert.AreEqual(expected, casted); - } - - - [Test] - public void Cast_FromStringToInt64_Throws() - { - var str = "ABC"; - Assert.Throws(() => Void((Id)str)); - } - - [Test] - public void Cast_FromInt64ToInt64_Trhows() - { - var guid = Guid.NewGuid(); - Assert.Throws(() => Void((Id)guid)); - } - - [Test] - public void Cast_FromStringToGuid_Throws() - { - var str = "12345"; - Assert.Throws(() => Void((Id)str)); - } - - [Test] - public void Cast_FromInt64ToGuid_Trhows() - { - var number = 12345L; - Assert.Throws(() => Void((Id)number)); - } - - private static void Void(object obj) { /* Do nothing */} + var fromNull = Id.Create(null); + Assert.IsTrue(fromNull.IsEmpty()); } + + [Test] + public void CreateGuid_Null_IsEmpty() + { + var fromNull = Id.Create(null); + Assert.IsTrue(fromNull.IsEmpty()); + } + + [Test] + public void CreateInt64_Null_IsEmpty() + { + var fromNull = Id.Create(null); + Assert.IsTrue(fromNull.IsEmpty()); + } + + [Test] + public void Create_StringForInt64_Throws() + { + var x = Assert.Catch(() => Id.Create("NaN")); + Assert.AreEqual("Cast from string to Qowaiv.Identifiers.Id is not valid.", x.Message); + } + + [Test] + public void Create_Int64ForGuid_Throws() + { + var x = Assert.Catch(() => Id.Create(13245L)); + Assert.AreEqual("Cast from long to Qowaiv.Identifiers.Id is not valid.", x.Message); + } + + [Test] + public void FromJson_NegativeValue_Throws() + { + var x = Assert.Catch(() => Id.FromJson(-1)); + Assert.AreEqual("Cast from long to Qowaiv.Identifiers.Id is not valid.", x.Message); + } + + [Test] + public void Cast_FromGuidToGuid_Successfull() + { + var guid = Guid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); + var casted = (Id)guid; + var expected = Id.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); + Assert.AreEqual(expected, casted); + } + + [Test] + public void Cast_FromGuidToString_Successfull() + { + var guid = Guid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); + var casted = (Id)guid; + var expected = Id.Parse("ad38ecd4-020f-475c-9318-dff2067da1d4"); + Assert.AreEqual(expected, casted); + } + + [Test] + public void Cast_FromInt64ToInt64_Successfull() + { + var number = 12345L; + var casted = (Id)number; + var expected = Id.Create(12345L); + Assert.AreEqual(expected, casted); + } + + [Test] + public void Cast_FromStringToInt64_Successfull() + { + var number = "12345"; + var casted = (Id)number; + var expected = Id.Create(12345L); + Assert.AreEqual(expected, casted); + } + + [Test] + public void Cast_FromInt64ToString_Successfull() + { + var number = 12345L; + var casted = (Id)number; + var expected = Id.Parse("12345"); + Assert.AreEqual(expected, casted); + } + + + [Test] + public void Cast_FromStringToInt64_Throws() + { + var str = "ABC"; + Assert.Throws(() => Void((Id)str)); + } + + [Test] + public void Cast_FromInt64ToInt64_Trhows() + { + var guid = Guid.NewGuid(); + Assert.Throws(() => Void((Id)guid)); + } + + [Test] + public void Cast_FromStringToGuid_Throws() + { + var str = "12345"; + Assert.Throws(() => Void((Id)str)); + } + + [Test] + public void Cast_FromInt64ToGuid_Trhows() + { + var number = 12345L; + Assert.Throws(() => Void((Id)number)); + } + + private static void Void(object obj) { /* Do nothing */} } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Mathematics/FractionTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Mathematics/FractionTest.cs index 8fec37e9e..f7e0389a3 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Mathematics/FractionTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Mathematics/FractionTest.cs @@ -1,381 +1,367 @@ -using FluentAssertions; -using NUnit.Framework; -using Qowaiv.Globalization; -using Qowaiv.Mathematics; -using Qowaiv.TestTools; -using Qowaiv.TestTools.Globalization; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using System.Xml.Serialization; - -namespace Qowaiv.UnitTests.Mathematics -{ - /// Tests the fraction SVO. - public class FractionTest - { - /// The test instance for most tests. - public static readonly Fraction TestStruct = Fraction.Parse("-69/17"); +namespace Qowaiv.UnitTests.Mathematics; - /// Fraction.Zero should be equal to the default of fraction. - [Test] - public void Zero_None_EqualsDefault() - { - Assert.AreEqual(default(Fraction), Fraction.Zero); - } +/// Tests the fraction SVO. +public class FractionTest +{ + /// The test instance for most tests. + public static readonly Fraction TestStruct = Fraction.Parse("-69/17"); - /// Fraction.IsZero() should be true for the default of fraction. - [Test] - public void IsZero_Default_IsTrue() - { - Assert.IsTrue(default(Fraction).IsZero()); - } + /// Fraction.Zero should be equal to the default of fraction. + [Test] + public void Zero_None_EqualsDefault() + { + Assert.AreEqual(default(Fraction), Fraction.Zero); + } - /// Fraction.IsZero() should be false for the TestStruct. - [Test] - public void IsZero_TestStruct_IsFalse() - { - Assert.IsFalse(TestStruct.IsZero()); - } + /// Fraction.IsZero() should be true for the default of fraction. + [Test] + public void IsZero_Default_IsTrue() + { + Assert.IsTrue(default(Fraction).IsZero()); + } - [Test] - public void Parse_InvalidInput_ThrowsFormatException() - { - using (TestCultures.En_GB.Scoped()) - { - Assert.Catch(() => - { - Fraction.Parse("InvalidInput"); - } - , "Not a valid fraction"); - } - } + /// Fraction.IsZero() should be false for the TestStruct. + [Test] + public void IsZero_TestStruct_IsFalse() + { + Assert.IsFalse(TestStruct.IsZero()); + } - [Test] - public void TryParse_TestStructInput_AreEqual() + [Test] + public void Parse_InvalidInput_ThrowsFormatException() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) + Assert.Catch(() => { - var exp = TestStruct; - var act = Fraction.TryParse(exp.ToString()); - Assert.AreEqual(exp, act); + Fraction.Parse("InvalidInput"); } + , "Not a valid fraction"); } + } - [Test] - public void from_invalid_as_null_with_TryParse() - => Fraction.TryParse("invalid input").Should().BeNull(); - - [TestCase("0/1", 0, 8, "Should set zero")] - [TestCase("1/4", 2, 8, "Should reduce")] - [TestCase("-1/4", -2, 8, "Should reduce")] - [TestCase("1/4", 3, 12, "Should reduce")] - [TestCase("-1/4", -3, 12, "Should reduce")] - [TestCase("3/7", -3, -7, "Should have no signs")] - [TestCase("-3/7", 3, -7, "Should have no sign on denominator")] - [TestCase("-3/7", -3, 7, "Should have no sign on denominator")] - public void Constructor(Fraction expected, long numerator, long denominator, string description) + [Test] + public void TryParse_TestStructInput_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - var actual = new Fraction(numerator, denominator); - Assert.AreEqual(expected, actual, description); + var exp = TestStruct; + var act = Fraction.TryParse(exp.ToString()); + Assert.AreEqual(exp, act); } + } - [Test] - public void GetObjectData_NulSerializationInfo_Throws() - { - ISerializable obj = TestStruct; - Assert.Catch(() => obj.GetObjectData(null, default)); - } + [Test] + public void from_invalid_as_null_with_TryParse() + => Fraction.TryParse("invalid input").Should().BeNull(); + + [TestCase("0/1", 0, 8, "Should set zero")] + [TestCase("1/4", 2, 8, "Should reduce")] + [TestCase("-1/4", -2, 8, "Should reduce")] + [TestCase("1/4", 3, 12, "Should reduce")] + [TestCase("-1/4", -3, 12, "Should reduce")] + [TestCase("3/7", -3, -7, "Should have no signs")] + [TestCase("-3/7", 3, -7, "Should have no sign on denominator")] + [TestCase("-3/7", -3, 7, "Should have no sign on denominator")] + public void Constructor(Fraction expected, long numerator, long denominator, string description) + { + var actual = new Fraction(numerator, denominator); + Assert.AreEqual(expected, actual, description); + } - [Test] - public void GetObjectData_SerializationInfo_AreEqual() - { - ISerializable obj = TestStruct; - var info = new SerializationInfo(typeof(Fraction), new FormatterConverter()); - obj.GetObjectData(info, default); - Assert.AreEqual(-69, info.GetInt64("numerator")); - Assert.AreEqual(17, info.GetInt64("denominator")); - } + [Test] + public void GetObjectData_NulSerializationInfo_Throws() + { + ISerializable obj = TestStruct; + Assert.Catch(() => obj.GetObjectData(null, default)); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp, act); - } + [Test] + public void GetObjectData_SerializationInfo_AreEqual() + { + ISerializable obj = TestStruct; + var info = new SerializationInfo(typeof(Fraction), new FormatterConverter()); + obj.GetObjectData(info, default); + Assert.AreEqual(-69, info.GetInt64("numerator")); + Assert.AreEqual(17, info.GetInt64("denominator")); + } - [Test] - public void DataContractSerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp, act); - } + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp, act); + } - [Test] - public void XmlSerialize_TestStruct_AreEqual() - { - var act = Serialize.Xml(TestStruct); - var exp = "-69/17"; - Assert.AreEqual(exp, act); - } + [Test] + public void DataContractSerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp, act); + } - [Test] - public void XmlDeserialize_XmlString_AreEqual() - { - var act =Deserialize.Xml("-69/17"); - Assert.AreEqual(TestStruct, act); - } + [Test] + public void XmlSerialize_TestStruct_AreEqual() + { + var act = Serialize.Xml(TestStruct); + var exp = "-69/17"; + Assert.AreEqual(exp, act); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_FractionSerializeObject_AreEqual() - { - var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void XmlDeserialize_XmlString_AreEqual() + { + var act =Deserialize.Xml("-69/17"); + Assert.AreEqual(TestStruct, act); + } - [Test] - public void XmlSerializeDeserialize_FractionSerializeObject_AreEqual() - { - var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_FractionSerializeObject_AreEqual() + { + var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void DataContractSerializeDeserialize_FractionSerializeObject_AreEqual() - { - var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void XmlSerializeDeserialize_FractionSerializeObject_AreEqual() + { + var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_Default_AreEqual() - { - var input = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; - var exp = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void DataContractSerializeDeserialize_FractionSerializeObject_AreEqual() + { + var input = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var exp = new FractionSerializeObject { Id = 17, Obj = TestStruct, Date = new DateTime(1970, 02, 14), }; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void XmlSerializeDeserialize_Default_AreEqual() - { - var input = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; - var exp = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_Default_AreEqual() + { + var input = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; + var exp = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void GetSchema_None_IsNull() - { - IXmlSerializable obj = TestStruct; - Assert.IsNull(obj.GetSchema()); - } + [Test] + public void XmlSerializeDeserialize_Default_AreEqual() + { + var input = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; + var exp = new FractionSerializeObject { Id = 17, Obj = default, Date = new DateTime(1970, 02, 14), }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void ToString_Zero_StringEmpty() - { - var act = Fraction.Zero.ToString(); - var exp = "0/1"; - Assert.AreEqual(exp, act); - } + [Test] + public void GetSchema_None_IsNull() + { + IXmlSerializable obj = TestStruct; + Assert.IsNull(obj.GetSchema()); + } - [Test] - public void ToString_CustomFormatter_SupportsCustomFormatting() - { - var act = TestStruct.ToString("[0] 0/000", FormatProvider.CustomFormatter); - var exp = "Unit Test Formatter, value: '-4 1/017', format: '[0] 0/000'"; - Assert.AreEqual(exp, act); - } + [Test] + public void ToString_Zero_StringEmpty() + { + var act = Fraction.Zero.ToString(); + var exp = "0/1"; + Assert.AreEqual(exp, act); + } - [TestCase("-2:7", "-2/7", "0:0")] - [TestCase("4÷3", "4/3", "0÷0")] - [TestCase("1 1/3", "4/3", "[0]0/0")] - [TestCase("-1 1/3", "-4/3", "[0]0/0")] - [TestCase("-1 1/3", "-4/3", "[0 ]0/0")] - [TestCase(".33", "1/3", "#.00")] - [TestCase("5¹¹⁄₁₂", "71/12", "[0]super⁄sub")] - [TestCase("5¹¹⁄12", "71/12", "[0]super⁄0")] - [TestCase("5 11⁄₁₂", "71/12", "[0] 0⁄sub")] - [TestCase("-3¹⁄₂", "-7/2", "[0]super⁄sub")] - [TestCase("-3 ¹⁄₂", "-7/2", "[0 ]super⁄sub")] - [TestCase("-¹⁄₂", "-1/2", "[#]super⁄sub")] - [TestCase("-0¹⁄₂", "-1/2", "[0]super⁄sub")] - [TestCase("⁷¹⁄₁₂", "71/12", "super⁄sub")] - [TestCase("-⁷⁄₂", "-7/2", "super⁄sub")] - public void ToString_WithFormat(string expected, Fraction fraction, string format) - { - var formatted = fraction.ToString(format, CultureInfo.InvariantCulture); - Assert.AreEqual(expected, formatted); - } + [Test] + public void ToString_CustomFormatter_SupportsCustomFormatting() + { + var act = TestStruct.ToString("[0] 0/000", FormatProvider.CustomFormatter); + var exp = "Unit Test Formatter, value: '-4 1/017', format: '[0] 0/000'"; + Assert.AreEqual(exp, act); + } - /// GetHash should not fail for Fraction.Zero. - [Test] - public void GetHash_Zero_Hash() - { - Assert.AreEqual(0, Fraction.Zero.GetHashCode()); - } + [TestCase("-2:7", "-2/7", "0:0")] + [TestCase("4÷3", "4/3", "0÷0")] + [TestCase("1 1/3", "4/3", "[0]0/0")] + [TestCase("-1 1/3", "-4/3", "[0]0/0")] + [TestCase("-1 1/3", "-4/3", "[0 ]0/0")] + [TestCase(".33", "1/3", "#.00")] + [TestCase("5¹¹⁄₁₂", "71/12", "[0]super⁄sub")] + [TestCase("5¹¹⁄12", "71/12", "[0]super⁄0")] + [TestCase("5 11⁄₁₂", "71/12", "[0] 0⁄sub")] + [TestCase("-3¹⁄₂", "-7/2", "[0]super⁄sub")] + [TestCase("-3 ¹⁄₂", "-7/2", "[0 ]super⁄sub")] + [TestCase("-¹⁄₂", "-1/2", "[#]super⁄sub")] + [TestCase("-0¹⁄₂", "-1/2", "[0]super⁄sub")] + [TestCase("⁷¹⁄₁₂", "71/12", "super⁄sub")] + [TestCase("-⁷⁄₂", "-7/2", "super⁄sub")] + public void ToString_WithFormat(string expected, Fraction fraction, string format) + { + var formatted = fraction.ToString(format, CultureInfo.InvariantCulture); + Assert.AreEqual(expected, formatted); + } - /// GetHash should not fail for the test struct. - [Test] - public void GetHash_TestStruct_Hash() - { - Assert.AreEqual(132548, TestStruct.GetHashCode()); - } + /// GetHash should not fail for Fraction.Zero. + [Test] + public void GetHash_Zero_Hash() + { + Assert.AreEqual(0, Fraction.Zero.GetHashCode()); + } - [Test] - public void Equals_ZeroZero_IsTrue() - { - Assert.IsTrue(Fraction.Zero.Equals(Fraction.Zero)); - } + /// GetHash should not fail for the test struct. + [Test] + public void GetHash_TestStruct_Hash() + { + Assert.AreEqual(132548, TestStruct.GetHashCode()); + } - [Test] - public void Equals_FormattedAndUnformatted_IsTrue() - { - var l = Fraction.Parse("-71,234/71,234", CultureInfo.InvariantCulture); - var r = Fraction.Parse("-1", CultureInfo.InvariantCulture); - Assert.IsTrue(l.Equals(r)); - } + [Test] + public void Equals_ZeroZero_IsTrue() + { + Assert.IsTrue(Fraction.Zero.Equals(Fraction.Zero)); + } - [Test] - public void Equals_TestStructTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals(TestStruct)); - } + [Test] + public void Equals_FormattedAndUnformatted_IsTrue() + { + var l = Fraction.Parse("-71,234/71,234", CultureInfo.InvariantCulture); + var r = Fraction.Parse("-1", CultureInfo.InvariantCulture); + Assert.IsTrue(l.Equals(r)); + } - [Test] - public void Equals_TestStructZero_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(Fraction.Zero)); - } + [Test] + public void Equals_TestStructTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals(TestStruct)); + } - [Test] - public void Equals_ZeroTestStruct_IsFalse() - { - Assert.IsFalse(Fraction.Zero.Equals(TestStruct)); - } + [Test] + public void Equals_TestStructZero_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(Fraction.Zero)); + } - [Test] - public void Equals_TestStructObjectTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals((object)TestStruct)); - } + [Test] + public void Equals_ZeroTestStruct_IsFalse() + { + Assert.IsFalse(Fraction.Zero.Equals(TestStruct)); + } - [Test] - public void Equals_TestStructNull_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(null)); - } + [Test] + public void Equals_TestStructObjectTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals((object)TestStruct)); + } - [Test] - public void Equals_TestStructObject_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(new object())); - } + [Test] + public void Equals_TestStructNull_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(null)); + } - [Test] - public void OperatorIs_TestStructTestStruct_IsTrue() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsTrue(l == r); - } + [Test] + public void Equals_TestStructObject_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(new object())); + } - [Test] - public void OperatorIsNot_TestStructTestStruct_IsFalse() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsFalse(l != r); - } + [Test] + public void OperatorIs_TestStructTestStruct_IsTrue() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsTrue(l == r); + } - [Test] - public void Explicit_Int32ToFraction_AreEqual() - { - var exp = 123456789.DividedBy(1); - var act = (Fraction)123456789; - Assert.AreEqual(exp, act); - } + [Test] + public void OperatorIsNot_TestStructTestStruct_IsFalse() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsFalse(l != r); + } - [Test] - public void Explicit_FractionToInt32_AreEqual() - { - Assert.AreEqual(-69 / 17, (int)TestStruct); - } + [Test] + public void Explicit_Int32ToFraction_AreEqual() + { + var exp = 123456789.DividedBy(1); + var act = (Fraction)123456789; + Assert.AreEqual(exp, act); + } - [Test] - public void Explicit_FractionToInt64_AreEqual() - { - Assert.AreEqual(-69 / 17L, (long)TestStruct); - } + [Test] + public void Explicit_FractionToInt32_AreEqual() + { + Assert.AreEqual(-69 / 17, (int)TestStruct); + } - [Test] - public void Explicit_FractionToDouble_AreEqual() - { - Assert.AreEqual(-69 / 17d, (double)TestStruct); - } + [Test] + public void Explicit_FractionToInt64_AreEqual() + { + Assert.AreEqual(-69 / 17L, (long)TestStruct); + } - [Test] - public void Explicit_FractionToDecimal_AreEqual() - { - Assert.AreEqual(-69 / 17m, (decimal)TestStruct); - } + [Test] + public void Explicit_FractionToDouble_AreEqual() + { + Assert.AreEqual(-69 / 17d, (double)TestStruct); + } - [Test] - public void ConverterExists_Fraction_IsTrue() - => typeof(Fraction).Should().HaveTypeConverterDefined(); - - [TestCase(null, "Null")] - [TestCase("", "String.Empty")] - [TestCase("NaN", "NaN")] - [TestCase("-Infinity", "-Infinity")] - [TestCase("+Infinity", "+Infinity")] - [TestCase("0xFF", "Hexa-decimal")] - [TestCase("15/", "Ends with an operator")] - [TestCase("1//4", "Two division operators")] - [TestCase("1/½", "Vulgar with division operator")] - [TestCase("½1", "Vulgar not at the end")] - [TestCase("²3/₇", "Normal and superscript mixed")] - [TestCase("²/₇3", "Normal and subscript mixed")] - [TestCase("²/3₇", "Normal and subscript mixed")] - [TestCase("₇/3", "Subscript first")] - [TestCase("9223372036854775808", "Long.MaxValue + 1")] - [TestCase("-9223372036854775808", "Long.MinValue")] - [TestCase("-9223372036854775809", "Long.MinValue - 1")] - public void IsInvalid_String(string str, string because) - => Fraction.TryParse(str).Should().BeNull(because); - } - - [Serializable] - public class FractionSerializeObject - { - public int Id { get; set; } - public Fraction Obj { get; set; } - public DateTime Date { get; set; } + [Test] + public void Explicit_FractionToDecimal_AreEqual() + { + Assert.AreEqual(-69 / 17m, (decimal)TestStruct); } + + [Test] + public void ConverterExists_Fraction_IsTrue() + => typeof(Fraction).Should().HaveTypeConverterDefined(); + + [TestCase(null, "Null")] + [TestCase("", "String.Empty")] + [TestCase("NaN", "NaN")] + [TestCase("-Infinity", "-Infinity")] + [TestCase("+Infinity", "+Infinity")] + [TestCase("0xFF", "Hexa-decimal")] + [TestCase("15/", "Ends with an operator")] + [TestCase("1//4", "Two division operators")] + [TestCase("1/½", "Vulgar with division operator")] + [TestCase("½1", "Vulgar not at the end")] + [TestCase("²3/₇", "Normal and superscript mixed")] + [TestCase("²/₇3", "Normal and subscript mixed")] + [TestCase("²/3₇", "Normal and subscript mixed")] + [TestCase("₇/3", "Subscript first")] + [TestCase("9223372036854775808", "Long.MaxValue + 1")] + [TestCase("-9223372036854775808", "Long.MinValue")] + [TestCase("-9223372036854775809", "Long.MinValue - 1")] + public void IsInvalid_String(string str, string because) + => Fraction.TryParse(str).Should().BeNull(because); +} + +[Serializable] +public class FractionSerializeObject +{ + public int Id { get; set; } + public Fraction Obj { get; set; } + public DateTime Date { get; set; } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/NumericSvoTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/NumericSvoTest.cs index 0ed36193e..b1a541790 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/NumericSvoTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/NumericSvoTest.cs @@ -1,379 +1,370 @@ -using NUnit.Framework; -using Qowaiv.Financial; -using Qowaiv.IO; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Qowaiv.UnitTests -{ - public class NumericSvoTest - { - internal const BindingFlags NonPublicInstance = BindingFlags.NonPublic | BindingFlags.Instance; - internal const BindingFlags PublicInstance = BindingFlags.Public | BindingFlags.Instance; - internal const BindingFlags PublicStatic = BindingFlags.Public | BindingFlags.Static; +namespace Qowaiv.UnitTests; +public class NumericSvoTest +{ + internal const BindingFlags NonPublicInstance = BindingFlags.NonPublic | BindingFlags.Instance; + internal const BindingFlags PublicInstance = BindingFlags.Public | BindingFlags.Instance; + internal const BindingFlags PublicStatic = BindingFlags.Public | BindingFlags.Static; - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - [TestCase(typeof(StreamSize))] - public void Abs(Type svo) - { - //Math.Abs - var methods = svo? - .GetMethods(PublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Abs)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - [TestCase(typeof(StreamSize))] - public void Plus(Type svo) - { - var methods = svo - .GetMethods(NonPublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Plus)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator("UnaryPlus") - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == svo) - .ToArray(); - - Assert.IsTrue(methods.Length == 1, nameof(methods)); - Assert.IsTrue(operators.Length == 1, nameof(operators)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + [TestCase(typeof(StreamSize))] + public void Abs(Type svo) + { + //Math.Abs + var methods = svo? + .GetMethods(PublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Abs)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - [TestCase(typeof(StreamSize))] - public void Negate(Type svo) - { - var methods = svo - .GetMethods(NonPublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Negate)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator("UnaryNegation") - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == svo) - .ToArray(); - - Assert.IsTrue(methods.Length == 1, nameof(methods)); - Assert.IsTrue(operators.Length == 1, nameof(operators)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + [TestCase(typeof(StreamSize))] + public void Plus(Type svo) + { + var methods = svo + .GetMethods(NonPublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Plus)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator("UnaryPlus") + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == svo) + .ToArray(); + + Assert.IsTrue(methods.Length == 1, nameof(methods)); + Assert.IsTrue(operators.Length == 1, nameof(operators)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - [TestCase(typeof(StreamSize))] - public void Increment(Type svo) - { - var methods = svo - .GetMethods(NonPublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Increment)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator(nameof(Increment)) - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == svo) - .ToArray(); - - Assert.IsTrue(methods.Length == 1, nameof(methods)); - Assert.IsTrue(operators.Length == 1, nameof(operators)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + [TestCase(typeof(StreamSize))] + public void Negate(Type svo) + { + var methods = svo + .GetMethods(NonPublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Negate)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator("UnaryNegation") + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == svo) + .ToArray(); + + Assert.IsTrue(methods.Length == 1, nameof(methods)); + Assert.IsTrue(operators.Length == 1, nameof(operators)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - [TestCase(typeof(StreamSize))] - public void Decrement(Type svo) - { - var methods = svo - .GetMethods(NonPublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Decrement)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator(nameof(Decrement)) - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == svo) - .ToArray(); - - Assert.IsTrue(methods.Length == 1, nameof(methods)); - Assert.IsTrue(operators.Length == 1, nameof(operators)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + [TestCase(typeof(StreamSize))] + public void Increment(Type svo) + { + var methods = svo + .GetMethods(NonPublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Increment)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator(nameof(Increment)) + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == svo) + .ToArray(); + + Assert.IsTrue(methods.Length == 1, nameof(methods)); + Assert.IsTrue(operators.Length == 1, nameof(operators)); + } - [TestCase(typeof(Amount), typeof(Amount), typeof(Percentage))] - [TestCase(typeof(Money), typeof(Money), typeof(Percentage))] - [TestCase(typeof(Percentage), typeof(Percentage))] - [TestCase(typeof(StreamSize), typeof(StreamSize), typeof(Percentage))] - public void Add(Type svo, params Type[] expected) - { - var methods = svo - .GetMethods(PublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Add)) - .SelectParameters() - .Where(pars => pars.Length == 1) - .Select(pars => pars[0]) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator("Addition") - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == svo) - .Select(pars => pars[1]) - .ToArray(); - - CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); - CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + [TestCase(typeof(StreamSize))] + public void Decrement(Type svo) + { + var methods = svo + .GetMethods(NonPublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Decrement)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator(nameof(Decrement)) + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == svo) + .ToArray(); + + Assert.IsTrue(methods.Length == 1, nameof(methods)); + Assert.IsTrue(operators.Length == 1, nameof(operators)); + } - [TestCase(typeof(Amount), typeof(Amount), typeof(Percentage))] - [TestCase(typeof(Money), typeof(Money), typeof(Percentage))] - [TestCase(typeof(Percentage), typeof(Percentage))] - [TestCase(typeof(StreamSize), typeof(StreamSize), typeof(Percentage))] - public void Subtract(Type svo, params Type[] expected) - { - var methods = svo - .GetMethods(PublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Subtract)) - .SelectParameters() - .Where(pars => pars.Length == 1) - .Select(pars => pars[0]) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator("Subtraction") - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == svo) - .Select(pars => pars[1]) - .ToArray(); - - CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); - CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); - } + [TestCase(typeof(Amount), typeof(Amount), typeof(Percentage))] + [TestCase(typeof(Money), typeof(Money), typeof(Percentage))] + [TestCase(typeof(Percentage), typeof(Percentage))] + [TestCase(typeof(StreamSize), typeof(StreamSize), typeof(Percentage))] + public void Add(Type svo, params Type[] expected) + { + var methods = svo + .GetMethods(PublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Add)) + .SelectParameters() + .Where(pars => pars.Length == 1) + .Select(pars => pars[0]) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator("Addition") + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == svo) + .Select(pars => pars[1]) + .ToArray(); + + CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); + CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); + } - [TestCase(typeof(Amount), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(Money), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(Percentage), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(StreamSize), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - public void Multiply(Type svo, params Type[] expected) - { - var methods = svo - .GetMethods(PublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Multiply)) - .SelectParameters() - .Where(pars => pars.Length == 1) - .Select(pars => pars[0]) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator(nameof(Multiply)) - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == svo) - .Select(pars => pars[1]) - .ToArray(); - - CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); - CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); - } + [TestCase(typeof(Amount), typeof(Amount), typeof(Percentage))] + [TestCase(typeof(Money), typeof(Money), typeof(Percentage))] + [TestCase(typeof(Percentage), typeof(Percentage))] + [TestCase(typeof(StreamSize), typeof(StreamSize), typeof(Percentage))] + public void Subtract(Type svo, params Type[] expected) + { + var methods = svo + .GetMethods(PublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Subtract)) + .SelectParameters() + .Where(pars => pars.Length == 1) + .Select(pars => pars[0]) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator("Subtraction") + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == svo) + .Select(pars => pars[1]) + .ToArray(); + + CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); + CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); + } - [TestCase(typeof(Amount), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(Money), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(Percentage), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - [TestCase(typeof(StreamSize), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] - public void Divide(Type svo, params Type[] expected) - { - var methods = svo - .GetMethods(PublicInstance) - .ExcludeObsolete() - .Returns(svo) - .Where(m => m.Name == nameof(Divide)) - .SelectParameters() - .Where(pars => pars.Length == 1) - .Select(pars => pars[0]) - .ToArray(); - - var operators = svo - .GetMethods(PublicStatic) - .ExcludeObsolete() - .Returns(svo) - .IsOperator("Division") - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == svo) - .Select(pars => pars[1]) - .ToArray(); - - CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); - CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); - } + [TestCase(typeof(Amount), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(Money), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(Percentage), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(StreamSize), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + public void Multiply(Type svo, params Type[] expected) + { + var methods = svo + .GetMethods(PublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Multiply)) + .SelectParameters() + .Where(pars => pars.Length == 1) + .Select(pars => pars[0]) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator(nameof(Multiply)) + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == svo) + .Select(pars => pars[1]) + .ToArray(); + + CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); + CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - public void Round(Type svo) - { - var methods = svo? - .GetMethods(PublicInstance) - .Returns(svo) - .Where(m => m.Name == nameof(Round)) - .SelectParameters() - .Where(pars => pars.Length == 0) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } + [TestCase(typeof(Amount), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(Money), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(Percentage), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + [TestCase(typeof(StreamSize), typeof(short), typeof(int), typeof(long), typeof(ushort), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(Percentage))] + public void Divide(Type svo, params Type[] expected) + { + var methods = svo + .GetMethods(PublicInstance) + .ExcludeObsolete() + .Returns(svo) + .Where(m => m.Name == nameof(Divide)) + .SelectParameters() + .Where(pars => pars.Length == 1) + .Select(pars => pars[0]) + .ToArray(); + + var operators = svo + .GetMethods(PublicStatic) + .ExcludeObsolete() + .Returns(svo) + .IsOperator("Division") + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == svo) + .Select(pars => pars[1]) + .ToArray(); + + CollectionAssert.AreEquivalent(expected, methods, nameof(methods)); + CollectionAssert.AreEquivalent(expected, operators, nameof(operators)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - public void Round_Decimals(Type svo) - { - var methods = svo? - .GetMethods(PublicInstance) - .Returns(svo) - .Where(m => m.Name == nameof(Round)) - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == typeof(int)) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + public void Round(Type svo) + { + var methods = svo? + .GetMethods(PublicInstance) + .Returns(svo) + .Where(m => m.Name == nameof(Round)) + .SelectParameters() + .Where(pars => pars.Length == 0) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); + } - [TestCase(typeof(Amount))] - [TestCase(typeof(Money))] - [TestCase(typeof(Percentage))] - public void Round_Decimals_DecimalRounding(Type svo) - { - var methods = svo? - .GetMethods(PublicInstance) - .Returns(svo) - .Where(m => m.Name == nameof(Round)) - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == typeof(int) && pars[1] == typeof(DecimalRounding)) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + public void Round_Decimals(Type svo) + { + var methods = svo? + .GetMethods(PublicInstance) + .Returns(svo) + .Where(m => m.Name == nameof(Round)) + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == typeof(int)) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); + } - [TestCase(typeof(Amount), typeof(decimal))] - [TestCase(typeof(Money), typeof(decimal))] - [TestCase(typeof(Percentage), typeof(Percentage))] - public void RoundToMultiple(Type svo, Type multiplyer) - { - var methods = svo? - .GetMethods(PublicInstance) - .Returns(svo) - .Where(m => m.Name == nameof(RoundToMultiple)) - .SelectParameters() - .Where(pars => pars.Length == 1 && pars[0] == multiplyer) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } + [TestCase(typeof(Amount))] + [TestCase(typeof(Money))] + [TestCase(typeof(Percentage))] + public void Round_Decimals_DecimalRounding(Type svo) + { + var methods = svo? + .GetMethods(PublicInstance) + .Returns(svo) + .Where(m => m.Name == nameof(Round)) + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == typeof(int) && pars[1] == typeof(DecimalRounding)) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); + } - [TestCase(typeof(Amount), typeof(decimal))] - [TestCase(typeof(Money), typeof(decimal))] - [TestCase(typeof(Percentage), typeof(Percentage))] - public void RoundToMultiple_DecimalRounding(Type svo, Type multiplyer) - { - var methods = svo? - .GetMethods(PublicInstance) - .Returns(svo) - .Where(m => m.Name == nameof(RoundToMultiple)) - .SelectParameters() - .Where(pars => pars.Length == 2 && pars[0] == multiplyer && pars[1] == typeof(DecimalRounding)) - .ToArray(); - - Assert.IsTrue(methods?.Length == 1, nameof(methods)); - } + [TestCase(typeof(Amount), typeof(decimal))] + [TestCase(typeof(Money), typeof(decimal))] + [TestCase(typeof(Percentage), typeof(Percentage))] + public void RoundToMultiple(Type svo, Type multiplyer) + { + var methods = svo? + .GetMethods(PublicInstance) + .Returns(svo) + .Where(m => m.Name == nameof(RoundToMultiple)) + .SelectParameters() + .Where(pars => pars.Length == 1 && pars[0] == multiplyer) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); + } + [TestCase(typeof(Amount), typeof(decimal))] + [TestCase(typeof(Money), typeof(decimal))] + [TestCase(typeof(Percentage), typeof(Percentage))] + public void RoundToMultiple_DecimalRounding(Type svo, Type multiplyer) + { + var methods = svo? + .GetMethods(PublicInstance) + .Returns(svo) + .Where(m => m.Name == nameof(RoundToMultiple)) + .SelectParameters() + .Where(pars => pars.Length == 2 && pars[0] == multiplyer && pars[1] == typeof(DecimalRounding)) + .ToArray(); + + Assert.IsTrue(methods?.Length == 1, nameof(methods)); } - internal static class NumericSvoTestExtensions +} + +internal static class NumericSvoTestExtensions +{ + public static IEnumerable ExcludeObsolete(this IEnumerable infos) { - public static IEnumerable ExcludeObsolete(this IEnumerable infos) + foreach (var info in infos) { - foreach (var info in infos) + if (info.GetCustomAttribute() is null) { - if (info.GetCustomAttribute() is null) - { - yield return info; - } + yield return info; } } + } - public static IEnumerable Returns(this IEnumerable infos, Type returnType) - { - return infos.Where(info => info.ReturnType == returnType); - } + public static IEnumerable Returns(this IEnumerable infos, Type returnType) + { + return infos.Where(info => info.ReturnType == returnType); + } - public static IEnumerable IsOperator(this IEnumerable infos, string nameSuffix) - { - return infos.Where(info => info.IsSpecialName && info.Name == "op_" + nameSuffix); - } + public static IEnumerable IsOperator(this IEnumerable infos, string nameSuffix) + { + return infos.Where(info => info.IsSpecialName && info.Name == "op_" + nameSuffix); + } - public static IEnumerable SelectParameters(this IEnumerable infos) - { - return infos.Select(info => info.GetParameters().Select(par => par.ParameterType).ToArray()); - } + public static IEnumerable SelectParameters(this IEnumerable infos) + { + return infos.Select(info => info.GetParameters().Select(par => par.ParameterType).ToArray()); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/UuidComparerTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/UuidComparerTest.cs index 1eea27167..3ea10be87 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/UuidComparerTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/UuidComparerTest.cs @@ -1,109 +1,104 @@ -using NUnit.Framework; -using System; -using System.Collections.Generic; +namespace Qowaiv.UnitTests; -namespace Qowaiv.UnitTests +public class UuidComparerTest { - public class UuidComparerTest + private readonly Guid guid = Guid.Parse("40E56044-F781-43BD-A4AE-AA08882B4E28"); + private readonly Uuid uuid = Uuid.Parse("BD411BB9-D8C9-4A4F-B739-57F2312E0BC5"); + + /// Proves that the has an higher priority than the paired + /// . + /// + [TestCase(10, 11)] + [TestCase(11, 12)] + [TestCase(12, 13)] + [TestCase(13, 14)] + [TestCase(14, 15)] + [TestCase(15, 08)] + [TestCase(08, 09)] + [TestCase(09, 06)] + [TestCase(06, 07)] + [TestCase(07, 04)] + [TestCase(04, 05)] + [TestCase(05, 00)] + [TestCase(00, 01)] + [TestCase(01, 02)] + [TestCase(02, 03)] + public void Compare_SqlServer(int index0, int index1) { - private readonly Guid guid = Guid.Parse("40E56044-F781-43BD-A4AE-AA08882B4E28"); - private readonly Uuid uuid = Uuid.Parse("BD411BB9-D8C9-4A4F-B739-57F2312E0BC5"); + var l = Simple(index0, index1, 1, 2); + var r = Simple(index0, index1, 2, 1); - /// Proves that the has an higher priority than the paired - /// . - /// - [TestCase(10, 11)] - [TestCase(11, 12)] - [TestCase(12, 13)] - [TestCase(13, 14)] - [TestCase(14, 15)] - [TestCase(15, 08)] - [TestCase(08, 09)] - [TestCase(09, 06)] - [TestCase(06, 07)] - [TestCase(07, 04)] - [TestCase(04, 05)] - [TestCase(05, 00)] - [TestCase(00, 01)] - [TestCase(01, 02)] - [TestCase(02, 03)] - public void Compare_SqlServer(int index0, int index1) - { - var l = Simple(index0, index1, 1, 2); - var r = Simple(index0, index1, 2, 1); + var compare = UuidComparer.SqlServer.Compare(l, r); + Assert.AreEqual(-1, compare); + } - var compare = UuidComparer.SqlServer.Compare(l, r); - Assert.AreEqual(-1, compare); - } + private static Uuid Simple(int i0, int i1, byte v0, byte v1) + { + var bytes = new byte[16]; + bytes[i0] = v0; + bytes[i1] = v1; + return new Guid(bytes); + } - private static Uuid Simple(int i0, int i1, byte v0, byte v1) - { - var bytes = new byte[16]; - bytes[i0] = v0; - bytes[i1] = v1; - return new Guid(bytes); - } + [Test] + public void Compare_Default_IsOrderComarerGuidDefault() + { + var uuids = new List(); - [Test] - public void Compare_Default_IsOrderComarerGuidDefault() + for (var i = 0; i < 1000; i++) { - var uuids = new List(); + uuids.Add(Uuid.NewUuid()); + } + uuids.Sort(UuidComparer.Default); - for (var i = 0; i < 1000; i++) - { - uuids.Add(Uuid.NewUuid()); - } - uuids.Sort(UuidComparer.Default); + CollectionAssert.IsOrdered(uuids, Comparer.Default); + } - CollectionAssert.IsOrdered(uuids, Comparer.Default); - } - - [Test] - public void Compare_NullNull_Zero() - { - Assert.AreEqual(0, UuidComparer.Default.Compare(null, null)); - } + [Test] + public void Compare_NullNull_Zero() + { + Assert.AreEqual(0, UuidComparer.Default.Compare(null, null)); + } - [Test] - public void Compare_NullGuid_Minus1() - { - Assert.AreEqual(-1, UuidComparer.Default.Compare(null, Guid.NewGuid())); - } + [Test] + public void Compare_NullGuid_Minus1() + { + Assert.AreEqual(-1, UuidComparer.Default.Compare(null, Guid.NewGuid())); + } - [Test] - public void Compare_NullUuid_Minus1() - { - Assert.AreEqual(-1, UuidComparer.Default.Compare(null, Uuid.NewUuid())); - } + [Test] + public void Compare_NullUuid_Minus1() + { + Assert.AreEqual(-1, UuidComparer.Default.Compare(null, Uuid.NewUuid())); + } - [Test] - public void Compare_GuidNull_Plus1() - { - Assert.AreEqual(+1, UuidComparer.Default.Compare(Guid.NewGuid(), null)); - } + [Test] + public void Compare_GuidNull_Plus1() + { + Assert.AreEqual(+1, UuidComparer.Default.Compare(Guid.NewGuid(), null)); + } - [Test] - public void Compare_UuidNull_Plus1() - { - Assert.AreEqual(+1, UuidComparer.Default.Compare(Uuid.NewUuid(), null)); - } + [Test] + public void Compare_UuidNull_Plus1() + { + Assert.AreEqual(+1, UuidComparer.Default.Compare(Uuid.NewUuid(), null)); + } - [Test] - public void Compare_GuidUuid_Minus1() - { - Assert.AreEqual(-1, UuidComparer.Default.Compare((object)guid, (object)uuid)); - } + [Test] + public void Compare_GuidUuid_Minus1() + { + Assert.AreEqual(-1, UuidComparer.Default.Compare((object)guid, (object)uuid)); + } - [Test] - public void Compare_UuidGuid_Plus1() - { - Assert.AreEqual(+1, UuidComparer.Default.Compare((object)uuid, (object)guid)); - } + [Test] + public void Compare_UuidGuid_Plus1() + { + Assert.AreEqual(+1, UuidComparer.Default.Compare((object)uuid, (object)guid)); + } - [Test] - public void Compare_UuidObject_Throws() - { - Assert.Throws(() => UuidComparer.Default.Compare((object)uuid, new object())); - } + [Test] + public void Compare_UuidObject_Throws() + { + Assert.Throws(() => UuidComparer.Default.Compare((object)uuid, new object())); } } diff --git a/specs/Qowaiv.Specs/UnitTests.OldStyle/Web/InternetMediaTypeTest.cs b/specs/Qowaiv.Specs/UnitTests.OldStyle/Web/InternetMediaTypeTest.cs index 2fa4976df..cea1a24db 100644 --- a/specs/Qowaiv.Specs/UnitTests.OldStyle/Web/InternetMediaTypeTest.cs +++ b/specs/Qowaiv.Specs/UnitTests.OldStyle/Web/InternetMediaTypeTest.cs @@ -1,764 +1,750 @@ -using FluentAssertions; -using NUnit.Framework; -using Qowaiv.TestTools; -using Qowaiv.TestTools.Globalization; -using Qowaiv.Web; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Xml.Serialization; - -namespace Qowaiv.UnitTests.Web +namespace Qowaiv.UnitTests.Web; + +/// Tests the Internet media type SVO. +public class InternetMediaTypeTest { - /// Tests the Internet media type SVO. - public class InternetMediaTypeTest - { - /// The test instance for most tests. - public static readonly InternetMediaType TestStruct = InternetMediaType.Parse("application/x-chess-pgn"); + /// The test instance for most tests. + public static readonly InternetMediaType TestStruct = InternetMediaType.Parse("application/x-chess-pgn"); - /// Represents text/html. - public static readonly InternetMediaType TextHtml = InternetMediaType.Parse("text/html"); + /// Represents text/html. + public static readonly InternetMediaType TextHtml = InternetMediaType.Parse("text/html"); - /// Represents cooltalk (x-conference/x-cooltalk). - public static readonly InternetMediaType XConferenceXCooltalk = InternetMediaType.Parse("x-conference/x-cooltalk"); + /// Represents cooltalk (x-conference/x-cooltalk). + public static readonly InternetMediaType XConferenceXCooltalk = InternetMediaType.Parse("x-conference/x-cooltalk"); - #region internet media type const tests + #region internet media type const tests - /// InternetMediaType.Empty should be equal to the default of internet media type. - [Test] - public void Empty_None_EqualsDefault() - { - Assert.AreEqual(default(InternetMediaType), InternetMediaType.Empty); - } + /// InternetMediaType.Empty should be equal to the default of internet media type. + [Test] + public void Empty_None_EqualsDefault() + { + Assert.AreEqual(default(InternetMediaType), InternetMediaType.Empty); + } - #endregion + #endregion - #region internet media type IsEmpty tests + #region internet media type IsEmpty tests - /// InternetMediaType.IsEmpty() should be true for the default of internet media type. - [Test] - public void IsEmpty_Default_IsTrue() - { - Assert.IsTrue(default(InternetMediaType).IsEmpty()); - } - /// InternetMediaType.IsEmpty() should be false for InternetMediaType.Unknown. - [Test] - public void IsEmpty_Unknown_IsFalse() - { - Assert.IsFalse(InternetMediaType.Unknown.IsEmpty()); - } - /// InternetMediaType.IsEmpty() should be false for the TestStruct. - [Test] - public void IsEmpty_TestStruct_IsFalse() - { - Assert.IsFalse(TestStruct.IsEmpty()); - } + /// InternetMediaType.IsEmpty() should be true for the default of internet media type. + [Test] + public void IsEmpty_Default_IsTrue() + { + Assert.IsTrue(default(InternetMediaType).IsEmpty()); + } + /// InternetMediaType.IsEmpty() should be false for InternetMediaType.Unknown. + [Test] + public void IsEmpty_Unknown_IsFalse() + { + Assert.IsFalse(InternetMediaType.Unknown.IsEmpty()); + } + /// InternetMediaType.IsEmpty() should be false for the TestStruct. + [Test] + public void IsEmpty_TestStruct_IsFalse() + { + Assert.IsFalse(TestStruct.IsEmpty()); + } - /// InternetMediaType.IsUnknown() should be false for the default of internet media type. - [Test] - public void IsUnknown_Default_IsFalse() - { - Assert.IsFalse(default(InternetMediaType).IsUnknown()); - } - /// InternetMediaType.IsUnknown() should be true for InternetMediaType.Unknown. - [Test] - public void IsUnknown_Unknown_IsTrue() - { - Assert.IsTrue(InternetMediaType.Unknown.IsUnknown()); - } - /// InternetMediaType.IsUnknown() should be false for the TestStruct. - [Test] - public void IsUnknown_TestStruct_IsFalse() - { - Assert.IsFalse(TestStruct.IsUnknown()); - } + /// InternetMediaType.IsUnknown() should be false for the default of internet media type. + [Test] + public void IsUnknown_Default_IsFalse() + { + Assert.IsFalse(default(InternetMediaType).IsUnknown()); + } + /// InternetMediaType.IsUnknown() should be true for InternetMediaType.Unknown. + [Test] + public void IsUnknown_Unknown_IsTrue() + { + Assert.IsTrue(InternetMediaType.Unknown.IsUnknown()); + } + /// InternetMediaType.IsUnknown() should be false for the TestStruct. + [Test] + public void IsUnknown_TestStruct_IsFalse() + { + Assert.IsFalse(TestStruct.IsUnknown()); + } - /// InternetMediaType.IsEmptyOrUnknown() should be true for the default of internet media type. - [Test] - public void IsEmptyOrUnknown_Default_IsFalse() - { - Assert.IsTrue(default(InternetMediaType).IsEmptyOrUnknown()); - } - /// InternetMediaType.IsEmptyOrUnknown() should be true for InternetMediaType.Unknown. - [Test] - public void IsEmptyOrUnknown_Unknown_IsTrue() - { - Assert.IsTrue(InternetMediaType.Unknown.IsEmptyOrUnknown()); - } - /// InternetMediaType.IsEmptyOrUnknown() should be false for the TestStruct. - [Test] - public void IsEmptyOrUnknown_TestStruct_IsFalse() - { - Assert.IsFalse(TestStruct.IsEmptyOrUnknown()); - } + /// InternetMediaType.IsEmptyOrUnknown() should be true for the default of internet media type. + [Test] + public void IsEmptyOrUnknown_Default_IsFalse() + { + Assert.IsTrue(default(InternetMediaType).IsEmptyOrUnknown()); + } + /// InternetMediaType.IsEmptyOrUnknown() should be true for InternetMediaType.Unknown. + [Test] + public void IsEmptyOrUnknown_Unknown_IsTrue() + { + Assert.IsTrue(InternetMediaType.Unknown.IsEmptyOrUnknown()); + } + /// InternetMediaType.IsEmptyOrUnknown() should be false for the TestStruct. + [Test] + public void IsEmptyOrUnknown_TestStruct_IsFalse() + { + Assert.IsFalse(TestStruct.IsEmptyOrUnknown()); + } - #endregion + #endregion - #region TryParse tests + #region TryParse tests - /// TryParse null should be valid. - [Test] - public void TryParse_Null_IsValid() - { - string str = null; + /// TryParse null should be valid. + [Test] + public void TryParse_Null_IsValid() + { + string str = null; - Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); - Assert.AreEqual(string.Empty, val.ToString(), "Value"); - } + Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); + Assert.AreEqual(string.Empty, val.ToString(), "Value"); + } - /// TryParse string.Empty should be valid. - [Test] - public void TryParse_StringEmpty_IsValid() - { + /// TryParse string.Empty should be valid. + [Test] + public void TryParse_StringEmpty_IsValid() + { - string str = string.Empty; + string str = string.Empty; - Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); - Assert.AreEqual(string.Empty, val.ToString(), "Value"); - } + Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); + Assert.AreEqual(string.Empty, val.ToString(), "Value"); + } - /// TryParse "?" should be valid and the result should be InternetMediaType.Unknown. - [Test] - public void TryParse_Questionmark_IsValid() - { - string str = "?"; + /// TryParse "?" should be valid and the result should be InternetMediaType.Unknown. + [Test] + public void TryParse_Questionmark_IsValid() + { + string str = "?"; - Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); - Assert.IsTrue(val.IsUnknown(), "Value"); - } + Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); + Assert.IsTrue(val.IsUnknown(), "Value"); + } - /// TryParse with specified string value should be valid. - [Test] - public void TryParse_StringValue_IsValid() - { - string str = "application/atom+xml"; + /// TryParse with specified string value should be valid. + [Test] + public void TryParse_StringValue_IsValid() + { + string str = "application/atom+xml"; - Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); - Assert.AreEqual(str, val.ToString(), "Value"); - } + Assert.IsTrue(InternetMediaType.TryParse(str, out var val), "Valid"); + Assert.AreEqual(str, val.ToString(), "Value"); + } - /// TryParse with specified string value should be invalid. - [Test] - public void TryParse_StringValue_IsNotValid() - { - string str = "string"; + /// TryParse with specified string value should be invalid. + [Test] + public void TryParse_StringValue_IsNotValid() + { + string str = "string"; - Assert.IsFalse(InternetMediaType.TryParse(str, out var val), "Valid"); - Assert.AreEqual(string.Empty, val.ToString(), "Value"); - } + Assert.IsFalse(InternetMediaType.TryParse(str, out var val), "Valid"); + Assert.AreEqual(string.Empty, val.ToString(), "Value"); + } - [Test] - public void Parse_Unknown_AreEqual() + [Test] + public void Parse_Unknown_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) - { - var act = InternetMediaType.Parse("?"); - var exp = InternetMediaType.Unknown; - Assert.AreEqual(exp, act); - } + var act = InternetMediaType.Parse("?"); + var exp = InternetMediaType.Unknown; + Assert.AreEqual(exp, act); } + } - [Test] - public void Parse_InvalidInput_ThrowsFormatException() + [Test] + public void Parse_InvalidInput_ThrowsFormatException() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) + Assert.Catch + (() => { - Assert.Catch - (() => - { - InternetMediaType.Parse("InvalidInput"); - }, - "Not a valid internet media type"); - } + InternetMediaType.Parse("InvalidInput"); + }, + "Not a valid internet media type"); } + } - [Test] - public void TryParse_TestStructInput_AreEqual() + [Test] + public void TryParse_TestStructInput_AreEqual() + { + using (TestCultures.En_GB.Scoped()) { - using (TestCultures.En_GB.Scoped()) - { - var exp = TestStruct; - var act = InternetMediaType.TryParse(exp.ToString()); + var exp = TestStruct; + var act = InternetMediaType.TryParse(exp.ToString()); - Assert.AreEqual(exp, act); - } + Assert.AreEqual(exp, act); } + } - [Test] - public void from_invalid_as_null_with_TryParse() - => InternetMediaType.TryParse("invalid input").Should().BeNull(); - - #endregion - - #region FromFile tests - - [Test] - public void FromFile_NullFileInfo_Empty() - { - var act = InternetMediaType.FromFile((FileInfo)null); - var exp = InternetMediaType.Empty; + [Test] + public void from_invalid_as_null_with_TryParse() + => InternetMediaType.TryParse("invalid input").Should().BeNull(); - Assert.AreEqual(exp, act); - } + #endregion - [Test] - public void FromFile_NullString_Empty() - { - var act = InternetMediaType.FromFile(Nil.String); - var exp = InternetMediaType.Empty; + #region FromFile tests - Assert.AreEqual(exp, act); - } + [Test] + public void FromFile_NullFileInfo_Empty() + { + var act = InternetMediaType.FromFile((FileInfo)null); + var exp = InternetMediaType.Empty; - [Test] - public void FromFile__StringEmpty_Empty() - { - var act = InternetMediaType.FromFile(string.Empty); - var exp = InternetMediaType.Empty; + Assert.AreEqual(exp, act); + } - Assert.AreEqual(exp, act); - } + [Test] + public void FromFile_NullString_Empty() + { + var act = InternetMediaType.FromFile(Nil.String); + var exp = InternetMediaType.Empty; - [Test] - public void FromFile__GamesDotPgn_ApplicationXChessPgn() - { - var act = InternetMediaType.FromFile(new FileInfo("games.pgn")); - var exp = TestStruct; + Assert.AreEqual(exp, act); + } - Assert.AreEqual(exp, act); - } + [Test] + public void FromFile__StringEmpty_Empty() + { + var act = InternetMediaType.FromFile(string.Empty); + var exp = InternetMediaType.Empty; - [Test] - public void FromFile__TestDotUnknown_Unknown() - { - var act = InternetMediaType.FromFile(new FileInfo("test.unknown")); - var exp = InternetMediaType.Unknown; + Assert.AreEqual(exp, act); + } - Assert.AreEqual(exp, act); - } + [Test] + public void FromFile__GamesDotPgn_ApplicationXChessPgn() + { + var act = InternetMediaType.FromFile(new FileInfo("games.pgn")); + var exp = TestStruct; - #endregion + Assert.AreEqual(exp, act); + } - #region (XML) (De)serialization tests + [Test] + public void FromFile__TestDotUnknown_Unknown() + { + var act = InternetMediaType.FromFile(new FileInfo("test.unknown")); + var exp = InternetMediaType.Unknown; - [Test] - public void GetObjectData_SerializationInfo_AreEqual() - { - ISerializable obj = TestStruct; - var info = new SerializationInfo(typeof(InternetMediaType), new System.Runtime.Serialization.FormatterConverter()); - obj.GetObjectData(info, default); + Assert.AreEqual(exp, act); + } - Assert.AreEqual("application/x-chess-pgn", info.GetString("Value")); - } + #endregion - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp, act); - } - [Test] - public void DataContractSerializeDeserialize_TestStruct_AreEqual() - { - var input = TestStruct; - var exp = TestStruct; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp, act); - } + #region (XML) (De)serialization tests - [Test] - public void XmlSerialize_TestStruct_AreEqual() - { - var act = Serialize.Xml(TestStruct); - var exp = "application/x-chess-pgn"; - Assert.AreEqual(exp, act); - } + [Test] + public void GetObjectData_SerializationInfo_AreEqual() + { + ISerializable obj = TestStruct; + var info = new SerializationInfo(typeof(InternetMediaType), new System.Runtime.Serialization.FormatterConverter()); + obj.GetObjectData(info, default); - [Test] - public void XmlDeserialize_XmlString_AreEqual() - { - var act =Deserialize.Xml("application/x-chess-pgn"); - Assert.AreEqual(TestStruct, act); - } + Assert.AreEqual("application/x-chess-pgn", info.GetString("Value")); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() - { - var input = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void XmlSerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() - { - var input = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void DataContractSerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() - { - var input = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var exp = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = TestStruct, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.DataContract(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp, act); + } + [Test] + public void DataContractSerializeDeserialize_TestStruct_AreEqual() + { + var input = TestStruct; + var exp = TestStruct; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp, act); + } - [Test] - [Obsolete("Usage of the binary formatter is considered harmful.")] - public void SerializeDeserialize_Empty_AreEqual() - { - var input = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = InternetMediaType.Empty, - Date = new DateTime(1970, 02, 14), - }; - var exp = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = InternetMediaType.Empty, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Binary(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } - [Test] - public void XmlSerializeDeserialize_Empty_AreEqual() - { - var input = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = InternetMediaType.Empty, - Date = new DateTime(1970, 02, 14), - }; - var exp = new InternetMediaTypeSerializeObject - { - Id = 17, - Obj = InternetMediaType.Empty, - Date = new DateTime(1970, 02, 14), - }; - var act = SerializeDeserialize.Xml(input); - Assert.AreEqual(exp.Id, act.Id, "Id"); - Assert.AreEqual(exp.Obj, act.Obj, "Obj"); - Assert.AreEqual(exp.Date, act.Date, "Date"); - } + [Test] + public void XmlSerialize_TestStruct_AreEqual() + { + var act = Serialize.Xml(TestStruct); + var exp = "application/x-chess-pgn"; + Assert.AreEqual(exp, act); + } - [Test] - public void GetSchema_None_IsNull() - { - IXmlSerializable obj = TestStruct; - Assert.IsNull(obj.GetSchema()); - } + [Test] + public void XmlDeserialize_XmlString_AreEqual() + { + var act =Deserialize.Xml("application/x-chess-pgn"); + Assert.AreEqual(TestStruct, act); + } - #endregion + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() + { + var input = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void XmlSerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() + { + var input = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void DataContractSerializeDeserialize_InternetMediaTypeSerializeObject_AreEqual() + { + var input = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var exp = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = TestStruct, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.DataContract(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - #region IFormattable / ToString tests + [Test] + [Obsolete("Usage of the binary formatter is considered harmful.")] + public void SerializeDeserialize_Empty_AreEqual() + { + var input = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = InternetMediaType.Empty, + Date = new DateTime(1970, 02, 14), + }; + var exp = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = InternetMediaType.Empty, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Binary(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } + [Test] + public void XmlSerializeDeserialize_Empty_AreEqual() + { + var input = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = InternetMediaType.Empty, + Date = new DateTime(1970, 02, 14), + }; + var exp = new InternetMediaTypeSerializeObject + { + Id = 17, + Obj = InternetMediaType.Empty, + Date = new DateTime(1970, 02, 14), + }; + var act = SerializeDeserialize.Xml(input); + Assert.AreEqual(exp.Id, act.Id, "Id"); + Assert.AreEqual(exp.Obj, act.Obj, "Obj"); + Assert.AreEqual(exp.Date, act.Date, "Date"); + } - [Test] - public void ToString_Empty_StringEmpty() - { - var act = InternetMediaType.Empty.ToString(); - var exp = ""; - Assert.AreEqual(exp, act); - } + [Test] + public void GetSchema_None_IsNull() + { + IXmlSerializable obj = TestStruct; + Assert.IsNull(obj.GetSchema()); + } - [Test] - public void ToString_Unknown_QuestionMark() - { - var act = InternetMediaType.Unknown.ToString(); - var exp = "application/octet-stream"; - Assert.AreEqual(exp, act); - } + #endregion - [Test] - public void ToString_CustomFormatter_SupportsCustomFormatting() - { - var act = TestStruct.ToString("Unit Test Format", FormatProvider.CustomFormatter); - var exp = "Unit Test Formatter, value: 'application/x-chess-pgn', format: 'Unit Test Format'"; + #region IFormattable / ToString tests - Assert.AreEqual(exp, act); - } - [Test] - public void ToString_TestStruct_ComplexPattern() - { - var act = TestStruct.ToString(string.Empty); - var exp = "application/x-chess-pgn"; - Assert.AreEqual(exp, act); - } + [Test] + public void ToString_Empty_StringEmpty() + { + var act = InternetMediaType.Empty.ToString(); + var exp = ""; + Assert.AreEqual(exp, act); + } - #endregion + [Test] + public void ToString_Unknown_QuestionMark() + { + var act = InternetMediaType.Unknown.ToString(); + var exp = "application/octet-stream"; + Assert.AreEqual(exp, act); + } - #region IEquatable tests + [Test] + public void ToString_CustomFormatter_SupportsCustomFormatting() + { + var act = TestStruct.ToString("Unit Test Format", FormatProvider.CustomFormatter); + var exp = "Unit Test Formatter, value: 'application/x-chess-pgn', format: 'Unit Test Format'"; - /// GetHash should not fail for InternetMediaType.Empty. - [Test] - public void GetHash_Empty_0() - { - Assert.AreEqual(0, InternetMediaType.Empty.GetHashCode()); - } + Assert.AreEqual(exp, act); + } + [Test] + public void ToString_TestStruct_ComplexPattern() + { + var act = TestStruct.ToString(string.Empty); + var exp = "application/x-chess-pgn"; + Assert.AreEqual(exp, act); + } - /// GetHash should not fail for the test struct. - [Test] - public void GetHash_TestStruct_NotZero() - { - Assert.NotZero(TestStruct.GetHashCode()); - } + #endregion - [Test] - public void Equals_EmptyEmpty_IsTrue() - { - Assert.IsTrue(InternetMediaType.Empty.Equals(InternetMediaType.Empty)); - } + #region IEquatable tests - [Test] - public void Equals_FormattedAndUnformatted_IsTrue() - { - var l = InternetMediaType.Parse("application/x-chess-pgn"); - var r = InternetMediaType.Parse("application/X-chess-PGN"); + /// GetHash should not fail for InternetMediaType.Empty. + [Test] + public void GetHash_Empty_0() + { + Assert.AreEqual(0, InternetMediaType.Empty.GetHashCode()); + } - Assert.IsTrue(l.Equals(r)); - } + /// GetHash should not fail for the test struct. + [Test] + public void GetHash_TestStruct_NotZero() + { + Assert.NotZero(TestStruct.GetHashCode()); + } - [Test] - public void Equals_TestStructTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals(TestStruct)); - } + [Test] + public void Equals_EmptyEmpty_IsTrue() + { + Assert.IsTrue(InternetMediaType.Empty.Equals(InternetMediaType.Empty)); + } - [Test] - public void Equals_TestStructEmpty_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(InternetMediaType.Empty)); - } + [Test] + public void Equals_FormattedAndUnformatted_IsTrue() + { + var l = InternetMediaType.Parse("application/x-chess-pgn"); + var r = InternetMediaType.Parse("application/X-chess-PGN"); - [Test] - public void Equals_EmptyTestStruct_IsFalse() - { - Assert.IsFalse(InternetMediaType.Empty.Equals(TestStruct)); - } + Assert.IsTrue(l.Equals(r)); + } - [Test] - public void Equals_TestStructObjectTestStruct_IsTrue() - { - Assert.IsTrue(TestStruct.Equals((object)TestStruct)); - } + [Test] + public void Equals_TestStructTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals(TestStruct)); + } - [Test] - public void Equals_TestStructNull_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(null)); - } + [Test] + public void Equals_TestStructEmpty_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(InternetMediaType.Empty)); + } - [Test] - public void Equals_TestStructObject_IsFalse() - { - Assert.IsFalse(TestStruct.Equals(new object())); - } + [Test] + public void Equals_EmptyTestStruct_IsFalse() + { + Assert.IsFalse(InternetMediaType.Empty.Equals(TestStruct)); + } - [Test] - public void OperatorIs_TestStructTestStruct_IsTrue() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsTrue(l == r); - } + [Test] + public void Equals_TestStructObjectTestStruct_IsTrue() + { + Assert.IsTrue(TestStruct.Equals((object)TestStruct)); + } - [Test] - public void OperatorIsNot_TestStructTestStruct_IsFalse() - { - var l = TestStruct; - var r = TestStruct; - Assert.IsFalse(l != r); - } + [Test] + public void Equals_TestStructNull_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(null)); + } - #endregion + [Test] + public void Equals_TestStructObject_IsFalse() + { + Assert.IsFalse(TestStruct.Equals(new object())); + } - #region IComparable tests + [Test] + public void OperatorIs_TestStructTestStruct_IsTrue() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsTrue(l == r); + } - /// Orders a list of internet media types ascending. - [Test] - public void OrderBy_InternetMediaType_AreEqual() - { - var item0 = InternetMediaType.Parse("audio/mp3"); - var item1 = InternetMediaType.Parse("image/jpeg"); - var item2 = InternetMediaType.Parse("text/x-markdown"); - var item3 = InternetMediaType.Parse("video/quicktime"); + [Test] + public void OperatorIsNot_TestStructTestStruct_IsFalse() + { + var l = TestStruct; + var r = TestStruct; + Assert.IsFalse(l != r); + } - var inp = new List { InternetMediaType.Empty, item3, item2, item0, item1, InternetMediaType.Empty }; - var exp = new List { InternetMediaType.Empty, InternetMediaType.Empty, item0, item1, item2, item3 }; - var act = inp.OrderBy(item => item).ToList(); + #endregion - CollectionAssert.AreEqual(exp, act); - } + #region IComparable tests - /// Orders a list of internet media types descending. - [Test] - public void OrderByDescending_InternetMediaType_AreEqual() - { - var item0 = InternetMediaType.Parse("audio/mp3"); - var item1 = InternetMediaType.Parse("image/jpeg"); - var item2 = InternetMediaType.Parse("text/x-markdown"); - var item3 = InternetMediaType.Parse("video/quicktime"); + /// Orders a list of internet media types ascending. + [Test] + public void OrderBy_InternetMediaType_AreEqual() + { + var item0 = InternetMediaType.Parse("audio/mp3"); + var item1 = InternetMediaType.Parse("image/jpeg"); + var item2 = InternetMediaType.Parse("text/x-markdown"); + var item3 = InternetMediaType.Parse("video/quicktime"); - var inp = new List { InternetMediaType.Empty, item3, item2, item0, item1, InternetMediaType.Empty }; - var exp = new List { item3, item2, item1, item0, InternetMediaType.Empty, InternetMediaType.Empty }; - var act = inp.OrderByDescending(item => item).ToList(); + var inp = new List { InternetMediaType.Empty, item3, item2, item0, item1, InternetMediaType.Empty }; + var exp = new List { InternetMediaType.Empty, InternetMediaType.Empty, item0, item1, item2, item3 }; + var act = inp.OrderBy(item => item).ToList(); - CollectionAssert.AreEqual(exp, act); - } + CollectionAssert.AreEqual(exp, act); + } - /// Compare with a to object casted instance should be fine. - [Test] - public void CompareTo_ObjectTestStruct_0() - { - object other = TestStruct; + /// Orders a list of internet media types descending. + [Test] + public void OrderByDescending_InternetMediaType_AreEqual() + { + var item0 = InternetMediaType.Parse("audio/mp3"); + var item1 = InternetMediaType.Parse("image/jpeg"); + var item2 = InternetMediaType.Parse("text/x-markdown"); + var item3 = InternetMediaType.Parse("video/quicktime"); - var exp = 0; - var act = TestStruct.CompareTo(other); + var inp = new List { InternetMediaType.Empty, item3, item2, item0, item1, InternetMediaType.Empty }; + var exp = new List { item3, item2, item1, item0, InternetMediaType.Empty, InternetMediaType.Empty }; + var act = inp.OrderByDescending(item => item).ToList(); - Assert.AreEqual(exp, act); - } + CollectionAssert.AreEqual(exp, act); + } - /// Compare with null should return 1. - [Test] - public void CompareTo_null_1() - { - object @null = null; - Assert.AreEqual(1, TestStruct.CompareTo(@null)); - } + /// Compare with a to object casted instance should be fine. + [Test] + public void CompareTo_ObjectTestStruct_0() + { + object other = TestStruct; - /// Compare with a random object should throw an exception. - [Test] - public void CompareTo_newObject_ThrowsArgumentException() - { - Func compare = () => TestStruct.CompareTo(new object()); - compare.Should().Throw(); - } - #endregion + var exp = 0; + var act = TestStruct.CompareTo(other); - #region Properties + Assert.AreEqual(exp, act); + } - [Test] - public void Length_DefaultValue_0() - { - var exp = 0; - var act = InternetMediaType.Empty.Length; - Assert.AreEqual(exp, act); - } - [Test] - public void Length_TestStruct_23() - { - var exp = 23; - var act = TestStruct.Length; - Assert.AreEqual(exp, act); - } + /// Compare with null should return 1. + [Test] + public void CompareTo_null_1() + { + object @null = null; + Assert.AreEqual(1, TestStruct.CompareTo(@null)); + } - [Test] - public void TopLevel_DefaultValue_0() - { - var exp = string.Empty; - var act = InternetMediaType.Empty.TopLevel; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevel_TextHtml_Text() - { - var exp = "text"; - var act = TextHtml.TopLevel; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevel_XConferenceXCooltalk_XConference() - { - var exp = "x-conference"; - var act = XConferenceXCooltalk.TopLevel; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevel_TestStruct_Application() - { - var exp = "application"; - var act = TestStruct.TopLevel; - Assert.AreEqual(exp, act); - } + /// Compare with a random object should throw an exception. + [Test] + public void CompareTo_newObject_ThrowsArgumentException() + { + Func compare = () => TestStruct.CompareTo(new object()); + compare.Should().Throw(); + } + #endregion - [Test] - public void TopLevelType_DefaultValue_0() - { - var exp = InternetMediaTopLevelType.None; - var act = InternetMediaType.Empty.TopLevelType; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevelType_TextHtml_Text() - { - var exp = InternetMediaTopLevelType.Text; - var act = TextHtml.TopLevelType; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevelType_XConferenceXCooltalk_Unregistered() - { - var exp = InternetMediaTopLevelType.Unregistered; - var act = XConferenceXCooltalk.TopLevelType; - Assert.AreEqual(exp, act); - } - [Test] - public void TopLevelType_TestStruct_Application() - { - var exp = InternetMediaTopLevelType.Application; - var act = TestStruct.TopLevelType; - Assert.AreEqual(exp, act); - } + #region Properties - [Test] - public void Subtype_DefaultValue_0() - { - var exp = string.Empty; - var act = InternetMediaType.Empty.Subtype; - Assert.AreEqual(exp, act); - } - [Test] - public void Subtype_TextHtml_Html() - { - var exp = "html"; - var act = TextHtml.Subtype; - Assert.AreEqual(exp, act); - } - [Test] - public void Subtype_XConferenceXCooltalk_XCooltalk() - { - var exp = "x-cooltalk"; - var act = XConferenceXCooltalk.Subtype; - Assert.AreEqual(exp, act); - } - [Test] - public void Subtype_TestStruct_XChessPgn() - { - var exp = "x-chess-pgn"; - var act = TestStruct.Subtype; - Assert.AreEqual(exp, act); - } + [Test] + public void Length_DefaultValue_0() + { + var exp = 0; + var act = InternetMediaType.Empty.Length; + Assert.AreEqual(exp, act); + } + [Test] + public void Length_TestStruct_23() + { + var exp = 23; + var act = TestStruct.Length; + Assert.AreEqual(exp, act); + } - [Test] - public void IsRegistered_DefaultValue_IsFalse() - { - var exp = false; - var act = InternetMediaType.Empty.IsRegistered; - Assert.AreEqual(exp, act); - } - [Test] - public void IsRegistered_TextHtml_IsTrue() - { - var exp = true; - var act = TextHtml.IsRegistered; - Assert.AreEqual(exp, act); - } - [Test] - public void IsRegistered_XConferenceXCooltalk_IsFalse() - { - var exp = false; - var act = XConferenceXCooltalk.IsRegistered; - Assert.AreEqual(exp, act); - } - [Test] - public void IsRegistered_TestStruct_IsFalse() - { - var exp = false; - var act = TestStruct.IsRegistered; - Assert.AreEqual(exp, act); - } - [Test] - public void IsRegistered_VideoSlashXDotTest_IsFalse() - { - var mime = InternetMediaType.Parse("video/x.test"); - var exp = false; - var act = mime.IsRegistered; - Assert.AreEqual(exp, act); - } + [Test] + public void TopLevel_DefaultValue_0() + { + var exp = string.Empty; + var act = InternetMediaType.Empty.TopLevel; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevel_TextHtml_Text() + { + var exp = "text"; + var act = TextHtml.TopLevel; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevel_XConferenceXCooltalk_XConference() + { + var exp = "x-conference"; + var act = XConferenceXCooltalk.TopLevel; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevel_TestStruct_Application() + { + var exp = "application"; + var act = TestStruct.TopLevel; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevelType_DefaultValue_0() + { + var exp = InternetMediaTopLevelType.None; + var act = InternetMediaType.Empty.TopLevelType; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevelType_TextHtml_Text() + { + var exp = InternetMediaTopLevelType.Text; + var act = TextHtml.TopLevelType; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevelType_XConferenceXCooltalk_Unregistered() + { + var exp = InternetMediaTopLevelType.Unregistered; + var act = XConferenceXCooltalk.TopLevelType; + Assert.AreEqual(exp, act); + } + [Test] + public void TopLevelType_TestStruct_Application() + { + var exp = InternetMediaTopLevelType.Application; + var act = TestStruct.TopLevelType; + Assert.AreEqual(exp, act); + } - [Test] - public void Suffix_DefaultValue_None() - { - var exp = InternetMediaSuffixType.None; - var act = InternetMediaType.Empty.Suffix; - Assert.AreEqual(exp, act); - } + [Test] + public void Subtype_DefaultValue_0() + { + var exp = string.Empty; + var act = InternetMediaType.Empty.Subtype; + Assert.AreEqual(exp, act); + } + [Test] + public void Subtype_TextHtml_Html() + { + var exp = "html"; + var act = TextHtml.Subtype; + Assert.AreEqual(exp, act); + } + [Test] + public void Subtype_XConferenceXCooltalk_XCooltalk() + { + var exp = "x-cooltalk"; + var act = XConferenceXCooltalk.Subtype; + Assert.AreEqual(exp, act); + } + [Test] + public void Subtype_TestStruct_XChessPgn() + { + var exp = "x-chess-pgn"; + var act = TestStruct.Subtype; + Assert.AreEqual(exp, act); + } - [Test] - public void Suffix_TestStruct_None() - { - var exp = InternetMediaSuffixType.None; - var act = TestStruct.Suffix; - Assert.AreEqual(exp, act); - } - [Test] - public void Suffix_ApplicationAtomXml_Xml() - { - var mime = InternetMediaType.Parse("application/atom+xml"); + [Test] + public void IsRegistered_DefaultValue_IsFalse() + { + var exp = false; + var act = InternetMediaType.Empty.IsRegistered; + Assert.AreEqual(exp, act); + } + [Test] + public void IsRegistered_TextHtml_IsTrue() + { + var exp = true; + var act = TextHtml.IsRegistered; + Assert.AreEqual(exp, act); + } + [Test] + public void IsRegistered_XConferenceXCooltalk_IsFalse() + { + var exp = false; + var act = XConferenceXCooltalk.IsRegistered; + Assert.AreEqual(exp, act); + } + [Test] + public void IsRegistered_TestStruct_IsFalse() + { + var exp = false; + var act = TestStruct.IsRegistered; + Assert.AreEqual(exp, act); + } + [Test] + public void IsRegistered_VideoSlashXDotTest_IsFalse() + { + var mime = InternetMediaType.Parse("video/x.test"); + var exp = false; + var act = mime.IsRegistered; + Assert.AreEqual(exp, act); + } - var exp = InternetMediaSuffixType.xml; - var act = mime.Suffix; - Assert.AreEqual(exp, act); - } - #endregion + [Test] + public void Suffix_DefaultValue_None() + { + var exp = InternetMediaSuffixType.None; + var act = InternetMediaType.Empty.Suffix; + Assert.AreEqual(exp, act); } - [Serializable] - public class InternetMediaTypeSerializeObject + [Test] + public void Suffix_TestStruct_None() { - public int Id { get; set; } - public InternetMediaType Obj { get; set; } - public DateTime Date { get; set; } + var exp = InternetMediaSuffixType.None; + var act = TestStruct.Suffix; + Assert.AreEqual(exp, act); } + [Test] + public void Suffix_ApplicationAtomXml_Xml() + { + var mime = InternetMediaType.Parse("application/atom+xml"); + + var exp = InternetMediaSuffixType.xml; + var act = mime.Suffix; + Assert.AreEqual(exp, act); + } + + #endregion +} + +[Serializable] +public class InternetMediaTypeSerializeObject +{ + public int Id { get; set; } + public InternetMediaType Obj { get; set; } + public DateTime Date { get; set; } } diff --git a/specs/Qowaiv.Specs/Unknown_specs.cs b/specs/Qowaiv.Specs/Unknown_specs.cs index 966e677a3..eb9a673d2 100644 --- a/specs/Qowaiv.Specs/Unknown_specs.cs +++ b/specs/Qowaiv.Specs/Unknown_specs.cs @@ -1,91 +1,86 @@ -using NUnit.Framework; -using Qowaiv; -using System.Globalization; +namespace Unknown_specs; -namespace Unknown_specs +public class Is_unknown { - public class Is_unknown + [Test] + public void question_mark_with_culture() { - [Test] - public void question_mark_with_culture() - { - Assert.IsTrue(Unknown.IsUnknown("?", new CultureInfo("nl-NL"))); - } + Assert.IsTrue(Unknown.IsUnknown("?", new CultureInfo("nl-NL"))); + } - [Test] - public void question_mark_without_culture() - { - Assert.IsTrue(Unknown.IsUnknown("?", null)); - } + [Test] + public void question_mark_without_culture() + { + Assert.IsTrue(Unknown.IsUnknown("?", null)); + } - [Test] - public void language_specific_unknown_for_specific_culture() - { - Assert.IsTrue(Unknown.IsUnknown("Não SABe", new CultureInfo("pt-PT"))); - } + [Test] + public void language_specific_unknown_for_specific_culture() + { + Assert.IsTrue(Unknown.IsUnknown("Não SABe", new CultureInfo("pt-PT"))); } +} - public class Is_not_unknown +public class Is_not_unknown +{ + [Test] + public void Null() { - [Test] - public void Null() - { - Assert.IsFalse(Unknown.IsUnknown(null)); - } + Assert.IsFalse(Unknown.IsUnknown(null)); + } - [Test] - public void string_empty() - { - Assert.IsFalse(Unknown.IsUnknown(string.Empty)); - } + [Test] + public void string_empty() + { + Assert.IsFalse(Unknown.IsUnknown(string.Empty)); + } - [Test] - public void string_not_representing_unknown_for_specified_culture() - { - Assert.IsFalse(Unknown.IsUnknown("onbekend", CultureInfo.InvariantCulture)); - } + [Test] + public void string_not_representing_unknown_for_specified_culture() + { + Assert.IsFalse(Unknown.IsUnknown("onbekend", CultureInfo.InvariantCulture)); } - - public class Can_be_resolved_for +} + +public class Can_be_resolved_for +{ + [Test] + public void value_type_with_unknown_value() + { + Assert.AreEqual(PostalCode.Unknown, Unknown.Value(typeof(PostalCode))); + } + [Test] + public void reference_type_with_unknown_value() { - [Test] - public void value_type_with_unknown_value() - { - Assert.AreEqual(PostalCode.Unknown, Unknown.Value(typeof(PostalCode))); - } - [Test] - public void reference_type_with_unknown_value() - { - Assert.AreEqual(ClassWithUnknownValue.Unknown, Unknown.Value(typeof(ClassWithUnknownValue))); - } - - private class ClassWithUnknownValue - { - public static ClassWithUnknownValue Unknown { get; } = new ClassWithUnknownValue(); - } + Assert.AreEqual(ClassWithUnknownValue.Unknown, Unknown.Value(typeof(ClassWithUnknownValue))); } - public class Can_not_be_resolved_for + + private class ClassWithUnknownValue { - [Test] - public void null_type() - => Assert.IsNull(Unknown.Value(null)); + public static ClassWithUnknownValue Unknown { get; } = new ClassWithUnknownValue(); + } +} +public class Can_not_be_resolved_for +{ + [Test] + public void null_type() + => Assert.IsNull(Unknown.Value(null)); - [Test] - public void value_type_without_unknown_value() - => Assert.IsNull(Unknown.Value(typeof(Uuid))); + [Test] + public void value_type_without_unknown_value() + => Assert.IsNull(Unknown.Value(typeof(Uuid))); - [Test] - public void value_type_with_unknown_value_of_wrong_type() - => Assert.IsNull(Unknown.Value(typeof(ClassWithUnknownValueOfWrongType))); + [Test] + public void value_type_with_unknown_value_of_wrong_type() + => Assert.IsNull(Unknown.Value(typeof(ClassWithUnknownValueOfWrongType))); - [Test] - public void reference_type_without_unknown_value() - => Assert.IsNull(Unknown.Value(typeof(object))); + [Test] + public void reference_type_without_unknown_value() + => Assert.IsNull(Unknown.Value(typeof(object))); - private class ClassWithUnknownValueOfWrongType - { - private ClassWithUnknownValueOfWrongType() { } - public static object Unknown { get; } = new object(); - } + private class ClassWithUnknownValueOfWrongType + { + private ClassWithUnknownValueOfWrongType() { } + public static object Unknown { get; } = new object(); } } diff --git a/src/Qowaiv.TestTools/JsonTester.cs b/src/Qowaiv.TestTools/JsonTester.cs index 8057d951b..871df7e26 100644 --- a/src/Qowaiv.TestTools/JsonTester.cs +++ b/src/Qowaiv.TestTools/JsonTester.cs @@ -56,12 +56,9 @@ static string ToString(object? val) var parameterType = val?.GetType(); var fromJson = typeof(T) .GetMethods(BindingFlags.Static | BindingFlags.Public) - .Find(m => FromJson(m, parameterType)); + .Find(m => FromJson(m, parameterType)) + ?? throw new InvalidOperationException($"Could not find {typeof(T).Name}.FromJson({parameterType?.Name ?? "null"})."); - if (fromJson is null) - { - throw new InvalidOperationException($"Could not find {typeof(T).Name}.FromJson({parameterType?.Name ?? "null"})."); - } try { return (T?)fromJson.Invoke(null, new[] { val }); diff --git a/src/Qowaiv.TestTools/Properties/GlobalUsings.cs b/src/Qowaiv.TestTools/Properties/GlobalUsings.cs index 4d31757d3..259bd0ab5 100644 --- a/src/Qowaiv.TestTools/Properties/GlobalUsings.cs +++ b/src/Qowaiv.TestTools/Properties/GlobalUsings.cs @@ -1,5 +1,4 @@ global using Qowaiv; -global using Qowaiv.Diagnostics; global using Qowaiv.Diagnostics.Contracts; global using System; global using System.Collections; diff --git a/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs b/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs index dff3c20d2..eaf138434 100644 --- a/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs +++ b/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs @@ -221,10 +221,7 @@ public string Format(string format, params object[] args) } } - if (fmt == null) - { - fmt = new StringBuilder(); - } + fmt ??= new StringBuilder(); fmt.Append(ch); } } @@ -267,7 +264,7 @@ public string Format(string format, params object[] args) } } - if (s == null) s = string.Empty; + s ??= string.Empty; int pad = width - s.Length; if (!leftJustify && pad > 0) sb.Append(' ', pad); sb.Append(s); diff --git a/src/Qowaiv/Formatting/StringFormatter.cs b/src/Qowaiv/Formatting/StringFormatter.cs index 1dd38440b..de84274c1 100644 --- a/src/Qowaiv/Formatting/StringFormatter.cs +++ b/src/Qowaiv/Formatting/StringFormatter.cs @@ -133,7 +133,7 @@ public static bool TryApplyCustomFormatter(string? format, object obj, IFormatPr /// The string to remove the diacritics from. /// [Pure] - [return: NotNullIfNotNull("str")] + [return: NotNullIfNotNull(nameof(str))] public static string? ToNonDiacritic(string? str) => ToNonDiacritic(str, string.Empty); @@ -145,7 +145,7 @@ public static bool TryApplyCustomFormatter(string? format, object obj, IFormatPr /// Diacritics at the ignore, will not be changed. /// [Pure] - [return: NotNullIfNotNull("str")] + [return: NotNullIfNotNull(nameof(str))] public static string? ToNonDiacritic(string? str, string ignore) => string.IsNullOrEmpty(str) ? str diff --git a/src/Qowaiv/Globalization/CountryToCurrency.cs b/src/Qowaiv/Globalization/CountryToCurrency.cs index c6d9d9643..9c2777506 100644 --- a/src/Qowaiv/Globalization/CountryToCurrency.cs +++ b/src/Qowaiv/Globalization/CountryToCurrency.cs @@ -2,7 +2,7 @@ namespace Qowaiv.Globalization; -internal partial struct CountryToCurrency : IEquatable +internal readonly partial struct CountryToCurrency : IEquatable { public CountryToCurrency(Country country, Currency currency, Date startdate) { diff --git a/src/Qowaiv/Globalization/CountryToCurrencyMappings.cs b/src/Qowaiv/Globalization/CountryToCurrencyMappings.cs index bbecdcd32..472b16efd 100644 --- a/src/Qowaiv/Globalization/CountryToCurrencyMappings.cs +++ b/src/Qowaiv/Globalization/CountryToCurrencyMappings.cs @@ -3,7 +3,7 @@ namespace Qowaiv.Globalization; -internal partial struct CountryToCurrency +internal readonly partial struct CountryToCurrency { public static readonly ReadOnlyCollection All = new(new List { diff --git a/src/Qowaiv/Text/CharBuffer.cs b/src/Qowaiv/Text/CharBuffer.cs index 41d96c2fb..c9f2e0a00 100644 --- a/src/Qowaiv/Text/CharBuffer.cs +++ b/src/Qowaiv/Text/CharBuffer.cs @@ -1,7 +1,5 @@ #nullable enable -using System.Runtime.CompilerServices; - namespace Qowaiv.Text; internal sealed partial class CharBuffer : IEnumerable