Skip to content

Commit ef04b30

Browse files
author
jaguzman
committed
Cleaned up testbase class
1 parent 428db43 commit ef04b30

File tree

1 file changed

+96
-99
lines changed
  • test/DotNetToolkit.Repository.Integration.Test/Data

1 file changed

+96
-99
lines changed

test/DotNetToolkit.Repository.Integration.Test/Data/TestBase.cs

Lines changed: 96 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -43,125 +43,131 @@ protected TestBase(ITestOutputHelper testOutputHelper)
4343
protected ILoggerProvider TestXUnitLoggerProvider { get; }
4444

4545
protected void ForRepositoryFactoryWithAllCachingProviders(ContextProviderType contextProvider, Action<IRepositoryFactory, CachingProviderType> action)
46-
{
47-
CachingProviders().ToList().ForEach(cachingProvider =>
48-
{
49-
var builder = GetRepositoryOptionsBuilder(contextProvider);
46+
=> CachingProviders()
47+
.ToList()
48+
.ForEach(cachingProvider =>
49+
{
50+
var builder = GetRepositoryOptionsBuilder(contextProvider);
5051

51-
ApplyCachingProvider(cachingProvider, builder);
52+
ApplyCachingProvider(cachingProvider, builder);
5253

53-
action(new RepositoryFactory(builder.Options), cachingProvider);
54-
});
55-
}
54+
action(new RepositoryFactory(builder.Options), cachingProvider);
55+
});
5656

5757
protected void ForRepositoryFactoryWithAllCachingProviders(ContextProviderType contextProvider, Action<IRepositoryFactory> action)
5858
=> ForRepositoryFactoryWithAllCachingProviders(contextProvider, (factory, type) => action(factory));
5959

6060
protected void ForRepositoryFactoryWithAllCachingProvidersAsync(ContextProviderType contextProvider, Func<IRepositoryFactory, CachingProviderType, Task> action)
61-
{
62-
CachingProviders().ToList().ForEach(async cachingProvider =>
63-
{
64-
var builder = GetRepositoryOptionsBuilder(contextProvider);
61+
=> CachingProviders()
62+
.ToList()
63+
.ForEach(async cachingProvider =>
64+
{
65+
var builder = GetRepositoryOptionsBuilder(contextProvider);
6566

66-
ApplyCachingProvider(cachingProvider, builder);
67+
ApplyCachingProvider(cachingProvider, builder);
6768

68-
await HandleExceptionAsync(() => action(new RepositoryFactory(builder.Options), cachingProvider));
69-
});
70-
}
69+
await HandleExceptionAsync(() => action(
70+
new RepositoryFactory(builder.Options),
71+
cachingProvider));
72+
});
7173

7274
protected void ForRepositoryFactoryWithAllCachingProvidersAsync(ContextProviderType contextProvider, Func<IRepositoryFactory, Task> action)
7375
=> ForRepositoryFactoryWithAllCachingProvidersAsync(contextProvider, (factory, type) => action(factory));
7476

7577
protected void ForAllRepositoryFactories(Action<IRepositoryFactory, ContextProviderType> action, params ContextProviderType[] exclude)
76-
{
77-
ContextProviders().ToList().ForEach(x =>
78-
{
79-
if (exclude != null && exclude.Contains(x))
80-
return;
78+
=> ContextProviders()
79+
.ToList()
80+
.ForEach(x =>
81+
{
82+
if (exclude != null && exclude.Contains(x))
83+
return;
8184

82-
action(new RepositoryFactory(BuildOptions(x)), x);
83-
});
84-
}
85+
action(new RepositoryFactory(BuildOptions(x)), x);
86+
});
8587

8688
protected void ForAllRepositoryFactories(Action<IRepositoryFactory> action, params ContextProviderType[] exclude)
8789
=> ForAllRepositoryFactories((factory, type) => action(factory), exclude);
8890

8991
protected void ForAllRepositoryFactoriesAsync(Func<IRepositoryFactory, ContextProviderType, Task> action, params ContextProviderType[] exclude)
90-
{
91-
ContextProviders().ToList().ForEach(async x =>
92-
{
93-
if (exclude != null && exclude.Contains(x))
94-
return;
92+
=> ContextProviders()
93+
.ToList()
94+
.ForEach(async x =>
95+
{
96+
if (exclude != null && exclude.Contains(x))
97+
return;
9598

96-
await HandleExceptionAsync(() => action(new RepositoryFactory(BuildOptions(x)), x));
97-
});
98-
}
99+
await HandleExceptionAsync(() => action(
100+
new RepositoryFactory(BuildOptions(x)), x));
101+
});
99102

100103
protected void ForAllRepositoryFactoriesAsync(Func<IRepositoryFactory, Task> action, params ContextProviderType[] exclude)
101104
=> ForAllRepositoryFactoriesAsync((factory, type) => action(factory), exclude);
102105

103106
protected void ForAllServiceFactories(Action<IServiceFactory, ContextProviderType> action, params ContextProviderType[] exclude)
104-
{
105-
ContextProviders().Where(SupportsTransactions).ToList().ForEach(x =>
106-
{
107-
if (exclude != null && exclude.Contains(x))
108-
return;
107+
=> ContextProviders()
108+
.Where(SupportsTransactions)
109+
.ToList()
110+
.ForEach(x =>
111+
{
112+
if (exclude != null && exclude.Contains(x))
113+
return;
109114

110-
action(new ServiceFactory(new UnitOfWorkFactory(BuildOptions(x))), x);
111-
});
112-
}
115+
action(new ServiceFactory(new UnitOfWorkFactory(BuildOptions(x))), x);
116+
});
113117

114118
protected void ForAllServiceFactories(Action<IServiceFactory> action, params ContextProviderType[] exclude)
115119
=> ForAllServiceFactories((factory, type) => action(factory), exclude);
116120

117121
protected void ForAllServiceFactoriesAsync(Func<IServiceFactory, ContextProviderType, Task> action, params ContextProviderType[] exclude)
118-
{
119-
ContextProviders().Where(SupportsTransactions).ToList().ForEach(async x =>
120-
{
121-
if (exclude != null && exclude.Contains(x))
122-
return;
123-
124-
await HandleExceptionAsync(() => action(new ServiceFactory(new UnitOfWorkFactory(BuildOptions(x))), x));
125-
});
126-
}
122+
=> ContextProviders()
123+
.Where(SupportsTransactions)
124+
.ToList()
125+
.ForEach(async x =>
126+
{
127+
if (exclude != null && exclude.Contains(x))
128+
return;
129+
130+
await HandleExceptionAsync(() => action(
131+
new ServiceFactory(
132+
new UnitOfWorkFactory(
133+
BuildOptions(x))), x));
134+
});
127135

128136
protected void ForAllServiceFactoriesAsync(Func<IServiceFactory, Task> action, params ContextProviderType[] exclude)
129137
=> ForAllServiceFactoriesAsync((factory, type) => action(factory), exclude);
130138

131139
protected void ForAllUnitOfWorkFactories(Action<IUnitOfWorkFactory, ContextProviderType> action)
132-
{
133-
ContextProviders().Where(SupportsTransactions).ToList().ForEach(x =>
134-
{
135-
action(new UnitOfWorkFactory(BuildOptions(x)), x);
136-
});
137-
}
140+
=> ContextProviders()
141+
.Where(SupportsTransactions)
142+
.ToList()
143+
.ForEach(x => action(new UnitOfWorkFactory(BuildOptions(x)), x));
138144

139145
protected void ForAllUnitOfWorkFactories(Action<IUnitOfWorkFactory> action)
140146
=> ForAllUnitOfWorkFactories((factory, type) => action(factory));
141147

142148
protected void ForAllUnitOfWorkFactoriesAsync(Func<IUnitOfWorkFactory, ContextProviderType, Task> action)
143-
{
144-
ContextProviders().Where(SupportsTransactions).ToList().ForEach(async x =>
145-
{
146-
await HandleExceptionAsync(() => action(new UnitOfWorkFactory(BuildOptions(x)), x));
147-
});
148-
}
149+
=> ContextProviders()
150+
.Where(SupportsTransactions)
151+
.ToList()
152+
.ForEach(async x => await HandleExceptionAsync(
153+
() => action(
154+
new UnitOfWorkFactory(
155+
BuildOptions(x)), x)));
149156

150157
protected void ForAllUnitOfWorkFactoriesAsync(Func<IUnitOfWorkFactory, Task> action)
151158
=> ForAllUnitOfWorkFactoriesAsync((factory, type) => action(factory));
152159

153160
protected void ForAllFileStreamContextProviders(Action<IRepositoryOptions, ContextProviderType> action)
154-
{
155-
FileStreamContextProviders().ToList().ForEach(x => action(BuildOptions(x), x));
156-
}
161+
=> FileStreamContextProviders()
162+
.ToList()
163+
.ForEach(x => action(BuildOptions(x), x));
157164

158165
protected void ForAllFileStreamContextProviders(Action<IRepositoryOptions> action)
159166
=> ForAllFileStreamContextProviders((options, type) => action(options));
160167

161168
private static bool SupportsTransactions(ContextProviderType x)
162-
{
163-
return SqlServerContextProviders().Contains(x);
164-
}
169+
=> SqlServerContextProviders()
170+
.Contains(x);
165171

166172
private static async Task HandleExceptionAsync(Func<Task> testCode)
167173
{
@@ -321,60 +327,40 @@ private static void ApplyCachingProvider(CachingProviderType cachingProvider, Re
321327
}
322328
}
323329

324-
protected IRepositoryOptions BuildOptions(ContextProviderType provider) => GetRepositoryOptionsBuilder(provider).Options;
330+
protected IRepositoryOptions BuildOptions(ContextProviderType provider)
331+
=> GetRepositoryOptionsBuilder(provider).Options;
325332

326-
protected static IEnumerable<ContextProviderType> InMemoryContextProviders()
327-
{
328-
return new[]
333+
protected static ContextProviderType[] InMemoryContextProviders()
334+
=> new[]
329335
{
330336
ContextProviderType.InMemory,
331337
ContextProviderType.EntityFrameworkCore,
332338
};
333-
}
334339

335-
protected static IEnumerable<ContextProviderType> FileStreamContextProviders()
336-
{
337-
return new[]
340+
protected static ContextProviderType[] FileStreamContextProviders()
341+
=> new[]
338342
{
339343
ContextProviderType.Json,
340344
ContextProviderType.Xml,
341345
};
342-
}
343346

344-
protected static IEnumerable<ContextProviderType> SqlServerContextProviders()
345-
{
346-
return new[]
347+
protected static ContextProviderType[] SqlServerContextProviders()
348+
=> new[]
347349
{
348350
ContextProviderType.AdoNet,
349351
ContextProviderType.NHibernate,
350352
ContextProviderType.EntityFramework,
351353
};
352-
}
353354

354-
protected static IEnumerable<ContextProviderType> AzureStorageContextProviders()
355-
{
356-
return new[]
355+
protected static ContextProviderType[] AzureStorageContextProviders()
356+
=> new[]
357357
{
358358
ContextProviderType.AzureStorageBlob,
359359
ContextProviderType.AzureStorageTable,
360360
};
361-
}
362-
363-
private static IEnumerable<ContextProviderType> ContextProviders()
364-
{
365-
var list = new List<ContextProviderType>();
366-
367-
list.AddRange(SqlServerContextProviders());
368-
list.AddRange(InMemoryContextProviders());
369-
list.AddRange(FileStreamContextProviders());
370-
list.AddRange(AzureStorageContextProviders());
371-
372-
return list;
373-
}
374361

375-
private static IEnumerable<CachingProviderType> CachingProviders()
376-
{
377-
return new[]
362+
private static CachingProviderType[] CachingProviders()
363+
=> new[]
378364
{
379365
CachingProviderType.MicrosoftInMemory,
380366
CachingProviderType.Redis,
@@ -384,6 +370,17 @@ private static IEnumerable<CachingProviderType> CachingProviders()
384370
//the server (similar to redis and memcached). I am going to comment out testing couchbase for now
385371
//CachingProviderType.Couchbase,
386372
};
373+
374+
private static ContextProviderType[] ContextProviders()
375+
{
376+
var list = new List<ContextProviderType>();
377+
378+
list.AddRange(SqlServerContextProviders());
379+
list.AddRange(InMemoryContextProviders());
380+
list.AddRange(FileStreamContextProviders());
381+
list.AddRange(AzureStorageContextProviders());
382+
383+
return list.ToArray();
387384
}
388385

389386
public enum ContextProviderType

0 commit comments

Comments
 (0)