From a3099bd42e2c75b2d5441415abd0722dcfab090c Mon Sep 17 00:00:00 2001 From: ildoc Date: Wed, 15 Jan 2025 11:20:18 +0100 Subject: [PATCH] close #28 --- src/Extensions/RandomExtensions.cs | 6 +- tests/Extensions.Tests/CharExtensionsTests.cs | 9 ++- .../DateTimeExtensionsTests.cs | 10 +-- .../DictionaryExtensionsTests.cs | 24 +++--- tests/Extensions.Tests/EnumExtensionsTests.cs | 4 +- .../Extensions.Tests/Extensions.Tests.csproj | 2 +- .../GenericExtensionsTests.cs | 36 +++++---- .../ICollectionExtensionsTests.cs | 8 +- .../IEnumerableExtensionsTests.cs | 6 +- .../IQueryableExtensionsTests.cs | 3 +- tests/Extensions.Tests/IntExtensionsTests.cs | 4 +- .../Extensions.Tests/RandomExtensionsTests.cs | 6 +- .../Extensions.Tests/StringExtensionsTests.cs | 81 ++++++++++--------- 13 files changed, 103 insertions(+), 96 deletions(-) diff --git a/src/Extensions/RandomExtensions.cs b/src/Extensions/RandomExtensions.cs index d66de73..9cbefe3 100644 --- a/src/Extensions/RandomExtensions.cs +++ b/src/Extensions/RandomExtensions.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Drawing; +using System.Linq; namespace Extensions { @@ -10,9 +12,9 @@ public static class RandomExtensions public static DateTime NextDatetime(this Random random, in DateTime from, in DateTime to) => from + new TimeSpan((long)(random.NextDouble() * (to - from).Ticks)); - public static T OneOf(this Random random, params T[] values) + public static T OneOf(this Random random, IEnumerable values) { - return values[random.Next(values.Length)]; + return values.ElementAt(random.Next(values.Count())); } public static string NextHexColor(this Random random) diff --git a/tests/Extensions.Tests/CharExtensionsTests.cs b/tests/Extensions.Tests/CharExtensionsTests.cs index 3691530..4cb6727 100644 --- a/tests/Extensions.Tests/CharExtensionsTests.cs +++ b/tests/Extensions.Tests/CharExtensionsTests.cs @@ -1,4 +1,5 @@ -using Xunit; +using Shouldly; +using Xunit; namespace Extensions.Tests { @@ -10,7 +11,7 @@ public class CharExtensionsTests [InlineData(' ', ' ')] public void ShouldTransformToUppercase(char value, char expected) { - Assert.Equal(expected, value.ToUpper()); + value.ToUpper().ShouldBe(expected); } [Theory] @@ -19,7 +20,7 @@ public void ShouldTransformToUppercase(char value, char expected) [InlineData(' ', ' ')] public void ShouldTransformToLowercase(char value, char expected) { - Assert.Equal(expected, value.ToLower()); + value.ToLower().ShouldBe(expected); } [Theory] @@ -28,7 +29,7 @@ public void ShouldTransformToLowercase(char value, char expected) [InlineData(' ', false)] public void ShouldReturnIfIsAlphabet(char value, bool expected) { - Assert.Equal(expected, value.IsAsciiAlphabetLetter()); + value.IsAsciiAlphabetLetter().ShouldBe(expected); } } } diff --git a/tests/Extensions.Tests/DateTimeExtensionsTests.cs b/tests/Extensions.Tests/DateTimeExtensionsTests.cs index 313f74f..b968869 100644 --- a/tests/Extensions.Tests/DateTimeExtensionsTests.cs +++ b/tests/Extensions.Tests/DateTimeExtensionsTests.cs @@ -1,5 +1,5 @@ using System; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -11,7 +11,7 @@ public void DayStartMinusOneMillisecondIsPreviousDay() { var date = DateTime.Now; - Assert.True(date.DayStart().AddMilliseconds(-1).Date == date.AddDays(-1).Date); + date.DayStart().AddMilliseconds(-1).Date.ShouldBe(date.AddDays(-1).Date); } [Fact] @@ -19,7 +19,7 @@ public void DayEndPlusOneMillisecondIsNextDay() { var date = DateTime.Now; - Assert.True(date.DayEnd().AddMilliseconds(1).Date == date.AddDays(1).Date); + date.DayEnd().AddMilliseconds(1).Date.ShouldBe(date.AddDays(1).Date); } [Fact] @@ -27,7 +27,7 @@ public void ShouldCalculateAgeOnSpecificDate() { var birthday = new DateTime(1990, 6, 22); - birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).Should().Be(31); + birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).ShouldBe(31); } } @@ -43,7 +43,7 @@ public class ObjectExtensionsTests [InlineData(-1.3, true)] public void ShouldCheckIfNumber(object o, bool expected) { - o.IsNumber().Should().Be(expected); + o.IsNumber().ShouldBe(expected); } } } diff --git a/tests/Extensions.Tests/DictionaryExtensionsTests.cs b/tests/Extensions.Tests/DictionaryExtensionsTests.cs index 1483eea..8e992a1 100644 --- a/tests/Extensions.Tests/DictionaryExtensionsTests.cs +++ b/tests/Extensions.Tests/DictionaryExtensionsTests.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using FluentAssertions; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -16,42 +16,42 @@ public void ShouldRunActionForEachItemWhileRemoving() _dict.RemoveAllWithAction(x => x.Key >= 3, x => str += x.Value); - _dict.Should().HaveCount(2); - str.Should().Be("cccddd"); + _dict.Count.ShouldBe(2); + str.ShouldBe("cccddd"); } [Fact] public void ShouldRemoveItemsWhere() { _dict.RemoveAll(x => x.Key >= 3); - _dict.Count.Should().Be(2); + _dict.Count.ShouldBe(2); } [Fact] public void ShouldTryGetValueIfExists() { - _dict.GetValue(2).Should().Be("bbb"); + _dict.GetValue(2).ShouldBe("bbb"); } [Fact] public void ShouldThrowIfValueDontExists() { - var message = Assert.Throws(() => _dict.GetValue(5)).Message; - message.Should().Be("'5' not found in Dictionary"); + var message = Should.Throw(() => _dict.GetValue(5)).Message; + message.ShouldBe("'5' not found in Dictionary"); } [Fact] public void ShouldReturnDefaultIfValueDontExists() { - _dict.GetValueOrDefault(4).Should().Be("ddd"); - _dict.GetValueOrDefault(5).Should().Be(default); + _dict.GetValueOrDefault(4).ShouldBe("ddd"); + _dict.GetValueOrDefault(5).ShouldBe(default); } [Fact] public void ShouldSwapKeyValues() { var outputdict = new Dictionary { { "aaa", 1 }, { "bbb", 2 }, { "ccc", 3 }, { "ddd", 4 } }; - _dict.SwapKeyValue().Should().BeEquivalentTo(outputdict); + _dict.SwapKeyValue().ShouldBeEquivalentTo(outputdict); } [Fact] @@ -60,7 +60,7 @@ public void ShouldRunActionForEachItem() var str = ""; _dict.Each(x => str += x.Value); - str.Should().Be("aaabbbcccddd"); + str.ShouldBe("aaabbbcccddd"); } [Fact] @@ -73,7 +73,7 @@ public void ShouldConvertToDictionary() new KeyValuePair(4,"ddd"), }; - list.ToDictionary().Should().BeEquivalentTo(_dict); + list.ToDictionary().ShouldBeEquivalentTo(_dict); } } } diff --git a/tests/Extensions.Tests/EnumExtensionsTests.cs b/tests/Extensions.Tests/EnumExtensionsTests.cs index 20caaed..79fadab 100644 --- a/tests/Extensions.Tests/EnumExtensionsTests.cs +++ b/tests/Extensions.Tests/EnumExtensionsTests.cs @@ -1,5 +1,5 @@ using System.ComponentModel; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -20,7 +20,7 @@ public enum TestEnum [InlineData(TestEnum.ValueB, "ValueB")] public void ShouldGetDescription(TestEnum testEnumValue, string expected) { - testEnumValue.GetDescription().Should().Be(expected); + testEnumValue.GetDescription().ShouldBe(expected); } } } diff --git a/tests/Extensions.Tests/Extensions.Tests.csproj b/tests/Extensions.Tests/Extensions.Tests.csproj index cfefa75..ec57468 100644 --- a/tests/Extensions.Tests/Extensions.Tests.csproj +++ b/tests/Extensions.Tests/Extensions.Tests.csproj @@ -7,8 +7,8 @@ - + all diff --git a/tests/Extensions.Tests/GenericExtensionsTests.cs b/tests/Extensions.Tests/GenericExtensionsTests.cs index 322f61f..29f62fd 100644 --- a/tests/Extensions.Tests/GenericExtensionsTests.cs +++ b/tests/Extensions.Tests/GenericExtensionsTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -12,7 +12,7 @@ public class GenericExtensionsTests [InlineData(false, false)] public void BoolShouldResolveAsBool(bool value, bool expected) { - value.ToBool().Should().Be(expected); + value.ToBool().ShouldBe(expected); } [Theory] @@ -22,7 +22,7 @@ public void BoolShouldResolveAsBool(bool value, bool expected) [InlineData(-7, true)] public void IntShouldResolveAsBool(int? value, bool expected) { - value.ToBool().Should().Be(expected); + value.ToBool().ShouldBe(expected); } [Theory] @@ -32,7 +32,7 @@ public void IntShouldResolveAsBool(int? value, bool expected) [InlineData("asd", false)] public void StringShouldResolveAsBool(string value, bool expected) { - value.ToBool().Should().Be(expected); + value.ToBool().ShouldBe(expected); } [Theory] @@ -42,7 +42,7 @@ public void StringShouldResolveAsBool(string value, bool expected) [InlineData(-7f, true)] public void FloatShouldResolveAsBool(float? value, bool expected) { - value.ToBool().Should().Be(expected); + value.ToBool().ShouldBe(expected); } [Theory] @@ -52,13 +52,13 @@ public void FloatShouldResolveAsBool(float? value, bool expected) [InlineData(-7.0, true)] public void DoubleShouldResolveAsBool(double? value, bool expected) { - value.ToBool().Should().Be(expected); + value.ToBool().ShouldBe(expected); } [Fact] public void ObjectShouldResolveAsTrue() { - new { Id = 7 }.ToBool().Should().BeTrue(); + new { Id = 7 }.ToBool().ShouldBeTrue(); } [Fact] @@ -66,7 +66,7 @@ public void NullShouldResolveAsFlase() { object value = null; - value.ToBool().Should().BeFalse(); + value.ToBool().ShouldBeFalse(); } [Theory] @@ -74,7 +74,7 @@ public void NullShouldResolveAsFlase() [InlineData('f', "abcd", false)] public void ShouldCheckIfValueIsInString(char value, string fullString, bool expected) { - value.IsIn(fullString).Should().Be(expected); + value.IsIn(fullString).ShouldBe(expected); } [Theory] @@ -82,7 +82,7 @@ public void ShouldCheckIfValueIsInString(char value, string fullString, bool exp [InlineData('f', "abcd", true)] public void ShouldCheckIfValueIsNotInString(char value, string fullString, bool expected) { - value.IsNotIn(fullString).Should().Be(expected); + value.IsNotIn(fullString).ShouldBe(expected); } [Fact] @@ -91,8 +91,8 @@ public void ShouldCheckIfStringIsInStrings() var value = "test"; var strings = new List { "this", "is", "a", "test" }; - value.IsIn(strings).Should().BeTrue(); - value.IsNotIn(strings).Should().BeFalse(); + value.IsIn(strings).ShouldBeTrue(); + value.IsNotIn(strings).ShouldBeFalse(); } [Fact] @@ -101,8 +101,8 @@ public void ShouldCheckIfStringIsNotInStrings() var value = "not"; var strings = new List { "this", "is", "a", "test" }; - value.IsIn(strings).Should().BeFalse(); - value.IsNotIn(strings).Should().BeTrue(); + value.IsIn(strings).ShouldBeFalse(); + value.IsNotIn(strings).ShouldBeTrue(); } [Fact] @@ -117,7 +117,9 @@ public void ShouldCastFromAnonymousObject() var casted = anon.AnonymousCastTo(); - casted.Should().BeEquivalentTo(anon); + casted.Id.ShouldBe(anon.Id); + casted.Description.ShouldBe(anon.Description); + casted.TimeStamp.ShouldBe(anon.TimeStamp); } [Fact] @@ -132,7 +134,7 @@ public void ShouldClone() var b = a.Clone(); - b.Should().BeEquivalentTo(a); + b.ShouldBeEquivalentTo(a); } [Theory] @@ -143,7 +145,7 @@ public void ShouldClone() [InlineData("asd", "asd", true)] public void ShouldReturnEqual(object a, object b, bool expected) { - a.IsEqualTo(b).Should().Be(expected); + a.IsEqualTo(b).ShouldBe(expected); } private class TestClass diff --git a/tests/Extensions.Tests/ICollectionExtensionsTests.cs b/tests/Extensions.Tests/ICollectionExtensionsTests.cs index 4ed5dad..b89d51d 100644 --- a/tests/Extensions.Tests/ICollectionExtensionsTests.cs +++ b/tests/Extensions.Tests/ICollectionExtensionsTests.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -15,8 +15,8 @@ public void AddIf() list.AddIf(_ => false, "Buzz"); // Doesn't add "Buzz" value - list.Should().Contain("Fizz"); - list.Should().NotContain("Buzz"); + list.ShouldContain("Fizz"); + list.ShouldNotContain("Buzz"); } [Fact] @@ -30,7 +30,7 @@ public void AddIfNotContains() list.AddIfNotContains("FizzExisting"); // Doesn't add "FizzExisting" value, the Collection already contains it. // Unit Test - list.Should().HaveCount(2); + list.Count.ShouldBe(2); } } } diff --git a/tests/Extensions.Tests/IEnumerableExtensionsTests.cs b/tests/Extensions.Tests/IEnumerableExtensionsTests.cs index c688139..0213c54 100644 --- a/tests/Extensions.Tests/IEnumerableExtensionsTests.cs +++ b/tests/Extensions.Tests/IEnumerableExtensionsTests.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -10,14 +10,14 @@ public class IEnumerableExtensionsTests public void ShouldJoinListString() { var list = new List { "questa", "è", "una", "lista" }; - list.Join(", ").Should().Be("questa, è, una, lista"); + list.Join(", ").ShouldBe("questa, è, una, lista"); } [Fact] public void ShouldJoinListChar() { var list = new List { "questa", "è", "una", "lista" }; - list.Join(',').Should().Be("questa,è,una,lista"); + list.Join(',').ShouldBe("questa,è,una,lista"); } } } diff --git a/tests/Extensions.Tests/IQueryableExtensionsTests.cs b/tests/Extensions.Tests/IQueryableExtensionsTests.cs index e03b378..d088e96 100644 --- a/tests/Extensions.Tests/IQueryableExtensionsTests.cs +++ b/tests/Extensions.Tests/IQueryableExtensionsTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Extensions.Enums; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -25,7 +26,7 @@ private class TestItem [InlineData(SortingOptions.Descending, "dddcccbbbaaa")] public void ShouldOrderBy(SortingOptions opt, string expected) { - Assert.Equal(expected, _items.OrderBy("Id", opt).Select(x => x.Name).Join("")); + _items.OrderBy("Id", opt).Select(x => x.Name).Join("").ShouldBe(expected); } } } diff --git a/tests/Extensions.Tests/IntExtensionsTests.cs b/tests/Extensions.Tests/IntExtensionsTests.cs index a86ff6d..9281552 100644 --- a/tests/Extensions.Tests/IntExtensionsTests.cs +++ b/tests/Extensions.Tests/IntExtensionsTests.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -12,7 +12,7 @@ public void ShouldExecuteXTimes() 3.Times(() => count++); - count.Should().Be(3); + count.ShouldBe(3); } } } diff --git a/tests/Extensions.Tests/RandomExtensionsTests.cs b/tests/Extensions.Tests/RandomExtensionsTests.cs index adf7f3b..a458d8d 100644 --- a/tests/Extensions.Tests/RandomExtensionsTests.cs +++ b/tests/Extensions.Tests/RandomExtensionsTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using FluentAssertions; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -16,7 +16,7 @@ public void ShouldGenerateRandomDateTimeWithinRange() for (var i = 0; i < 100; i++) dateList.Add(r.NextDatetime(new DateTime(2010, 1, 1), new DateTime(2020, 1, 1))); - dateList.Should().Contain(x => x >= new DateTime(2010, 1, 1) && x <= new DateTime(2020, 1, 1)); + dateList.ShouldContain(x => x >= new DateTime(2010, 1, 1) && x <= new DateTime(2020, 1, 1)); } [Fact] @@ -30,7 +30,7 @@ public void ShouldPickOneOfList() var one = r.OneOf(list); - list.Should().Contain(one); + list.ShouldContain(one); } } } diff --git a/tests/Extensions.Tests/StringExtensionsTests.cs b/tests/Extensions.Tests/StringExtensionsTests.cs index 4a45a08..2a8d0b7 100644 --- a/tests/Extensions.Tests/StringExtensionsTests.cs +++ b/tests/Extensions.Tests/StringExtensionsTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; +using Shouldly; using Xunit; namespace Extensions.Tests @@ -19,14 +20,14 @@ public enum TestEnum [InlineData(default, default)] public void EnumStringShouldResolveToEnum(TestEnum expected, string value) { - Assert.Equal(expected, value.ToEnum()); + value.ToEnum().ShouldBe(expected); } [Fact] public void UnrecognizedEnumStringShouldThrowException() { - var message = Assert.Throws(() => "ValueC".ToEnum()).Message; - Assert.Equal("Cannot parse ValueC to TestEnum", message); + var message = Should.Throw(() => "ValueC".ToEnum()).Message; + message.ShouldBe("Cannot parse ValueC to TestEnum"); } [Theory] @@ -38,7 +39,7 @@ public void UnrecognizedEnumStringShouldThrowException() [InlineData(default, default, true)] public void ShouldReturnIfEqualCaseInsensitive(string value1, string value2, bool expected) { - Assert.Equal(expected, value1.IsEqualTo(value2)); + value1.IsEqualTo(value2).ShouldBe(expected); } [Theory] @@ -50,7 +51,7 @@ public void ShouldReturnIfEqualCaseInsensitive(string value1, string value2, boo [InlineData(default, default, true)] public void ShouldReturnIfEqualCaseInsensitiveWithParam(string value1, string value2, bool expected) { - Assert.Equal(expected, value1.IsEqualTo(value2, caseSensitive: false)); + value1.IsEqualTo(value2, caseSensitive: false).ShouldBe(expected); } [Theory] @@ -62,29 +63,29 @@ public void ShouldReturnIfEqualCaseInsensitiveWithParam(string value1, string va [InlineData(default, default, true)] public void ShouldReturnIfEqualCaseSensitive(string value1, string value2, bool expected) { - Assert.Equal(expected, value1.IsEqualTo(value2, caseSensitive: true)); + value1.IsEqualTo(value2, caseSensitive: true).ShouldBe(expected); } [Fact] public void ShouldReturnAbsolutePathIfRelative() { var path = Path.Combine(Directory.GetCurrentDirectory(), "Test"); - Assert.Equal(path, "Test".Absolutize()); + "Test".Absolutize().ShouldBe(path); } [Fact] public void ShouldReturnAbsolutePathIfAlreadyAbsolute() { var path = Path.Combine(Directory.GetCurrentDirectory(), "Test"); - Assert.Equal(path, path.Absolutize()); + path.Absolutize().ShouldBe(path); } [Fact] public void AbsolutizeShouldThrowExceptionIfStringIsNull() { string test = default; - var message = Assert.Throws(() => test.Absolutize()).Message; - Assert.Equal("Cannot absolutize a null path", message); + var message = Should.Throw(() => test.Absolutize()).Message; + message.ShouldBe("Cannot absolutize a null path"); } [Theory] @@ -95,15 +96,15 @@ public void AbsolutizeShouldThrowExceptionIfStringIsNull() [InlineData("MIxeDCasE", "M Ixe D Cas E")] public void ShouldDivideStringBasedOnCamelCase(string value, string expected) { - Assert.Equal(expected, value.FromCamelCase()); + value.FromCamelCase().ShouldBe(expected); } [Fact] public void FromCamelCaseShouldThrowExceptionIfStartIsNegative() { string test = default; - var message = Assert.Throws(() => test.FromCamelCase()).Message; - Assert.Equal("Cannot perform FromCamelCase on a null string", message); + var message = Should.Throw(() => test.FromCamelCase()).Message; + message.ShouldBe("Cannot perform FromCamelCase on a null string"); } [Theory] @@ -113,7 +114,7 @@ public void FromCamelCaseShouldThrowExceptionIfStartIsNegative() [InlineData(default, default, default)] public void ShouldReplaceStringIfReplaceIsNotNull(string value, string replace, string expected) { - Assert.Equal(expected, value.ReplaceWith(replace)); + value.ReplaceWith(replace).ShouldBe(expected); } [Theory] @@ -122,7 +123,7 @@ public void ShouldReplaceStringIfReplaceIsNotNull(string value, string replace, [InlineData("", true)] public void ShouldCheckIfStringIsNullOrEmpty(string value, bool expected) { - Assert.Equal(expected, value.IsNullOrEmpty()); + value.IsNullOrEmpty().ShouldBe(expected); } [Theory] @@ -132,13 +133,13 @@ public void ShouldCheckIfStringIsNullOrEmpty(string value, bool expected) [InlineData("", true)] public void ShouldCheckIfStringIsNullOrWhiteSpace(string value, bool expected) { - Assert.Equal(expected, value.IsNullOrWhiteSpace()); + value.IsNullOrWhiteSpace().ShouldBe(expected); } [Fact] public void IsNullOrWhiteSpaceShouldReturnTrueWithStringEmpty() { - Assert.True(string.Empty.IsNullOrWhiteSpace()); + string.Empty.IsNullOrWhiteSpace().ShouldBeTrue(); } [Theory] @@ -158,7 +159,7 @@ public void IsNullOrWhiteSpaceShouldReturnTrueWithStringEmpty() [InlineData(" - 3.3 ", false)] public void ShouldCheckIfStringIsNumeric(string value, bool expected) { - Assert.Equal(expected, value.IsNumeric()); + value.IsNumeric().ShouldBe(expected); } [Fact] @@ -166,15 +167,15 @@ public void ShouldSplitString() { var source = "splitted"; var expected = new List { "s", "p", "l", "i", "t", "t", "e", "d" }; - Assert.Equal(expected, source.SplitString()); + source.SplitString().ShouldBe(expected); } [Fact] public void SplitStringShouldThrowExceptionIfStringIsNull() { string test = default; - var message = Assert.Throws(() => test.SplitString()).Message; - Assert.Equal("Cannot split a null string", message); + var message = Should.Throw(() => test.SplitString()).Message; + message.ShouldBe("Cannot split a null string"); } [Theory] @@ -184,7 +185,7 @@ public void SplitStringShouldThrowExceptionIfStringIsNull() [InlineData("string", 15, "string")] public void ShouldThrowNoErrorsOnTolerantSubstring(string value, int startIndex, string expected) { - Assert.Equal(expected, value.TolerantSubstring(startIndex)); + value.TolerantSubstring(startIndex).ShouldBe(expected); } [Theory] @@ -196,19 +197,19 @@ public void ShouldThrowNoErrorsOnTolerantSubstring(string value, int startIndex, [InlineData("string", 2, 15, "ring")] public void ShouldThrowNoErrorsOnTolerantSubstringWithLength(string value, int startIndex, int length, string expected) { - Assert.Equal(expected, value.TolerantSubstring(startIndex, length)); + value.TolerantSubstring(startIndex, length).ShouldBe(expected); } [Fact] public void TolerantSubstringShouldThrowExceptionIfIndexIsNegative() { - Assert.Throws(() => "string".TolerantSubstring(-3)); + Should.Throw(() => "string".TolerantSubstring(-3)); } [Fact] public void TolerantSubstringShouldThrowExceptionIfLengthIsNegative() { - Assert.Throws(() => "string".TolerantSubstring(0, -3)); + Should.Throw(() => "string".TolerantSubstring(0, -3)); } [Theory] @@ -216,7 +217,7 @@ public void TolerantSubstringShouldThrowExceptionIfLengthIsNegative() [InlineData("test diacritics èòàùçé", "test diacritics eoauce")] public void ShouldRemoveDiacritics(string input, string expected) { - Assert.Equal(expected, input.RemoveDiacritics()); + input.RemoveDiacritics().ShouldBe(expected); } [Theory] @@ -226,7 +227,7 @@ public void ShouldRemoveDiacritics(string input, string expected) [InlineData("32.1", 0)] public void ShouldConvertToInt32(string input, int expected) { - Assert.Equal(expected, input.ToInt32()); + input.ToInt32().ShouldBe(expected); } [Theory] @@ -236,14 +237,14 @@ public void ShouldConvertToInt32(string input, int expected) [InlineData("32,1", 32.1)] public void ShouldConvertToDouble(string input, double expected) { - Assert.Equal(expected, input.ToDouble()); + input.ToDouble().ShouldBe(expected); } [Theory] [InlineData("provaprova", "oa", "prvprv")] public void ShouldRemoveCharFromString(string text1, string text2, string expected) { - Assert.Equal(expected, text1.Except(text2)); + text1.Except(text2).ShouldBe(expected); } [Theory] @@ -255,7 +256,7 @@ public void ShouldRemoveCharFromString(string text1, string text2, string expect [InlineData(default, default)] public void ShouldLowerFirstChar(string str, string expected) { - Assert.Equal(expected, str.LowerFirstLetter()); + str.LowerFirstLetter().ShouldBe(expected); } [Theory] @@ -263,7 +264,7 @@ public void ShouldLowerFirstChar(string str, string expected) [InlineData("This is a test", 20, "This is a test")] public void ShouldTruncateAtWithEllipsis(string str, int charNum, string expected) { - Assert.Equal(expected, str.TruncateAt(charNum, true)); + str.TruncateAt(charNum, true).ShouldBe(expected); } [Theory] @@ -271,13 +272,13 @@ public void ShouldTruncateAtWithEllipsis(string str, int charNum, string expecte [InlineData("This is a test", 20, "This is a test")] public void ShouldTruncateAtWithoutEllipsis(string str, int charNum, string expected) { - Assert.Equal(expected, str.TruncateAt(charNum)); + str.TruncateAt(charNum).ShouldBe(expected); } [Fact] public void ShouldThrowIfTruncateAtIsNegative() { - Assert.Throws(() => "string".TruncateAt(-3)); + Should.Throw(() => "string".TruncateAt(-3)); } [Fact] @@ -292,7 +293,7 @@ public void ShouldTransformTemplate() var template = "{{Name}} {{Surname}} ha detto '{{Phrase}}'"; var expected = "Pino Cammino ha detto 'Come una catapulta!'"; - Assert.Equal(expected, template.TransformTemplate(o)); + template.TransformTemplate(o).ShouldBe(expected); } [Theory] @@ -306,7 +307,7 @@ public void ShouldTransformTemplate() [InlineData(default, default)] public void ShouldCapitalizeFirstChar(string str, string expected) { - Assert.Equal(expected, str.CapitalizeFirstLetter()); + str.CapitalizeFirstLetter().ShouldBe(expected); } [Theory] @@ -322,7 +323,7 @@ public void ShouldCapitalizeFirstChar(string str, string expected) [InlineData(default, default)] public void ShouldCapitalizeEachFirstLetter(string str, string expected) { - Assert.Equal(expected, str.ToTitleCase()); + str.ToTitleCase().ShouldBe(expected); } [Theory] @@ -332,7 +333,7 @@ public void ShouldCapitalizeEachFirstLetter(string str, string expected) [InlineData(default, default)] public void ShouldReverseString(string str, string expected) { - Assert.Equal(expected, str.Reverse()); + str.Reverse().ShouldBe(expected); } [Theory] @@ -342,7 +343,7 @@ public void ShouldReverseString(string str, string expected) [InlineData("-", 5, "-----")] public void ShouldRepeatString(string str, int times, string expected) { - Assert.Equal(expected, str.Repeat(times)); + str.Repeat(times).ShouldBe(expected); } [Theory] @@ -351,7 +352,7 @@ public void ShouldRepeatString(string str, int times, string expected) [InlineData("_withprefix", "_", "_withprefix")] public void ShouldEnsureStringStartsWith(string str, string value, string expected) { - Assert.Equal(expected, str.EnsureStartsWith(value)); + str.EnsureStartsWith(value).ShouldBe(expected); } [Theory] @@ -360,7 +361,7 @@ public void ShouldEnsureStringStartsWith(string str, string value, string expect [InlineData("https://ildoc.dev/", "/", "https://ildoc.dev/")] public void ShouldEnsureStringEndsWith(string str, string value, string expected) { - Assert.Equal(expected, str.EnsureEndsWith(value)); + str.EnsureEndsWith(value).ShouldBe(expected); } } }