Skip to content

Commit 76cf896

Browse files
committed
style: cleanup of variable names
1 parent be08867 commit 76cf896

File tree

8 files changed

+28
-46
lines changed

8 files changed

+28
-46
lines changed

src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using JsonApiDotNetCore.Configuration;
3-
using JsonApiDotNetCore.Graph;
43
using JsonApiDotNetCore.Internal;
54
using JsonApiDotNetCore.Internal.Contracts;
65
using JsonApiDotNetCore.Models;

src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public JsonApiApplicationBuilder(IServiceCollection services, IMvcCoreBuilder mv
3838
_mvcBuilder = mvcBuilder;
3939
}
4040

41-
4241
public void ConfigureJsonApiOptions(Action<JsonApiOptions> configureOptions) => configureOptions(JsonApiOptions);
4342

4443
public void ConfigureMvc()

src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public class ResourceGraphBuilder : IResourceGraphBuilder
1919
{
2020
private readonly List<ContextEntity> _entities = new List<ContextEntity>();
2121
private readonly List<ValidationResult> _validationResults = new List<ValidationResult>();
22-
private readonly Dictionary<Type, List<Type>> _controllerMapper = new Dictionary<Type, List<Type>>() { };
23-
private readonly List<Type> _undefinedMapper = new List<Type>() { };
24-
private bool _usesDbContext;
2522
private readonly IResourceNameFormatter _resourceNameFormatter = new KebabCaseFormatter();
2623

2724
public ResourceGraphBuilder() { }
@@ -184,25 +181,17 @@ protected virtual Type GetRelationshipType(RelationshipAttribute relation, Prope
184181
/// <inheritdoc />
185182
public IResourceGraphBuilder AddDbContext<T>() where T : DbContext
186183
{
187-
_usesDbContext = true;
188-
189184
var contextType = typeof(T);
190-
191185
var contextProperties = contextType.GetProperties();
192-
193186
foreach (var property in contextProperties)
194187
{
195188
var dbSetType = property.PropertyType;
196-
197189
if (dbSetType.GetTypeInfo().IsGenericType
198190
&& dbSetType.GetGenericTypeDefinition() == typeof(DbSet<>))
199191
{
200192
var entityType = dbSetType.GetGenericArguments()[0];
201-
202193
AssertEntityIsNotAlreadyDefined(entityType);
203-
204194
var (isJsonApiResource, idType) = GetIdType(entityType);
205-
206195
if (isJsonApiResource)
207196
_entities.Add(GetEntity(GetResourceNameFromDbSetProperty(property, entityType), entityType, idType));
208197
}

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ internal class ResourceHookExecutor : IResourceHookExecutor
2121
private readonly ITraversalHelper _traversalHelper;
2222
private readonly IIncludeService _includeService;
2323
private readonly ITargetedFields _targetedFields;
24-
private readonly IInverseRelationships _inverseRelationships;
24+
private readonly IResourceGraphExplorer _inverseRelationships;
2525
public ResourceHookExecutor(
2626
IHookExecutorHelper executorHelper,
2727
ITraversalHelper traversalHelper,
2828
ITargetedFields targetedFields,
2929
IIncludeService includedRelationships,
30-
IInverseRelationships inverseRelationships)
30+
IResourceGraphExplorer graph)
3131
{
3232
_executorHelper = executorHelper;
3333
_traversalHelper = traversalHelper;
3434
_targetedFields = targetedFields;
3535
_includeService = includedRelationships;
36-
_inverseRelationships = inverseRelationships;
36+
_inverseRelationships = graph;
3737
}
3838

3939
/// <inheritdoc/>

src/JsonApiDotNetCore/Internal/Contracts/IContextEntityProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public interface IResourceGraphExplorer : IContextEntityProvider
5252
/// </summary>
5353
/// <param name="type">The resource type. Must extend IIdentifiable.</param>
5454
List<RelationshipAttribute> GetRelationships(Type type);
55+
56+
/// <summary>
57+
/// Traverses the resource graph for the inverse relationship of the provided
58+
/// <paramref name="relationship"/>;
59+
/// </summary>
60+
/// <param name="relationship"></param>
61+
RelationshipAttribute GetInverse(RelationshipAttribute relationship);
5562
}
5663

5764
/// <summary>

src/JsonApiDotNetCore/Internal/InverseRelationships.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.Linq;
31
using JsonApiDotNetCore.Data;
42
using JsonApiDotNetCore.Internal.Contracts;
53
using JsonApiDotNetCore.Models;
@@ -26,13 +24,6 @@ public interface IInverseRelationships
2624
/// </summary>
2725
void Resolve();
2826

29-
30-
/// <summary>
31-
/// Traverses the resource graph for the inverse relationship of the provided
32-
/// <paramref name="relationship"/>;
33-
/// </summary>
34-
/// <param name="relationship"></param>
35-
RelationshipAttribute GetInverse(RelationshipAttribute relationship);
3627
}
3728

3829
/// <inheritdoc />
@@ -47,15 +38,6 @@ public InverseRelationships(IContextEntityProvider provider, IDbContextResolver
4738
_resolver = resolver;
4839
}
4940

50-
/// <inheritdoc />
51-
public RelationshipAttribute GetInverse(RelationshipAttribute relationship)
52-
{
53-
if (relationship.InverseNavigation == null) return null;
54-
return _provider.GetContextEntity(relationship.DependentType)
55-
.Relationships
56-
.SingleOrDefault(r => r.InternalRelationshipName == relationship.InverseNavigation);
57-
}
58-
5941
/// <inheritdoc />
6042
public void Resolve()
6143
{
@@ -81,9 +63,6 @@ public void Resolve()
8163
/// If EF Core is not being used, we're expecting the resolver to not be registered.
8264
/// </summary>
8365
/// <returns><c>true</c>, if entity framework core was enabled, <c>false</c> otherwise.</returns>
84-
private bool EntityFrameworkCoreIsEnabled()
85-
{
86-
return _resolver != null;
87-
}
66+
private bool EntityFrameworkCoreIsEnabled() => _resolver != null;
8867
}
8968
}

src/JsonApiDotNetCore/Internal/ResourceGraph.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public List<RelationshipAttribute> GetRelationships(Type type)
6666
return GetContextEntity(type).Relationships.ToList();
6767
}
6868

69+
/// <inheritdoc />
70+
public RelationshipAttribute GetInverse(RelationshipAttribute relationship)
71+
{
72+
if (relationship.InverseNavigation == null) return null;
73+
return GetContextEntity(relationship.DependentType)
74+
.Relationships
75+
.SingleOrDefault(r => r.InternalRelationshipName == relationship.InverseNavigation);
76+
}
77+
6978
private IEnumerable<IResourceField> Getter<T>(Expression<Func<T, dynamic>> selector = null, FieldFilterType type = FieldFilterType.None) where T : IIdentifiable
7079
{
7180
IEnumerable<IResourceField> available;

test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ protected List<TodoItem> CreateTodoWithOwner()
141141

142142
public class HooksTestsSetup : HooksDummyData
143143
{
144-
(IInverseRelationships, Mock<ITargetedFields>, Mock<IIncludeService>, Mock<IGenericProcessorFactory>, IJsonApiOptions) CreateMocks()
144+
(Mock<ITargetedFields>, Mock<IIncludeService>, Mock<IGenericProcessorFactory>, IJsonApiOptions) CreateMocks()
145145
{
146146
var pfMock = new Mock<IGenericProcessorFactory>();
147147
var ufMock = new Mock<ITargetedFields>();
148148
var iqsMock = new Mock<IIncludeService>();
149149
var optionsMock = new JsonApiOptions { LoaDatabaseValues = false };
150-
return (new InverseRelationships(_graph), ufMock, iqsMock, pfMock, optionsMock);
150+
return (ufMock, iqsMock, pfMock, optionsMock);
151151
}
152152

153153
internal (Mock<IIncludeService>, ResourceHookExecutor, Mock<IResourceHookContainer<TMain>>) CreateTestObjects<TMain>(IHooksDiscovery<TMain> mainDiscovery = null)
@@ -157,13 +157,13 @@ public class HooksTestsSetup : HooksDummyData
157157
var mainResource = CreateResourceDefinition(mainDiscovery);
158158

159159
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
160-
var (inverse, ufMock, iqMock, gpfMock, options) = CreateMocks();
160+
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
161161

162162
SetupProcessorFactoryForResourceDefinition(gpfMock, mainResource.Object, mainDiscovery, null);
163163

164164
var execHelper = new HookExecutorHelper(gpfMock.Object, options);
165165
var traversalHelper = new TraversalHelper(_graph, ufMock.Object);
166-
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, inverse);
166+
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, _graph);
167167

168168
return (iqMock, hookExecutor, mainResource);
169169
}
@@ -182,7 +182,7 @@ public class HooksTestsSetup : HooksDummyData
182182
var nestedResource = CreateResourceDefinition(nestedDiscovery);
183183

184184
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
185-
var (inverse, ufMock, iqMock, gpfMock, options) = CreateMocks();
185+
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
186186

187187
var dbContext = repoDbContextOptions != null ? new AppDbContext(repoDbContextOptions) : null;
188188

@@ -191,7 +191,7 @@ public class HooksTestsSetup : HooksDummyData
191191

192192
var execHelper = new HookExecutorHelper(gpfMock.Object, options);
193193
var traversalHelper = new TraversalHelper(_graph, ufMock.Object);
194-
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, inverse);
194+
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, _graph);
195195

196196
return (iqMock, ufMock, hookExecutor, mainResource, nestedResource);
197197
}
@@ -213,7 +213,7 @@ public class HooksTestsSetup : HooksDummyData
213213
var secondNestedResource = CreateResourceDefinition(secondNestedDiscovery);
214214

215215
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
216-
var (inverse, ufMock, iqMock, gpfMock, options) = CreateMocks();
216+
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
217217

218218
var dbContext = repoDbContextOptions != null ? new AppDbContext(repoDbContextOptions) : null;
219219

@@ -223,7 +223,7 @@ public class HooksTestsSetup : HooksDummyData
223223

224224
var execHelper = new HookExecutorHelper(gpfMock.Object, options);
225225
var traversalHelper = new TraversalHelper(_graph, ufMock.Object);
226-
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, inverse);
226+
var hookExecutor = new ResourceHookExecutor(execHelper, traversalHelper, ufMock.Object, iqMock.Object, _graph);
227227

228228
return (iqMock, hookExecutor, mainResource, firstNestedResource, secondNestedResource);
229229
}

0 commit comments

Comments
 (0)