Skip to content

Commit e1b8003

Browse files
author
Jeff Treuting
committed
Added 2 unit tests for new EF5 and MongoDb PK overrides
1 parent 181d07b commit e1b8003

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Data.Entity;
2+
using System.Reflection;
3+
using NUnit.Framework;
4+
using SharpRepository.Repository.Caching;
5+
using SharpRepository.Tests.TestObjects.PrimaryKeys;
6+
using Should;
7+
8+
namespace SharpRepository.Tests.PrimaryKey
9+
{
10+
[TestFixture]
11+
public class Ef5PrimaryKeyTests
12+
{
13+
[Test]
14+
public void Should_Return_KeyInt2_Property()
15+
{
16+
var repos = new TestEf5Repository<ObjectKeys, int>(new DbContext("test"));
17+
var propInfo = repos.TestGetPrimaryKeyPropertyInfo();
18+
19+
propInfo.PropertyType.ShouldEqual(typeof(int));
20+
propInfo.Name.ShouldEqual("KeyInt2");
21+
}
22+
}
23+
24+
internal class TestEf5Repository<T, TKey> : Ef5Repository.Ef5Repository<T, TKey> where T : class, new()
25+
{
26+
public TestEf5Repository(DbContext dbContext, ICachingStrategy<T, TKey> cachingStrategy = null) : base(dbContext, cachingStrategy)
27+
{
28+
}
29+
30+
public PropertyInfo TestGetPrimaryKeyPropertyInfo()
31+
{
32+
return GetPrimaryKeyPropertyInfo();
33+
}
34+
}
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using NUnit.Framework;
3+
using SharpRepository.Tests.TestObjects.PrimaryKeys;
4+
using Should;
5+
6+
namespace SharpRepository.Tests.PrimaryKey
7+
{
8+
[TestFixture]
9+
public class MongoDbPrimaryKeyTests
10+
{
11+
[Test]
12+
public void Should_Return_KeyInt1_Property()
13+
{
14+
var repos = new TestMongoDbRepository<ObjectKeys, int>();
15+
var propInfo = repos.TestGetPrimaryKeyPropertyInfo();
16+
17+
propInfo.PropertyType.ShouldEqual(typeof(int));
18+
propInfo.Name.ShouldEqual("KeyInt1");
19+
}
20+
}
21+
22+
internal class TestMongoDbRepository<T, TKey> : MongoDbRepository.MongoDbRepository<T, TKey> where T : class, new()
23+
{
24+
public PropertyInfo TestGetPrimaryKeyPropertyInfo()
25+
{
26+
return GetPrimaryKeyPropertyInfo();
27+
}
28+
}
29+
}

SharpRepository.Tests/SharpRepository.Tests.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<Reference Include="Enyim.Caching">
4242
<HintPath>..\packages\EnyimMemcached.2.12\lib\net35\Enyim.Caching.dll</HintPath>
4343
</Reference>
44+
<Reference Include="MongoDB.Bson">
45+
<HintPath>..\SharpRepository.Tests.Integration\bin\Release\MongoDB.Bson.dll</HintPath>
46+
</Reference>
4447
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
4548
<SpecificVersion>False</SpecificVersion>
4649
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
@@ -64,6 +67,7 @@
6467
<HintPath>..\packages\Should.1.1.12.0\lib\Should.dll</HintPath>
6568
</Reference>
6669
<Reference Include="System" />
70+
<Reference Include="System.ComponentModel.DataAnnotations" />
6771
<Reference Include="System.Configuration" />
6872
<Reference Include="System.Core" />
6973
<Reference Include="System.Data.Entity" />
@@ -88,6 +92,8 @@
8892
<Compile Include="Configuration\ConfigurationTests.cs" />
8993
<Compile Include="Enumerable\ForEachTests.cs" />
9094
<Compile Include="FetchStrategies\FetchStrategyTests.cs" />
95+
<Compile Include="PrimaryKey\Ef5PrimaryKeyTests.cs" />
96+
<Compile Include="PrimaryKey\MongoDbPrimaryKeyTests.cs" />
9197
<Compile Include="PrimaryKey\RepositoryPrimaryKeyAttributeTests.cs" />
9298
<Compile Include="QueryOptions\PagingOptionsTests.cs" />
9399
<Compile Include="QueryOptions\SortingOptionsTests.cs" />
@@ -103,6 +109,7 @@
103109
<Compile Include="TestObjects\ContactType.cs" />
104110
<Compile Include="TestObjects\EmailAddress.cs" />
105111
<Compile Include="TestObjects\PhoneNumber.cs" />
112+
<Compile Include="TestObjects\PrimaryKeys\ObjectKeys.cs" />
106113
<Compile Include="TestObjects\TestObjectEntities.cs" />
107114
<Compile Include="Traits\ICanGetTraitTests.cs" />
108115
<Compile Include="Traits\ICanUpdateTraitTests.cs" />
@@ -133,6 +140,10 @@
133140
<Project>{13AD3FCA-4C9D-4674-B786-F30843638D3B}</Project>
134141
<Name>SharpRepository.InMemoryRepository</Name>
135142
</ProjectReference>
143+
<ProjectReference Include="..\SharpRepository.MongoDbRepository\SharpRepository.MongoDbRepository.csproj">
144+
<Project>{dc40febe-2e39-4cb8-ae11-dfe9f6865bd2}</Project>
145+
<Name>SharpRepository.MongoDbRepository</Name>
146+
</ProjectReference>
136147
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
137148
<Project>{710DEE79-25CE-4F68-B8B1-D08A135AD154}</Project>
138149
<Name>SharpRepository.Repository</Name>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
using MongoDB.Bson.Serialization.Attributes;
4+
5+
namespace SharpRepository.Tests.TestObjects.PrimaryKeys
6+
{
7+
public class ObjectKeys
8+
{
9+
public int Id { get; set; }
10+
11+
[BsonId]
12+
public int KeyInt1 { get; set; }
13+
14+
[Key]
15+
public int KeyInt2 { get; set; }
16+
17+
public Guid KeyGuid { get; set; }
18+
19+
public string KeyString { get; set; }
20+
}
21+
}

0 commit comments

Comments
 (0)