Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: format code according to new rules
  • Loading branch information
feO2x committed Mar 25, 2025
commit a690b799531fe0418581f7def17e646f8f4dcfc2
4 changes: 2 additions & 2 deletions Code/Light.SharedCore.Tests/Entities/GuidEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void SetIdAfterInitializationShouldThrowWhenGuidIsEmpty()
var action = () => new Entity().ToMutable().SetId(Guid.Empty);

action.Should().Throw<EmptyGuidException>()
.And.ParamName.Should().Be("id");
.And.ParamName.Should().Be("id");
}

[Fact]
Expand All @@ -176,4 +176,4 @@ public Entity() { }

public Entity(Guid id) : base(id) { }
}
}
}
5 changes: 3 additions & 2 deletions Code/Light.SharedCore.Tests/Entities/Int32EntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public static void TwoNullReferencesAreEqual()
[InlineData(1)]
[InlineData(12)]
[InlineData(5000)]
public static void ToStringShouldReturnSimpleTypeNameAndId(int id) => new Entity(id).ToString().Should().Be("Entity " + id);
public static void ToStringShouldReturnSimpleTypeNameAndId(int id) =>
new Entity(id).ToString().Should().Be("Entity " + id);

[Theory]
[MemberData(nameof(NegativeIds))]
Expand Down Expand Up @@ -277,4 +278,4 @@ public Entity() { }

public Entity(int id) : base(id) { }
}
}
}
5 changes: 3 additions & 2 deletions Code/Light.SharedCore.Tests/Entities/Int64EntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public static void TwoNullReferencesAreEqual()
[InlineData(5L)]
[InlineData(359_544L)]
[InlineData(10001L)]
public static void ToStringShouldReturnSimpleTypeNameAndId(long id) => new Entity(id).ToString().Should().Be("Entity " + id);
public static void ToStringShouldReturnSimpleTypeNameAndId(long id) =>
new Entity(id).ToString().Should().Be("Entity " + id);

[Theory]
[MemberData(nameof(NegativeIds))]
Expand Down Expand Up @@ -274,4 +275,4 @@ private sealed class Entity : Int64Entity<Entity>
public Entity() { }
public Entity(long id) : base(id) { }
}
}
}
26 changes: 13 additions & 13 deletions Code/Light.SharedCore.Tests/Entities/StringEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ namespace Light.SharedCore.Tests.Entities;

public static class StringEntityTests
{
public static TheoryData<string> InvalidIds { get; } =
new ()
{
null!,
string.Empty,
"\t",
" ",
" IdWithWhiteSpaceAtTheBeginning",
"IdWithWhiteSpaceAtTheEnd\r\n",
new string('x', 201) // Too long
};

[Fact]
public static void MustImplementIEntityOfString() =>
typeof(StringEntity<>).Should().Implement<IEntity<string>>();
Expand Down Expand Up @@ -163,23 +175,11 @@ public static void ExchangeValidationMethod(string technicallyInvalidId)
}
}

public static TheoryData<string> InvalidIds { get; } =
new()
{
null!,
string.Empty,
"\t",
" ",
" IdWithWhiteSpaceAtTheBeginning",
"IdWithWhiteSpaceAtTheEnd\r\n",
new ('x', 201) // Too long
};


private sealed class Entity : StringEntity
{
public Entity() { }

public Entity(string id) : base(id) { }
}
}
}
30 changes: 15 additions & 15 deletions Code/Light.SharedCore.Tests/Light.SharedCore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="Light.SharedCore.Tests.Local.props" Condition="Exists('Light.SharedCore.Tests.Local.props')" />

<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)' == '' AND '$(TargetFrameworks)' == ''">net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<Import Project="Light.SharedCore.Tests.Local.props" Condition="Exists('Light.SharedCore.Tests.Local.props')" />

<ItemGroup>
<ProjectReference Include="..\Light.SharedCore\Light.SharedCore.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Light.Xunit" Version="1.0.0" />
</ItemGroup>
<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)' == '' AND '$(TargetFrameworks)' == ''">net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Light.SharedCore\Light.SharedCore.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Light.Xunit" Version="1.0.0" />
</ItemGroup>

</Project>
88 changes: 45 additions & 43 deletions Code/Light.SharedCore.Tests/Parsing/DecimalParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
using System;
using FluentAssertions;
using FluentAssertions;
using Light.SharedCore.Parsing;
using Xunit;
#if !NETFRAMEWORK
using System;
#endif

namespace Light.SharedCore.Tests.Parsing;

public static class DecimalParserTests
{
public static readonly TheoryData<string, decimal> NumbersWithDecimalPoint =
new ()
{
{ "0.74", 0.74m },
{ "1.34", 1.34m },
{ "391202.9", 391202.9m },
{ "-20.816", -20.816m },
{ "15,019.33", 15_019.33m }
};

public static readonly TheoryData<string, decimal> DecimalCommaData =
new ()
{
{ "000,7832", 0.7832m },
{ "-0,499", -0.499m },
{ "40593,84", 40593.84m },
{ "1.943.100,84", 1_943_100.84m }
};

public static readonly TheoryData<string, decimal> IntegerData =
new ()
{
{ "15", 15.0m },
{ "-743923", -743923.0m },
{ "239.482.392.923", 239_482_392_923.0m },
{ "21,500,000", 21_500_000.0m }
};

public static readonly TheoryData<string?> InvalidNumbers =
new ()
{
"Foo",
"Bar",
"",
null,
"9392gk381"
};

[Theory]
[MemberData(nameof(NumbersWithDecimalPoint))]
public static void ParseFloatingPointNumberWithDecimalPoint(string text, decimal expectedValue) =>
Expand All @@ -19,16 +59,6 @@ public static void ParseFloatingPointNumberWithDecimalPointAsSpan(string text, d
CheckNumberAsSpan(text, expectedValue);
#endif

public static readonly TheoryData<string, decimal> NumbersWithDecimalPoint =
new ()
{
{ "0.74", 0.74m },
{ "1.34", 1.34m },
{ "391202.9", 391202.9m },
{ "-20.816", -20.816m },
{ "15,019.33", 15_019.33m }
};

[Theory]
[MemberData(nameof(DecimalCommaData))]
public static void ParseFloatingPointNumberWithDecimalComma(string text, decimal expectedValue) =>
Expand All @@ -41,15 +71,6 @@ public static void ParseFloatingPointNumberWithDecimalCommaAsSpan(string text, d
CheckNumberAsSpan(text, expectedValue);
#endif

public static readonly TheoryData<string, decimal> DecimalCommaData =
new ()
{
{ "000,7832", 0.7832m },
{ "-0,499", -0.499m },
{ "40593,84", 40593.84m },
{ "1.943.100,84", 1_943_100.84m }
};

[Theory]
[MemberData(nameof(IntegerData))]
public static void ParseInteger(string text, decimal expectedValue) =>
Expand All @@ -62,15 +83,6 @@ public static void ParseIntegerAsSpan(string text, decimal expectedValue) =>
CheckNumberAsSpan(text, expectedValue);
#endif

public static readonly TheoryData<string, decimal> IntegerData =
new ()
{
{ "15", 15.0m },
{ "-743923", -743923.0m },
{ "239.482.392.923", 239_482_392_923.0m },
{ "21,500,000", 21_500_000.0m }
};

private static void CheckNumber(string text, decimal expectedValue)
{
var result = DecimalParser.TryParse(text, out var parsedValue);
Expand All @@ -96,7 +108,7 @@ public static void InvalidNumber(string? text)
var result = DecimalParser.TryParse(text, out var actualValue);

result.Should().BeFalse();
actualValue.Should().Be(default);
actualValue.Should().Be(0);
}

#if !NETFRAMEWORK
Expand All @@ -107,17 +119,7 @@ public static void InvalidNumberAsSpan(string? text)
var result = DecimalParser.TryParse(text.AsSpan(), out var actualValue);

result.Should().BeFalse();
actualValue.Should().Be(default);
actualValue.Should().Be(0);
}
#endif

public static readonly TheoryData<string?> InvalidNumbers =
new ()
{
"Foo",
"Bar",
"",
null,
"9392gk381",
};
}
}
8 changes: 4 additions & 4 deletions Code/Light.SharedCore.Tests/Parsing/DoubleParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void ParseFloatingPointNumberWithDecimalComma(string text, double
public static void ParseFloatingPointNumberWithDecimalCommaAsSpan(string text, double expectedValue) =>
CheckNumberAsSpan(text, expectedValue);
#endif


public static readonly TheoryData<string, double> NumbersWithDecimalComma =
new ()
Expand Down Expand Up @@ -101,7 +101,7 @@ public static void InvalidNumber(string? text)
var result = DoubleParser.TryParse(text, out var actualValue);

result.Should().BeFalse();
actualValue.Should().Be(default);
actualValue.Should().Be(0);
}

#if !NETFRAMEWORK
Expand All @@ -112,7 +112,7 @@ public static void InvalidNumberAsSpan(string? text)
var result = DoubleParser.TryParse(text.AsSpan(), out var actualValue);

result.Should().BeFalse();
actualValue.Should().Be(default);
actualValue.Should().Be(0);
}
#endif

Expand All @@ -125,4 +125,4 @@ public static void InvalidNumberAsSpan(string? text)
null,
"9392gk381"
};
}
}
Loading