Skip to content

Commit a5f71b2

Browse files
committed
Resolve #38 - Fix issues, include file & add test coverage
This resolves the problem where a file was accidentally not included in the compiled library. It also had a few issues/bugs which were not apparent previously (because it had not been built). I have also added some happy-path test coverage for it as well, while I was re-enabling it anyway.
1 parent c6dcc74 commit a5f71b2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CSF.Entities/CSF.Entities.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
<LogicalName>Strings.resx.resources</LogicalName>
5050
</EmbeddedResource>
5151
</ItemGroup>
52-
<ItemGroup>
53-
<Compile Remove="Identity.cs" />
54-
</ItemGroup>
5552
<ItemGroup>
5653
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Resources\ExceptionMessages.Designer.cs">
5754
<DependentUpon>ExceptionMessages.resx</DependentUpon>
@@ -63,7 +60,4 @@
6360
<ItemGroup>
6461
<Folder Include="Resources\" />
6562
</ItemGroup>
66-
<ItemGroup>
67-
<None Include="Identity.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
68-
</ItemGroup>
6963
</Project>

CSF.Entities/Identity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class Identity
3737
{
3838
static readonly IGetsIdentityType identityTypeProvider = new IdentityTypeProvider();
3939
static readonly ICreatesIdentity identityFactory = new IdentityFactory();
40-
static readonly IUpCastsIdentity caster = new IdentityCaster();
40+
static readonly ICastsIdentityType caster = new IdentityTypeCaster();
4141
static readonly IParsesIdentity parser = new IdentityParser();
4242

4343
/// <summary>
@@ -69,7 +69,7 @@ public static IIdentity<TEntity> Parse<TEntity>(object value) where TEntity : IE
6969
/// <param name="identity">The identity to convert to a different entity type.</param>
7070
/// <typeparam name="TCast">The desired entity type.</typeparam>
7171
/// <exception cref="InvalidCastException">If the <paramref name="identity"/> is not suitable for the entity type <typeparamref name="TCast"/>.</exception>
72-
public static IIdentity<TCast> Cast<TCast>(this IIdentity identity)
72+
public static IIdentity<TCast> Cast<TCast>(this IIdentity identity) where TCast : IEntity
7373
=> caster.CastIdentity<TCast>(identity);
7474
}
7575
}

Tests/CSF.Entities.Tests/IdentityTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void Equals_returns_false_for_two_identities_with_incompatible_entity_typ
3737
var identity2 = new Identity<long, Person>(5);
3838
Assert.That(identity1.Equals(identity2), Is.False);
3939
}
40+
4041
[Test, AutoMoqData]
4142
public void Equals_operator_returns_true_for_two_equal_identities()
4243
{
@@ -69,6 +70,27 @@ public void Equals_operator_returns_false_for_two_identities_with_incompatible_e
6970
Assert.That(identity1 == identity2, Is.False);
7071
}
7172

73+
[Test, AutoMoqData]
74+
public void Create_creates_identity_with_correct_value()
75+
{
76+
var identity = Identity.Create<Cat>(5);
77+
Assert.That(identity.Value, Is.EqualTo(5));
78+
}
79+
80+
[Test, AutoMoqData]
81+
public void Parse_returns_identity_with_correct_value()
82+
{
83+
var identity = Identity.Parse<Cat>("66");
84+
Assert.That(identity.Value, Is.EqualTo(66));
85+
}
86+
87+
[Test, AutoMoqData]
88+
public void Cast_returns_appropriate_identity()
89+
{
90+
var identity = new Identity<long,Animal>(5);
91+
Assert.That(() => Identity.Cast<Cat>(identity).Value, Is.EqualTo(5));
92+
}
93+
7294
[Test, AutoMoqData]
7395
public void GetValueAsString_returns_correct_value()
7496
{

0 commit comments

Comments
 (0)