Skip to content

Commit

Permalink
Tidied up casting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Sep 30, 2024
1 parent 3decd94 commit 5ccd497
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 84 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
Expand Down
6 changes: 5 additions & 1 deletion Consumers.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/SourceGeneratedFilesSweaEnabled/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=73fd4671_002Dd5e9_002D496f_002D8f6b_002Dd9da10b3147f/@EntryIndexedValue"></s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=73fd4671_002Dd5e9_002D496f_002D8f6b_002Dd9da10b3147f/@EntryIndexRemoved">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="TEST_TYPE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb_aaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CustomTools/CustomToolsData/@EntryValue"></s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vogen/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
7 changes: 6 additions & 1 deletion tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false
trim_trailing_whitespace = false

dotnet_style_namespace_match_folder = false
dotnet_naming_rule.types_should_be_pascal_case.severity = none

resharper_inconsistent_naming_highlighting = none;
45 changes: 32 additions & 13 deletions tests/ConsumerTests/Casting/ForClasses.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
using FluentAssertions.Execution;

namespace ConsumerTests.CastOperators;
namespace ConsumerTests.CastOperators.Classes;

public class ForClasses
{
[Fact]
public void Defaulting()
public void Explicit_casting()
{
using var _ = new AssertionScope();

var vo = Class_default.From("abc");
Vo originalVo = Vo.From("abc");

string prim = (string) vo;
Vo voCastFromString = (Vo) "abc";
string stringCastFromVo = (string)originalVo;

prim.Should().Be(vo.Value);
voCastFromString.Should().Be(originalVo);
voCastFromString.Value.Should().Be(stringCastFromVo);

var vo2 = (Class_default) prim;
stringCastFromVo.Should().Be(originalVo.Value);

vo2.Value.Should().Be(prim);
var voRecastFromCastedString = (Vo) stringCastFromVo;
voRecastFromCastedString.Value.Should().Be(stringCastFromVo);
}

[Fact]
public void Just_implicit_to_primitive()
{
using var _ = new AssertionScope();

var vo = Class_implicit_to_primitive_nothing_from_primitive.From("abc");
var vo = Implicit_to_primitive_nothing_from_primitive.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);
}

[Fact]
public void Implicit_both_ways()
public void implicit_casting_both_ways()
{
using var _ = new AssertionScope();

var vo = Class_implicit_both_ways.From("abc");
var vo = Implicit_both_ways.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);

Class_implicit_both_ways vo2 = prim;
Implicit_both_ways vo2 = prim;
vo2.Should().Be(vo);
}

Expand All @@ -52,14 +55,30 @@ public void Implicit_both_ways_with_normalization()
{
using var _ = new AssertionScope();

var vo = Class_implicit_both_ways_with_normalization.From("abc");
var vo = Classes.Implicit_both_ways_with_normalization.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);

Class_implicit_both_ways_with_normalization vo2 = prim;
Implicit_both_ways_with_normalization vo2 = prim;
vo2.Should().Be(vo);
vo2.Value.Should().Be("ABC");
}
}


[ValueObject<string>]
public partial class Vo;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.None)]
public partial class Implicit_to_primitive_nothing_from_primitive;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.Implicit)]
public partial class Implicit_both_ways;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.Implicit)]
public partial class Implicit_both_ways_with_normalization
{
private static string NormalizeInput(string input) => input.ToUpper();
}
43 changes: 31 additions & 12 deletions tests/ConsumerTests/Casting/ForStructs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions.Execution;

namespace ConsumerTests.CastOperators;
namespace ConsumerTests.CastOperators.Structs;

public class ForStructs
{
Expand All @@ -9,41 +9,44 @@ public void Defaulting()
{
using var _ = new AssertionScope();

var vo = Struct_default.From("abc");
Vo originalVo = Vo.From("abc");

string prim = (string) vo;
Vo voCastFromString = (Vo) "abc";
string stringCastFromVo = (string)originalVo;

prim.Should().Be(vo.Value);
voCastFromString.Should().Be(originalVo);
voCastFromString.Value.Should().Be(stringCastFromVo);

var vo2 = (Struct_default) prim;
stringCastFromVo.Should().Be(originalVo.Value);

vo2.Value.Should().Be(prim);
var voRecastFromCastedString = (Vo) stringCastFromVo;
voRecastFromCastedString.Value.Should().Be(stringCastFromVo);
}

[Fact]
public void Just_implicit_to_primitive()
{
using var _ = new AssertionScope();

var vo = Struct_implicit_to_primitive_nothing_from_primitive.From("abc");
var vo = Implicit_to_primitive_nothing_from_primitive.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);
}

[Fact]
public void Implicit_both_ways()
public void Implicit_casting_both_ways()
{
using var _ = new AssertionScope();

var vo = Struct_implicit_both_ways.From("abc");
var vo = Implicit_both_ways.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);

Struct_implicit_both_ways vo2 = prim;
Implicit_both_ways vo2 = prim;
vo2.Should().Be(vo);
}

Expand All @@ -52,15 +55,31 @@ public void Implicit_both_ways_with_normalization()
{
using var _ = new AssertionScope();

var vo = Struct_implicit_both_ways_with_normalization.From("abc");
var vo = Structs.Implicit_both_ways_with_normalization.From("abc");

string prim = vo;

prim.Should().Be(vo.Value);

Struct_implicit_both_ways_with_normalization vo2 = prim;
Implicit_both_ways_with_normalization vo2 = prim;
vo2.Should().Be(vo);
vo2.Value.Should().Be("ABC");
}

}


[ValueObject<string>]
public partial class Vo;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.None)]
public partial class Implicit_to_primitive_nothing_from_primitive;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.Implicit)]
public partial class Implicit_both_ways;

[ValueObject<string>(toPrimitiveCasting: CastOperator.Implicit, fromPrimitiveCasting: CastOperator.Implicit)]
public partial class Implicit_both_ways_with_normalization
{
private static string NormalizeInput(string input) => input.ToUpper();
}
53 changes: 0 additions & 53 deletions tests/ConsumerTests/Casting/Types.cs

This file was deleted.

0 comments on commit 5ccd497

Please sign in to comment.