Skip to content

Commit 15f1f79

Browse files
committed
Unloked some tests
1 parent 86a5d8e commit 15f1f79

26 files changed

Lines changed: 301 additions & 229 deletions

SharpRepository.Repository/RepositoryBase.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,12 +1743,8 @@ protected virtual PropertyInfo GetPrimaryKeyPropertyInfo()
17431743
var propertyName = Conventions.GetPrimaryKeyName(type);
17441744

17451745
if (String.IsNullOrEmpty(propertyName)) return null;
1746-
1747-
#if NET451
1748-
var propInfo = type.GetProperty(propertyName);
1749-
#elif NETSTANDARD1_6
1746+
17501747
var propInfo = type.GetTypeInfo().GetDeclaredProperty(propertyName);
1751-
#endif
17521748
propInfo = propInfo == null || propInfo.PropertyType != pkType ? null : propInfo;
17531749

17541750
InternalCache.PrimaryKeyMapping[tupleKey] = propInfo;
@@ -1759,19 +1755,5 @@ private void Error(Exception ex)
17591755
{
17601756
RunAspect(aspect => aspect.OnError(new RepositoryActionContext<T, TKey>(this), ex));
17611757
}
1762-
1763-
// private static PropertyInfo GetPropertyCaseInsensitive(IReflect type, string propertyName, Type propertyType)
1764-
// {
1765-
// // make the property reflection lookup case insensitive
1766-
// const BindingFlags bindingFlags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
1767-
//
1768-
// return type.GetProperty(propertyName, bindingFlags, null, propertyType, new Type[0], new ParameterModifier[0]);
1769-
// }
1770-
1771-
// public abstract IEnumerator<T> GetEnumerator();
1772-
// IEnumerator IEnumerable.GetEnumerator()
1773-
// {
1774-
// return GetEnumerator();
1775-
// }
17761758
}
17771759
}

SharpRepository.Tests.Integration/AggregateQueriesTests.cs

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -343,58 +343,57 @@ public void Max_With_Predicate_Should_Return_Max(IRepository<Contact, string> re
343343

344344
repository.Max(x => x.ContactTypeId < 3, x => x.ContactTypeId).ShouldBe(2);
345345
}
346-
347-
//
348-
// [ExecuteForAllRepositoriesExcept(RepositoryType.CouchDb, RepositoryType.MongoDb, RepositoryType.RavenDb, Reason = "GroupBy Not Supported")]
349-
// public void GroupMin_Should_Return_Proper_Counts(IRepository<Contact, string> repository)
350-
// {
351-
// for (var i = 1; i <= 3; i++)
352-
// {
353-
// var contact = new Contact { Name = "Test User " + i, ContactTypeId =1, SumDecimal = 0.5m + i};
354-
// repository.Add(contact);
355-
// }
356-
// for (var i = 4; i <= 7; i++)
357-
// {
358-
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 2, SumDecimal = 0.5m + i};
359-
// repository.Add(contact);
360-
// }
361-
//
362-
// var groups = repository.GroupMin(x =>x.ContactTypeId, x => x.SumDecimal);
363-
//
364-
// groups.Count().ShouldBe(2);
365-
//
366-
//
367-
// groups[1].ShouldBe(1.5m);
368-
// groups[2].ShouldBe(4.5m);
369-
// }
370-
//
371-
// [ExecuteForAllRepositoriesExcept(RepositoryType.CouchDb, RepositoryType.MongoDb, RepositoryType.RavenDb, Reason = "GroupBy Not Supported")]
372-
// public void GroupMax_Should_Return_Proper_Counts(IRepository<Contact, string> repository)
373-
// {
374-
// for (var i = 1; i <= 3; i++)
375-
// {
376-
// var contact = new Contact { Name = "Test User " + i, ContactTypeId =1, SumDecimal = 0.5m + i};
377-
// repository.Add(contact);
378-
// }
379-
// for (var i = 4; i <= 7; i++)
380-
// {
381-
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 2, SumDecimal = 0.5m + i};
382-
// repository.Add(contact);
383-
// }
384-
//
385-
// var groups = repository.GroupBy(x => x.ContactTypeId,
386-
// x => new {Key = x.Key, Max = x.Max(o => o.SumDecimal)});
387-
//
388-
// //var groups = repository.GroupMax(x =>x.ContactTypeId, x => x.SumDecimal);
389-
//
390-
// groups.Count().ShouldBe(2);
391-
// groups.First().Key.ShouldBe(1);
392-
// groups.First().Max.ShouldBe(3.5m);
393-
// groups.Last().Key.ShouldBe(2);
394-
// groups.Last().Max.ShouldBe(7.5m);
395-
//// groups[1].ShouldBe(3.5m);
396-
//// groups[2].ShouldBe(7.5m);
397-
// }
346+
347+
//[ExecuteForAllRepositoriesExcept(RepositoryType.CouchDb, RepositoryType.MongoDb, RepositoryType.RavenDb, Reason = "GroupBy Not Supported")]
348+
//public void GroupMin_Should_Return_Proper_Counts(IRepository<Contact, string> repository)
349+
//{
350+
// for (var i = 1; i <= 3; i++)
351+
// {
352+
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 1, SumDecimal = 0.5m + i };
353+
// repository.Add(contact);
354+
// }
355+
// for (var i = 4; i <= 7; i++)
356+
// {
357+
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 2, SumDecimal = 0.5m + i };
358+
// repository.Add(contact);
359+
// }
360+
361+
// var groups = repository.GroupMin(x => x.ContactTypeId, x => x.SumDecimal);
362+
363+
// groups.Count().ShouldBe(2);
364+
365+
366+
// groups[1].ShouldBe(1.5m);
367+
// groups[2].ShouldBe(4.5m);
368+
//}
369+
370+
//[ExecuteForAllRepositoriesExcept(RepositoryType.CouchDb, RepositoryType.MongoDb, RepositoryType.RavenDb, Reason = "GroupBy Not Supported")]
371+
//public void GroupMax_Should_Return_Proper_Counts(IRepository<Contact, string> repository)
372+
//{
373+
// for (var i = 1; i <= 3; i++)
374+
// {
375+
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 1, SumDecimal = 0.5m + i };
376+
// repository.Add(contact);
377+
// }
378+
// for (var i = 4; i <= 7; i++)
379+
// {
380+
// var contact = new Contact { Name = "Test User " + i, ContactTypeId = 2, SumDecimal = 0.5m + i };
381+
// repository.Add(contact);
382+
// }
383+
384+
// var groups = repository.GroupBy(x => x.ContactTypeId,
385+
// x => new { Key = x.Key, Max = x.Max(o => o.SumDecimal) });
386+
387+
// var groups = repository.GroupMax(x => x.ContactTypeId, x => x.SumDecimal);
388+
389+
// groups.Count().ShouldBe(2);
390+
// groups.First().Key.ShouldBe(1);
391+
// groups.First().Max.ShouldBe(3.5m);
392+
// groups.Last().Key.ShouldBe(2);
393+
// groups.Last().Max.ShouldBe(7.5m);
394+
// groups[1].ShouldBe(3.5m);
395+
// groups[2].ShouldBe(7.5m);
396+
//}
398397

399398
}
400399
}

SharpRepository.Tests.Integration/CompoundKeyRepositoryDeleteTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public void Delete_Should_Remove_Item(ICompoundKeyRepository<User, string, int>
1717
var item = new User {Username = "Test User", Age = 11, FullName = "Test User - 11"};
1818
repository.Add(item);
1919

20-
//var result = repository.Get(contact.ContactId);
21-
//result.ShouldNotBeNull();
20+
var result = repository.Get("Test User", 11);
21+
result.ShouldNotBeNull();
2222

2323
repository.Delete(item);
24-
//result = repository.Get(contact.ContactId);
25-
//result.ShouldBeNull();
24+
result = repository.Get("Test User", 11);
25+
result.ShouldBeNull();
2626
}
2727

2828
[ExecuteForAllCompoundKeyRepositories]
@@ -67,11 +67,11 @@ public void Delete_Should_Wait_To_Remove_Item_If_Item_Exists_In_BatchMode(ICompo
6767
public void Delete_Should_Remove_Multiple_Items(ICompoundKeyRepository<User, string, int> repository)
6868
{
6969
IList<User> users = new List<User>
70-
{
71-
new User { Username = "Test User", Age = 11, FullName = "Test User - 11" },
72-
new User { Username = "Test User", Age = 21, FullName = "Test User - 21" },
73-
new User { Username = "Test User 2", Age = 11, FullName = "Test User 2- 11" },
74-
};
70+
{
71+
new User { Username = "Test User", Age = 11, FullName = "Test User - 11" },
72+
new User { Username = "Test User", Age = 21, FullName = "Test User - 21" },
73+
new User { Username = "Test User 2", Age = 11, FullName = "Test User 2- 11" },
74+
};
7575

7676
repository.Add(users);
7777
var items = repository.GetAll().ToList();

SharpRepository.Tests.Integration/CompoundKeyRepositoryGetTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,15 @@ public void TryGet_Should_Return_True_And_Item_If_Item_Exists(ICompoundKeyReposi
8585
var item = new User { Username = "Test User", Age = 21 };
8686
repository.Add(item);
8787

88-
User result;
89-
repository.TryGet(item.Username, item.Age, out result).ShouldBeTrue();
88+
repository.TryGet(item.Username, item.Age, out User result).ShouldBeTrue();
9089
result.Username.ShouldBe(item.Username);
9190
result.Age.ShouldBe(item.Age);
9291
}
9392

9493
[ExecuteForAllCompoundKeyRepositories]
9594
public void TryGet_Should_Return_False_And_Null_If_Item_Does_Not_Exists(ICompoundKeyRepository<User, string, int> repository)
9695
{
97-
User result;
98-
repository.TryGet(string.Empty, 0, out result).ShouldBeFalse();
96+
repository.TryGet(string.Empty, 0, out User result).ShouldBeFalse();
9997
result.ShouldBeNull();
10098
}
10199

SharpRepository.Tests.Integration/CompoundKeyRepositoryJoinTests.cs

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,67 @@
55
using SharpRepository.Tests.Integration.TestObjects;
66
using Shouldly;
77
using SharpRepository.InMemoryRepository;
8+
using SharpRepository.EfCoreRepository;
9+
using Microsoft.EntityFrameworkCore;
10+
using Microsoft.Data.Sqlite;
11+
using SharpRepository.Tests.Integration.Data;
12+
using SharpRepository.MongoDbRepository;
13+
using System;
814

915
namespace SharpRepository.Tests.Integration
1016
{
1117
[TestFixture]
1218
public class CompoundKeyRepositoryJoinTests : TestBase
1319
{
14-
// TODO: create a foreign key class to use to do the join with
15-
// [ExecuteForAllRepositories]
16-
// public void Join_GetAll_Should_Return_All_Items(ICompoundKeyRepository<User, string, int> repository)
17-
// {
18-
// for (var i = 1; i <= 5; i++)
19-
// {
20-
// var item = new User { Username = "Test User " + 1, Age = (i % 2) + 1 };
21-
// repository.Add(item);
22-
// }
23-
//
24-
// var userRepository = new InMemoryRepository<User, string, int>();
25-
// userRepository.Add(new ContactType() { ContactTypeId = 1, Abbreviation = "T1" });
26-
// userRepository.Add(new ContactType() { ContactTypeId = 2, Abbreviation = "T2" });
27-
//
28-
// var compositeRepos = repository.Join(contactTypeRepository, c => c.ContactTypeId, ct => ct.ContactTypeId,
29-
// (c, ct) => new { Id = c.ContactId, Name = c.Name, TypeAbbrev = ct.Abbreviation });
30-
//
31-
// var all = compositeRepos.GetAll().ToList();
32-
//
33-
// all.Count.ShouldBe(5);
34-
//
35-
// //IEnumerable<Contact> result = repository.GetAll().ToList();
36-
// //result.Count().ShouldBe(5);
37-
// }
20+
21+
[Test]
22+
public void Join_GetAll_Should_Return_All_Items_InMemory()
23+
{
24+
var inMemoryRepository = new InMemoryRepository<User, string, int>();
25+
Join_GetAll_Should_Return_All_Items(inMemoryRepository);
26+
}
27+
28+
[Test]
29+
public void Join_GetAll_Should_Return_All_Items_EfCore()
30+
{
31+
var connection = new SqliteConnection("DataSource=:memory:");
32+
connection.Open();
33+
34+
var options = new DbContextOptionsBuilder<TestObjectContext>()
35+
.UseSqlite(connection)
36+
.Options;
37+
38+
// Create the schema in the database
39+
var context = new TestObjectContext(options);
40+
context.Database.EnsureCreated();
41+
var efCoreRepository = new EfCoreRepository<User, string, int>(context);
42+
Join_GetAll_Should_Return_All_Items(efCoreRepository);
43+
}
44+
45+
public void Join_GetAll_Should_Return_All_Items(ICompoundKeyRepository<User, string, int> repository)
46+
{
47+
for (var i = 1; i <= 5; i++)
48+
{
49+
var item = new User { Username = "Test User " + i.ToString(), Age = (i % 2) + 1, ContactTypeId = i == 1 ? 1 : 2 };
50+
repository.Add(item);
51+
}
52+
53+
var contactTypeRepository = new InMemoryRepository<ContactType, int>();
54+
contactTypeRepository.Add(new ContactType() { ContactTypeId = 1, Abbreviation = "T1" });
55+
contactTypeRepository.Add(new ContactType() { ContactTypeId = 2, Abbreviation = "T2" });
56+
57+
var compositeRepos = repository.Join(contactTypeRepository, c => c.ContactTypeId, ct => ct.ContactTypeId,
58+
(c, ct) => new { Name = c.Username, TypeAbbrev = ct.Abbreviation });
59+
60+
var all = compositeRepos.GetAll().ToList();
61+
62+
all.Count.ShouldBe(5);
63+
64+
all.Single(c => c.Name == "Test User 1").TypeAbbrev.ShouldBe("T1");
65+
all.Single(c => c.Name == "Test User 2").TypeAbbrev.ShouldBe("T2");
66+
all.Single(c => c.Name == "Test User 3").TypeAbbrev.ShouldBe("T2");
67+
all.Single(c => c.Name == "Test User 4").TypeAbbrev.ShouldBe("T2");
68+
all.Single(c => c.Name == "Test User 5").TypeAbbrev.ShouldBe("T2");
69+
}
3870
}
3971
}

SharpRepository.Tests.Integration/CompoundKeyRepositoryUpdateTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ public void Update_Should_Save_Modified_Business_Name(ICompoundKeyRepository<Use
2929
updated.FullName.ShouldBe("Test User - 22 - Updated");
3030
notUpdated.FullName.ShouldBe("Test User 2 - 22");
3131
}
32-
33-
32+
3433
[ExecuteForAllCompoundKeyRepositories]
3534
public void Update_Should_Update_Multiple_Items(ICompoundKeyRepository<User, string, int> repository)
3635
{
37-
var users = new List<User>
38-
{
39-
new User { Username = "Test User", Age = 11, FullName = "Test User - 11" },
40-
new User { Username = "Test User", Age = 21, FullName = "Test User - 21" },
41-
new User { Username = "Test User 2", Age = 11, FullName = "Test User 2- 11" },
42-
};
36+
var users = new List<User>
37+
{
38+
new User { Username = "Test User", Age = 11, FullName = "Test User - 11" },
39+
new User { Username = "Test User", Age = 21, FullName = "Test User - 21" },
40+
new User { Username = "Test User 2", Age = 11, FullName = "Test User 2- 11" },
41+
};
4342

4443
repository.Add(users);
4544
var items = repository.GetAll().ToList();

SharpRepository.Tests.Integration/Data/RepositoryTestCaseDataFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//using SharpRepository.XmlRepository;
1212
//using SharpRepository.EfRepository;
1313
//using SharpRepository.RavenDbRepository;
14-
//using SharpRepository.MongoDbRepository;
14+
using SharpRepository.MongoDbRepository;
1515
using SharpRepository.InMemoryRepository;
1616
using SharpRepository.EfCoreRepository;
1717
//using SharpRepository.CacheRepository;
@@ -65,16 +65,16 @@ public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
6565
// yield return new TestCaseData(new Db4oRepository<Contact, string>(dbPath)).SetName("Db4oRepository Test");
6666
//}
6767

68-
//if (includeType.Contains(RepositoryType.MongoDb))
69-
//{
70-
// string connectionString = MongoDbConnectionStringFactory.Build("Contact");
68+
if (includeType.Contains(RepositoryType.MongoDb))
69+
{
70+
string connectionString = MongoDbConnectionStringFactory.Build("Contact");
7171

72-
// if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
73-
// {
74-
// MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
75-
// yield return new TestCaseData(new MongoDbRepository<Contact, string>(connectionString)).SetName("MongoDb Test");
76-
// }
77-
//}
72+
if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
73+
{
74+
MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
75+
yield return new TestCaseData(new MongoDbRepository<Contact, string>(connectionString)).SetName("MongoDb Test");
76+
}
77+
}
7878

7979
//if (includeType.Contains(RepositoryType.RavenDb))
8080
//{

0 commit comments

Comments
 (0)