Skip to content

Commit 5dc1452

Browse files
Merge pull request #38 from DickBaker/Dev_defaults
tidy/spelling/modernize refactoring changes
2 parents b748baa + 97f077f commit 5dc1452

9 files changed

Lines changed: 54 additions & 69 deletions

src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFramworkCoreTestsBase.cs renamed to src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFrameworkCoreTestsBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace AutoMapper.Collection.EntityFrameworkCore.Tests
99
{
10-
public abstract class EntityFramworkCoreTestsBase
10+
public abstract class EntityFrameworkCoreTestsBase
1111
{
1212
protected abstract DBContextBase GetDbContext();
1313
protected abstract IMapper GetMapper();
@@ -292,13 +292,14 @@ public class Thing
292292
{
293293
public int ID { get; set; }
294294
public string Title { get; set; }
295-
public override string ToString() { return Title; }
295+
public override string ToString() => Title;
296296
}
297297

298298
public class ThingDto
299299
{
300300
public int ID { get; set; }
301301
public string Title { get; set; }
302+
public override string ToString() => Title;
302303
}
303304
}
304305
}

src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFramworkCoreUsingCtorTests.cs renamed to src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFrameworkCoreUsingCtorTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace AutoMapper.Collection.EntityFrameworkCore.Tests
66
{
7-
public class EntityFramworkCoreUsingCtorTests : EntityFramworkCoreTestsBase
7+
public class EntityFrameworkCoreUsingCtorTests : EntityFrameworkCoreTestsBase
88
{
99
private readonly Mapper _mapper;
1010

11-
public EntityFramworkCoreUsingCtorTests()
11+
public EntityFrameworkCoreUsingCtorTests()
1212
{
1313
_mapper = new Mapper(new MapperConfiguration(x =>
1414
{
@@ -18,15 +18,9 @@ public EntityFramworkCoreUsingCtorTests()
1818
}));
1919
}
2020

21-
protected override DBContextBase GetDbContext()
22-
{
23-
return new DB();
24-
}
21+
protected override DBContextBase GetDbContext() => new DB();
2522

26-
protected override IMapper GetMapper()
27-
{
28-
return _mapper;
29-
}
23+
protected override IMapper GetMapper() => _mapper;
3024

3125
public class DB : DBContextBase
3226
{

src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFramworkCoreUsingDITests.cs renamed to src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFrameworkCoreUsingDITests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using System;
2-
using AutoMapper.EntityFrameworkCore;
32
using AutoMapper.EquivalencyExpression;
43
using Microsoft.EntityFrameworkCore;
54
using Microsoft.Extensions.DependencyInjection;
65

76
namespace AutoMapper.Collection.EntityFrameworkCore.Tests
87
{
9-
public class EntityFramworkCoreUsingDITests : EntityFramworkCoreTestsBase, IDisposable
8+
public class EntityFrameworkCoreUsingDITests : EntityFrameworkCoreTestsBase, IDisposable
109
{
1110
private readonly ServiceProvider _serviceProvider;
1211
private readonly Mapper _mapper;
1312
private readonly IServiceScope _serviceScope;
1413

15-
public EntityFramworkCoreUsingDITests()
14+
public EntityFrameworkCoreUsingDITests()
1615
{
1716
var services = new ServiceCollection();
1817

@@ -39,15 +38,9 @@ public void Dispose()
3938
_serviceProvider?.Dispose();
4039
}
4140

42-
protected override DBContextBase GetDbContext()
43-
{
44-
return _serviceScope.ServiceProvider.GetRequiredService<DB>();
45-
}
41+
protected override DBContextBase GetDbContext() => _serviceScope.ServiceProvider.GetRequiredService<DB>();
4642

47-
protected override IMapper GetMapper()
48-
{
49-
return _mapper;
50-
}
43+
protected override IMapper GetMapper() => _mapper;
5144

5245
public class DB : DBContextBase
5346
{

src/AutoMapper.Collection.EntityFrameworkCore.Tests/EntityFrameworkCoreUsingMicrosoftDITests.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace AutoMapper.Collection.EntityFrameworkCore.Tests
88
{
9-
public class EntityFrameworkCoreUsingMicrosoftDITests : EntityFramworkCoreTestsBase, IDisposable
9+
public class EntityFrameworkCoreUsingMicrosoftDITests : EntityFrameworkCoreTestsBase, IDisposable
1010
{
1111
private readonly ServiceProvider _serviceProvider;
1212
private readonly IServiceScope _serviceScope;
@@ -26,25 +26,19 @@ public EntityFrameworkCoreUsingMicrosoftDITests()
2626
x.CreateMap<ThingDto, Thing>().ReverseMap();
2727
}, new Assembly[0]);
2828

29-
this._serviceProvider = services.BuildServiceProvider();
30-
this._serviceScope = this._serviceProvider.CreateScope();
29+
_serviceProvider = services.BuildServiceProvider();
30+
_serviceScope = _serviceProvider.CreateScope();
3131
}
3232

3333
public void Dispose()
3434
{
35-
this._serviceScope?.Dispose();
36-
this._serviceProvider?.Dispose();
35+
_serviceScope?.Dispose();
36+
_serviceProvider?.Dispose();
3737
}
3838

39-
protected override DBContextBase GetDbContext()
40-
{
41-
return this._serviceScope.ServiceProvider.GetRequiredService<DB>();
42-
}
39+
protected override DBContextBase GetDbContext() => _serviceScope.ServiceProvider.GetRequiredService<DB>();
4340

44-
protected override IMapper GetMapper()
45-
{
46-
return this._serviceScope.ServiceProvider.GetRequiredService<IMapper>();
47-
}
41+
protected override IMapper GetMapper() => _serviceScope.ServiceProvider.GetRequiredService<IMapper>();
4842

4943
public class DB : DBContextBase
5044
{

src/AutoMapper.Collection.EntityFrameworkCore/AutoMapper.Collection.EntityFrameworkCore.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020

2121
<ItemGroup>
2222
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="2.0.0" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="3.3.0">
24+
<PrivateAssets>all</PrivateAssets>
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
</PackageReference>
2327
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.1" />
28+
<PackageReference Include="Roslynator.Analyzers" Version="2.3.0">
29+
<PrivateAssets>all</PrivateAssets>
30+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
31+
</PackageReference>
2432
</ItemGroup>
2533

2634
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">

src/AutoMapper.Collection.EntityFrameworkCore/GenerateEntityFrameworkCorePrimaryKeyPropertyMaps.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ public class GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<TDatabaseContext>
1212
{
1313
private readonly IModel _model;
1414

15-
public GenerateEntityFrameworkCorePrimaryKeyPropertyMaps()
16-
{
17-
throw new InvalidOperationException($"Use {nameof(MapperConfigurationExpressionExtensions.UseEntityFrameworkCoreModel)} instead of using SetGeneratePropertyMaps.");
18-
}
15+
public GenerateEntityFrameworkCorePrimaryKeyPropertyMaps() => throw new InvalidOperationException($"Use {nameof(MapperConfigurationExpressionExtensions.UseEntityFrameworkCoreModel)} instead of using SetGeneratePropertyMaps.");
1916

2017
public GenerateEntityFrameworkCorePrimaryKeyPropertyMaps(IModel model) => _model = model;
2118

src/AutoMapper.Collection.EntityFrameworkCore/IPersistence.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IPersistence<TTo>
2323
/// <param name="from">Object to update to <see cref="T:System.Data.Entity.DbSet`1"/></param>
2424
/// <param name="cancellationToken">A cancellation token to observe the task.</param>
2525
/// <returns>A task containing the updated or inserted entity</returns>
26-
Task<TTo> InsertOrUpdateAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default(CancellationToken)) where TFrom : class;
26+
Task<TTo> InsertOrUpdateAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default) where TFrom : class;
2727

2828
/// <summary>
2929
/// Insert Or Update the <see cref="T:System.Data.Entity.DbSet`1"/> with <paramref name="from"/>
@@ -42,7 +42,7 @@ public interface IPersistence<TTo>
4242
/// <param name="from">Object to update to <see cref="T:System.Data.Entity.DbSet`1"/></param>
4343
/// <param name="cancellationToken">A cancellation token to observe the task.</param>
4444
/// <returns>A task containing the updated or inserted entity</returns>
45-
Task<TTo> InsertOrUpdateAsync(Type type, object from, CancellationToken cancellationToken = default(CancellationToken));
45+
Task<TTo> InsertOrUpdateAsync(Type type, object from, CancellationToken cancellationToken = default);
4646

4747
/// <summary>
4848
/// Remove from <see cref="T:System.Data.Entity.DbSet`1"/> with <paramref name="from"/>
@@ -60,7 +60,6 @@ public interface IPersistence<TTo>
6060
/// <param name="from">Object to remove that is Equivalent in <see cref="T:System.Data.Entity.DbSet`1"/></param>
6161
/// <param name="cancellationToken">A cancellation token to observe the task.</param>
6262
/// <returns>A task object indicating the status of the asynchronous operation</returns>
63-
Task RemoveAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default(CancellationToken)) where TFrom : class;
64-
63+
Task RemoveAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default) where TFrom : class;
6564
}
6665
}

src/AutoMapper.Collection.EntityFrameworkCore/MapperConfigurationExpressionExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ public static void UseEntityFrameworkCoreModel<TContext>(this IMapperConfigurati
5656
/// only used if you are using <see cref="DbContextOptionsBuilder.UseModel(IModel)"/>.
5757
/// </summary>
5858
public static void UseEntityFrameworkCoreModel<TContext>(this IMapperConfigurationExpression config, IModel model)
59-
where TContext : DbContext
60-
{
61-
config.SetGeneratePropertyMaps(new GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<TContext>(model));
62-
}
59+
where TContext : DbContext => config.SetGeneratePropertyMaps(new GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<TContext>(model));
6360
}
6461
}

src/AutoMapper.Collection.EntityFrameworkCore/Persistence.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,33 @@ public Persistence(DbSet<TTo> sourceSet, IMapper mapper)
2020
}
2121

2222
public TTo InsertOrUpdate<TFrom>(TFrom from)
23-
where TFrom : class
24-
{
25-
return InsertOrUpdate(typeof(TFrom), from);
26-
}
23+
where TFrom : class => InsertOrUpdate(typeof(TFrom), from);
2724

28-
public Task<TTo> InsertOrUpdateAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default(CancellationToken))
29-
where TFrom : class
30-
{
31-
return InsertOrUpdateAsync(typeof(TFrom), from, cancellationToken);
32-
}
25+
public Task<TTo> InsertOrUpdateAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default)
26+
where TFrom : class => InsertOrUpdateAsync(typeof(TFrom), from, cancellationToken);
3327

3428
public TTo InsertOrUpdate(Type type, object from)
3529
{
3630
var equivExpr = GetEquivalenceExpression(type, from);
3731
if (equivExpr == null)
38-
throw new ArgumentException($"Could not retreive equivalency expression for mapping {type.Name} --> {typeof(TTo).Name}");
32+
{
33+
throw new ArgumentException($"Could not retrieve equivalency expression for mapping {type.Name} --> {typeof(TTo).Name}");
34+
}
3935

4036
var to = _sourceSet.FirstOrDefault(equivExpr);
4137

4238
return MapObject(type, from, to);
4339
}
4440

45-
public async Task<TTo> InsertOrUpdateAsync(Type type, object from, CancellationToken cancellationToken = default(CancellationToken))
41+
public async Task<TTo> InsertOrUpdateAsync(Type type, object from, CancellationToken cancellationToken = default)
4642
{
4743
cancellationToken.ThrowIfCancellationRequested();
4844

4945
var equivExpr = GetEquivalenceExpression(type, from);
5046
if (equivExpr == null)
51-
throw new ArgumentException($"Could not retreive equivalency expression for mapping {type.Name} --> {typeof(TTo).Name}");
47+
{
48+
throw new ArgumentException($"Could not retrieve equivalency expression for mapping {type.Name} --> {typeof(TTo).Name}");
49+
}
5250

5351
var to = await _sourceSet.FirstOrDefaultAsync(equivExpr, cancellationToken).ConfigureAwait(false);
5452

@@ -60,25 +58,35 @@ public void Remove<TFrom>(TFrom from)
6058
{
6159
var equivExpr = GetEquivalenceExpression(from);
6260
if (equivExpr == null)
61+
{
6362
return;
63+
}
64+
6465
var to = _sourceSet.FirstOrDefault(equivExpr);
6566

6667
if (to != null)
68+
{
6769
_sourceSet.Remove(to);
70+
}
6871
}
6972

70-
public async Task RemoveAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default(CancellationToken))
73+
public async Task RemoveAsync<TFrom>(TFrom from, CancellationToken cancellationToken = default)
7174
where TFrom : class
7275
{
7376
cancellationToken.ThrowIfCancellationRequested();
7477

7578
var equivExpr = GetEquivalenceExpression(from);
7679
if (equivExpr == null)
80+
{
7781
return;
82+
}
83+
7884
var to = await _sourceSet.FirstOrDefaultAsync(equivExpr, cancellationToken).ConfigureAwait(false);
7985

8086
if (to != null)
87+
{
8188
_sourceSet.Remove(to);
89+
}
8290
}
8391

8492
private TTo MapObject(Type type, object from, TTo to)
@@ -95,14 +103,8 @@ private TTo MapObject(Type type, object from, TTo to)
95103
return to;
96104
}
97105

98-
private Expression<Func<TTo, bool>> GetEquivalenceExpression<TFrom>(TFrom from)
99-
{
100-
return GetEquivalenceExpression(typeof(TFrom), from);
101-
}
106+
private Expression<Func<TTo, bool>> GetEquivalenceExpression<TFrom>(TFrom from) => GetEquivalenceExpression(typeof(TFrom), from);
102107

103-
private Expression<Func<TTo, bool>> GetEquivalenceExpression(Type type, object from)
104-
{
105-
return _mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>;
106-
}
108+
private Expression<Func<TTo, bool>> GetEquivalenceExpression(Type type, object from) => _mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>;
107109
}
108110
}

0 commit comments

Comments
 (0)