Skip to content

Commit 523e4dd

Browse files
committed
Test con nome parametrizzato
1 parent acf13d8 commit 523e4dd

6 files changed

Lines changed: 37 additions & 20 deletions

SharpRepository.Tests.Integration/Data/RepositoryTestCaseDataFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ namespace SharpRepository.Tests.Integration.Data
2626
{
2727
public class RepositoryTestCaseDataFactory
2828
{
29-
public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
29+
public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType, string testName = "Test")
3030
{
3131
if (includeType.Contains(RepositoryType.InMemory))
3232
{
33-
yield return new TestCaseData(new InMemoryRepository<Contact, string>()).SetName("InMemoryRepository Test");
33+
yield return new TestCaseData(new InMemoryRepository<Contact, string>()).SetName("InMemoryRepository " + testName);
3434
}
3535

3636
if (includeType.Contains(RepositoryType.Xml))
3737
{
3838
var xmlDataDirectoryPath = XmlDataDirectoryFactory.Build("Contact");
3939
yield return
40-
new TestCaseData(new XmlRepository<Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository Test");
40+
new TestCaseData(new XmlRepository<Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository" + testName);
4141
}
4242

4343
if (includeType.Contains(RepositoryType.Ef))
4444
{
4545
var dbPath = EfDataDirectoryFactory.Build();
4646
yield return
47-
new TestCaseData(new EfRepository<Contact, string>(new TestObjectContext("Data Source=" + dbPath))).SetName("EfRepository Test");
47+
new TestCaseData(new EfRepository<Contact, string>(new TestObjectContext("Data Source=" + dbPath))).SetName("EfRepository" + testName);
4848
}
4949

5050
if (includeType.Contains(RepositoryType.EfCore))
@@ -59,13 +59,13 @@ public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
5959
// Create the schema in the database
6060
var context = new TestObjectContextCore(options);
6161
context.Database.EnsureCreated();
62-
yield return new TestCaseData(new EfCoreRepository<Contact, string>(context)).SetName("EfCoreRepository Test");
62+
yield return new TestCaseData(new EfCoreRepository<Contact, string>(context)).SetName("EfCoreRepository " + testName);
6363
}
6464

6565
if (includeType.Contains(RepositoryType.Dbo4))
6666
{
6767
var dbPath = Db4oDataDirectoryFactory.Build("Contact");
68-
yield return new TestCaseData(new Db4oRepository<Contact, string>(dbPath)).SetName("Db4oRepository Test");
68+
yield return new TestCaseData(new Db4oRepository<Contact, string>(dbPath)).SetName("Db4oRepository " + testName);
6969
}
7070

7171
if (includeType.Contains(RepositoryType.MongoDb))
@@ -75,7 +75,7 @@ public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
7575
if (MongoDbRepositoryManager.ServerIsRunning(connectionString))
7676
{
7777
MongoDbRepositoryManager.DropDatabase(connectionString); // Pre-test cleanup
78-
yield return new TestCaseData(new MongoDbRepository<Contact, string>(connectionString)).SetName("MongoDb Test");
78+
yield return new TestCaseData(new MongoDbRepository<Contact, string>(connectionString)).SetName("MongoDb " + testName);
7979
}
8080
}
8181

@@ -92,13 +92,13 @@ public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
9292
}
9393

9494
IDocumentStore x = new EmbeddableDocumentStore();
95-
yield return new TestCaseData(new RavenDbRepository<Contact, string>(documentStore: documentStore)).SetName("RavenDbRepository Test");
95+
yield return new TestCaseData(new RavenDbRepository<Contact, string>(documentStore: documentStore)).SetName("RavenDbRepository " + testName);
9696
}
9797

9898
if (includeType.Contains(RepositoryType.Cache))
9999
{
100100
var cachingProvider = new InMemoryCachingProvider(new MemoryCache(new MemoryCacheOptions()));
101-
yield return new TestCaseData(new CacheRepository<Contact, string>(CachePrefixFactory.Build(), cachingProvider)).SetName("CacheRepository Test");
101+
yield return new TestCaseData(new CacheRepository<Contact, string>(CachePrefixFactory.Build(), cachingProvider)).SetName("CacheRepository " + testName);
102102
}
103103

104104
if (includeType.Contains(RepositoryType.CouchDb))
@@ -109,7 +109,7 @@ public static IEnumerable<TestCaseData> Build(RepositoryType[] includeType)
109109
CouchDbRepositoryManager.DropDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);
110110
CouchDbRepositoryManager.CreateDatabase(CouchDbUrl.Host, CouchDbUrl.Port, databaseName);
111111

112-
yield return new TestCaseData(new CouchDbRepository<Contact, string>(CouchDbUrl.Host, CouchDbUrl.Port, databaseName)).SetName("CouchDbRepository Test");
112+
yield return new TestCaseData(new CouchDbRepository<Contact, string>(CouchDbUrl.Host, CouchDbUrl.Port, databaseName)).SetName("CouchDbRepository " + testName);
113113
}
114114

115115
}

SharpRepository.Tests.Integration/RepositoryAddTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Add_Should_Result_In_Proper_Total_Items(IRepository<Contact, string>
7575
result.Count().ShouldBe(1);
7676
}
7777

78-
[ExecuteForAllRepositories]
78+
[ExecuteForAllRepositories("Add_InBatchMode_Should_Delay_The_Action")]
7979
public void Add_InBatchMode_Should_Delay_The_Action(IRepository<Contact, string> repository)
8080
{
8181
using (var batch = repository.BeginBatch())

SharpRepository.Tests.Integration/SharpRepository.Tests.Integration.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net461</TargetFramework>
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<DebugType>Full</DebugType>
56
<AssemblyName>SharpRepository.Tests.Integration</AssemblyName>
67
<RootNamespace>SharpRepository.Tests.Integration</RootNamespace>
78
</PropertyGroup>
@@ -18,7 +19,6 @@
1819
<PackageReference Include="StructureMap" Version="4.5.2" />
1920
<PackageReference Include="System.Data.SQLite" Version="1.0.105.2" />
2021
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
21-
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

SharpRepository.Tests.Integration/TestAttributes/ExecuteForAllRepositoriesAttribute.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ namespace SharpRepository.Tests.Integration.TestAttributes
66
{
77
public class ExecuteForAllRepositoriesAttribute : TestCaseSourceAttribute
88
{
9+
private static string _testName;
10+
911
private static IEnumerable<TestCaseData> ForAllRepositoriesTestCaseData
1012
{
11-
get { return RepositoryTestCaseDataFactory.Build(RepositoryTypes.All); }
13+
get { return RepositoryTestCaseDataFactory.Build(RepositoryTypes.All, _testName); }
1214
}
1315

14-
public ExecuteForAllRepositoriesAttribute() : base(typeof(ExecuteForAllRepositoriesAttribute), "ForAllRepositoriesTestCaseData")
16+
public ExecuteForAllRepositoriesAttribute(string testName = "Test") : base(typeof(ExecuteForAllRepositoriesAttribute), "ForAllRepositoriesTestCaseData")
1517
{
18+
_testName = testName;
1619
}
1720
}
1821
}

SharpRepository.Tests.Integration/TestAttributes/ExecuteForAllRepositoriesExcept.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private static IEnumerable<TestCaseData> ForAllRepositoriesExceptTestCaseData
1111
{
1212
get
1313
{
14-
return RepositoryTestCaseDataFactory.Build(RemoveExceptions(RepositoryTypes.All));
14+
return RepositoryTestCaseDataFactory.Build(RemoveExceptions(RepositoryTypes.All), _testName);
1515
}
1616
}
1717

@@ -31,11 +31,18 @@ private static RepositoryType[] RemoveExceptions(RepositoryType[] repositoryType
3131
}
3232

3333
private static RepositoryType[] _exceptions;
34+
private static string _testName;
3435
public string Reason { get; set; }
3536

36-
public ExecuteForAllRepositoriesExceptAttribute(params RepositoryType[] exceptions) : this()
37+
38+
public ExecuteForAllRepositoriesExceptAttribute(string testName, params RepositoryType[] exceptions) : this()
3739
{
3840
_exceptions = exceptions;
41+
_testName = testName;
42+
}
43+
44+
public ExecuteForAllRepositoriesExceptAttribute(params RepositoryType[] exceptions) : this("Test", exceptions)
45+
{
3946
}
4047

4148
public ExecuteForAllRepositoriesExceptAttribute()

SharpRepository.Tests.Integration/TestAttributes/ExecuteForRepositoriesAttribute.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ namespace SharpRepository.Tests.Integration.TestAttributes
66
{
77
public class ExecuteForRepositoriesAttribute : TestCaseSourceAttribute
88
{
9+
private static string _testName;
10+
911
private static IEnumerable<TestCaseData> ForRepositoriesTestCaseData
1012
{
1113
get
1214
{
13-
return RepositoryTestCaseDataFactory.Build(_includeType);
15+
return RepositoryTestCaseDataFactory.Build(_includeType, _testName);
1416
}
1517
}
1618

@@ -21,7 +23,12 @@ public ExecuteForRepositoriesAttribute(params RepositoryType[] repositoryType) :
2123
_includeType = repositoryType;
2224
}
2325

24-
public ExecuteForRepositoriesAttribute() : base(typeof(ExecuteForRepositoriesAttribute), "ForRepositoriesTestCaseData")
26+
public ExecuteForRepositoriesAttribute(string testName = "Test", params RepositoryType[] repositoryType ) : this()
27+
{
28+
_includeType = repositoryType;
29+
}
30+
31+
public ExecuteForRepositoriesAttribute(string testName = "Test") : base(typeof(ExecuteForRepositoriesAttribute), "ForRepositoriesTestCaseData")
2532
{
2633
}
2734
}

0 commit comments

Comments
 (0)