From e89c2d14c989828a6a852dc16fabf8fb84c63e10 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:19:29 +0100 Subject: [PATCH 01/73] Fixed: XML comment is not placed on a valid language element --- .../Resources/UserResource.cs | 4 ++-- .../Acceptance/KebabCaseFormatterTests.cs | 24 +++++++++---------- .../Spec/UpdatingRelationshipsTests.cs | 8 +++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs index aa4552cae6..551b6e28c4 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs @@ -26,8 +26,8 @@ private IQueryable FirstCharacterFilter(IQueryable users, FilterQuer { switch (filterQuery.Operation) { - /// In EF core >= 3.0 we need to explicitly evaluate the query first. This could probably be translated - /// into a query by building expression trees. + // In EF core >= 3.0 we need to explicitly evaluate the query first. This could probably be translated + // into a query by building expression trees. case "lt": return users.ToList().Where(u => u.Username.First() < filterQuery.Value[0]).AsQueryable(); default: diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs index 842e533d36..79793a1c7a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs @@ -20,15 +20,15 @@ public KebabCaseFormatterTests(KebabCaseApplicationFactory factory) : base(facto [Fact] public async Task KebabCaseFormatter_GetAll_IsReturned() { - /// Arrange + // Arrange var model = _faker.Generate(); _dbContext.KebabCasedModels.Add(model); _dbContext.SaveChanges(); - /// Act + // Act var (body, response) = await Get("api/v1/kebab-cased-models"); - /// Assert + // Assert AssertEqualStatusCode(HttpStatusCode.OK, response); var responseItem = _deserializer.DeserializeList(body).Data; Assert.True(responseItem.Count > 0); @@ -37,15 +37,15 @@ public async Task KebabCaseFormatter_GetAll_IsReturned() [Fact] public async Task KebabCaseFormatter_GetSingle_IsReturned() { - /// Arrange + // Arrange var model = _faker.Generate(); _dbContext.KebabCasedModels.Add(model); _dbContext.SaveChanges(); - /// Act + // Act var (body, response) = await Get($"api/v1/kebab-cased-models/{model.Id}"); - /// Assert + // Assert AssertEqualStatusCode(HttpStatusCode.OK, response); var responseItem = _deserializer.DeserializeSingle(body).Data; Assert.Equal(model.Id, responseItem.Id); @@ -54,14 +54,14 @@ public async Task KebabCaseFormatter_GetSingle_IsReturned() [Fact] public async Task KebabCaseFormatter_Create_IsCreated() { - /// Arrange + // Arrange var model = _faker.Generate(); var serializer = GetSerializer(kcm => new { kcm.CompoundAttr }); - /// Act + // Act var (body, response) = await Post($"api/v1/kebab-cased-models", serializer.Serialize(model)); - /// Assert + // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); var responseItem = _deserializer.DeserializeSingle(body).Data; var x = _dbContext.KebabCasedModels.Where(kcm => kcm.Id.Equals(responseItem.Id)).Single(); @@ -71,17 +71,17 @@ public async Task KebabCaseFormatter_Create_IsCreated() [Fact] public async Task KebabCaseFormatter_Update_IsUpdated() { - /// Arrange + // Arrange var model = _faker.Generate(); _dbContext.KebabCasedModels.Add(model); _dbContext.SaveChanges(); model.CompoundAttr = _faker.Generate().CompoundAttr; var serializer = GetSerializer(kcm => new { kcm.CompoundAttr }); - /// Act + // Act var (body, response) = await Patch($"api/v1/kebab-cased-models/{model.Id}", serializer.Serialize(model)); - /// Assert + // Assert AssertEqualStatusCode(HttpStatusCode.OK, response); var responseItem = _deserializer.DeserializeSingle(body).Data; Assert.Equal(model.CompoundAttr, responseItem.CompoundAttr); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index e3c9c9e3f4..ecc6e985aa 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -291,8 +291,8 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource() Assert.Equal(HttpStatusCode.OK, response.StatusCode); - /// we are expecting two, not three, because the request does - /// a "complete replace". + // we are expecting two, not three, because the request does + // a "complete replace". Assert.Equal(2, updatedTodoItems.Count); } @@ -370,8 +370,8 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource_When_Targe Assert.Equal(HttpStatusCode.OK, response.StatusCode); - /// we are expecting two, not three, because the request does - /// a "complete replace". + // we are expecting two, not three, because the request does + // a "complete replace". Assert.Equal(2, updatedTodoItems.Count); } From 8fb115fb4c08e5f34f78df00503959957d25e56f Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:20:35 +0100 Subject: [PATCH 02/73] Fixed: Convert to method group --- src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs | 2 +- src/Examples/ReportsExample/Services/ReportService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs index 551b6e28c4..6ba4826a2f 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs @@ -18,7 +18,7 @@ public override QueryFilters GetQueryFilters() { return new QueryFilters { - { "firstCharacter", (users, queryFilter) => FirstCharacterFilter(users, queryFilter) } + { "firstCharacter", FirstCharacterFilter } }; } diff --git a/src/Examples/ReportsExample/Services/ReportService.cs b/src/Examples/ReportsExample/Services/ReportService.cs index 542b276a5b..f2239d2445 100644 --- a/src/Examples/ReportsExample/Services/ReportService.cs +++ b/src/Examples/ReportsExample/Services/ReportService.cs @@ -19,7 +19,7 @@ public Task> GetAsync() { _logger.LogError("GetAsync"); - var task = new Task>(() => Get()); + var task = new Task>(Get); task.RunSynchronously(TaskScheduler.Default); From 4100e7d561d3e42f9aa5ba81229cb1cf7883b05f Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:22:34 +0100 Subject: [PATCH 03/73] Fixed: Use null propagation --- .../Extensions/IApplicationBuilderExtensions.cs | 4 ++-- .../QueryParameterServices/FilterService.cs | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs index bd1f2bc91a..bf882426ea 100644 --- a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs @@ -81,9 +81,9 @@ private static void LogResourceGraphValidations(IApplicationBuilder app) var logger = app.ApplicationServices.GetService(typeof(ILogger)) as ILogger; var resourceGraph = app.ApplicationServices.GetService(typeof(IResourceGraph)) as ResourceGraph; - if (logger != null && resourceGraph != null) + if (logger != null) { - resourceGraph.ValidationResults.ForEach((v) => + resourceGraph?.ValidationResults.ForEach((v) => logger.Log( v.LogLevel, new EventId(), diff --git a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs index bf921383ef..6be77fad8d 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs @@ -39,15 +39,12 @@ public virtual void Parse(KeyValuePair queryParameter) private FilterQueryContext GetQueryContexts(FilterQuery query) { var queryContext = new FilterQueryContext(query); - if (_requestResourceDefinition != null) + var customQuery = _requestResourceDefinition?.GetCustomQueryFilter(query.Target); + if (customQuery != null) { - var customQuery = _requestResourceDefinition.GetCustomQueryFilter(query.Target); - if (customQuery != null) - { - queryContext.IsCustom = true; - queryContext.CustomQuery = customQuery; - return queryContext; - } + queryContext.IsCustom = true; + queryContext.CustomQuery = customQuery; + return queryContext; } queryContext.Relationship = GetRelationship(query.Relationship); From 8c70342b3205b81a280256964974fb62de39387e Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:23:25 +0100 Subject: [PATCH 04/73] Fixed: Use string interpolation expression --- src/JsonApiDotNetCore/Internal/Query/BaseQueryContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Internal/Query/BaseQueryContext.cs b/src/JsonApiDotNetCore/Internal/Query/BaseQueryContext.cs index c35dd64c88..5ad0d0a386 100644 --- a/src/JsonApiDotNetCore/Internal/Query/BaseQueryContext.cs +++ b/src/JsonApiDotNetCore/Internal/Query/BaseQueryContext.cs @@ -23,7 +23,7 @@ protected BaseQueryContext(TQuery query) public string GetPropertyPath() { if (IsAttributeOfRelationship) - return string.Format("{0}.{1}", Relationship.InternalRelationshipName, Attribute.PropertyInfo.Name); + return $"{Relationship.InternalRelationshipName}.{Attribute.PropertyInfo.Name}"; return Attribute.PropertyInfo.Name; } From b04cadd8e9b451e3734d1495a436eec013191607 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:25:39 +0100 Subject: [PATCH 05/73] Fixed: Use lambda expression --- .../Services/TodoItemService.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs index 09078cda2c..170e268172 100644 --- a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs +++ b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs @@ -39,18 +39,16 @@ private async Task> QueryAsync(Func> GetAsync() { - return await QueryAsync(async connection => - { - return await connection.QueryAsync("select * from \"TodoItems\""); - }); + return await QueryAsync(async connection => + await connection.QueryAsync("select * from \"TodoItems\"")); } public async Task GetAsync(int id) { - return (await QueryAsync(async connection => - { - return await connection.QueryAsync("select * from \"TodoItems\" where \"Id\"= @id", new { id }); - })).SingleOrDefault(); + var query = await QueryAsync(async connection => + await connection.QueryAsync("select * from \"TodoItems\" where \"Id\"= @id", new {id})); + + return query.SingleOrDefault(); } public Task GetRelationshipAsync(int id, string relationshipName) From 56d200b5d9e26c40434fe1a1c6eb0a1da626382f Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:27:46 +0100 Subject: [PATCH 06/73] Fixed: Convert to compound assignment --- src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs | 4 ++-- src/JsonApiDotNetCore/Internal/ResourceContext.cs | 2 +- .../QueryParameterServices/SparseFieldsService.cs | 2 +- .../Serialization/Common/ResourceObjectBuilder.cs | 2 +- .../Serialization/Server/Builders/LinkBuilder.cs | 2 +- .../Server/Builders/ResponseResourceObjectBuilder.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs index f9d8c9da13..0c65d81c29 100644 --- a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs @@ -109,7 +109,7 @@ protected virtual List GetAttributes(Type entityType) if (attribute == null) continue; - attribute.PublicAttributeName = attribute.PublicAttributeName ?? _formatter.FormatPropertyName(prop); + attribute.PublicAttributeName ??= _formatter.FormatPropertyName(prop); attribute.PropertyInfo = prop; attributes.Add(attribute); @@ -126,7 +126,7 @@ protected virtual List GetRelationships(Type entityType) var attribute = (RelationshipAttribute)prop.GetCustomAttribute(typeof(RelationshipAttribute)); if (attribute == null) continue; - attribute.PublicRelationshipName = attribute.PublicRelationshipName ?? _formatter.FormatPropertyName(prop); + attribute.PublicRelationshipName ??= _formatter.FormatPropertyName(prop); attribute.InternalRelationshipName = prop.Name; attribute.RightType = GetRelationshipType(attribute, prop); attribute.LeftType = entityType; diff --git a/src/JsonApiDotNetCore/Internal/ResourceContext.cs b/src/JsonApiDotNetCore/Internal/ResourceContext.cs index 15ab4b4c7a..3aaad31f35 100644 --- a/src/JsonApiDotNetCore/Internal/ResourceContext.cs +++ b/src/JsonApiDotNetCore/Internal/ResourceContext.cs @@ -43,7 +43,7 @@ public class ResourceContext public List Relationships { get; set; } private List _fields; - public List Fields { get { return _fields = _fields ?? Attributes.Cast().Concat(Relationships).ToList(); } } + public List Fields { get { return _fields ??= Attributes.Cast().Concat(Relationships).ToList(); } } /// /// Configures which links to show in the diff --git a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs index c56319fe93..404db49a53 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs @@ -103,7 +103,7 @@ private void RegisterRequestResourceField(string field) if (attr == null) throw new JsonApiException(400, $"'{_requestResource.ResourceName}' does not contain '{field}'."); - (_selectedFields = _selectedFields ?? new List()).Add(attr); + (_selectedFields ??= new List()).Add(attr); } } } diff --git a/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilder.cs b/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilder.cs index 21aa663844..d62434b8df 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilder.cs @@ -127,7 +127,7 @@ private void ProcessRelationships(IIdentifiable entity, IEnumerable()).Add(rel.PublicRelationshipName, relData); + (ro.Relationships ??= new Dictionary()).Add(rel.PublicRelationshipName, relData); } } diff --git a/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs b/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs index 5d81048988..d8b432b959 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs @@ -140,7 +140,7 @@ public RelationshipLinks GetRelationshipLinks(RelationshipAttribute relationship if (ShouldAddRelationshipLink(parentResourceContext, relationship, Link.Self)) { - links = links ?? new RelationshipLinks(); + links ??= new RelationshipLinks(); links.Self = GetSelfRelationshipLink(parentResourceContext.ResourceName, parent.StringId, childNavigation); } diff --git a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs index 2291610391..367039f333 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs @@ -55,7 +55,7 @@ protected override RelationshipEntry GetRelationshipData(RelationshipAttribute r var links = _linkBuilder.GetRelationshipLinks(relationship, entity); if (links != null) // if links relationshipLinks should be built for this entry, populate the "links" field. - (relationshipEntry = relationshipEntry ?? new RelationshipEntry()).Links = links; + (relationshipEntry ??= new RelationshipEntry()).Links = links; // if neither "links" nor "data" was popupated, return null, which will omit this entry from the output. // (see the NullValueHandling settings on ) From a2a0f5ae22ee278e4cf621deaa67d03e9ce0d035 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:28:45 +0100 Subject: [PATCH 07/73] Fixed: Convert to 'using' declaration --- .../Services/TodoItemService.cs | 8 +++----- src/JsonApiDotNetCore/Formatters/JsonApiReader.cs | 12 +++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs index 170e268172..a5664fccfd 100644 --- a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs +++ b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs @@ -30,11 +30,9 @@ private IDbConnection Connection private async Task> QueryAsync(Func>> query) { - using (IDbConnection dbConnection = Connection) - { - dbConnection.Open(); - return await query(dbConnection); - } + using IDbConnection dbConnection = Connection; + dbConnection.Open(); + return await query(dbConnection); } public async Task> GetAsync() diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs index 784f16fd0b..309705e03d 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs @@ -111,13 +111,11 @@ private bool CheckForId(IList modelList) /// String content of body sent to server. private async Task GetRequestBody(Stream body) { - using (var reader = new StreamReader(body)) - { - // This needs to be set to async because - // Synchronous IO operations are - // https://github.com/aspnet/AspNetCore/issues/7644 - return await reader.ReadToEndAsync(); - } + using var reader = new StreamReader(body); + // This needs to be set to async because + // Synchronous IO operations are + // https://github.com/aspnet/AspNetCore/issues/7644 + return await reader.ReadToEndAsync(); } } } From 2f23e13452285c228d5969222489f72703e21900 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:31:45 +0100 Subject: [PATCH 08/73] Fixed: Use 'await using' --- src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs | 2 +- .../IntegrationTests/Data/EntityRepositoryTests.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs b/src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs index 0b2c615581..2620fcdd25 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs @@ -35,7 +35,7 @@ public async Task WriteAsync(OutputFormatterWriteContext context) throw new ArgumentNullException(nameof(context)); var response = context.HttpContext.Response; - using var writer = context.WriterFactory(response.Body, Encoding.UTF8); + await using var writer = context.WriterFactory(response.Body, Encoding.UTF8); string responseContent; if (_serializer == null) diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index 35dbbe878c..c9b2ef4f42 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -23,7 +23,7 @@ public async Task UpdateAsync_AttributesUpdated_ShouldHaveSpecificallyThoseAttri // Arrange var itemId = 213; var seed = Guid.NewGuid(); - using (var arrangeContext = GetContext(seed)) + await using (var arrangeContext = GetContext(seed)) { var (repository, targetedFields) = Setup(arrangeContext); var todoItemUpdates = new TodoItem @@ -46,7 +46,7 @@ public async Task UpdateAsync_AttributesUpdated_ShouldHaveSpecificallyThoseAttri } // Assert - in different context - using var assertContext = GetContext(seed); + await using var assertContext = GetContext(seed); { var (repository, targetedFields) = Setup(assertContext); @@ -65,7 +65,7 @@ public async Task UpdateAsync_AttributesUpdated_ShouldHaveSpecificallyThoseAttri public async Task Paging_PageNumberIsPositive_ReturnCorrectIdsAtTheFront(int pageSize, int pageNumber, int[] expectedResult) { // Arrange - using var context = GetContext(); + await using var context = GetContext(); var (repository, targetedFields) = Setup(context); context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9)); await context.SaveChangesAsync(); @@ -84,7 +84,7 @@ public async Task Paging_PageNumberIsPositive_ReturnCorrectIdsAtTheFront(int pag public async Task Paging_PageSizeNonPositive_DoNothing(int pageSize) { // Arrange - using var context = GetContext(); + await using var context = GetContext(); var (repository, targetedFields) = Setup(context); var items = TodoItems(2, 3, 1); context.AddRange(items); @@ -102,7 +102,7 @@ public async Task Paging_PageNumberDoesNotExist_ReturnEmptyAQueryable() { // Arrange var items = TodoItems(2, 3, 1); - using var context = GetContext(); + await using var context = GetContext(); var (repository, targetedFields) = Setup(context); context.AddRange(items); @@ -117,7 +117,7 @@ public async Task Paging_PageNumberDoesNotExist_ReturnEmptyAQueryable() public async Task Paging_PageNumberIsZero_PretendsItsOne() { // Arrange - using var context = GetContext(); + await using var context = GetContext(); var (repository, targetedFields) = Setup(context); context.AddRange(TodoItems(2, 3, 4, 5, 6, 7, 8, 9)); await context.SaveChangesAsync(); @@ -136,7 +136,7 @@ public async Task Paging_PageNumberIsZero_PretendsItsOne() public async Task Paging_PageNumberIsNegative_GiveBackReverseAmountOfIds(int pageSize, int pageNumber, int[] expectedIds) { // Arrange - using var context = GetContext(); + await using var context = GetContext(); var repository = Setup(context).Repository; context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9)); context.SaveChanges(); From 53c0a08aa80ba7bca383ed37a9da6735ab983db4 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:33:17 +0100 Subject: [PATCH 09/73] Fixed: Convert to '?:' expression --- .../Common/QueryParameterService.cs | 19 ++++++------------- .../Client/ResponseDeserializer.cs | 8 +++----- .../Services/DefaultResourceService.cs | 7 +++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs index cf363bef65..16cf8145c4 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs @@ -20,14 +20,9 @@ protected QueryParameterService(IResourceGraph resourceGraph, ICurrentRequest cu { _mainRequestResource = currentRequest.GetRequestResource(); _resourceGraph = resourceGraph; - if (currentRequest.RequestRelationship != null) - { - _requestResource= resourceGraph.GetResourceContext(currentRequest.RequestRelationship.RightType); - } - else - { - _requestResource = _mainRequestResource; - } + _requestResource = currentRequest.RequestRelationship != null + ? resourceGraph.GetResourceContext(currentRequest.RequestRelationship.RightType) + : _mainRequestResource; } protected QueryParameterService() { } @@ -53,11 +48,9 @@ protected QueryParameterService() { } /// protected AttrAttribute GetAttribute(string target, RelationshipAttribute relationship = null) { - AttrAttribute attribute; - if (relationship != null) - attribute = _resourceGraph.GetAttributes(relationship.RightType).FirstOrDefault(a => a.Is(target)); - else - attribute = _requestResource.Attributes.FirstOrDefault(attr => attr.Is(target)); + var attribute = relationship != null + ? _resourceGraph.GetAttributes(relationship.RightType).FirstOrDefault(a => a.Is(target)) + : _requestResource.Attributes.FirstOrDefault(attr => attr.Is(target)); if (attribute == null) throw new JsonApiException(400, $"'{target}' is not a valid attribute."); diff --git a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs index 38ed9dd1f0..08dca3ee4f 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs @@ -62,12 +62,10 @@ protected override void AfterProcessField(IIdentifiable entity, IResourceField f return; if (field is HasOneAttribute hasOneAttr) - { // add attributes and relationships of a parsed HasOne relationship + { + // add attributes and relationships of a parsed HasOne relationship var rio = data.SingleData; - if (rio == null) - hasOneAttr.SetValue(entity, null); - else - hasOneAttr.SetValue(entity, ParseIncludedRelationship(hasOneAttr, rio)); + hasOneAttr.SetValue(entity, rio == null ? null : ParseIncludedRelationship(hasOneAttr, rio)); } else if (field is HasManyAttribute hasManyAttr) { // add attributes and relationships of a parsed HasMany relationship diff --git a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs index d7eaed4001..a090518dc9 100644 --- a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs +++ b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs @@ -188,10 +188,9 @@ public virtual async Task UpdateRelationshipsAsync(TId id, string relationshipNa string[] relationshipIds = null; if (related != null) { - if (relationship is HasOneAttribute) - relationshipIds = new string[] { ((IIdentifiable)related).StringId }; - else - relationshipIds = ((IEnumerable)related).Select(e => e.StringId).ToArray(); + relationshipIds = relationship is HasOneAttribute + ? new[] {((IIdentifiable) related).StringId} + : ((IEnumerable) related).Select(e => e.StringId).ToArray(); } await _repository.UpdateRelationshipsAsync(entity, relationship, relationshipIds ?? new string[0] ); From fd932c099b94e26cb86c213d548fdffd9140acc7 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:34:55 +0100 Subject: [PATCH 10/73] Fixed: Merge conditional expression --- .../Serialization/Client/ResponseDeserializer.cs | 4 ++-- test/IntegrationTests/Data/EntityRepositoryTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs index 08dca3ee4f..d535a6f290 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs @@ -23,7 +23,7 @@ public DeserializedSingleResponse DeserializeSingle(string { Links = _document.Links, Meta = _document.Meta, - Data = entity == null ? null : (TResource)entity, + Data = (TResource) entity, JsonApi = null, Errors = null }; @@ -37,7 +37,7 @@ public DeserializedListResponse DeserializeList(string bod { Links = _document.Links, Meta = _document.Meta, - Data = entities == null ? null : ((List)entities).Cast().ToList(), + Data = ((List) entities)?.Cast().ToList(), JsonApi = null, Errors = null }; diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index c9b2ef4f42..d1ab6ea78c 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -161,7 +161,7 @@ public async Task Paging_PageNumberIsNegative_GiveBackReverseAmountOfIds(int pag private AppDbContext GetContext(Guid? seed = null) { - Guid actualSeed = seed == null ? Guid.NewGuid() : seed.GetValueOrDefault(); + Guid actualSeed = seed ?? Guid.NewGuid(); var options = new DbContextOptionsBuilder() .UseInMemoryDatabase(databaseName: $"IntegrationDatabaseRepository{actualSeed}") .Options; From 2e17fe72e58667497e74b73e89f12f72046e9cf0 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:37:39 +0100 Subject: [PATCH 11/73] Fixed: Use object initializer --- .../ResourceDefinitionTests.cs | 12 ++++--- .../Acceptance/Spec/ContentNegotiation.cs | 10 +++--- .../Acceptance/Spec/UpdatingDataTests.cs | 3 +- .../Spec/UpdatingRelationshipsTests.cs | 30 +++++++++-------- .../Acceptance/TodoItemsControllerTests.cs | 33 ++++++++++++------- .../Extensibility/NoEntityFrameworkTests.cs | 6 ++-- .../BaseJsonApiController_Tests.cs | 17 +++++++--- .../CurrentRequestMiddlewareTests.cs | 7 ++-- test/UnitTests/Models/IdentifiableTests.cs | 6 ++-- 9 files changed, 73 insertions(+), 51 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index 0fbace3280..d13f595ee3 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -79,8 +79,10 @@ public async Task Can_Create_User_With_Password() var httpMethod = new HttpMethod("POST"); var route = $"/api/v1/users"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(serializer.Serialize(user)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(serializer.Serialize(user)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -113,8 +115,10 @@ public async Task Can_Update_User_Password() var serializer = _fixture.GetSerializer(p => new { p.Password }); var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/users/{user.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(serializer.Serialize(user)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(serializer.Serialize(user)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs index bccb8ebf83..ab36df4249 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs @@ -48,10 +48,9 @@ public async Task Server_Responds_415_With_MediaType_Parameters() var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(string.Empty); - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); - request.Content.Headers.ContentType.CharSet = "ISO-8859-4"; + var request = new HttpRequestMessage(httpMethod, route) {Content = new StringContent(string.Empty)}; + request.Content.Headers.ContentType = + new MediaTypeHeaderValue("application/vnd.api+json") {CharSet = "ISO-8859-4"}; // Act var response = await client.SendAsync(request); @@ -70,8 +69,7 @@ public async Task ServerResponds_406_If_RequestAcceptHeader_Contains_MediaTypePa var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); - var acceptHeader = new MediaTypeWithQualityHeaderValue("application/vnd.api+json"); - acceptHeader.CharSet = "ISO-8859-4"; + var acceptHeader = new MediaTypeWithQualityHeaderValue("application/vnd.api+json") {CharSet = "ISO-8859-4"}; client.DefaultRequestHeaders .Accept .Add(acceptHeader); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs index ea9ea6004c..162763b15f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs @@ -249,9 +249,8 @@ public async Task Can_Patch_Entity_And_HasOne_Relationships() private HttpRequestMessage PrepareRequest(string method, string route, string content) { var httpMethod = new HttpMethod(method); - var request = new HttpRequestMessage(httpMethod, route); + var request = new HttpRequestMessage(httpMethod, route) {Content = new StringContent(content)}; - request.Content = new StringContent(content); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); return request; } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index ecc6e985aa..6450ee6445 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -232,8 +232,7 @@ public async Task Can_Update_Both_Cyclic_ToOne_And_ToMany_Relationship_By_Patchi public async Task Can_Update_ToMany_Relationship_By_Patching_Resource() { // Arrange - var todoCollection = new TodoItemCollection(); - todoCollection.TodoItems = new List(); + var todoCollection = new TodoItemCollection {TodoItems = new List()}; var person = _personFaker.Generate(); var todoItem = _todoItemFaker.Generate(); todoCollection.Owner = person; @@ -306,8 +305,7 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource_When_Targe // this user may not be reattached to the db context in the repository. // Arrange - var todoCollection = new TodoItemCollection(); - todoCollection.TodoItems = new List(); + var todoCollection = new TodoItemCollection {TodoItems = new List()}; var person = _personFaker.Generate(); var todoItem = _todoItemFaker.Generate(); todoCollection.Owner = person; @@ -379,8 +377,7 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource_When_Targe public async Task Can_Update_ToMany_Relationship_By_Patching_Resource_With_Overlap() { // Arrange - var todoCollection = new TodoItemCollection(); - todoCollection.TodoItems = new List(); + var todoCollection = new TodoItemCollection {TodoItems = new List()}; var person = _personFaker.Generate(); var todoItem1 = _todoItemFaker.Generate(); var todoItem2 = _todoItemFaker.Generate(); @@ -472,9 +469,11 @@ public async Task Can_Update_ToMany_Relationship_ThroughLink() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/people/{person.Id}/relationships/todoItems"; - var request = new HttpRequestMessage(httpMethod, route); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; - request.Content = new StringContent(JsonConvert.SerializeObject(content)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -510,9 +509,8 @@ public async Task Can_Update_ToOne_Relationship_ThroughLink() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}/relationships/owner"; - var request = new HttpRequestMessage(httpMethod, route); + var request = new HttpRequestMessage(httpMethod, route) {Content = new StringContent(content)}; - request.Content = new StringContent(content); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -560,8 +558,10 @@ public async Task Can_Delete_ToOne_Relationship_By_Patching_Resource() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -660,9 +660,11 @@ public async Task Can_Delete_Relationship_By_Patching_Relationship() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}/relationships/owner"; - var request = new HttpRequestMessage(httpMethod, route); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; - request.Content = new StringContent(JsonConvert.SerializeObject(content)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index 63b88a311c..a4ac66c9f6 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -526,8 +526,10 @@ public async Task Can_Post_TodoItem() var httpMethod = new HttpMethod("POST"); var route = $"/api/v1/todoItems"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(serializer.Serialize(todoItem)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(serializer.Serialize(todoItem)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -592,8 +594,10 @@ public async Task Can_Post_TodoItem_With_Different_Owner_And_Assignee() var httpMethod = new HttpMethod("POST"); var route = $"/api/v1/todoItems"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -645,8 +649,10 @@ public async Task Can_Patch_TodoItem() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -698,8 +704,10 @@ public async Task Can_Patch_TodoItemWithNullable() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -750,8 +758,10 @@ public async Task Can_Patch_TodoItemWithNullValue() var httpMethod = new HttpMethod("PATCH"); var route = $"/api/v1/todoItems/{todoItem.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act @@ -783,8 +793,7 @@ public async Task Can_Delete_TodoItem() var httpMethod = new HttpMethod("DELETE"); var route = $"/api/v1/todoItems/{todoItem.Id}"; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(string.Empty); + var request = new HttpRequestMessage(httpMethod, route) {Content = new StringContent(string.Empty)}; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); // Act diff --git a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs index dc6506afdc..610f288961 100644 --- a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs +++ b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs @@ -92,8 +92,10 @@ public async Task Can_Create_TodoItems() } }; - var request = new HttpRequestMessage(httpMethod, route); - request.Content = new StringContent(JsonConvert.SerializeObject(content)); + var request = new HttpRequestMessage(httpMethod, route) + { + Content = new StringContent(JsonConvert.SerializeObject(content)) + }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json"); var builder = new WebHostBuilder() diff --git a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs index 2044ca72dd..d445316206 100644 --- a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs +++ b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs @@ -251,8 +251,14 @@ public async Task PostAsync_ModelStateInvalid_ValidateModelStateDisabled() // Arrange var resource = new Resource(); var serviceMock = new Mock>(); - var controller = new ResourceController(new JsonApiOptions { ValidateModelState = false }, NullLoggerFactory.Instance, create: serviceMock.Object); - controller.ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext { HttpContext = new DefaultHttpContext() }; + var controller = new ResourceController(new JsonApiOptions {ValidateModelState = false}, + NullLoggerFactory.Instance, create: serviceMock.Object) + { + ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext + { + HttpContext = new DefaultHttpContext() + } + }; serviceMock.Setup(m => m.CreateAsync(It.IsAny())).ReturnsAsync(resource); // Act @@ -269,8 +275,11 @@ public async Task PostAsync_ModelStateInvalid_ValidateModelStateEnabled() // Arrange var resource = new Resource(); var serviceMock = new Mock>(); - var controller = new ResourceController(new JsonApiOptions { ValidateModelState = true }, NullLoggerFactory.Instance, create: serviceMock.Object); - controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; + var controller = new ResourceController(new JsonApiOptions {ValidateModelState = true}, + NullLoggerFactory.Instance, create: serviceMock.Object) + { + ControllerContext = new ControllerContext {HttpContext = new DefaultHttpContext()} + }; controller.ModelState.AddModelError("TestAttribute", "Failed Validation"); serviceMock.Setup(m => m.CreateAsync(It.IsAny())).ReturnsAsync(resource); diff --git a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs index c224207a5d..7c876a6f2d 100644 --- a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs +++ b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs @@ -161,9 +161,10 @@ private static DefaultHttpContext CreateHttpContext(string path, bool isRelation var context = new DefaultHttpContext(); context.Request.Path = new PathString(path); context.Response.Body = new MemoryStream(); - var feature = new RouteValuesFeature(); - feature.RouteValues["controller"] = "fake!"; - feature.RouteValues["action"] = isRelationship ? "GetRelationship" : action; + var feature = new RouteValuesFeature + { + RouteValues = {["controller"] = "fake!", ["action"] = isRelationship ? "GetRelationship" : action} + }; if(id != null) { feature.RouteValues["id"] = id; diff --git a/test/UnitTests/Models/IdentifiableTests.cs b/test/UnitTests/Models/IdentifiableTests.cs index da4e30360a..954daedb8d 100644 --- a/test/UnitTests/Models/IdentifiableTests.cs +++ b/test/UnitTests/Models/IdentifiableTests.cs @@ -8,16 +8,14 @@ public class IdentifiableTests [Fact] public void Can_Set_StringId_To_Value_Type() { - var resource = new IntId(); - resource.StringId = "1"; + var resource = new IntId {StringId = "1"}; Assert.Equal(1, resource.Id); } [Fact] public void Setting_StringId_To_Null_Sets_Id_As_Default() { - var resource = new IntId(); - resource.StringId = null; + var resource = new IntId {StringId = null}; Assert.Equal(0, resource.Id); } From 5db43f61ff4175d753c68f3fcd23e406c021a177 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:38:35 +0100 Subject: [PATCH 12/73] Fixed: Qualifier is redundant --- .../Acceptance/Spec/DocumentTests/Included.cs | 2 +- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 2 +- .../Acceptance/TodoItemsControllerTests.cs | 6 +++--- test/UnitTests/Controllers/BaseJsonApiController_Tests.cs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs index 5c98837e1d..a874265508 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs @@ -20,7 +20,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests public class Included { private readonly AppDbContext _context; - private readonly Bogus.Faker _personFaker; + private readonly Faker _personFaker; private readonly Faker _todoItemFaker; private readonly Faker _todoItemCollectionFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index 6450ee6445..e069185b23 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -25,7 +25,7 @@ public class UpdatingRelationshipsTests { private TestFixture _fixture; private AppDbContext _context; - private Bogus.Faker _personFaker; + private Faker _personFaker; private Faker _todoItemFaker; public UpdatingRelationshipsTests(TestFixture fixture) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index a4ac66c9f6..fd59bf7dcd 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -677,13 +677,13 @@ public async Task Can_Patch_TodoItemWithNullable() _context.SaveChanges(); var todoItem = _todoItemFaker.Generate(); - todoItem.AchievedDate = System.DateTime.Now; + todoItem.AchievedDate = DateTime.Now; todoItem.Owner = person; _context.TodoItems.Add(todoItem); _context.SaveChanges(); var newTodoItem = _todoItemFaker.Generate(); - newTodoItem.AchievedDate = System.DateTime.Now.AddDays(2); + newTodoItem.AchievedDate = DateTime.Now.AddDays(2); var content = new { @@ -732,7 +732,7 @@ public async Task Can_Patch_TodoItemWithNullValue() _context.SaveChanges(); var todoItem = _todoItemFaker.Generate(); - todoItem.AchievedDate = System.DateTime.Now; + todoItem.AchievedDate = DateTime.Now; todoItem.Owner = person; _context.TodoItems.Add(todoItem); _context.SaveChanges(); diff --git a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs index d445316206..5d328e05d3 100644 --- a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs +++ b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs @@ -236,7 +236,7 @@ public async Task PostAsync_Calls_Service() var controller = new ResourceController(new JsonApiOptions(), NullLoggerFactory.Instance, create: serviceMock.Object); serviceMock.Setup(m => m.CreateAsync(It.IsAny())).ReturnsAsync(resource); - controller.ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext { HttpContext = new DefaultHttpContext() }; + controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; // Act await controller.PostAsync(resource); @@ -254,7 +254,7 @@ public async Task PostAsync_ModelStateInvalid_ValidateModelStateDisabled() var controller = new ResourceController(new JsonApiOptions {ValidateModelState = false}, NullLoggerFactory.Instance, create: serviceMock.Object) { - ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext + ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } From fd783ef470edc3d159a8cbbf2db14799716cb93d Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:40:43 +0100 Subject: [PATCH 13/73] Fixed: Using directive is not required by the code and can be safely removed --- .../ResourceDefinitionExample/ModelDefinition.cs | 1 - src/Examples/JsonApiDotNetCoreExample/Models/User.cs | 1 - .../JsonApiDotNetCoreExample/Resources/TagResource.cs | 1 - .../JsonApiDotNetCoreExample/Resources/UserResource.cs | 1 - .../JsonApiDotNetCoreExample/Startups/MetaStartup.cs | 1 - src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs | 2 -- .../Builders/JsonApiApplicationBuilder.cs | 1 - src/JsonApiDotNetCore/Data/IDbContextResolver.cs | 1 - .../Extensions/IApplicationBuilderExtensions.cs | 2 -- .../Extensions/IServiceCollectionExtensions.cs | 2 -- src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs | 1 - .../Middleware/CurrentRequestMiddleware.cs | 2 -- .../Models/Annotation/HasManyAttribute.cs | 1 - .../QueryParameterServices/SparseFieldsService.cs | 1 - .../Serialization/Client/DeserializedResponse.cs | 1 - .../Serialization/Common/DocumentBuilder.cs | 1 - .../Serialization/Server/Contracts/IJsonApiSerializer.cs | 4 +--- .../Server/Contracts/IJsonApiSerializerFactory.cs | 4 +--- .../Serialization/Server/ResponseSerializer.cs | 4 +--- .../Services/Contract/IUpdateRelationshipService.cs | 1 - .../Acceptance/Spec/DeletingDataTests.cs | 1 - .../Acceptance/Spec/PagingTests.cs | 1 - .../Acceptance/Spec/SparseFieldSetTests.cs | 2 -- .../Acceptance/Spec/UpdatingDataTests.cs | 1 - .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 3 --- .../Helpers/Extensions/DocumentExtensions.cs | 7 ------- test/UnitTests/Builders/ContextGraphBuilder_Tests.cs | 1 - test/UnitTests/Builders/LinkBuilderTests.cs | 1 - test/UnitTests/Data/DefaultEntityRepositoryTest.cs | 4 ---- .../Extensions/IServiceCollectionExtensionsTests.cs | 1 - test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs | 5 ----- test/UnitTests/Models/AttributesEqualsTests.cs | 1 - test/UnitTests/Models/LinkTests.cs | 3 +-- test/UnitTests/Models/ResourceDefinitionTests.cs | 1 - test/UnitTests/QueryParameters/IncludeServiceTests.cs | 1 - .../ResourceHookExecutor/Delete/BeforeDeleteTests.cs | 1 - .../Serialization/Client/RequestSerializerTests.cs | 2 -- .../UnitTests/Serialization/Common/DocumentBuilderTests.cs | 5 +---- test/UnitTests/Serialization/Common/DocumentParserTests.cs | 1 - .../Serialization/Common/ResourceObjectBuilderTests.cs | 1 - test/UnitTests/Serialization/SerializerTestsSetup.cs | 7 ++----- .../Serialization/Server/RequestDeserializerTests.cs | 2 -- .../Server/ResponseResourceObjectBuilderTests.cs | 1 - .../Serialization/Server/ResponseSerializerTests.cs | 1 - 44 files changed, 7 insertions(+), 80 deletions(-) diff --git a/src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs b/src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs index 1948a13dd7..ac89fc97f2 100644 --- a/src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs +++ b/src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/User.cs b/src/Examples/JsonApiDotNetCoreExample/Models/User.cs index d0e38b93e7..ddf706540b 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/User.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/User.cs @@ -1,4 +1,3 @@ -using System; using JsonApiDotNetCore.Models; namespace JsonApiDotNetCoreExample.Models diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/TagResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/TagResource.cs index 1999936e34..f65a0490d0 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/TagResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/TagResource.cs @@ -3,7 +3,6 @@ using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; -using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; namespace JsonApiDotNetCoreExample.Resources diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs index 6ba4826a2f..517e9137c0 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs @@ -3,7 +3,6 @@ using JsonApiDotNetCoreExample.Models; using JsonApiDotNetCore.Internal.Query; using JsonApiDotNetCore.Internal.Contracts; -using JsonApiDotNetCore.Services; namespace JsonApiDotNetCoreExample.Resources { diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs index 6cc0dd1e81..192534787d 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.DependencyInjection; using JsonApiDotNetCore.Services; using System.Collections.Generic; -using Microsoft.Extensions.Configuration; namespace JsonApiDotNetCoreExample { diff --git a/src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs index 3b38531918..897cc4e47f 100644 --- a/src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using JsonApiDotNetCore.Graph; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; -using Microsoft.EntityFrameworkCore; namespace JsonApiDotNetCore.Builders { diff --git a/src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs b/src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs index c2ae694b64..bea0fbc292 100644 --- a/src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs @@ -20,7 +20,6 @@ using JsonApiDotNetCore.Serialization.Server.Builders; using JsonApiDotNetCore.Serialization.Server; using Microsoft.Extensions.DependencyInjection.Extensions; -using JsonApiDotNetCore.Extensions; namespace JsonApiDotNetCore.Builders { diff --git a/src/JsonApiDotNetCore/Data/IDbContextResolver.cs b/src/JsonApiDotNetCore/Data/IDbContextResolver.cs index 7d2f5a66dc..f1b4533f26 100644 --- a/src/JsonApiDotNetCore/Data/IDbContextResolver.cs +++ b/src/JsonApiDotNetCore/Data/IDbContextResolver.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.EntityFrameworkCore; namespace JsonApiDotNetCore.Data diff --git a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs index bf882426ea..2dd6f1e915 100644 --- a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs @@ -4,9 +4,7 @@ using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Middleware; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace JsonApiDotNetCore.Extensions diff --git a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs index 1b0b6d455d..0805843cb6 100644 --- a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs @@ -5,13 +5,11 @@ using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Graph; using JsonApiDotNetCore.Internal; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using JsonApiDotNetCore.Builders; using JsonApiDotNetCore.Serialization.Client; using JsonApiDotNetCore.Serialization; using JsonApiDotNetCore.Internal.Contracts; -using JsonApiDotNetCore.Serialization.Server; namespace JsonApiDotNetCore.Extensions { diff --git a/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs b/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs index 7c2359eb1c..ba5219be99 100644 --- a/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Reflection; using JsonApiDotNetCore.Internal; diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index 68a169ee0d..115a77a745 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using JsonApiDotNetCore.Configuration; @@ -7,7 +6,6 @@ using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Managers.Contracts; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Primitives; diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs index a6b33bb12e..c940412c47 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs @@ -1,4 +1,3 @@ -using System; using JsonApiDotNetCore.Models.Links; namespace JsonApiDotNetCore.Models diff --git a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs index 404db49a53..5fa44682fe 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using JsonApiDotNetCore.Internal; diff --git a/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs b/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs index 179e62a34f..2851d6a382 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Models.Links; diff --git a/src/JsonApiDotNetCore/Serialization/Common/DocumentBuilder.cs b/src/JsonApiDotNetCore/Serialization/Common/DocumentBuilder.cs index 2e4a2444f4..9f31e18e2c 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/DocumentBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/DocumentBuilder.cs @@ -1,6 +1,5 @@ using System.Collections; using System.Collections.Generic; -using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; namespace JsonApiDotNetCore.Serialization diff --git a/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializer.cs b/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializer.cs index 46281e1e85..6d056940c0 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializer.cs @@ -1,6 +1,4 @@ -using JsonApiDotNetCore.Models; - -namespace JsonApiDotNetCore.Serialization.Server +namespace JsonApiDotNetCore.Serialization.Server { /// /// Serializer used internally in JsonApiDotNetCore to serialize responses. diff --git a/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializerFactory.cs b/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializerFactory.cs index ab9502e666..def323437a 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializerFactory.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Contracts/IJsonApiSerializerFactory.cs @@ -1,6 +1,4 @@ -using System; - -namespace JsonApiDotNetCore.Serialization.Server +namespace JsonApiDotNetCore.Serialization.Server { public interface IJsonApiSerializerFactory { diff --git a/src/JsonApiDotNetCore/Serialization/Server/ResponseSerializer.cs b/src/JsonApiDotNetCore/Serialization/Server/ResponseSerializer.cs index 4c86f29e2e..cca8487f15 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/ResponseSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/ResponseSerializer.cs @@ -1,9 +1,7 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; -using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; -using JsonApiDotNetCore.Query; using Newtonsoft.Json; using JsonApiDotNetCore.Managers.Contracts; using JsonApiDotNetCore.Serialization.Server.Builders; diff --git a/src/JsonApiDotNetCore/Services/Contract/IUpdateRelationshipService.cs b/src/JsonApiDotNetCore/Services/Contract/IUpdateRelationshipService.cs index 188e827701..44b45222f4 100644 --- a/src/JsonApiDotNetCore/Services/Contract/IUpdateRelationshipService.cs +++ b/src/JsonApiDotNetCore/Services/Contract/IUpdateRelationshipService.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Threading.Tasks; using JsonApiDotNetCore.Models; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs index 099128e71c..2b76e55e6b 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs @@ -8,7 +8,6 @@ using JsonApiDotNetCoreExample.Models; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; -using Microsoft.EntityFrameworkCore; using Xunit; namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs index 3ff55bf427..b8c7228d81 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs @@ -6,7 +6,6 @@ using JsonApiDotNetCore.Models; using JsonApiDotNetCoreExample; using JsonApiDotNetCoreExample.Models; -using JsonApiDotNetCoreExampleTests.Helpers.Models; using Newtonsoft.Json; using Xunit; using Person = JsonApiDotNetCoreExample.Models.Person; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs index a3acd23ce2..edb091076e 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs @@ -9,7 +9,6 @@ using JsonApiDotNetCoreExample; using JsonApiDotNetCoreExample.Data; using JsonApiDotNetCoreExample.Models; -using JsonApiDotNetCoreExampleTests.Helpers.Extensions; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Microsoft.EntityFrameworkCore; @@ -21,7 +20,6 @@ using JsonApiDotNetCore.Serialization.Client; using JsonApiDotNetCore.Builders; using JsonApiDotNetCoreExampleTests.Helpers.Models; -using JsonApiDotNetCore.Services; using JsonApiDotNetCore.Internal.Contracts; namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs index 162763b15f..c858eb3045 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index e069185b23..5a305bb1ca 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -1,12 +1,10 @@ using System.Collections.Generic; -using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Bogus; -using JsonApiDotNetCore.Models; using JsonApiDotNetCoreExample; using JsonApiDotNetCoreExample.Data; using JsonApiDotNetCoreExample.Models; @@ -14,7 +12,6 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Xunit; using Person = JsonApiDotNetCoreExample.Models.Person; diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs index 298b86812c..470e77b53c 100644 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs +++ b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs @@ -1,13 +1,6 @@ -using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using JsonApiDotNetCore.Models; -using Microsoft.EntityFrameworkCore.Internal; -using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Query.Internal; -using Microsoft.EntityFrameworkCore.Storage; -using Database = Microsoft.EntityFrameworkCore.Storage.Database; namespace JsonApiDotNetCoreExampleTests.Helpers.Extensions { diff --git a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs index 434f2ba27d..abfea6b890 100644 --- a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs +++ b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs @@ -4,7 +4,6 @@ using System.Reflection; using Humanizer; using JsonApiDotNetCore.Builders; -using JsonApiDotNetCore.Extensions; using JsonApiDotNetCore.Extensions.EntityFrameworkCore; using JsonApiDotNetCore.Graph; using JsonApiDotNetCore.Internal.Contracts; diff --git a/test/UnitTests/Builders/LinkBuilderTests.cs b/test/UnitTests/Builders/LinkBuilderTests.cs index 5408fbf809..bf7c628552 100644 --- a/test/UnitTests/Builders/LinkBuilderTests.cs +++ b/test/UnitTests/Builders/LinkBuilderTests.cs @@ -1,4 +1,3 @@ -using System; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; diff --git a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs index 3c9fca2951..0d41041679 100644 --- a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs +++ b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs @@ -1,15 +1,11 @@ -using JsonApiDotNetCore.Builders; using JsonApiDotNetCore.Data; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Serialization; -using JsonApiDotNetCoreExample.Data; using JsonApiDotNetCoreExample.Models; using Microsoft.EntityFrameworkCore; using Moq; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging.Abstractions; using Xunit; diff --git a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs index 2b9f3c2cb8..80fc27167c 100644 --- a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs +++ b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs @@ -1,4 +1,3 @@ -using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Data; using JsonApiDotNetCore.Extensions; using JsonApiDotNetCore.Formatters; diff --git a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs index 7c876a6f2d..06908a2fd9 100644 --- a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs +++ b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs @@ -1,20 +1,15 @@ using JsonApiDotNetCore.Configuration; -using JsonApiDotNetCore.Controllers; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Managers; using JsonApiDotNetCore.Middleware; using JsonApiDotNetCore.Models; -using JsonApiDotNetCoreExample.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Routing; using Moq; using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; using Xunit; diff --git a/test/UnitTests/Models/AttributesEqualsTests.cs b/test/UnitTests/Models/AttributesEqualsTests.cs index 297216db61..39ca127372 100644 --- a/test/UnitTests/Models/AttributesEqualsTests.cs +++ b/test/UnitTests/Models/AttributesEqualsTests.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using JsonApiDotNetCore.Models; using Xunit; diff --git a/test/UnitTests/Models/LinkTests.cs b/test/UnitTests/Models/LinkTests.cs index f8f163fa03..a1b64e1ea6 100644 --- a/test/UnitTests/Models/LinkTests.cs +++ b/test/UnitTests/Models/LinkTests.cs @@ -1,5 +1,4 @@ -using JsonApiDotNetCore.Models; -using JsonApiDotNetCore.Models.Links; +using JsonApiDotNetCore.Models.Links; using Xunit; namespace UnitTests.Models diff --git a/test/UnitTests/Models/ResourceDefinitionTests.cs b/test/UnitTests/Models/ResourceDefinitionTests.cs index d498042b34..800f79ade0 100644 --- a/test/UnitTests/Models/ResourceDefinitionTests.cs +++ b/test/UnitTests/Models/ResourceDefinitionTests.cs @@ -2,7 +2,6 @@ using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Internal.Query; using JsonApiDotNetCore.Models; -using JsonApiDotNetCore.Services; using System.Linq; using Xunit; diff --git a/test/UnitTests/QueryParameters/IncludeServiceTests.cs b/test/UnitTests/QueryParameters/IncludeServiceTests.cs index 5c98aa2f04..33ad5ac671 100644 --- a/test/UnitTests/QueryParameters/IncludeServiceTests.cs +++ b/test/UnitTests/QueryParameters/IncludeServiceTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using JsonApiDotNetCore.Internal; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs index eda31fe2ac..35eb20b1b2 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs @@ -1,7 +1,6 @@ using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; -using System.Collections.Generic; using Xunit; namespace UnitTests.ResourceHooks diff --git a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs index ce4e2ad578..397edb3d93 100644 --- a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs +++ b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Text.RegularExpressions; using JsonApiDotNetCore.Models; @@ -6,7 +5,6 @@ using JsonApiDotNetCore.Serialization.Client; using Xunit; using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; namespace UnitTests.Serialization.Client { diff --git a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs index 75cc825ad3..2c8339d1af 100644 --- a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Serialization; using Moq; using Xunit; using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; + namespace UnitTests.Serialization.Serializer { public class BaseDocumentBuilderTests : SerializerTestsSetup diff --git a/test/UnitTests/Serialization/Common/DocumentParserTests.cs b/test/UnitTests/Serialization/Common/DocumentParserTests.cs index 68a1d6f62f..9da6504e89 100644 --- a/test/UnitTests/Serialization/Common/DocumentParserTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentParserTests.cs @@ -6,7 +6,6 @@ using Newtonsoft.Json; using Xunit; using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; namespace UnitTests.Serialization.Deserializer { diff --git a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs index 46304c5e9d..9971bacbe8 100644 --- a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs @@ -6,7 +6,6 @@ using JsonApiDotNetCore.Serialization; using Xunit; using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; namespace UnitTests.Serialization.Serializer { diff --git a/test/UnitTests/Serialization/SerializerTestsSetup.cs b/test/UnitTests/Serialization/SerializerTestsSetup.cs index de4f00825c..73ce8c3ba1 100644 --- a/test/UnitTests/Serialization/SerializerTestsSetup.cs +++ b/test/UnitTests/Serialization/SerializerTestsSetup.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Managers.Contracts; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Models.Links; @@ -9,8 +8,6 @@ using JsonApiDotNetCore.Serialization; using JsonApiDotNetCore.Serialization.Server; using JsonApiDotNetCore.Serialization.Server.Builders; -using JsonApiDotNetCore.Services; -using JsonApiDotNetCoreExample.Models; using Moq; namespace UnitTests.Serialization diff --git a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs index faef53944e..226b600594 100644 --- a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs +++ b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs @@ -5,8 +5,6 @@ using JsonApiDotNetCore.Serialization.Server; using Moq; using Newtonsoft.Json; -using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; using Xunit; diff --git a/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs index c6fa74e7b1..7795990eff 100644 --- a/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs @@ -3,7 +3,6 @@ using JsonApiDotNetCore.Models; using Xunit; using UnitTests.TestModels; -using Person = UnitTests.TestModels.Person; namespace UnitTests.Serialization.Server { diff --git a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs index 200c8e273f..9dee6c741d 100644 --- a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; From 340d34db1d5c854d92a89849afa53e2228771743 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:42:27 +0100 Subject: [PATCH 14/73] Fixed: Redundant explicit array type specification --- .../Controllers/TestValuesController.cs | 2 +- .../JsonApiDotNetCoreExample/Resources/PersonResource.cs | 2 +- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 4 ++-- src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs | 4 ++-- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 4 ++-- src/JsonApiDotNetCore/Services/DefaultResourceService.cs | 2 +- .../Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs | 2 +- test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs index a29295c426..29bb211cfd 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs @@ -8,7 +8,7 @@ public class TestValuesController : ControllerBase [HttpGet] public IActionResult Get() { - var result = new string[] { "value" }; + var result = new[] { "value" }; return Ok(result); } } diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs index 4c786b238c..c25d49741f 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs @@ -31,7 +31,7 @@ public Dictionary GetMeta() { return new Dictionary { { "copyright", "Copyright 2015 Example Corp." }, - { "authors", new string[] { "Jared Nance", "Maurits Moeys", "Harro van der Kroft" } } + { "authors", new[] { "Jared Nance", "Maurits Moeys", "Harro van der Kroft" } } }; } } diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 2f66d34837..aea232137f 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -356,14 +356,14 @@ private static IQueryable CallGenericSelectMethod(IQueryable new Item() {Id = y.Id, Name = y.Name}).ToList() } bindExpression = Expression.Call( typeof(Enumerable), "ToList", - new Type[] { singleType }, + new[] { singleType }, selectMethod); } // [HasOne] attribute diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index d619eacd58..cb2d8ab94e 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -135,7 +135,7 @@ IEnumerable GetWhereAndInclude(IEnumerable ids, var query = repo.Get().Where(e => ids.Contains(e.Id)); foreach (var inclusionChainElement in relationshipsToNextLayer) { - query = repo.Include(query, new RelationshipAttribute[] { inclusionChainElement }); + query = repo.Include(query, new[] { inclusionChainElement }); } return query.ToList(); } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 13591fd926..97548e1a0a 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -69,7 +69,7 @@ public RootNode CreateRootNode(IEnumerable root /// Root node. public NodeLayer CreateNextLayer(INode rootNode) { - return CreateNextLayer(new INode[] { rootNode }); + return CreateNextLayer(new[] { rootNode }); } /// @@ -151,7 +151,7 @@ Dictionary>> if (proxy.IsContextRelation || uniqueRightEntities.Any()) { AddToRelationshipGroup(rightEntitiesGrouped, proxy, uniqueRightEntities); - AddToRelationshipGroup(leftEntitiesGrouped, proxy, new IIdentifiable[] { leftEntity }); + AddToRelationshipGroup(leftEntitiesGrouped, proxy, new[] { leftEntity }); } } } diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index ec3954b069..a4ab06d049 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -189,7 +189,7 @@ public static object CreateInstanceOfOpenType(Type openType, Type[] parameters, /// Open generic type public static object CreateInstanceOfOpenType(Type openType, Type parameter, params object[] constructorArguments) { - return CreateInstanceOfOpenType(openType, new Type[] { parameter }, constructorArguments); + return CreateInstanceOfOpenType(openType, new[] { parameter }, constructorArguments); } /// @@ -197,7 +197,7 @@ public static object CreateInstanceOfOpenType(Type openType, Type parameter, par /// public static object CreateInstanceOfOpenType(Type openType, Type parameter, bool hasInternalConstructor, params object[] constructorArguments) { - return CreateInstanceOfOpenType(openType, new Type[] { parameter }, hasInternalConstructor, constructorArguments); + return CreateInstanceOfOpenType(openType, new[] { parameter }, hasInternalConstructor, constructorArguments); } diff --git a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs index a090518dc9..f65d7e533d 100644 --- a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs +++ b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs @@ -178,7 +178,7 @@ public virtual async Task UpdateAsync(TId id, TResource entity) public virtual async Task UpdateRelationshipsAsync(TId id, string relationshipName, object related) { var relationship = GetRelationship(relationshipName); - var entityQuery = _repository.Include(_repository.Get(id), new RelationshipAttribute[] { relationship }); + var entityQuery = _repository.Include(_repository.Get(id), new[] { relationship }); var entity = await _repository.FirstOrDefaultAsync(entityQuery); if (entity == null) throw new JsonApiException(404, $"Entity with id {id} could not be found."); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index d13f595ee3..16206d5f33 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -235,7 +235,7 @@ public async Task Tag_Is_Hidden() string toBeExcluded = "This should be not be included"; tags[0].Name = toBeExcluded; - var articleTags = new ArticleTag[] + var articleTags = new[] { new ArticleTag { diff --git a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs index 28f35f2c83..619d695a49 100644 --- a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs +++ b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs @@ -241,7 +241,7 @@ protected IHooksDiscovery SetDiscoverableHooks(ResourceHoo .Returns(enableDbValuesHooks); } mock.Setup(discovery => discovery.DatabaseValuesEnabledHooks) - .Returns(new ResourceHook[] { ResourceHook.BeforeImplicitUpdateRelationship }.Concat(enableDbValuesHooks).ToArray()); + .Returns(new[] { ResourceHook.BeforeImplicitUpdateRelationship }.Concat(enableDbValuesHooks).ToArray()); return mock.Object; } From a2617d1480849419a0edb06e9bc92f7721a4037f Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:43:14 +0100 Subject: [PATCH 15/73] Fixed: Type argument specification is redundant --- .../NoEntityFrameworkExample/Services/TodoItemService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs index a5664fccfd..5f8a21e350 100644 --- a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs +++ b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs @@ -61,7 +61,7 @@ public Task GetRelationshipsAsync(int id, string relationshipName) public async Task CreateAsync(TodoItem entity) { - return (await QueryAsync(async connection => + return (await QueryAsync(async connection => { var query = "insert into \"TodoItems\" (\"Description\", \"IsLocked\", \"Ordinal\", \"GuidProperty\") values (@description, @isLocked, @ordinal, @guidProperty) returning \"Id\",\"Description\", \"IsLocked\", \"Ordinal\", \"GuidProperty\""; var result = await connection.QueryAsync(query, new { description = entity.Description, ordinal = entity.Ordinal, guidProperty = entity.GuidProperty, isLocked = entity.IsLocked}); From 87773a4dadc055c29b9af41c7bd4c99113cfe50b Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:44:15 +0100 Subject: [PATCH 16/73] Fixed: Comparison with true is redundant --- .../Extensions/IServiceCollectionExtensions.cs | 2 +- src/JsonApiDotNetCore/Extensions/TypeExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs index 0805843cb6..c09214f120 100644 --- a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs @@ -103,7 +103,7 @@ private static HashSet GetResourceTypesFromServiceImplementa if (i.IsGenericType) { var firstGenericArgument = i.GenericTypeArguments.FirstOrDefault(); - if (TypeLocator.TryGetResourceDescriptor(firstGenericArgument, out var resourceDescriptor) == true) + if (TypeLocator.TryGetResourceDescriptor(firstGenericArgument, out var resourceDescriptor)) { resourceDescriptors.Add(resourceDescriptor); } diff --git a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs index ea0f7ee4ea..ca9d1d4a10 100644 --- a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs @@ -48,7 +48,7 @@ public static Type GetElementType(this IEnumerable enumerable) { var enumerableTypes = enumerable.GetType() .GetInterfaces() - .Where(t => t.IsGenericType == true && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + .Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)) .ToList(); var numberOfEnumerableTypes = enumerableTypes.Count; From b6a99561bf3438e6b3ce7c3fbb2415be2d859053 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:47:28 +0100 Subject: [PATCH 17/73] Fixed: Redundant string interpolation --- .../Hooks/Discovery/HooksDiscovery.cs | 6 +++--- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 2 +- .../SparseFieldsService.cs | 4 ++-- .../Serialization/Client/ResponseDeserializer.cs | 2 +- .../Extensibility/CustomControllerTests.cs | 4 ++-- .../Acceptance/Extensibility/RequestMetaTests.cs | 2 +- .../Acceptance/KebabCaseFormatterTests.cs | 2 +- .../Acceptance/ManyToManyTests.cs | 2 +- .../ResourceDefinitionTests.cs | 14 +++++++------- .../Acceptance/Spec/AttributeSortTests.cs | 2 +- .../Acceptance/Spec/DocumentTests/Included.cs | 8 ++++---- .../Acceptance/Spec/DocumentTests/Meta.cs | 8 ++++---- .../Spec/DocumentTests/Relationships.cs | 4 ++-- .../Acceptance/Spec/FetchingDataTests.cs | 6 +++--- .../Acceptance/Spec/PagingTests.cs | 2 +- .../Acceptance/Spec/SparseFieldSetTests.cs | 2 +- .../Acceptance/TodoItemsControllerTests.cs | 16 ++++++++-------- .../Extensibility/NoEntityFrameworkTests.cs | 4 ++-- .../QueryParameters/OmitDefaultService.cs | 2 +- .../UnitTests/QueryParameters/OmitNullService.cs | 2 +- .../QueryParameters/PageServiceTests.cs | 4 ++-- .../QueryParameters/SortServiceTests.cs | 2 +- 22 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs index bfade1c50d..e01620cb82 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using JsonApiDotNetCore.Internal; @@ -69,7 +69,7 @@ void DiscoverImplementedHooks(Type containerType) { if (!_databaseValuesAttributeAllowed.Contains(hook)) { - throw new JsonApiSetupException($"DatabaseValuesAttribute cannot be used on hook" + + throw new JsonApiSetupException("DatabaseValuesAttribute cannot be used on hook" + $"{hook.ToString("G")} in resource definition {containerType.Name}"); } var targetList = attr.value ? databaseValuesEnabledHooks : databaseValuesDisabledHooks; @@ -82,4 +82,4 @@ void DiscoverImplementedHooks(Type containerType) DatabaseValuesEnabledHooks = databaseValuesEnabledHooks.ToArray(); } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index a4ab06d049..9f676c1c7d 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -24,7 +24,7 @@ public static bool IsNullable(Type type) public static object ConvertType(object value, Type type) { if (value == null && !IsNullable(type)) - throw new FormatException($"Cannot convert null to a non-nullable type"); + throw new FormatException("Cannot convert null to a non-nullable type"); if (value == null) return null; diff --git a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs index 5fa44682fe..53909588f2 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs @@ -63,8 +63,8 @@ public virtual void Parse(KeyValuePair queryParameter) // if not, no longer support this type of sparse field selection. if (navigation == _requestResource.ResourceName && !_requestResource.Relationships.Any(a => a.Is(navigation))) throw new JsonApiException(400, $"Use '?fields=...' instead of 'fields[{navigation}]':" + - $" the square bracket navigations is now reserved " + - $"for relationships only. See https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/555#issuecomment-543100865"); + " the square bracket navigations is now reserved " + + "for relationships only. See https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/555#issuecomment-543100865"); if (navigation.Contains(QueryConstants.DOT)) throw new JsonApiException(400, $"fields[{navigation}] is not valid: deeply nested sparse field selection is not yet supported."); diff --git a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs index d535a6f290..30061007cb 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs @@ -106,7 +106,7 @@ private ResourceObject GetLinkedResource(ResourceIdentifierObject relatedResourc } catch (InvalidOperationException e) { - throw new InvalidOperationException($"A compound document MUST NOT include more than one resource object for each type and id pair." + throw new InvalidOperationException("A compound document MUST NOT include more than one resource object for each type and id pair." + $"The duplicate pair was '{relatedResourceIdentifier.Type}, {relatedResourceIdentifier.Id}'", e); } } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs index a03a213534..b34f633ba8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs @@ -39,7 +39,7 @@ public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes() var builder = new WebHostBuilder() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"testValues"; + var route = "testValues"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -59,7 +59,7 @@ public async Task CustomRouteControllers_Uses_Dasherized_Collection_Route() var builder = new WebHostBuilder() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/custom/route/todoItems"; + var route = "/custom/route/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs index 5f31c447b6..b14f7aaee8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs @@ -29,7 +29,7 @@ public async Task Injecting_IRequestMeta_Adds_Meta_Data() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/people"; + var route = "/api/v1/people"; var server = new TestServer(builder); var client = server.CreateClient(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs index 79793a1c7a..25050da4e8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs @@ -59,7 +59,7 @@ public async Task KebabCaseFormatter_Create_IsCreated() var serializer = GetSerializer(kcm => new { kcm.CompoundAttr }); // Act - var (body, response) = await Post($"api/v1/kebab-cased-models", serializer.Serialize(model)); + var (body, response) = await Post("api/v1/kebab-cased-models", serializer.Serialize(model)); // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs index 1ef254b8dd..9c69719560 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs @@ -50,7 +50,7 @@ public async Task Can_Fetch_Many_To_Many_Through_All() }; context.ArticleTags.Add(articleTag); await context.SaveChangesAsync(); - var route = $"/api/v1/articles?include=tags"; + var route = "/api/v1/articles?include=tags"; // @TODO - Use fixture var builder = new WebHostBuilder() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index 16206d5f33..a5c06c4386 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -77,7 +77,7 @@ public async Task Can_Create_User_With_Password() var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/users"; + var route = "/api/v1/users"; var request = new HttpRequestMessage(httpMethod, route) { @@ -143,7 +143,7 @@ public async Task Can_Update_User_Password() public async Task Unauthorized_TodoItem() { // Arrange - var route = $"/api/v1/todoItems/1337"; + var route = "/api/v1/todoItems/1337"; var httpMethod = new HttpMethod("GET"); var request = new HttpRequestMessage(httpMethod, route); @@ -159,7 +159,7 @@ public async Task Unauthorized_TodoItem() public async Task Unauthorized_Passport() { // Arrange - var route = $"/api/v1/people/1?include=passport"; + var route = "/api/v1/people/1?include=passport"; var httpMethod = new HttpMethod("GET"); var request = new HttpRequestMessage(httpMethod, route); @@ -208,7 +208,7 @@ public async Task Article_Is_Hidden() context.Articles.AddRange(articles); await context.SaveChangesAsync(); - var route = $"/api/v1/articles"; + var route = "/api/v1/articles"; var httpMethod = new HttpMethod("GET"); var request = new HttpRequestMessage(httpMethod, route); @@ -251,7 +251,7 @@ public async Task Tag_Is_Hidden() context.ArticleTags.AddRange(articleTags); await context.SaveChangesAsync(); - var route = $"/api/v1/articles?include=tags"; + var route = "/api/v1/articles?include=tags"; var httpMethod = new HttpMethod("GET"); var request = new HttpRequestMessage(httpMethod, route); @@ -301,7 +301,7 @@ public async Task Cascade_Permission_Error_Create_ToOne_Relationship() }; var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/people"; + var route = "/api/v1/people"; var request = new HttpRequestMessage(httpMethod, route); string serializedContent = JsonConvert.SerializeObject(content); @@ -474,7 +474,7 @@ public async Task Cascade_Permission_Error_Create_ToMany_Relationship() }; var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var request = new HttpRequestMessage(httpMethod, route); string serializedContent = JsonConvert.SerializeObject(content); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs index 6b387fed64..baf90bded5 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs @@ -21,7 +21,7 @@ public async Task Cannot_Sort_If_Explicitly_Forbidden() { // Arrange var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?include=owner&sort=achievedDate"; + var route = "/api/v1/todoItems?include=owner&sort=achievedDate"; var request = new HttpRequestMessage(httpMethod, route); // Act diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs index a874265508..a47b7f9bf2 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs @@ -54,7 +54,7 @@ public async Task GET_Included_Contains_SideLoadedData_ForManyToOne() var builder = new WebHostBuilder().UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?include=owner"; + var route = "/api/v1/todoItems?include=owner"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -132,7 +132,7 @@ public async Task GET_Included_Contains_SideLoadedData_OneToMany() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/people?include=todoItems"; + var route = "/api/v1/people?include=todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -210,7 +210,7 @@ public async Task GET_Included_DoesNot_Duplicate_Records_If_HasOne_Exists_Twice( .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?include=owner"; + var route = "/api/v1/todoItems?include=owner"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -419,7 +419,7 @@ public async Task Can_Ignore_Null_Parent_In_Nested_Include() var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?sort=-createdDate&page[size]=2&include=owner.role"; // last two todoItems + var route = "/api/v1/todoItems?sort=-createdDate&page[size]=2&include=owner.role"; // last two todoItems var server = new TestServer(builder); var client = server.CreateClient(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs index 59928ffccd..3d5bab8acb 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs @@ -37,7 +37,7 @@ public async Task Total_Record_Count_Included() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -64,7 +64,7 @@ public async Task Total_Record_Count_Included_When_None() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -91,7 +91,7 @@ public async Task Total_Record_Count_Not_Included_In_POST_Response() .UseStartup(); var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); @@ -172,7 +172,7 @@ public async Task EntityThatImplements_IHasMeta_Contains_MetaData() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/people"; + var route = "/api/v1/people"; var server = new TestServer(builder); var client = server.CreateClient(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs index 3d1097a3be..bf96abce15 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using JsonApiDotNetCoreExample; @@ -101,7 +101,7 @@ public async Task Correct_RelationshipObjects_For_OneToMany_Relationships() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/people"; + var route = "/api/v1/people"; var server = new TestServer(builder); var client = server.CreateClient(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs index c58fc94663..9d3a905c45 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; @@ -110,7 +110,7 @@ public async Task GetResources_NoDefaultPageSize_ReturnsResources() var builder = new WebHostBuilder() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var server = new TestServer(builder); var client = server.CreateClient(); var request = new HttpRequestMessage(httpMethod, route); @@ -135,7 +135,7 @@ public async Task GetSingleResource_ResourceDoesNotExist_ReturnsNotFoundWithNull var builder = new WebHostBuilder() .UseStartup(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems/123"; + var route = "/api/v1/todoItems/123"; var server = new TestServer(builder); var client = server.CreateClient(); var request = new HttpRequestMessage(httpMethod, route); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs index b8c7228d81..863b848a29 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs @@ -87,7 +87,7 @@ public async Task Pagination_OnGivenPage_DisplaysCorrectTopLevelLinks(int pageNu Context.TodoItems.AddRange(todoItems); Context.SaveChanges(); - string route = $"/api/v1/todoItems"; + string route = "/api/v1/todoItems"; if (pageNum != 1) { route += $"?page[size]=5&page[number]={pageNum}"; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs index edb091076e..e6d4c9ba38 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs @@ -168,7 +168,7 @@ public async Task Fields_Query_Selects_All_Fieldset_With_HasOne() using var server = new TestServer(builder); var client = server.CreateClient(); - var route = $"/api/v1/todoItems?include=owner&fields[owner]=firstName,age"; + var route = "/api/v1/todoItems?include=owner&fields[owner]=firstName,age"; var request = new HttpRequestMessage(httpMethod, route); var resourceGraph = new ResourceGraphBuilder().AddResource().AddResource("todoItems").Build(); var deserializer = new ResponseDeserializer(resourceGraph); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index fd59bf7dcd..ff3b0049d7 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -165,7 +165,7 @@ public async Task Can_Filter_TodoItems_Using_IsNotNull_Operator() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?filter[updatedDate]=isnotnull:"; + var route = "/api/v1/todoItems?filter[updatedDate]=isnotnull:"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -196,7 +196,7 @@ public async Task Can_Filter_TodoItems_ByParent_Using_IsNotNull_Operator() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?filter[assignee.id]=isnotnull:"; + var route = "/api/v1/todoItems?filter[assignee.id]=isnotnull:"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -224,7 +224,7 @@ public async Task Can_Filter_TodoItems_Using_IsNull_Operator() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?filter[updatedDate]=isnull:"; + var route = "/api/v1/todoItems?filter[updatedDate]=isnull:"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -254,7 +254,7 @@ public async Task Can_Filter_TodoItems_ByParent_Using_IsNull_Operator() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?filter[assignee.id]=isnull:"; + var route = "/api/v1/todoItems?filter[assignee.id]=isnull:"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -316,7 +316,7 @@ public async Task Can_Sort_TodoItems_By_Ordinal_Ascending() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?sort=ordinal"; + var route = "/api/v1/todoItems?sort=ordinal"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -431,7 +431,7 @@ public async Task Can_Sort_TodoItems_By_Ordinal_Descending() _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems?sort=-ordinal"; + var route = "/api/v1/todoItems?sort=-ordinal"; var request = new HttpRequestMessage(httpMethod, route); // Act @@ -524,7 +524,7 @@ public async Task Can_Post_TodoItem() todoItem.OffsetDate = nowOffset; var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var request = new HttpRequestMessage(httpMethod, route) { @@ -592,7 +592,7 @@ public async Task Can_Post_TodoItem_With_Different_Owner_And_Assignee() }; var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var request = new HttpRequestMessage(httpMethod, route) { diff --git a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs index 610f288961..bd9036b0bf 100644 --- a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs +++ b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs @@ -31,7 +31,7 @@ public async Task Can_Get_TodoItems() var client = _fixture.Server.CreateClient(); var httpMethod = new HttpMethod("GET"); - var route = $"/api/v1/todoItems"; + var route = "/api/v1/todoItems"; var request = new HttpRequestMessage(httpMethod, route); @@ -78,7 +78,7 @@ public async Task Can_Create_TodoItems() // Arrange var description = Guid.NewGuid().ToString(); var httpMethod = new HttpMethod("POST"); - var route = $"/api/v1/todoItems/"; + var route = "/api/v1/todoItems/"; var content = new { data = new diff --git a/test/UnitTests/QueryParameters/OmitDefaultService.cs b/test/UnitTests/QueryParameters/OmitDefaultService.cs index 522c15049c..497942e4f9 100644 --- a/test/UnitTests/QueryParameters/OmitDefaultService.cs +++ b/test/UnitTests/QueryParameters/OmitDefaultService.cs @@ -39,7 +39,7 @@ public void Name_OmitNullService_IsCorrect() public void Parse_QueryConfigWithApiSettings_CanParse(string queryConfig, bool @default, bool @override, bool expected) { // Arrange - var query = new KeyValuePair($"omitNull", new StringValues(queryConfig)); + var query = new KeyValuePair("omitNull", new StringValues(queryConfig)); var service = GetService(@default, @override); // Act diff --git a/test/UnitTests/QueryParameters/OmitNullService.cs b/test/UnitTests/QueryParameters/OmitNullService.cs index f4ec0e0ed5..448971d129 100644 --- a/test/UnitTests/QueryParameters/OmitNullService.cs +++ b/test/UnitTests/QueryParameters/OmitNullService.cs @@ -39,7 +39,7 @@ public void Name_OmitNullService_IsCorrect() public void Parse_QueryConfigWithApiSettings_CanParse(string queryConfig, bool @default, bool @override, bool expected) { // Arrange - var query = new KeyValuePair($"omitNull", new StringValues(queryConfig)); + var query = new KeyValuePair("omitNull", new StringValues(queryConfig)); var service = GetService(@default, @override); // Act diff --git a/test/UnitTests/QueryParameters/PageServiceTests.cs b/test/UnitTests/QueryParameters/PageServiceTests.cs index c59b8a6e82..1d763c8c21 100644 --- a/test/UnitTests/QueryParameters/PageServiceTests.cs +++ b/test/UnitTests/QueryParameters/PageServiceTests.cs @@ -40,7 +40,7 @@ public void Name_PageService_IsCorrect() public void Parse_PageSize_CanParse(string value, int expectedValue, int? maximumPageSize, bool shouldThrow) { // Arrange - var query = new KeyValuePair($"page[size]", new StringValues(value)); + var query = new KeyValuePair("page[size]", new StringValues(value)); var service = GetService(maximumPageSize: maximumPageSize); // Act @@ -65,7 +65,7 @@ public void Parse_PageSize_CanParse(string value, int expectedValue, int? maximu public void Parse_PageNumber_CanParse(string value, int expectedValue, int? maximumPageNumber, bool shouldThrow) { // Arrange - var query = new KeyValuePair($"page[number]", new StringValues(value)); + var query = new KeyValuePair("page[number]", new StringValues(value)); var service = GetService(maximumPageNumber: maximumPageNumber); // Act diff --git a/test/UnitTests/QueryParameters/SortServiceTests.cs b/test/UnitTests/QueryParameters/SortServiceTests.cs index 4284b89790..efbb078f70 100644 --- a/test/UnitTests/QueryParameters/SortServiceTests.cs +++ b/test/UnitTests/QueryParameters/SortServiceTests.cs @@ -33,7 +33,7 @@ public void Name_SortService_IsCorrect() public void Parse_InvalidSortQuery_ThrowsJsonApiException(string stringSortQuery) { // Arrange - var query = new KeyValuePair($"sort", stringSortQuery); + var query = new KeyValuePair("sort", stringSortQuery); var sortService = GetService(); // Act, assert From 2e8aa9f2c8c0e9d3838a2439a74116e082cc9846 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:49:09 +0100 Subject: [PATCH 18/73] Fixed: Conditional access qualifier expression is known to be not null --- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 2 +- src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs | 4 ++-- src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs | 4 ++-- .../Serialization/Client/RequestSerializer.cs | 4 ++-- test/IntegrationTests/Data/EntityRepositoryTests.cs | 2 +- .../Acceptance/Spec/PagingTests.cs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index 9f676c1c7d..7c77d6a532 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -38,7 +38,7 @@ public static object ConvertType(object value, Type type) type = Nullable.GetUnderlyingType(type) ?? type; - var stringValue = value?.ToString(); + var stringValue = value.ToString(); if (string.IsNullOrEmpty(stringValue)) return GetDefaultType(type); diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs index c940412c47..0c04d30fab 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasManyAttribute.cs @@ -35,8 +35,8 @@ public HasManyAttribute(string publicName = null, Link relationshipLinks = Link. /// public override object GetValue(object entity) { - return entity?.GetType()? - .GetProperty(InternalRelationshipName)? + return entity?.GetType() + .GetProperty(InternalRelationshipName)? .GetValue(entity); } diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs index 183f5b46c3..e3423c6cf9 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs @@ -38,8 +38,8 @@ public HasOneAttribute(string publicName = null, Link links = Link.NotConfigured public override object GetValue(object entity) { - return entity?.GetType()? - .GetProperty(InternalRelationshipName)? + return entity?.GetType() + .GetProperty(InternalRelationshipName)? .GetValue(entity); } diff --git a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs index 21815794f2..13a8b6f9f1 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs @@ -29,7 +29,7 @@ public string Serialize(IIdentifiable entity) if (entity == null) return JsonConvert.SerializeObject(Build(entity, new List(), new List())); - _currentTargetedResource = entity?.GetType(); + _currentTargetedResource = entity.GetType(); var document = Build(entity, GetAttributesToSerialize(entity), GetRelationshipsToSerialize(entity)); _currentTargetedResource = null; return JsonConvert.SerializeObject(document); @@ -47,7 +47,7 @@ public string Serialize(IEnumerable entities) if (entity == null) return JsonConvert.SerializeObject(Build(entities, new List(), new List())); - _currentTargetedResource = entity?.GetType(); + _currentTargetedResource = entity.GetType(); var attributes = GetAttributesToSerialize(entity); var relationships = GetRelationshipsToSerialize(entity); var document = base.Build(entities, attributes, relationships); diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index d1ab6ea78c..209f91d089 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -181,7 +181,7 @@ private class IdComparer : IEqualityComparer { public bool Equals(T x, T y) => x?.StringId == y?.StringId; - public int GetHashCode(T obj) => obj?.StringId?.GetHashCode() ?? 0; + public int GetHashCode(T obj) => obj.StringId?.GetHashCode() ?? 0; } } } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs index 863b848a29..e8ec643431 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs @@ -143,7 +143,7 @@ private class IdComparer : IEqualityComparer { public bool Equals(T x, T y) => x?.StringId == y?.StringId; - public int GetHashCode(T obj) => obj?.StringId?.GetHashCode() ?? 0; + public int GetHashCode(T obj) => obj.StringId?.GetHashCode() ?? 0; } } } From ec1974aed9ef5d13926f706342e3d94ab6599586 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:50:09 +0100 Subject: [PATCH 19/73] Fixed: Empty object or collection initializer list is redundant --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 2 +- .../ResourceDefinitions/ResourceDefinitionTests.cs | 4 ++-- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 5 +---- .../UnitTests/Serialization/Client/RequestSerializerTests.cs | 2 +- test/UnitTests/Serialization/Common/DocumentParserTests.cs | 4 ++-- test/UnitTests/Serialization/DeserializerTestsSetup.cs | 4 ++-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index aea232137f..901dd7d15a 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -307,7 +307,7 @@ private static IQueryable CallGenericSelectMethod(IQueryable(); var sourceType = typeof(TSource); var parameter = Expression.Parameter(source.ElementType, "x"); - var sourceProperties = new List() { }; + var sourceProperties = new List(); // Store all property names to it's own related property (name as key) var nestedTypesAndProperties = new Dictionary>(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index a5c06c4386..a5d4867358 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -327,7 +327,7 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship() var passport = new Passport() { IsLocked = true }; person.Passport = passport; context.People.AddRange(person); - var newPassport = new Passport() { }; + var newPassport = new Passport(); context.Passports.Add(newPassport); await context.SaveChangesAsync(); @@ -374,7 +374,7 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship_Deletion( var passport = new Passport() { IsLocked = true }; person.Passport = passport; context.People.AddRange(person); - var newPassport = new Passport() { }; + var newPassport = new Passport(); context.Passports.Add(newPassport); await context.SaveChangesAsync(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index 5a305bb1ca..ef8c28ae0f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -601,10 +601,7 @@ public async Task Can_Delete_ToMany_Relationship_By_Patching_Resource() { { "todoItems", new { - data = new List - { - - } + data = new List() } } } diff --git a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs index 397edb3d93..e703525685 100644 --- a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs +++ b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs @@ -232,7 +232,7 @@ public void SerializeSingle_Null_CanBuild() public void SerializeMany_EmptyList_CanBuild() { // Arrange - var entities = new List { }; + var entities = new List(); _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => tr.StringField); // Act diff --git a/test/UnitTests/Serialization/Common/DocumentParserTests.cs b/test/UnitTests/Serialization/Common/DocumentParserTests.cs index 9da6504e89..6695a1e51e 100644 --- a/test/UnitTests/Serialization/Common/DocumentParserTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentParserTests.cs @@ -43,7 +43,7 @@ public void DeserializeResourceIdentifiers_SingleData_CanDeserialize() public void DeserializeResourceIdentifiers_EmptySingleData_CanDeserialize() { // Arrange - var content = new Document { }; + var content = new Document(); var body = JsonConvert.SerializeObject(content); // Act @@ -80,7 +80,7 @@ public void DeserializeResourceIdentifiers_ArrayData_CanDeserialize() [Fact] public void DeserializeResourceIdentifiers_EmptyArrayData_CanDeserialize() { - var content = new Document { Data = new List { } }; + var content = new Document { Data = new List()}; var body = JsonConvert.SerializeObject(content); // Act diff --git a/test/UnitTests/Serialization/DeserializerTestsSetup.cs b/test/UnitTests/Serialization/DeserializerTestsSetup.cs index bfdfdacfee..d8f9dcea20 100644 --- a/test/UnitTests/Serialization/DeserializerTestsSetup.cs +++ b/test/UnitTests/Serialization/DeserializerTestsSetup.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Internal.Contracts; +using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Serialization; using System.Collections.Generic; @@ -34,7 +34,7 @@ protected Document CreateDocumentWithRelationships(string mainType) { Id = "1", Type = mainType, - Relationships = new Dictionary { } + Relationships = new Dictionary() } }; } From 143139b327c8b3513ee8e0cf5cbd50619a9897e0 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:51:57 +0100 Subject: [PATCH 20/73] Fixed: Redundant explicit array creation in argument of 'params' parameter --- src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs | 7 +++---- .../Acceptance/Spec/DocumentTests/Included.cs | 2 +- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 4 ++-- .../Acceptance/TodoItemsControllerTests.cs | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 97548e1a0a..13e2fbec1d 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -287,7 +287,7 @@ void AddToRelationshipGroup(Dictionary> t INode CreateNodeInstance(RightType nodeType, RelationshipProxy[] relationshipsToNext, IEnumerable relationshipsFromPrev) { IRelationshipsFromPreviousLayer prev = CreateRelationshipsFromInstance(nodeType, relationshipsFromPrev); - return (INode)TypeHelper.CreateInstanceOfOpenType(typeof(ChildNode<>), nodeType, new object[] { relationshipsToNext, prev }); + return (INode)TypeHelper.CreateInstanceOfOpenType(typeof(ChildNode<>), nodeType, relationshipsToNext, prev); } /// @@ -296,7 +296,7 @@ INode CreateNodeInstance(RightType nodeType, RelationshipProxy[] relationshipsTo IRelationshipsFromPreviousLayer CreateRelationshipsFromInstance(RightType nodeType, IEnumerable relationshipsFromPrev) { var cast = relationshipsFromPrev.Cast(relationshipsFromPrev.First().GetType()); - return (IRelationshipsFromPreviousLayer)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipsFromPreviousLayer<>), nodeType, new object[] { cast }); + return (IRelationshipsFromPreviousLayer)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipsFromPreviousLayer<>), nodeType, cast); } /// @@ -306,8 +306,7 @@ IRelationshipGroup CreateRelationshipGroupInstance(Type thisLayerType, Relations { var rightEntitiesHashed = TypeHelper.CreateInstanceOfOpenType(typeof(HashSet<>), thisLayerType, rightEntities.Cast(thisLayerType)); return (IRelationshipGroup)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipGroup<>), - thisLayerType, - new object[] { proxy, new HashSet(leftEntities), rightEntitiesHashed }); + thisLayerType, proxy, new HashSet(leftEntities), rightEntitiesHashed); } } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs index a47b7f9bf2..bfd5d10c04 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs @@ -203,7 +203,7 @@ public async Task GET_Included_DoesNot_Duplicate_Records_If_HasOne_Exists_Twice( var todoItem2 = _todoItemFaker.Generate(); todoItem1.Owner = person; todoItem2.Owner = person; - _context.TodoItems.AddRange(new[] { todoItem1, todoItem2 }); + _context.TodoItems.AddRange(todoItem1, todoItem2); _context.SaveChanges(); var builder = new WebHostBuilder() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index ef8c28ae0f..fe77c4ecbf 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -239,7 +239,7 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource() var newTodoItem1 = _todoItemFaker.Generate(); var newTodoItem2 = _todoItemFaker.Generate(); - _context.AddRange(new TodoItem[] { newTodoItem1, newTodoItem2 }); + _context.AddRange(newTodoItem1, newTodoItem2); _context.SaveChanges(); var builder = new WebHostBuilder() @@ -313,7 +313,7 @@ public async Task Can_Update_ToMany_Relationship_By_Patching_Resource_When_Targe var newTodoItem1 = _todoItemFaker.Generate(); var newTodoItem2 = _todoItemFaker.Generate(); - _context.AddRange(new TodoItem[] { newTodoItem1, newTodoItem2 }); + _context.AddRange(newTodoItem1, newTodoItem2); _context.SaveChanges(); var builder = new WebHostBuilder() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index ff3b0049d7..ebc33cd7a8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -161,7 +161,7 @@ public async Task Can_Filter_TodoItems_Using_IsNotNull_Operator() var otherTodoItem = _todoItemFaker.Generate(); otherTodoItem.UpdatedDate = null; - _context.TodoItems.AddRange(new[] { todoItem, otherTodoItem }); + _context.TodoItems.AddRange(todoItem, otherTodoItem); _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); @@ -192,7 +192,7 @@ public async Task Can_Filter_TodoItems_ByParent_Using_IsNotNull_Operator() otherTodoItem.Assignee = null; _context.RemoveRange(_context.TodoItems); - _context.TodoItems.AddRange(new[] { todoItem, otherTodoItem }); + _context.TodoItems.AddRange(todoItem, otherTodoItem); _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); @@ -220,7 +220,7 @@ public async Task Can_Filter_TodoItems_Using_IsNull_Operator() var otherTodoItem = _todoItemFaker.Generate(); otherTodoItem.UpdatedDate = new DateTime(); - _context.TodoItems.AddRange(new[] { todoItem, otherTodoItem }); + _context.TodoItems.AddRange(todoItem, otherTodoItem); _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); @@ -250,7 +250,7 @@ public async Task Can_Filter_TodoItems_ByParent_Using_IsNull_Operator() var otherTodoItem = _todoItemFaker.Generate(); otherTodoItem.Assignee = new Person(); - _context.TodoItems.AddRange(new[] { todoItem, otherTodoItem }); + _context.TodoItems.AddRange(todoItem, otherTodoItem); _context.SaveChanges(); var httpMethod = new HttpMethod("GET"); From 3258c0fb8287788e584433f3ab2eaca93341aee6 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:53:40 +0100 Subject: [PATCH 21/73] Fixed: Type cast is redundant --- src/JsonApiDotNetCore/Services/DefaultResourceService.cs | 3 +-- .../Acceptance/Spec/DocumentTests/Meta.cs | 2 +- .../Serialization/Client/ResponseDeserializerTests.cs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs index f65d7e533d..4c4f33cb87 100644 --- a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs +++ b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs @@ -202,8 +202,7 @@ protected virtual async Task> ApplyPageQueryAsync(IQuerya { if (!(_pageService.CurrentPageSize > 0)) { - var allEntities = await _repository.ToListAsync(entities); - return allEntities as IEnumerable; + return await _repository.ToListAsync(entities); } int pageOffset = _pageService.CurrentPage; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs index 3d5bab8acb..a442516d05 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs @@ -51,7 +51,7 @@ public async Task Total_Record_Count_Included() // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(documents.Meta); - Assert.Equal((long)expectedCount, (long)documents.Meta["total-records"]); + Assert.Equal(expectedCount, (long)documents.Meta["total-records"]); } [Fact] diff --git a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs index 0ffdc6f5ef..8fd8c4a5db 100644 --- a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs +++ b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs @@ -57,7 +57,7 @@ public void DeserializeSingle_EmptyResponseWithTopLevelLinks_CanDeserialize() // Assert Assert.Null(result.Data); Assert.NotNull(result.Links); - TopLevelLinks links = (TopLevelLinks)result.Links; + TopLevelLinks links = result.Links; Assert.Equal(_linkValues["self"], links.Self); Assert.Equal(_linkValues["next"], links.Next); Assert.Equal(_linkValues["last"], links.Last); @@ -80,7 +80,7 @@ public void DeserializeList_EmptyResponseWithTopLevelLinks_CanDeserialize() // Assert Assert.Empty(result.Data); Assert.NotNull(result.Links); - TopLevelLinks links = (TopLevelLinks)result.Links; + TopLevelLinks links = result.Links; Assert.Equal(_linkValues["self"], links.Self); Assert.Equal(_linkValues["next"], links.Next); Assert.Equal(_linkValues["last"], links.Last); From 3d121051094f0cafe2341122ab8f027083f68db9 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:56:34 +0100 Subject: [PATCH 22/73] Fixed: The parameter {name} has the same default value --- .../Controllers/BaseJsonApiController_Tests.cs | 13 ++++++------- .../ResourceHooks/ResourceHooksTestsSetup.cs | 2 +- .../Serialization/Common/DocumentBuilderTests.cs | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs index 5d328e05d3..ea61a83b0c 100644 --- a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs +++ b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs @@ -92,7 +92,7 @@ public async Task GetAsyncById_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, getById: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.GetAsync(id)); @@ -121,7 +121,7 @@ public async Task GetRelationshipsAsync_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, getRelationships: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.GetRelationshipsAsync(id, string.Empty)); @@ -150,7 +150,7 @@ public async Task GetRelationshipAsync_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, getRelationship: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.GetRelationshipAsync(id, string.Empty)); @@ -218,7 +218,7 @@ public async Task PatchAsync_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, update: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.PatchAsync(id, It.IsAny())); @@ -312,7 +312,7 @@ public async Task PatchRelationshipsAsync_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, updateRelationships: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.PatchRelationshipsAsync(id, string.Empty, null)); @@ -341,8 +341,7 @@ public async Task DeleteAsync_Throws_405_If_No_Service() { // Arrange const int id = 0; - var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance, - delete: null); + var controller = new ResourceController(new Mock().Object, NullLoggerFactory.Instance); // Act var exception = await Assert.ThrowsAsync(() => controller.DeleteAsync(id)); diff --git a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs index 619d695a49..8bf423a8cd 100644 --- a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs +++ b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs @@ -159,7 +159,7 @@ public class HooksTestsSetup : HooksDummyData // mocking the genericServiceFactory and JsonApiContext and wiring them up. var (ufMock, iqMock, gpfMock, options) = CreateMocks(); - SetupProcessorFactoryForResourceDefinition(gpfMock, mainResource.Object, mainDiscovery, null); + SetupProcessorFactoryForResourceDefinition(gpfMock, mainResource.Object, mainDiscovery); var execHelper = new HookExecutorHelper(gpfMock.Object, options); var traversalHelper = new TraversalHelper(_resourceGraph, ufMock.Object); diff --git a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs index 2c8339d1af..915cfe4a48 100644 --- a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs @@ -26,7 +26,7 @@ public void EntityToDocument_NullEntity_CanBuild() TestResource entity = null; // Act - var document = _builder.Build(entity, null, null); + var document = _builder.Build(entity); // Assert Assert.Null(document.Data); @@ -41,7 +41,7 @@ public void EntityToDocument_EmptyList_CanBuild() var entities = new List(); // Act - var document = _builder.Build(entities, null, null); + var document = _builder.Build(entities); // Assert Assert.NotNull(document.Data); @@ -56,7 +56,7 @@ public void EntityToDocument_SingleEntity_CanBuild() IIdentifiable dummy = new Identifiable(); // Act - var document = _builder.Build(dummy, null, null); + var document = _builder.Build(dummy); // Assert Assert.NotNull(document.Data); @@ -70,7 +70,7 @@ public void EntityToDocument_EntityList_CanBuild() var entities = new List() { new Identifiable(), new Identifiable() }; // Act - var document = _builder.Build(entities, null, null); + var document = _builder.Build(entities); var data = (List)document.Data; // Assert From 50f8c1a8d89008b883042a2b311cb3458758cac6 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 17:57:44 +0100 Subject: [PATCH 23/73] Fixed: Empty argument list is redundant --- .../Builders/ResourceGraphBuilder.cs | 2 +- .../Configuration/JsonApiOptions.cs | 2 +- .../Extensions/IQueryableExtensions.cs | 2 +- .../Hooks/Execution/HookExecutorHelper.cs | 2 +- .../Hooks/ResourceHookExecutor.cs | 2 +- .../Hooks/Traversal/ChildNode.cs | 2 +- .../Client/ResponseDeserializer.cs | 4 +- .../ResourceDefinitionTests.cs | 4 +- .../Spec/UpdatingRelationshipsTests.cs | 6 +- .../Acceptance/TodoItemsControllerTests.cs | 8 +-- .../Data/DefaultEntityRepositoryTest.cs | 6 +- .../AffectedEntitiesHelperTests.cs | 8 +-- .../ManyToMany_OnReturnTests.cs | 2 +- .../ResourceHookExecutor/ScenarioTests.cs | 14 ++--- .../Update/BeforeUpdate_WithDbValues_Tests.cs | 2 +- .../ResourceHooks/ResourceHooksTestsSetup.cs | 8 +-- .../Client/RequestSerializerTests.cs | 12 ++-- .../Client/ResponseDeserializerTests.cs | 58 +++++++++---------- .../Common/DocumentBuilderTests.cs | 2 +- .../Common/ResourceObjectBuilderTests.cs | 4 +- .../Server/ResponseSerializerTests.cs | 12 ++-- 21 files changed, 82 insertions(+), 80 deletions(-) diff --git a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs index 0c65d81c29..a0e7d9120c 100644 --- a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs @@ -96,7 +96,7 @@ protected virtual List GetAttributes(Type entityType) // spec point of view. if (prop.Name == nameof(Identifiable.Id)) { - var idAttr = new AttrAttribute() + var idAttr = new AttrAttribute { PublicAttributeName = _formatter.FormatPropertyName(prop), PropertyInfo = prop diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index 88e281fd5f..ad3a291ffd 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -140,7 +140,7 @@ public class JsonApiOptions : IJsonApiOptions /// public bool ValidateModelState { get; set; } - public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings() + public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 901dd7d15a..3a14069c5a 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -317,7 +317,7 @@ private static IQueryable CallGenericSelectMethod(IQueryable 1) // Nested property { if (nestedTypesAndProperties.TryGetValue(props[0], out var properties) == false) - nestedTypesAndProperties.Add(props[0], new List() { nameof(Identifiable.Id), props[1] }); + nestedTypesAndProperties.Add(props[0], new List { nameof(Identifiable.Id), props[1] }); else properties.Add(props[1]); } diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index cb2d8ab94e..cb85490860 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -58,7 +58,7 @@ public IResourceHookContainer GetResourceHookContainer(RightType rightType, Reso } else { - targetHooks = new List() { hook }; + targetHooks = new List { hook }; } foreach (ResourceHook targetHook in targetHooks) diff --git a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs index 549704d908..8b2a258409 100644 --- a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs +++ b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs @@ -41,7 +41,7 @@ public virtual void BeforeRead(ResourcePipeline pipeline, string stri { var hookContainer = _executorHelper.GetResourceHookContainer(ResourceHook.BeforeRead); hookContainer?.BeforeRead(pipeline, false, stringId); - var calledContainers = new List() { typeof(TResource) }; + var calledContainers = new List { typeof(TResource) }; foreach (var chain in _includeService.Get()) RecursiveBeforeRead(chain, pipeline, calledContainers); } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index 7d9dd0bd30..c5086ec6a7 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -79,7 +79,7 @@ public void Reassign(IEnumerable updated = null) } else if (currentValue is IIdentifiable relationshipSingle) { - if (!unique.Intersect(new HashSet() { relationshipSingle }, _comparer).Any()) + if (!unique.Intersect(new HashSet { relationshipSingle }, _comparer).Any()) { proxy.SetValue(left, null); } diff --git a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs index 30061007cb..fcda16f3ac 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs @@ -19,7 +19,7 @@ public ResponseDeserializer(IResourceContextProvider provider) : base(provider) public DeserializedSingleResponse DeserializeSingle(string body) where TResource : class, IIdentifiable { var entity = base.Deserialize(body); - return new DeserializedSingleResponse() + return new DeserializedSingleResponse { Links = _document.Links, Meta = _document.Meta, @@ -33,7 +33,7 @@ public DeserializedSingleResponse DeserializeSingle(string public DeserializedListResponse DeserializeList(string body) where TResource : class, IIdentifiable { var entities = base.Deserialize(body); - return new DeserializedListResponse() + return new DeserializedListResponse { Links = _document.Links, Meta = _document.Meta, diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index a5d4867358..942f42081a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -324,7 +324,7 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship() // Arrange var context = _fixture.GetService(); var person = _personFaker.Generate(); - var passport = new Passport() { IsLocked = true }; + var passport = new Passport { IsLocked = true }; person.Passport = passport; context.People.AddRange(person); var newPassport = new Passport(); @@ -371,7 +371,7 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship_Deletion( // Arrange var context = _fixture.GetService(); var person = _personFaker.Generate(); - var passport = new Passport() { IsLocked = true }; + var passport = new Passport { IsLocked = true }; person.Passport = passport; context.People.AddRange(person); var newPassport = new Passport(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index fe77c4ecbf..0d4ceb7bfc 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -581,7 +581,7 @@ public async Task Can_Delete_ToMany_Relationship_By_Patching_Resource() // Arrange var person = _personFaker.Generate(); var todoItem = _todoItemFaker.Generate(); - person.TodoItems = new List() { todoItem }; + person.TodoItems = new List { todoItem }; _context.People.Add(person); _context.SaveChanges(); @@ -683,7 +683,7 @@ public async Task Updating_ToOne_Relationship_With_Implicit_Remove() var person1 = _personFaker.Generate(); person1.Passport = passport; var person2 = _personFaker.Generate(); - context.People.AddRange(new List() { person1, person2 }); + context.People.AddRange(new List { person1, person2 }); await context.SaveChangesAsync(); var passportId = person1.PassportId; var content = new @@ -731,7 +731,7 @@ public async Task Updating_ToMany_Relationship_With_Implicit_Remove() person1.TodoItems = _todoItemFaker.Generate(3).ToList(); var person2 = _personFaker.Generate(); person2.TodoItems = _todoItemFaker.Generate(2).ToList(); - context.People.AddRange(new List() { person1, person2 }); + context.People.AddRange(new List { person1, person2 }); await context.SaveChangesAsync(); var todoItem1Id = person1.TodoItems[0].Id; var todoItem2Id = person1.TodoItems[1].Id; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index ebc33cd7a8..e2eb798ef3 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -563,7 +563,7 @@ public async Task Can_Post_TodoItem_With_Different_Owner_And_Assignee() data = new { type = "todoItems", - attributes = new Dictionary() + attributes = new Dictionary { { "description", todoItem.Description }, { "ordinal", todoItem.Ordinal }, @@ -637,7 +637,7 @@ public async Task Can_Patch_TodoItem() { id = todoItem.Id, type = "todoItems", - attributes = new Dictionary() + attributes = new Dictionary { { "description", newTodoItem.Description }, { "ordinal", newTodoItem.Ordinal }, @@ -691,7 +691,7 @@ public async Task Can_Patch_TodoItemWithNullable() { id = todoItem.Id, type = "todoItems", - attributes = new Dictionary() + attributes = new Dictionary { { "description", newTodoItem.Description }, { "ordinal", newTodoItem.Ordinal }, @@ -745,7 +745,7 @@ public async Task Can_Patch_TodoItemWithNullValue() { id = todoItem.Id, type = "todoItems", - attributes = new Dictionary() + attributes = new Dictionary { { "description", newTodoItem.Description }, { "ordinal", newTodoItem.Ordinal }, diff --git a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs index 0d41041679..8461d2cc9f 100644 --- a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs +++ b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs @@ -23,7 +23,8 @@ public async Task PageAsync_IQueryableIsAListAndPageNumberPositive_CanStillCount // Arrange var repository = Setup(); - var todoItems = new List() { + var todoItems = new List + { new TodoItem{ Id = 1 }, new TodoItem{ Id = 2 } }; @@ -43,7 +44,8 @@ public async Task PageAsync_IQueryableIsAListAndPageNumberNegative_CanStillCount // Arrange var repository = Setup(); - var todoItems = new List() { + var todoItems = new List + { new TodoItem{ Id = 1 }, new TodoItem{ Id = 2 }, new TodoItem{ Id = 3 }, diff --git a/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs b/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs index 972442b155..7b450c4351 100644 --- a/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs +++ b/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs @@ -31,10 +31,10 @@ public class RelationshipDictionaryTests public readonly HasManyAttribute ToManyAttr; public readonly Dictionary> Relationships = new Dictionary>(); - public readonly HashSet FirstToOnesEntities = new HashSet { new Dummy() { Id = 1 }, new Dummy() { Id = 2 }, new Dummy() { Id = 3 } }; - public readonly HashSet SecondToOnesEntities = new HashSet { new Dummy() { Id = 4 }, new Dummy() { Id = 5 }, new Dummy() { Id = 6 } }; - public readonly HashSet ToManiesEntities = new HashSet { new Dummy() { Id = 7 }, new Dummy() { Id = 8 }, new Dummy() { Id = 9 } }; - public readonly HashSet NoRelationshipsEntities = new HashSet { new Dummy() { Id = 10 }, new Dummy() { Id = 11 }, new Dummy() { Id = 12 } }; + public readonly HashSet FirstToOnesEntities = new HashSet { new Dummy { Id = 1 }, new Dummy { Id = 2 }, new Dummy { Id = 3 } }; + public readonly HashSet SecondToOnesEntities = new HashSet { new Dummy { Id = 4 }, new Dummy { Id = 5 }, new Dummy { Id = 6 } }; + public readonly HashSet ToManiesEntities = new HashSet { new Dummy { Id = 7 }, new Dummy { Id = 8 }, new Dummy { Id = 9 } }; + public readonly HashSet NoRelationshipsEntities = new HashSet { new Dummy { Id = 10 }, new Dummy { Id = 11 }, new Dummy { Id = 12 } }; public readonly HashSet AllEntities; public RelationshipDictionaryTests() { diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs index cb99e26b93..2d32e1dfdd 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs @@ -37,7 +37,7 @@ public class ManyToMany_OnReturnTests : HooksTestsSetup var allJoins = joinsSubSet.Concat(completeJoin).ToList(); - var articles = new List
() { articleTagsSubset, articleWithAllTags }; + var articles = new List
{ articleTagsSubset, articleWithAllTags }; return (articles, allJoins, allTags); } diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs index 544b3df2e0..10a5c1fbb9 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs @@ -19,11 +19,11 @@ public void Entity_Has_Multiple_Relations_To_Same_Type() var (_, _, hookExecutor, todoResourceMock, ownerResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery); var person1 = new Person(); var todo = new TodoItem { Owner = person1 }; - var person2 = new Person { AssignedTodoItems = new List() { todo } }; + var person2 = new Person { AssignedTodoItems = new List { todo } }; todo.Assignee = person2; var person3 = new Person { StakeHolderTodoItem = todo }; todo.StakeHolders = new List { person3 }; - var todoList = new List() { todo }; + var todoList = new List { todo }; // Act hookExecutor.OnReturn(todoList, ResourcePipeline.Post); @@ -43,7 +43,7 @@ public void Entity_Has_Cyclic_Relations() var todo = new TodoItem(); todo.ParentTodo = todo; todo.ChildrenTodos = new List { todo }; - var todoList = new List() { todo }; + var todoList = new List { todo }; // Act hookExecutor.OnReturn(todoList, ResourcePipeline.Post); @@ -59,15 +59,15 @@ public void Entity_Has_Nested_Cyclic_Relations() // Arrange var todoDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); (var contextMock, var hookExecutor, var todoResourceMock) = CreateTestObjects(todoDiscovery); - var rootTodo = new TodoItem() { Id = 1 }; + var rootTodo = new TodoItem { Id = 1 }; var child = new TodoItem { ParentTodo = rootTodo, Id = 2 }; rootTodo.ChildrenTodos = new List { child }; - var grandChild = new TodoItem() { ParentTodo = child, Id = 3 }; + var grandChild = new TodoItem { ParentTodo = child, Id = 3 }; child.ChildrenTodos = new List { grandChild }; - var greatGrandChild = new TodoItem() { ParentTodo = grandChild, Id = 4 }; + var greatGrandChild = new TodoItem { ParentTodo = grandChild, Id = 4 }; grandChild.ChildrenTodos = new List { greatGrandChild }; greatGrandChild.ChildrenTodos = new List { rootTodo }; - var todoList = new List() { rootTodo }; + var todoList = new List { rootTodo }; // Act hookExecutor.OnReturn(todoList, ResourcePipeline.Post); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs index 156aa3c99a..39271372cb 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs @@ -85,7 +85,7 @@ public void BeforeUpdate_Deleting_Relationship() ufMock.Setup(c => c.Relationships).Returns(_resourceGraph.GetRelationships((TodoItem t) => t.OneToOnePerson)); // Act - var _todoList = new List() { new TodoItem { Id = this.todoList[0].Id } }; + var _todoList = new List { new TodoItem { Id = this.todoList[0].Id } }; hookExecutor.BeforeUpdate(_todoList, ResourcePipeline.Patch); // Assert diff --git a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs index 8bf423a8cd..d21541688c 100644 --- a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs +++ b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs @@ -64,7 +64,7 @@ protected List CreateTodoWithToOnePerson() { var todoItem = _todoFaker.Generate(); var person = _personFaker.Generate(); - var todoList = new List() { todoItem }; + var todoList = new List { todoItem }; person.OneToOneTodoItem = todoItem; todoItem.OneToOnePerson = person; return todoList; @@ -74,7 +74,7 @@ protected List CreateTodoWithOwner() { var todoItem = _todoFaker.Generate(); var person = _personFaker.Generate(); - var todoList = new List() { todoItem }; + var todoList = new List { todoItem }; person.AssignedTodoItems = todoList; todoItem.Owner = person; return todoList; @@ -106,7 +106,7 @@ protected List CreateTodoWithOwner() var allJoins = joinsSubSet.Concat(completeJoin).ToList(); - var articles = new List
() { articleTagsSubset, articleWithAllTags }; + var articles = new List
{ articleTagsSubset, articleWithAllTags }; return (articles, allJoins, allTags); } @@ -134,7 +134,7 @@ protected List CreateTodoWithOwner() } var allJoins = joinsSubSet.Concat(completeJoin).ToList(); - var articles = new List
() { articleTagsSubset, articleWithAllTags }; + var articles = new List
{ articleTagsSubset, articleWithAllTags }; return (articles, allJoins, allTags); } } diff --git a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs index e703525685..d2b5525f37 100644 --- a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs +++ b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs @@ -22,7 +22,7 @@ public RequestSerializerTests() public void SerializeSingle_ResourceWithDefaultTargetFields_CanBuild() { // Arrange - var entity = new TestResource() { Id = 1, StringField = "value", NullableIntField = 123 }; + var entity = new TestResource { Id = 1, StringField = "value", NullableIntField = 123 }; // Act string serialized = _serializer.Serialize(entity); @@ -53,7 +53,7 @@ public void SerializeSingle_ResourceWithDefaultTargetFields_CanBuild() public void SerializeSingle_ResourceWithTargetedSetAttributes_CanBuild() { // Arrange - var entity = new TestResource() { Id = 1, StringField = "value", NullableIntField = 123 }; + var entity = new TestResource { Id = 1, StringField = "value", NullableIntField = 123 }; _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => tr.StringField); // Act @@ -78,7 +78,7 @@ public void SerializeSingle_ResourceWithTargetedSetAttributes_CanBuild() public void SerializeSingle_NoIdWithTargetedSetAttributes_CanBuild() { // Arrange - var entityNoId = new TestResource() { Id = 0, StringField = "value", NullableIntField = 123 }; + var entityNoId = new TestResource { Id = 0, StringField = "value", NullableIntField = 123 }; _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => tr.StringField); // Act @@ -103,7 +103,7 @@ public void SerializeSingle_NoIdWithTargetedSetAttributes_CanBuild() public void SerializeSingle_ResourceWithoutTargetedAttributes_CanBuild() { // Arrange - var entity = new TestResource() { Id = 1, StringField = "value", NullableIntField = 123 }; + var entity = new TestResource { Id = 1, StringField = "value", NullableIntField = 123 }; _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => new { }); // Act @@ -177,8 +177,8 @@ public void SerializeMany_ResourcesWithTargetedAttributes_CanBuild() // Arrange var entities = new List { - new TestResource() { Id = 1, StringField = "value1", NullableIntField = 123 }, - new TestResource() { Id = 2, StringField = "value2", NullableIntField = 123 } + new TestResource { Id = 1, StringField = "value1", NullableIntField = 123 }, + new TestResource { Id = 2, StringField = "value2", NullableIntField = 123 } }; _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => tr.StringField); diff --git a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs index 8fd8c4a5db..0ef49c5069 100644 --- a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs +++ b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs @@ -115,19 +115,19 @@ public void DeserializeSingle_MultipleDependentRelationshipsWithIncluded_CanDese content.SingleData.Relationships.Add("emptyToManies", CreateRelationshipData(isToManyData: true)); var toOneAttributeValue = "populatedToOne member content"; var toManyAttributeValue = "populatedToManies member content"; - content.Included = new List() + content.Included = new List { - new ResourceObject() + new ResourceObject { Type = "oneToOneDependents", Id = "10", - Attributes = new Dictionary() { {"attributeMember", toOneAttributeValue } } + Attributes = new Dictionary { {"attributeMember", toOneAttributeValue } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyDependents", Id = "10", - Attributes = new Dictionary() { {"attributeMember", toManyAttributeValue } } + Attributes = new Dictionary { {"attributeMember", toManyAttributeValue } } } }; var body = JsonConvert.SerializeObject(content); @@ -158,19 +158,19 @@ public void DeserializeSingle_MultiplePrincipalRelationshipsWithIncluded_CanDese content.SingleData.Relationships.Add("emptyToMany", CreateRelationshipData()); var toOneAttributeValue = "populatedToOne member content"; var toManyAttributeValue = "populatedToManies member content"; - content.Included = new List() + content.Included = new List { - new ResourceObject() + new ResourceObject { Type = "oneToOnePrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", toOneAttributeValue } } + Attributes = new Dictionary { {"attributeMember", toOneAttributeValue } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", toManyAttributeValue } } + Attributes = new Dictionary { {"attributeMember", toManyAttributeValue } } } }; var body = JsonConvert.SerializeObject(content); @@ -197,20 +197,20 @@ public void DeserializeSingle_NestedIncluded_CanDeserialize() content.SingleData.Relationships.Add("populatedToManies", CreateRelationshipData("oneToManyDependents", isToManyData: true)); var toManyAttributeValue = "populatedToManies member content"; var nestedIncludeAttributeValue = "nested include member content"; - content.Included = new List() + content.Included = new List { - new ResourceObject() + new ResourceObject { Type = "oneToManyDependents", Id = "10", - Attributes = new Dictionary() { {"attributeMember", toManyAttributeValue } }, + Attributes = new Dictionary { {"attributeMember", toManyAttributeValue } }, Relationships = new Dictionary { { "principal", CreateRelationshipData("oneToManyPrincipals") } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", nestedIncludeAttributeValue } } + Attributes = new Dictionary { {"attributeMember", nestedIncludeAttributeValue } } } }; var body = JsonConvert.SerializeObject(content); @@ -241,27 +241,27 @@ public void DeserializeSingle_DeeplyNestedIncluded_CanDeserialize() var includedAttributeValue = "multi member content"; var nestedIncludedAttributeValue = "nested include member content"; var deeplyNestedIncludedAttributeValue = "deeply nested member content"; - content.Included = new List() + content.Included = new List { - new ResourceObject() + new ResourceObject { Type = "multiPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", includedAttributeValue } }, + Attributes = new Dictionary { {"attributeMember", includedAttributeValue } }, Relationships = new Dictionary { { "populatedToManies", CreateRelationshipData("oneToManyDependents", isToManyData: true) } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyDependents", Id = "10", - Attributes = new Dictionary() { {"attributeMember", nestedIncludedAttributeValue } }, + Attributes = new Dictionary { {"attributeMember", nestedIncludedAttributeValue } }, Relationships = new Dictionary { { "principal", CreateRelationshipData("oneToManyPrincipals") } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", deeplyNestedIncludedAttributeValue } } + Attributes = new Dictionary { {"attributeMember", deeplyNestedIncludedAttributeValue } } }, }; var body = JsonConvert.SerializeObject(content); @@ -293,27 +293,27 @@ public void DeserializeList_DeeplyNestedIncluded_CanDeserialize() var includedAttributeValue = "multi member content"; var nestedIncludedAttributeValue = "nested include member content"; var deeplyNestedIncludedAttributeValue = "deeply nested member content"; - content.Included = new List() + content.Included = new List { - new ResourceObject() + new ResourceObject { Type = "multiPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", includedAttributeValue } }, + Attributes = new Dictionary { {"attributeMember", includedAttributeValue } }, Relationships = new Dictionary { { "populatedToManies", CreateRelationshipData("oneToManyDependents", isToManyData: true) } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyDependents", Id = "10", - Attributes = new Dictionary() { {"attributeMember", nestedIncludedAttributeValue } }, + Attributes = new Dictionary { {"attributeMember", nestedIncludedAttributeValue } }, Relationships = new Dictionary { { "principal", CreateRelationshipData("oneToManyPrincipals") } } }, - new ResourceObject() + new ResourceObject { Type = "oneToManyPrincipals", Id = "10", - Attributes = new Dictionary() { {"attributeMember", deeplyNestedIncludedAttributeValue } } + Attributes = new Dictionary { {"attributeMember", deeplyNestedIncludedAttributeValue } } }, }; var body = JsonConvert.SerializeObject(content); diff --git a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs index 915cfe4a48..f32347a0c3 100644 --- a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs @@ -67,7 +67,7 @@ public void EntityToDocument_SingleEntity_CanBuild() public void EntityToDocument_EntityList_CanBuild() { // Arrange - var entities = new List() { new Identifiable(), new Identifiable() }; + var entities = new List { new Identifiable(), new Identifiable() }; // Act var document = _builder.Build(entities); diff --git a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs index 9971bacbe8..4b14f884c3 100644 --- a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs @@ -38,7 +38,7 @@ public void EntityToResourceObject_EmptyResource_CanBuild() public void EntityToResourceObject_ResourceWithId_CanBuild() { // Arrange - var entity = new TestResource() { Id = 1 }; + var entity = new TestResource { Id = 1 }; // Act var resourceObject = _builder.Build(entity); @@ -56,7 +56,7 @@ public void EntityToResourceObject_ResourceWithId_CanBuild() public void EntityToResourceObject_ResourceWithIncludedAttrs_CanBuild(string stringFieldValue, int? intFieldValue) { // Arrange - var entity = new TestResource() { StringField = stringFieldValue, NullableIntField = intFieldValue }; + var entity = new TestResource { StringField = stringFieldValue, NullableIntField = intFieldValue }; var attrs = _resourceGraph.GetAttributes(tr => new { tr.StringField, tr.NullableIntField }); // Act diff --git a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs index 9dee6c741d..a0abbcf562 100644 --- a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs @@ -15,7 +15,7 @@ public class ResponseSerializerTests : SerializerTestsSetup public void SerializeSingle_ResourceWithDefaultTargetFields_CanSerialize() { // Arrange - var entity = new TestResource() { Id = 1, StringField = "value", NullableIntField = 123 }; + var entity = new TestResource { Id = 1, StringField = "value", NullableIntField = 123 }; var serializer = GetResponseSerializer(); // Act @@ -49,7 +49,7 @@ public void SerializeSingle_ResourceWithDefaultTargetFields_CanSerialize() public void SerializeMany_ResourceWithDefaultTargetFields_CanSerialize() { // Arrange - var entity = new TestResource() { Id = 1, StringField = "value", NullableIntField = 123 }; + var entity = new TestResource { Id = 1, StringField = "value", NullableIntField = 123 }; var serializer = GetResponseSerializer(); // Act @@ -360,7 +360,7 @@ public void SerializeSingle_NullWithLinksAndMeta_StillShowsLinksAndMeta() public void SerializeSingleWithRequestRelationship_NullToOneRelationship_CanSerialize() { // Arrange - var entity = new OneToOnePrincipal() { Id = 2, Dependent = null }; + var entity = new OneToOnePrincipal { Id = 2, Dependent = null }; var serializer = GetResponseSerializer(); var requestRelationship = _resourceGraph.GetRelationships((OneToOnePrincipal t) => t.Dependent).First(); serializer.RequestRelationship = requestRelationship; @@ -378,7 +378,7 @@ public void SerializeSingleWithRequestRelationship_NullToOneRelationship_CanSeri public void SerializeSingleWithRequestRelationship_PopulatedToOneRelationship_CanSerialize() { // Arrange - var entity = new OneToOnePrincipal() { Id = 2, Dependent = new OneToOneDependent { Id = 1 } }; + var entity = new OneToOnePrincipal { Id = 2, Dependent = new OneToOneDependent { Id = 1 } }; var serializer = GetResponseSerializer(); var requestRelationship = _resourceGraph.GetRelationships((OneToOnePrincipal t) => t.Dependent).First(); serializer.RequestRelationship = requestRelationship; @@ -405,7 +405,7 @@ public void SerializeSingleWithRequestRelationship_PopulatedToOneRelationship_Ca public void SerializeSingleWithRequestRelationship_EmptyToManyRelationship_CanSerialize() { // Arrange - var entity = new OneToManyPrincipal() { Id = 2, Dependents = new List() }; + var entity = new OneToManyPrincipal { Id = 2, Dependents = new List() }; var serializer = GetResponseSerializer(); var requestRelationship = _resourceGraph.GetRelationships((OneToManyPrincipal t) => t.Dependents).First(); serializer.RequestRelationship = requestRelationship; @@ -424,7 +424,7 @@ public void SerializeSingleWithRequestRelationship_EmptyToManyRelationship_CanSe public void SerializeSingleWithRequestRelationship_PopulatedToManyRelationship_CanSerialize() { // Arrange - var entity = new OneToManyPrincipal() { Id = 2, Dependents = new List { new OneToManyDependent { Id = 1 } } }; + var entity = new OneToManyPrincipal { Id = 2, Dependents = new List { new OneToManyDependent { Id = 1 } } }; var serializer = GetResponseSerializer(); var requestRelationship = _resourceGraph.GetRelationships((OneToManyPrincipal t) => t.Dependents).First(); serializer.RequestRelationship = requestRelationship; From ea572a1275cd4b911fc7501212b168db41942702 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:00:35 +0100 Subject: [PATCH 24/73] Fixed: Expression is always null --- .../Hooks/Execution/HookExecutorHelper.cs | 2 +- .../Middleware/CurrentRequestMiddleware.cs | 2 +- .../Serialization/Client/RequestSerializer.cs | 2 +- .../Serialization/Client/RequestSerializerTests.cs | 3 +-- .../Serialization/Common/DocumentBuilderTests.cs | 5 +---- .../Serialization/Server/ResponseSerializerTests.cs | 9 +++++---- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index cb85490860..b582b61345 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -46,7 +46,7 @@ public IResourceHookContainer GetResourceHookContainer(RightType rightType, Reso container = (_genericProcessorFactory.Get(typeof(ResourceDefinition<>), rightType)); _hookContainers[rightType] = container; } - if (container == null) return container; + if (container == null) return null; // if there was a container, first check if it implements the hook we // want to use it for. diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index 115a77a745..342de71aa8 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -223,7 +223,7 @@ private ResourceContext GetCurrentEntity() var requestResource = _resourceGraph.GetResourceContext(resourceType); if (requestResource == null) { - return requestResource; + return null; } if (_routeValues.TryGetValue("relationshipName", out object relationshipName)) { diff --git a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs index 13a8b6f9f1..8b8ac50470 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs @@ -27,7 +27,7 @@ public RequestSerializer(IResourceGraph resourceGraph, public string Serialize(IIdentifiable entity) { if (entity == null) - return JsonConvert.SerializeObject(Build(entity, new List(), new List())); + return JsonConvert.SerializeObject(Build((IIdentifiable) null, new List(), new List())); _currentTargetedResource = entity.GetType(); var document = Build(entity, GetAttributesToSerialize(entity), GetRelationshipsToSerialize(entity)); diff --git a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs index d2b5525f37..3f038c70ef 100644 --- a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs +++ b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs @@ -216,8 +216,7 @@ public void SerializeSingle_Null_CanBuild() _serializer.AttributesToSerialize = _resourceGraph.GetAttributes(tr => tr.StringField); // Act - IIdentifiable obj = null; - string serialized = _serializer.Serialize(obj); + string serialized = _serializer.Serialize((IIdentifiable) null); // Assert var expectedFormatted = diff --git a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs index f32347a0c3..169968ad9d 100644 --- a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs @@ -22,11 +22,8 @@ public BaseDocumentBuilderTests() [Fact] public void EntityToDocument_NullEntity_CanBuild() { - // Arrange - TestResource entity = null; - // Act - var document = _builder.Build(entity); + var document = _builder.Build((TestResource) null); // Assert Assert.Null(document.Data); diff --git a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs index a0abbcf562..7412a0479b 100644 --- a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs @@ -233,9 +233,9 @@ public void SerializeSingle_Null_CanSerialize() { // Arrange var serializer = GetResponseSerializer(); - TestResource entity = null; + // Act - string serialized = serializer.SerializeSingle(entity); + string serialized = serializer.SerializeSingle(null); // Assert var expectedFormatted = @"{ ""data"": null }"; @@ -334,10 +334,11 @@ public void SerializeSingle_NullWithLinksAndMeta_StillShowsLinksAndMeta() { // Arrange var meta = new Dictionary { { "test", "meta" } }; - OneToManyPrincipal entity = null; var serializer = GetResponseSerializer(metaDict: meta, topLinks: _dummyTopLevelLinks, relationshipLinks: _dummyRelationshipLinks, resourceLinks: _dummyResourceLinks); + // Act - string serialized = serializer.SerializeSingle(entity); + string serialized = serializer.SerializeSingle(null); + // Assert var expectedFormatted = @"{ From 889ea3d34b8da24b4c7997b498476e43c39fd806 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:01:57 +0100 Subject: [PATCH 25/73] Fixed: Value assigned is not used in any execution path --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 6 +++--- src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs | 2 +- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 3a14069c5a..cd92ecc57a 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -244,8 +244,8 @@ private static IQueryable CallGenericWhereMethod(IQueryable CallGenericWhereMethod(IQueryable CallGenericSelectMethod(IQueryable source, List columns) { - var sourceBindings = new List(); + List sourceBindings; var sourceType = typeof(TSource); var parameter = Expression.Parameter(source.ElementType, "x"); var sourceProperties = new List(); diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index b582b61345..5fe21b7aa3 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -160,7 +160,7 @@ public Dictionary LoadImplicitlyAffected( foreach (IIdentifiable ip in includedLefts) { - IList dbRightEntityList = null; + IList dbRightEntityList; var relationshipValue = relationship.GetValue(ip); if (!(relationshipValue is IEnumerable)) { diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index 7c77d6a532..aa783730d6 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -93,7 +93,7 @@ public static Type GetTypeOfList(Type type) ///
public static PropertyInfo ParseNavigationExpression(Expression> NavigationExpression) { - MemberExpression Exp = null; + MemberExpression Exp; //this line is necessary, because sometimes the expression comes in as Convert(originalExpression) if (NavigationExpression.Body is UnaryExpression) From b7cb5be84343d8a4598176ff6a0a06b272b47d27 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:03:02 +0100 Subject: [PATCH 26/73] Fixed: Redundant 'IEnumerable.Cast' call --- src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs | 2 +- src/JsonApiDotNetCore/Internal/ResourceGraph.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 13e2fbec1d..8b1220aa32 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -57,7 +57,7 @@ public RootNode CreateRootNode(IEnumerable root _processedEntities = new Dictionary>(); RegisterRelationshipProxies(typeof(TResource)); var uniqueEntities = ProcessEntities(rootEntities); - var populatedRelationshipsToNextLayer = GetPopulatedRelationships(typeof(TResource), uniqueEntities.Cast()); + var populatedRelationshipsToNextLayer = GetPopulatedRelationships(typeof(TResource), uniqueEntities); var allRelationshipsFromType = _relationshipProxies.Select(entry => entry.Value).Where(proxy => proxy.LeftType == typeof(TResource)).ToArray(); return new RootNode(uniqueEntities, populatedRelationshipsToNextLayer, allRelationshipsFromType); } diff --git a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs index 2dc5dda57a..571e86692a 100644 --- a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs +++ b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs @@ -75,9 +75,9 @@ private IEnumerable Getter(Expression> selec { IEnumerable available; if (type == FieldFilterType.Attribute) - available = GetResourceContext(typeof(T)).Attributes.Cast(); + available = GetResourceContext(typeof(T)).Attributes; else if (type == FieldFilterType.Relationship) - available = GetResourceContext(typeof(T)).Relationships.Cast(); + available = GetResourceContext(typeof(T)).Relationships; else available = GetResourceContext(typeof(T)).Fields; From 6fce99dfccc5715297ede56d1d7c9afa3247f95b Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:04:13 +0100 Subject: [PATCH 27/73] Fixed: '??' right operand is always null --- .../Serialization/Common/BaseDocumentParser.cs | 2 +- test/UnitTests/Serialization/SerializerTestsSetup.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs index 62cbf096c7..5021ceb33c 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs @@ -166,7 +166,7 @@ private object SetHasOneRelationship(IIdentifiable entity, RelationshipEntry relationshipData) { var rio = (ResourceIdentifierObject)relationshipData.Data; - var relatedId = rio?.Id ?? null; + var relatedId = rio?.Id; // this does not make sense in the following case: if we're setting the dependent of a one-to-one relationship, IdentifiablePropertyName should be null. var foreignKeyProperty = entityProperties.FirstOrDefault(p => p.Name == attr.IdentifiablePropertyName); diff --git a/test/UnitTests/Serialization/SerializerTestsSetup.cs b/test/UnitTests/Serialization/SerializerTestsSetup.cs index 73ce8c3ba1..2d4bd96c22 100644 --- a/test/UnitTests/Serialization/SerializerTestsSetup.cs +++ b/test/UnitTests/Serialization/SerializerTestsSetup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using JsonApiDotNetCore.Managers.Contracts; @@ -125,13 +125,13 @@ public TestDocumentBuilder(IResourceObjectBuilder resourceObjectBuilder) : base( public new Document Build(IIdentifiable entity, List attributes = null, List relationships = null) { - return base.Build(entity, attributes ?? null, relationships ?? null); + return base.Build(entity, attributes, relationships); } public new Document Build(IEnumerable entities, List attributes = null, List relationships = null) { - return base.Build(entities, attributes ?? null, relationships ?? null); + return base.Build(entities, attributes, relationships); } } } -} \ No newline at end of file +} From aaad695784aae52d27c816afd04c5d3a35689ad4 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:04:55 +0100 Subject: [PATCH 28/73] Fixed: Redundant 'Object.ToString()' call --- .../Serialization/Common/BaseDocumentParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs index 5021ceb33c..6cd9ad0a08 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs @@ -146,7 +146,7 @@ private IIdentifiable ParseResourceObject(ResourceObject data) entity = SetRelationships(entity, data.Relationships, resourceContext.Relationships); if (data.Id != null) - entity.StringId = data.Id?.ToString(); + entity.StringId = data.Id; return entity; } From dc1a2b12e08aef10a17da7be725bb2c8b257d78c Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:05:43 +0100 Subject: [PATCH 29/73] Fixed: Qualifier 'base.' is redundant --- .../Serialization/Client/RequestSerializer.cs | 2 +- .../Serialization/Client/ResponseDeserializer.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs index 8b8ac50470..94fd06cb39 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/RequestSerializer.cs @@ -50,7 +50,7 @@ public string Serialize(IEnumerable entities) _currentTargetedResource = entity.GetType(); var attributes = GetAttributesToSerialize(entity); var relationships = GetRelationshipsToSerialize(entity); - var document = base.Build(entities, attributes, relationships); + var document = Build(entities, attributes, relationships); _currentTargetedResource = null; return JsonConvert.SerializeObject(document); } diff --git a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs index fcda16f3ac..57f1c74ca9 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs @@ -18,7 +18,7 @@ public ResponseDeserializer(IResourceContextProvider provider) : base(provider) /// public DeserializedSingleResponse DeserializeSingle(string body) where TResource : class, IIdentifiable { - var entity = base.Deserialize(body); + var entity = Deserialize(body); return new DeserializedSingleResponse { Links = _document.Links, @@ -32,7 +32,7 @@ public DeserializedSingleResponse DeserializeSingle(string /// public DeserializedListResponse DeserializeList(string body) where TResource : class, IIdentifiable { - var entities = base.Deserialize(body); + var entities = Deserialize(body); return new DeserializedListResponse { Links = _document.Links, From 09ea66e1186b1c8593c6b6b91c3e8c58a47a44c4 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:07:13 +0100 Subject: [PATCH 30/73] Fixed: The field is always assigned before being used and can be converted to local variable --- src/JsonApiDotNetCore/Models/ResourceDefinition.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs index 6983cba452..78201ec14d 100644 --- a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs +++ b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs @@ -1,4 +1,3 @@ -using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Internal.Query; using JsonApiDotNetCore.Hooks; @@ -26,19 +25,17 @@ public interface IResourceDefinition /// The resource type public class ResourceDefinition : IResourceDefinition, IResourceHookContainer where TResource : class, IIdentifiable { - private readonly ResourceContext _resourceContext; private readonly IResourceGraph _resourceGraph; private List _allowedAttributes; private List _allowedRelationships; public ResourceDefinition(IResourceGraph resourceGraph) { - _resourceContext = resourceGraph.GetResourceContext(typeof(TResource)); - _allowedAttributes = _resourceContext.Attributes; - _allowedRelationships = _resourceContext.Relationships; + var resourceContext = resourceGraph.GetResourceContext(typeof(TResource)); + _allowedAttributes = resourceContext.Attributes; + _allowedRelationships = resourceContext.Relationships; _resourceGraph = resourceGraph; } - public List GetAllowedRelationships() => _allowedRelationships; public List GetAllowedAttributes() => _allowedAttributes; From dc2dc1106fa336cd0c1db5897502f7c329a71460 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Fri, 14 Feb 2020 18:12:10 +0100 Subject: [PATCH 31/73] Fixed: Merge cast with type check --- src/JsonApiDotNetCore/Extensions/TypeExtensions.cs | 4 ++-- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 11 +++++------ .../Serialization/Common/BaseDocumentParser.cs | 4 ++-- .../Acceptance/Extensibility/RequestMetaTests.cs | 3 +-- .../Acceptance/Spec/DocumentTests/Meta.cs | 3 +-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs index ca9d1d4a10..2e52e58d7b 100644 --- a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs @@ -17,9 +17,9 @@ public static void AddRange(this IList list, IEnumerable items) if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); - if (list is List) + if (list is List genericList) { - ((List)list).AddRange(items); + genericList.AddRange(items); } else { diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index aa783730d6..4f02ad4fe6 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -96,21 +96,20 @@ public static PropertyInfo ParseNavigationExpression(Expression Date: Mon, 17 Feb 2020 10:35:30 +0100 Subject: [PATCH 32/73] Fixed: Replace with single call to First(..) --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 5 ++--- .../Acceptance/Spec/CreatingDataTests.cs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index cd92ecc57a..50ad8bb342 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -21,9 +21,8 @@ private static MethodInfo ContainsMethod if (_containsMethod == null) { _containsMethod = typeof(Enumerable) - .GetMethods(BindingFlags.Static | BindingFlags.Public) - .Where(m => m.Name == nameof(Enumerable.Contains) && m.GetParameters().Count() == 2) - .First(); + .GetMethods(BindingFlags.Static | BindingFlags.Public) + .First(m => m.Name == nameof(Enumerable.Contains) && m.GetParameters().Count() == 2); } return _containsMethod; } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs index b5a0ef5140..4636b9c475 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs @@ -43,7 +43,7 @@ public async Task CreateResource_ModelWithEntityFrameworkInheritance_IsCreated() // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); var createdSuperUser = _deserializer.DeserializeSingle(body).Data; - var created = _dbContext.SuperUsers.Where(e => e.Id.Equals(createdSuperUser.Id)).First(); + var created = _dbContext.SuperUsers.First(e => e.Id.Equals(createdSuperUser.Id)); } [Fact] From b84797ba2cc5dea3301ad6c2c97ca4b4f11518f1 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 10:37:11 +0100 Subject: [PATCH 33/73] Fixed: Replace 'Enumerable.Count()' invocation with collection count property access --- .../Extensions/IQueryableExtensions.cs | 2 +- .../QueryParameterServices/SparseFieldsService.cs | 2 +- .../Acceptance/Spec/AttributeFilterTests.cs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 50ad8bb342..75a7066b6f 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -22,7 +22,7 @@ private static MethodInfo ContainsMethod { _containsMethod = typeof(Enumerable) .GetMethods(BindingFlags.Static | BindingFlags.Public) - .First(m => m.Name == nameof(Enumerable.Contains) && m.GetParameters().Count() == 2); + .First(m => m.Name == nameof(Enumerable.Contains) && m.GetParameters().Length == 2); } return _containsMethod; } diff --git a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs index 53909588f2..db6691923b 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs @@ -50,7 +50,7 @@ public virtual void Parse(KeyValuePair queryParameter) var keySplit = queryParameter.Key.Split(QueryConstants.OPEN_BRACKET, QueryConstants.CLOSE_BRACKET); - if (keySplit.Count() == 1) + if (keySplit.Length == 1) { // input format: fields=prop1,prop2 foreach (var field in fields) RegisterRequestResourceField(field); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs index 49472014f1..a2bd604862 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs @@ -139,7 +139,7 @@ public async Task Can_Filter_On_In_Array_Values() { context.TodoItems.Add(item); // Exclude 2 items - if (guids.Count < (todoItems.Count() - 2)) + if (guids.Count < (todoItems.Count - 2)) guids.Add(item.GuidProperty); else notInGuids.Add(item.GuidProperty); @@ -160,7 +160,7 @@ public async Task Can_Filter_On_In_Array_Values() // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(guids.Count(), deserializedTodoItems.Count()); + Assert.Equal(guids.Count, deserializedTodoItems.Count); foreach (var item in deserializedTodoItems) { Assert.Contains(item.GuidProperty, guids); @@ -196,7 +196,7 @@ public async Task Can_Filter_On_Related_In_Array_Values() // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(ownerFirstNames.Count(), documents.ManyData.Count()); + Assert.Equal(ownerFirstNames.Count, documents.ManyData.Count); Assert.NotNull(included); Assert.NotEmpty(included); foreach (var item in included) @@ -218,7 +218,7 @@ public async Task Can_Filter_On_Not_In_Array_Values() { context.TodoItems.Add(item); // Exclude 2 items - if (guids.Count < (todoItems.Count() - 2)) + if (guids.Count < (todoItems.Count - 2)) guids.Add(item.GuidProperty); else notInGuids.Add(item.GuidProperty); @@ -239,7 +239,7 @@ public async Task Can_Filter_On_Not_In_Array_Values() // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(totalCount - notInGuids.Count(), deserializedTodoItems.Count()); + Assert.Equal(totalCount - notInGuids.Count, deserializedTodoItems.Count); foreach (var item in deserializedTodoItems) { Assert.DoesNotContain(item.GuidProperty, notInGuids); From 67ae0e8718b7c9851532b9664f3205ae8af705be Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 10:38:37 +0100 Subject: [PATCH 34/73] Fixed: Use format specifier --- src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs | 2 +- src/JsonApiDotNetCore/Internal/ResourceGraph.cs | 2 +- src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs | 6 +++--- .../Models/Annotation/RelationshipAttribute.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs index e01620cb82..4dec1e95ff 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs @@ -70,7 +70,7 @@ void DiscoverImplementedHooks(Type containerType) if (!_databaseValuesAttributeAllowed.Contains(hook)) { throw new JsonApiSetupException("DatabaseValuesAttribute cannot be used on hook" + - $"{hook.ToString("G")} in resource definition {containerType.Name}"); + $"{hook:G} in resource definition {containerType.Name}"); } var targetList = attr.value ? databaseValuesEnabledHooks : databaseValuesDisabledHooks; targetList.Add(hook); diff --git a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs index 571e86692a..d1a98a915b 100644 --- a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs +++ b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs @@ -128,7 +128,7 @@ private IEnumerable Getter(Expression> selec private void ThrowNotExposedError(string memberName, FieldFilterType type) { - throw new ArgumentException($"{memberName} is not an json:api exposed {type.ToString("g")}."); + throw new ArgumentException($"{memberName} is not an json:api exposed {type:g}."); } /// diff --git a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs index 1c071723f1..96907a880a 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs @@ -9,13 +9,13 @@ public class LinksAttribute : Attribute public LinksAttribute(Link topLevelLinks = Link.NotConfigured, Link resourceLinks = Link.NotConfigured, Link relationshipLinks = Link.NotConfigured) { if (topLevelLinks == Link.Related) - throw new JsonApiSetupException($"{Link.Related.ToString("g")} not allowed for argument {nameof(topLevelLinks)}"); + throw new JsonApiSetupException($"{Link.Related:g} not allowed for argument {nameof(topLevelLinks)}"); if (resourceLinks == Link.Paging) - throw new JsonApiSetupException($"{Link.Paging.ToString("g")} not allowed for argument {nameof(resourceLinks)}"); + throw new JsonApiSetupException($"{Link.Paging:g} not allowed for argument {nameof(resourceLinks)}"); if (relationshipLinks == Link.Paging) - throw new JsonApiSetupException($"{Link.Paging.ToString("g")} not allowed for argument {nameof(relationshipLinks)}"); + throw new JsonApiSetupException($"{Link.Paging:g} not allowed for argument {nameof(relationshipLinks)}"); TopLevelLinks = topLevelLinks; ResourceLinks = resourceLinks; diff --git a/src/JsonApiDotNetCore/Models/Annotation/RelationshipAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/RelationshipAttribute.cs index 00e348f8c0..a5b61cce62 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/RelationshipAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/RelationshipAttribute.cs @@ -10,7 +10,7 @@ public abstract class RelationshipAttribute : Attribute, IResourceField protected RelationshipAttribute(string publicName, Link relationshipLinks, bool canInclude) { if (relationshipLinks == Link.Paging) - throw new JsonApiSetupException($"{Link.Paging.ToString("g")} not allowed for argument {nameof(relationshipLinks)}"); + throw new JsonApiSetupException($"{Link.Paging:g} not allowed for argument {nameof(relationshipLinks)}"); PublicRelationshipName = publicName; RelationshipLinks = relationshipLinks; From 6c8c20cf10ec0a07c16c328b103b4c5964333d52 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 10:53:33 +0100 Subject: [PATCH 35/73] Fixed: Field is assigned but its value is never used --- .../Acceptance/Spec/ContentNegotiation.cs | 6 ------ .../Acceptance/Spec/DeletingDataTests.cs | 9 --------- .../Acceptance/Spec/DocumentTests/Relationships.cs | 2 -- .../Acceptance/Spec/QueryParameters.cs | 6 ------ test/UnitTests/Models/ResourceDefinitionTests.cs | 10 ---------- 5 files changed, 33 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs index ab36df4249..e6b67a78ed 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs @@ -12,12 +12,6 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class ContentNegotiation { - private TestFixture _fixture; - public ContentNegotiation(TestFixture fixture) - { - _fixture = fixture; - } - [Fact] public async Task Server_Sends_Correct_ContentType_Header() { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs index 2b76e55e6b..2c227a4185 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs @@ -2,10 +2,8 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; -using Bogus; using JsonApiDotNetCoreExample; using JsonApiDotNetCoreExample.Data; -using JsonApiDotNetCoreExample.Models; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Xunit; @@ -15,18 +13,11 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class DeletingDataTests { - private TestFixture _fixture; private AppDbContext _context; - private Faker _todoItemFaker; public DeletingDataTests(TestFixture fixture) { - _fixture = fixture; _context = fixture.GetService(); - _todoItemFaker = new Faker() - .RuleFor(t => t.Description, f => f.Lorem.Sentence()) - .RuleFor(t => t.Ordinal, f => f.Random.Number()) - .RuleFor(t => t.CreatedDate, f => f.Date.Past()); } [Fact] diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs index bf96abce15..1db3a617c0 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs @@ -17,13 +17,11 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests [Collection("WebHostCollection")] public class Relationships { - private TestFixture _fixture; private AppDbContext _context; private Faker _todoItemFaker; public Relationships(TestFixture fixture) { - _fixture = fixture; _context = fixture.GetService(); _todoItemFaker = new Faker() .RuleFor(t => t.Description, f => f.Lorem.Sentence()) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs index 1c64f41dab..7efe3f594f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs @@ -13,12 +13,6 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class QueryParameters { - private TestFixture _fixture; - public QueryParameters(TestFixture fixture) - { - _fixture = fixture; - } - [Fact] public async Task Server_Returns_400_ForUnknownQueryParam() { diff --git a/test/UnitTests/Models/ResourceDefinitionTests.cs b/test/UnitTests/Models/ResourceDefinitionTests.cs index 800f79ade0..d7e635b8eb 100644 --- a/test/UnitTests/Models/ResourceDefinitionTests.cs +++ b/test/UnitTests/Models/ResourceDefinitionTests.cs @@ -1,5 +1,4 @@ using JsonApiDotNetCore.Builders; -using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Internal.Query; using JsonApiDotNetCore.Models; using System.Linq; @@ -9,15 +8,6 @@ namespace UnitTests.Models { public class ResourceDefinition_Scenario_Tests { - private readonly IResourceGraph _resourceGraph; - - public ResourceDefinition_Scenario_Tests() - { - _resourceGraph = new ResourceGraphBuilder() - .AddResource("models") - .Build(); - } - [Fact] public void Request_Filter_Uses_Member_Expression() { From 77d93d48f437d1999f32b91cd53f3485a4ca3abf Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:03:55 +0100 Subject: [PATCH 36/73] Fixed: Field can be made readonly --- src/Examples/ReportsExample/Services/ReportService.cs | 2 +- .../Data/DefaultResourceRepository.cs | 2 +- src/JsonApiDotNetCore/Graph/TypeLocator.cs | 2 +- .../Hooks/Execution/DiffableEntityHashSet.cs | 2 +- .../QueryParameterServices/FilterService.cs | 2 +- .../Acceptance/Extensibility/CustomControllerTests.cs | 6 +++--- .../Acceptance/Extensibility/RequestMetaTests.cs | 2 +- .../Acceptance/ManyToManyTests.cs | 2 +- .../ResourceDefinitions/QueryFiltersTests.cs | 6 +++--- .../ResourceDefinitions/ResourceDefinitionTests.cs | 10 +++++----- .../Acceptance/Spec/AttributeFilterTests.cs | 4 ++-- .../Acceptance/Spec/AttributeSortTests.cs | 2 +- .../Acceptance/Spec/DeeplyNestedInclusionTests.cs | 2 +- .../Acceptance/Spec/DeletingDataTests.cs | 2 +- .../Acceptance/Spec/DocumentTests/Meta.cs | 4 ++-- .../Acceptance/Spec/DocumentTests/Relationships.cs | 4 ++-- .../Acceptance/Spec/FetchingDataTests.cs | 6 +++--- .../Acceptance/Spec/FetchingRelationshipsTests.cs | 4 ++-- .../Acceptance/Spec/PagingTests.cs | 2 +- .../Acceptance/Spec/UpdatingDataTests.cs | 6 +++--- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 6 +++--- .../Acceptance/TestFixture.cs | 2 +- .../Acceptance/TodoItemsControllerTests.cs | 8 ++++---- test/NoEntityFrameworkTests/TestFixture.cs | 2 +- .../TestScopedServiceProvider.cs | 2 +- test/UnitTests/TestScopedServiceProvider.cs | 2 +- 26 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Examples/ReportsExample/Services/ReportService.cs b/src/Examples/ReportsExample/Services/ReportService.cs index f2239d2445..f329558648 100644 --- a/src/Examples/ReportsExample/Services/ReportService.cs +++ b/src/Examples/ReportsExample/Services/ReportService.cs @@ -8,7 +8,7 @@ namespace ReportsExample.Services { public class ReportService : IGetAllService { - private ILogger _logger; + private readonly ILogger _logger; public ReportService(ILoggerFactory loggerFactory) { diff --git a/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs b/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs index f03e3e4f24..582cdc197b 100644 --- a/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs +++ b/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs @@ -27,7 +27,7 @@ public class DefaultResourceRepository : IResourceRepository _dbSet; private readonly IResourceGraph _resourceGraph; private readonly IGenericServiceFactory _genericServiceFactory; - private ILogger> _logger; + private readonly ILogger> _logger; public DefaultResourceRepository( ITargetedFields targetedFields, diff --git a/src/JsonApiDotNetCore/Graph/TypeLocator.cs b/src/JsonApiDotNetCore/Graph/TypeLocator.cs index d2a5bf1840..ce1be25c25 100644 --- a/src/JsonApiDotNetCore/Graph/TypeLocator.cs +++ b/src/JsonApiDotNetCore/Graph/TypeLocator.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Graph static class TypeLocator { private static Dictionary _typeCache = new Dictionary(); - private static Dictionary> _identifiableTypeCache = new Dictionary>(); + private static readonly Dictionary> _identifiableTypeCache = new Dictionary>(); /// diff --git a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs index e0de8a11ff..7909d00208 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs @@ -33,7 +33,7 @@ public class DiffableEntityHashSet : EntityHashSet, IDiffa { private readonly HashSet _databaseValues; private readonly bool _databaseValuesLoaded; - private Dictionary> _updatedAttributes; + private readonly Dictionary> _updatedAttributes; public DiffableEntityHashSet(HashSet requestEntities, HashSet databaseEntities, diff --git a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs index 6be77fad8d..e03295ca2c 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Query public class FilterService : QueryParameterService, IFilterService { private readonly List _filters; - private IResourceDefinition _requestResourceDefinition; + private readonly IResourceDefinition _requestResourceDefinition; public FilterService(IResourceDefinitionProvider resourceDefinitionProvider, IResourceGraph resourceGraph, ICurrentRequest currentRequest) : base(resourceGraph, currentRequest) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs index b34f633ba8..a9f0d15da4 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs @@ -17,9 +17,9 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility [Collection("WebHostCollection")] public class CustomControllerTests { - private TestFixture _fixture; - private Faker _todoItemFaker; - private Faker _personFaker; + private readonly TestFixture _fixture; + private readonly Faker _todoItemFaker; + private readonly Faker _personFaker; public CustomControllerTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs index 95416dc54a..57d6840cbf 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility [Collection("WebHostCollection")] public class RequestMetaTests { - private TestFixture _fixture; + private readonly TestFixture _fixture; public RequestMetaTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs index 9c69719560..14533f3927 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs @@ -26,7 +26,7 @@ public class ManyToManyTests private static readonly Faker _tagFaker = new Faker().RuleFor(a => a.Name, f => f.Random.AlphaNumeric(10)); - private TestFixture _fixture; + private readonly TestFixture _fixture; public ManyToManyTests(TestFixture fixture) { _fixture = fixture; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs index 1f4c426b55..e561f5cd0a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs @@ -15,9 +15,9 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance [Collection("WebHostCollection")] public class QueryFiltersTests { - private TestFixture _fixture; - private AppDbContext _context; - private Faker _userFaker; + private readonly TestFixture _fixture; + private readonly AppDbContext _context; + private readonly Faker _userFaker; public QueryFiltersTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index 942f42081a..3b3b01ad84 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -19,11 +19,11 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance [Collection("WebHostCollection")] public class ResourceDefinitionTests { - private TestFixture _fixture; - private AppDbContext _context; - private Faker _userFaker; - private Faker _todoItemFaker; - private Faker _personFaker; + private readonly TestFixture _fixture; + private readonly AppDbContext _context; + private readonly Faker _userFaker; + private readonly Faker _todoItemFaker; + private readonly Faker _personFaker; private static readonly Faker
_articleFaker = new Faker
() .RuleFor(a => a.Name, f => f.Random.AlphaNumeric(10)) .RuleFor(a => a.Author, f => new Author()); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs index a2bd604862..f35898ad1e 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs @@ -18,8 +18,8 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class AttributeFilterTests { - private TestFixture _fixture; - private Faker _todoItemFaker; + private readonly TestFixture _fixture; + private readonly Faker _todoItemFaker; private readonly Faker _personFaker; public AttributeFilterTests(TestFixture fixture) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs index baf90bded5..84e2adcdc2 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class AttributeSortTests { - private TestFixture _fixture; + private readonly TestFixture _fixture; public AttributeSortTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs index 6130e81e45..d513280175 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs @@ -19,7 +19,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class DeeplyNestedInclusionTests { - private TestFixture _fixture; + private readonly TestFixture _fixture; public DeeplyNestedInclusionTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs index 2c227a4185..625882667b 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class DeletingDataTests { - private AppDbContext _context; + private readonly AppDbContext _context; public DeletingDataTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs index 1e27afc730..6a61ab092f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs @@ -17,8 +17,8 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests [Collection("WebHostCollection")] public class Meta { - private TestFixture _fixture; - private AppDbContext _context; + private readonly TestFixture _fixture; + private readonly AppDbContext _context; public Meta(TestFixture fixture) { _fixture = fixture; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs index 1db3a617c0..3df536b3e5 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs @@ -17,8 +17,8 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests [Collection("WebHostCollection")] public class Relationships { - private AppDbContext _context; - private Faker _todoItemFaker; + private readonly AppDbContext _context; + private readonly Faker _todoItemFaker; public Relationships(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs index 9d3a905c45..5973fc2c8a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs @@ -18,9 +18,9 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class FetchingDataTests { - private TestFixture _fixture; - private Faker _todoItemFaker; - private Faker _personFaker; + private readonly TestFixture _fixture; + private readonly Faker _todoItemFaker; + private readonly Faker _personFaker; public FetchingDataTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs index a3ec7d83d0..8812d49383 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs @@ -14,8 +14,8 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class FetchingRelationshipsTests { - private TestFixture _fixture; - private Faker _todoItemFaker; + private readonly TestFixture _fixture; + private readonly Faker _todoItemFaker; public FetchingRelationshipsTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs index e8ec643431..7538831918 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs @@ -15,7 +15,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class PagingTests : TestFixture { - private TestFixture _fixture; + private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; public PagingTests(TestFixture fixture) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs index c858eb3045..de8b6011bc 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs @@ -21,9 +21,9 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class UpdatingDataTests : EndToEndTest { - private AppDbContext _context; - private Faker _todoItemFaker; - private Faker _personFaker; + private readonly AppDbContext _context; + private readonly Faker _todoItemFaker; + private readonly Faker _personFaker; public UpdatingDataTests(TestFixture fixture) : base(fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index 0d4ceb7bfc..f1aec3431c 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -20,10 +20,10 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec [Collection("WebHostCollection")] public class UpdatingRelationshipsTests { - private TestFixture _fixture; + private readonly TestFixture _fixture; private AppDbContext _context; - private Faker _personFaker; - private Faker _todoItemFaker; + private readonly Faker _personFaker; + private readonly Faker _todoItemFaker; public UpdatingRelationshipsTests(TestFixture fixture) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs index 79a19c8c9a..affadfca0a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs @@ -18,7 +18,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance public class TestFixture : IDisposable where TStartup : class { private readonly TestServer _server; - private IServiceProvider _services; + private readonly IServiceProvider _services; public TestFixture() { var builder = new WebHostBuilder() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index e2eb798ef3..7e1b6cbe53 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -22,10 +22,10 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance [Collection("WebHostCollection")] public class TodoItemControllerTests { - private TestFixture _fixture; - private AppDbContext _context; - private Faker _todoItemFaker; - private Faker _personFaker; + private readonly TestFixture _fixture; + private readonly AppDbContext _context; + private readonly Faker _todoItemFaker; + private readonly Faker _personFaker; public TodoItemControllerTests(TestFixture fixture) { diff --git a/test/NoEntityFrameworkTests/TestFixture.cs b/test/NoEntityFrameworkTests/TestFixture.cs index 6a5f294a94..97a1bae837 100644 --- a/test/NoEntityFrameworkTests/TestFixture.cs +++ b/test/NoEntityFrameworkTests/TestFixture.cs @@ -16,7 +16,7 @@ public class TestFixture : IDisposable { public AppDbContext Context { get; private set; } public TestServer Server { get; private set; } - private IServiceProvider _services; + private readonly IServiceProvider _services; public TestFixture() { var builder = new WebHostBuilder().UseStartup(); diff --git a/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs b/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs index 69628ff8f1..1800efe8a5 100644 --- a/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs +++ b/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs @@ -8,7 +8,7 @@ namespace NoEntityFrameworkTests public class TestScopedServiceProvider : IScopedServiceProvider { private readonly IServiceProvider _serviceProvider; - private Mock _httpContextAccessorMock = new Mock(); + private readonly Mock _httpContextAccessorMock = new Mock(); public TestScopedServiceProvider(IServiceProvider serviceProvider) { diff --git a/test/UnitTests/TestScopedServiceProvider.cs b/test/UnitTests/TestScopedServiceProvider.cs index af68e340b9..6e73079bb6 100644 --- a/test/UnitTests/TestScopedServiceProvider.cs +++ b/test/UnitTests/TestScopedServiceProvider.cs @@ -8,7 +8,7 @@ namespace UnitTests public class TestScopedServiceProvider : IScopedServiceProvider { private readonly IServiceProvider _serviceProvider; - private Mock _httpContextAccessorMock = new Mock(); + private readonly Mock _httpContextAccessorMock = new Mock(); public TestScopedServiceProvider(IServiceProvider serviceProvider) { From 56e81b2a72895d34dc829d033520fe07bf5462fc Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:07:40 +0100 Subject: [PATCH 37/73] Fixed: Redundant method override --- .../JsonApiDotNetCoreExample/Resources/PersonResource.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs b/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs index c25d49741f..c1969e9b19 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs @@ -11,11 +11,6 @@ public class PersonResource : LockableResource, IHasMeta { public PersonResource(IResourceGraph resourceGraph) : base(resourceGraph) { } - public override IEnumerable BeforeUpdate(IDiffableEntityHashSet entities, ResourcePipeline pipeline) - { - return base.BeforeUpdate(entities, pipeline); - } - public override IEnumerable BeforeUpdateRelationship(HashSet ids, IRelationshipsDictionary entitiesByRelationship, ResourcePipeline pipeline) { BeforeImplicitUpdateRelationship(entitiesByRelationship, pipeline); From 0685677b5f44df9e26649d11bc922f3a503a7b58 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:09:43 +0100 Subject: [PATCH 38/73] Fixed: Method is never used --- src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs | 7 ------- src/JsonApiDotNetCore/Data/DbContextResolver.cs | 3 --- src/JsonApiDotNetCore/Models/JsonApiExtension.cs | 7 ------- 3 files changed, 17 deletions(-) delete mode 100644 src/JsonApiDotNetCore/Models/JsonApiExtension.cs diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index ad3a291ffd..8f63623eca 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; using JsonApiDotNetCore.Graph; -using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Models.Links; using Newtonsoft.Json; @@ -144,10 +142,5 @@ public class JsonApiOptions : IJsonApiOptions { NullValueHandling = NullValueHandling.Ignore }; - - public void EnableExtension(JsonApiExtension extension) - => EnabledExtensions.Add(extension); - - internal List EnabledExtensions { get; set; } = new List(); } } diff --git a/src/JsonApiDotNetCore/Data/DbContextResolver.cs b/src/JsonApiDotNetCore/Data/DbContextResolver.cs index 3c9e20b9da..39c1cd8c97 100644 --- a/src/JsonApiDotNetCore/Data/DbContextResolver.cs +++ b/src/JsonApiDotNetCore/Data/DbContextResolver.cs @@ -13,8 +13,5 @@ public DbContextResolver(TContext context) } public DbContext GetContext() => _context; - - public DbSet GetDbSet() where TResource : class => null; - } } diff --git a/src/JsonApiDotNetCore/Models/JsonApiExtension.cs b/src/JsonApiDotNetCore/Models/JsonApiExtension.cs deleted file mode 100644 index 7d3b0c87ea..0000000000 --- a/src/JsonApiDotNetCore/Models/JsonApiExtension.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace JsonApiDotNetCore.Models -{ - public enum JsonApiExtension - { - Operations = 0 - } -} From 2124c2c4c2f821b09a97d24e86c81d930f48758e Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:11:44 +0100 Subject: [PATCH 39/73] Fixed: Base interface is redundant --- .../Controllers/HttpMethodRestrictionFilter.cs | 2 +- src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs | 2 +- .../Server/Builders/ResponseResourceObjectBuilder.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs b/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs index ca9a2ff138..58cc56a2d0 100644 --- a/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs +++ b/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs @@ -5,7 +5,7 @@ namespace JsonApiDotNetCore.Controllers { - public abstract class HttpRestrictAttribute : ActionFilterAttribute, IAsyncActionFilter + public abstract class HttpRestrictAttribute : ActionFilterAttribute { protected abstract string[] Methods { get; } diff --git a/src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs b/src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs index ca84b60a47..1e7ac181ab 100644 --- a/src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs +++ b/src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs @@ -33,7 +33,7 @@ namespace JsonApiDotNetCore.Internal /// public class SomeVeryCustomController{SomeResource} : JsonApiMixin { } /// // => /someVeryCustoms/relationship/relatedResource /// - public class DefaultRoutingConvention : IJsonApiRoutingConvention, IControllerResourceMapping + public class DefaultRoutingConvention : IJsonApiRoutingConvention { private readonly string _namespace; private readonly IResourceNameFormatter _formatter; diff --git a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs index 367039f333..5a16ac5c14 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.Serialization.Server { - public class ResponseResourceObjectBuilder : ResourceObjectBuilder, IResourceObjectBuilder + public class ResponseResourceObjectBuilder : ResourceObjectBuilder { private readonly IIncludedResourceObjectBuilder _includedBuilder; private readonly IIncludeService _includeService; From 89df3a8afbafe45e7a79e6c4640d4977e91e35f3 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:21:32 +0100 Subject: [PATCH 40/73] Fixed: Field is never used --- src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs | 1 - src/JsonApiDotNetCore/Graph/TypeLocator.cs | 4 +--- test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs index ae3fef30f6..1c668488ae 100644 --- a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs @@ -47,7 +47,6 @@ public class ServiceDiscoveryFacade : IServiceDiscoveryFacade }; private readonly IServiceCollection _services; private readonly IResourceGraphBuilder _resourceGraphBuilder; - private readonly List _identifiables = new List(); public ServiceDiscoveryFacade(IServiceCollection services, IResourceGraphBuilder resourceGraphBuilder) { diff --git a/src/JsonApiDotNetCore/Graph/TypeLocator.cs b/src/JsonApiDotNetCore/Graph/TypeLocator.cs index ce1be25c25..557a518703 100644 --- a/src/JsonApiDotNetCore/Graph/TypeLocator.cs +++ b/src/JsonApiDotNetCore/Graph/TypeLocator.cs @@ -12,10 +12,8 @@ namespace JsonApiDotNetCore.Graph ///
static class TypeLocator { - private static Dictionary _typeCache = new Dictionary(); private static readonly Dictionary> _identifiableTypeCache = new Dictionary>(); - /// /// Determine whether or not this is a json:api resource by checking if it implements . /// Returns the status and the resultant id type, either `(true, Type)` OR `(false, null)` @@ -30,7 +28,7 @@ public static Type GetIdType(Type resourceType) /// Get all implementations of in the assembly /// public static IEnumerable GetIdentifiableTypes(Assembly assembly) - => (_identifiableTypeCache.TryGetValue(assembly, out var descriptors) == false) + => (_identifiableTypeCache.TryGetValue(assembly, out _) == false) ? FindIdentifiableTypes(assembly) : _identifiableTypeCache[assembly]; diff --git a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs index c4a7ba4644..c7b395f0c2 100644 --- a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs +++ b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs @@ -101,8 +101,6 @@ public class TestModel : Identifiable { } public class TestModelService : DefaultResourceService { - private static IResourceRepository _repo = new Mock>().Object; - public TestModelService( IEnumerable queryParameters, IJsonApiOptions options, From 46bafaa71ca6da48c2fe51f5b34a184bedb48650 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:35:31 +0100 Subject: [PATCH 41/73] Fixed: Local variable is never used --- .../Hooks/Traversal/TraversalHelper.cs | 2 +- .../Middleware/CurrentRequestMiddleware.cs | 8 -------- .../QueryParameterServices/FilterService.cs | 2 +- .../ServiceDiscoveryFacadeTests.cs | 1 - .../Data/EntityRepositoryTests.cs | 12 ++++++------ .../Acceptance/KebabCaseFormatterTests.cs | 1 - .../Acceptance/ManyToManyTests.cs | 2 -- .../ResourceDefinitions/QueryFiltersTests.cs | 1 - .../ResourceDefinitionTests.cs | 13 ------------- .../Acceptance/Spec/AttributeFilterTests.cs | 3 +-- .../Acceptance/Spec/CreatingDataTests.cs | 10 ++++------ .../Acceptance/Spec/SparseFieldSetTests.cs | 4 ---- .../Acceptance/Spec/UpdatingDataTests.cs | 1 - .../Spec/UpdatingRelationshipsTests.cs | 18 +++--------------- test/UnitTests/ResourceHooks/DiscoveryTests.cs | 2 +- .../Delete/BeforeDelete_WithDbValue_Tests.cs | 3 --- .../IdentifiableManyToMany_OnReturnTests.cs | 8 ++++---- .../ManyToMany_OnReturnTests.cs | 8 ++++---- .../Read/BeforeReadTests.cs | 10 +--------- .../IdentifiableManyToMany_AfterReadTests.cs | 8 ++++---- .../Read/ManyToMany_AfterReadTests.cs | 8 ++++---- .../ResourceHookExecutor/ScenarioTests.cs | 6 +++--- .../Update/BeforeUpdate_WithDbValues_Tests.cs | 1 - .../IncludedResourceObjectBuilderTests.cs | 11 ++++------- .../Server/RequestDeserializerTests.cs | 2 +- 25 files changed, 42 insertions(+), 103 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 8b1220aa32..54f6407f2f 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -203,7 +203,7 @@ void RegisterRelationshipProxies(RightType type) foreach (RelationshipAttribute attr in _resourceGraph.GetRelationships(type)) { if (!attr.CanInclude) continue; - if (!_relationshipProxies.TryGetValue(attr, out RelationshipProxy proxies)) + if (!_relationshipProxies.TryGetValue(attr, out _)) { RightType rightType = GetRightTypeFromRelationship(attr); bool isContextRelation = false; diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index 342de71aa8..41852205d6 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -74,7 +74,6 @@ private string GetBaseId() } private string GetRelationshipId() { - var resource = _currentRequest.GetRequestResource(); if (!_currentRequest.IsRelationshipPath) { return null; @@ -82,13 +81,6 @@ private string GetRelationshipId() var components = SplitCurrentPath(); var toReturn = components.ElementAtOrDefault(4); - if (toReturn == null) - { - return null; - } - var relType = _currentRequest.RequestRelationship.RightType; - var relResource = _resourceGraph.GetResourceContext(relType); - var relIdentityType = relResource.IdentityType; return toReturn; } private string[] SplitCurrentPath() diff --git a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs index e03295ca2c..04e28369be 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs @@ -111,7 +111,7 @@ private string GetFilterOperation(string value) var operation = values[0]; // remove prefix from value - if (Enum.TryParse(operation, out FilterOperation op) == false) + if (Enum.TryParse(operation, out FilterOperation _) == false) return string.Empty; return operation; diff --git a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs index c7b395f0c2..30a899d943 100644 --- a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs +++ b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs @@ -29,7 +29,6 @@ public class ServiceDiscoveryFacadeTests public ServiceDiscoveryFacadeTests() { - var contextMock = new Mock(); var dbResolverMock = new Mock(); dbResolverMock.Setup(m => m.GetContext()).Returns(new Mock().Object); TestModelRepository._dbContextResolver = dbResolverMock.Object; diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index 209f91d089..074f57db76 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -42,13 +42,13 @@ public async Task UpdateAsync_AttributesUpdated_ShouldHaveSpecificallyThoseAttri targetedFields.Setup(m => m.Relationships).Returns(new List()); // Act - var updatedItem = await repository.UpdateAsync(todoItemUpdates); + await repository.UpdateAsync(todoItemUpdates); } // Assert - in different context await using var assertContext = GetContext(seed); { - var (repository, targetedFields) = Setup(assertContext); + var (repository, _) = Setup(assertContext); var fetchedTodo = repository.Get(itemId).First(); Assert.NotNull(fetchedTodo); @@ -66,7 +66,7 @@ public async Task Paging_PageNumberIsPositive_ReturnCorrectIdsAtTheFront(int pag { // Arrange await using var context = GetContext(); - var (repository, targetedFields) = Setup(context); + var (repository, _) = Setup(context); context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9)); await context.SaveChangesAsync(); @@ -85,7 +85,7 @@ public async Task Paging_PageSizeNonPositive_DoNothing(int pageSize) { // Arrange await using var context = GetContext(); - var (repository, targetedFields) = Setup(context); + var (repository, _) = Setup(context); var items = TodoItems(2, 3, 1); context.AddRange(items); await context.SaveChangesAsync(); @@ -103,7 +103,7 @@ public async Task Paging_PageNumberDoesNotExist_ReturnEmptyAQueryable() // Arrange var items = TodoItems(2, 3, 1); await using var context = GetContext(); - var (repository, targetedFields) = Setup(context); + var (repository, _) = Setup(context); context.AddRange(items); // Act @@ -118,7 +118,7 @@ public async Task Paging_PageNumberIsZero_PretendsItsOne() { // Arrange await using var context = GetContext(); - var (repository, targetedFields) = Setup(context); + var (repository, _) = Setup(context); context.AddRange(TodoItems(2, 3, 4, 5, 6, 7, 8, 9)); await context.SaveChangesAsync(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs index 25050da4e8..c023ff5676 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs @@ -64,7 +64,6 @@ public async Task KebabCaseFormatter_Create_IsCreated() // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); var responseItem = _deserializer.DeserializeSingle(body).Data; - var x = _dbContext.KebabCasedModels.Where(kcm => kcm.Id.Equals(responseItem.Id)).Single(); Assert.Equal(model.CompoundAttr, responseItem.CompoundAttr); } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs index 14533f3927..883c1073e8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs @@ -281,8 +281,6 @@ public async Task Can_Create_Many_To_Many() context.AuthorDifferentDbContextName.Add(author); await context.SaveChangesAsync(); - var article = _articleFaker.Generate(); - var route = "/api/v1/articles"; var request = new HttpRequestMessage(new HttpMethod("POST"), route); var content = new diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs index e561f5cd0a..25131b9ae8 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs @@ -53,7 +53,6 @@ public async Task FiltersWithCustomQueryFiltersEquals() Assert.Equal(HttpStatusCode.OK, response.StatusCode); var body = await response.Content.ReadAsStringAsync(); var deserializedBody = _fixture.GetDeserializer().DeserializeList(body).Data; - var usersWithFirstCharacter = _context.Users.Where(u => u.Username[0] == firstUsernameCharacter); Assert.True(deserializedBody.All(u => u.Username[0] == firstUsernameCharacter)); } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index 3b3b01ad84..206ab5472b 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -129,7 +129,6 @@ public async Task Can_Update_User_Password() // response assertions var body = await response.Content.ReadAsStringAsync(); - var returnedUser = _fixture.GetDeserializer().DeserializeSingle(body).Data; var document = JsonConvert.DeserializeObject(body); Assert.False(document.SingleData.Attributes.ContainsKey("password")); Assert.Equal(user.Username, document.SingleData.Attributes["username"]); @@ -144,8 +143,6 @@ public async Task Unauthorized_TodoItem() { // Arrange var route = "/api/v1/todoItems/1337"; - var httpMethod = new HttpMethod("GET"); - var request = new HttpRequestMessage(httpMethod, route); // Act var response = await _fixture.Client.GetAsync(route); @@ -160,8 +157,6 @@ public async Task Unauthorized_Passport() { // Arrange var route = "/api/v1/people/1?include=passport"; - var httpMethod = new HttpMethod("GET"); - var request = new HttpRequestMessage(httpMethod, route); // Act var response = await _fixture.Client.GetAsync(route); @@ -210,10 +205,6 @@ public async Task Article_Is_Hidden() var route = "/api/v1/articles"; - var httpMethod = new HttpMethod("GET"); - var request = new HttpRequestMessage(httpMethod, route); - - // Act var response = await _fixture.Client.GetAsync(route); @@ -253,10 +244,6 @@ public async Task Tag_Is_Hidden() var route = "/api/v1/articles?include=tags"; - var httpMethod = new HttpMethod("GET"); - var request = new HttpRequestMessage(httpMethod, route); - - // Act var response = await _fixture.Client.GetAsync(route); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs index f35898ad1e..b5c2a2138a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs @@ -146,7 +146,6 @@ public async Task Can_Filter_On_In_Array_Values() } context.SaveChanges(); - var totalCount = context.TodoItems.Count(); var httpMethod = new HttpMethod("GET"); var route = $"/api/v1/todoItems?filter[guidProperty]=in:{string.Join(",", guids)}"; var request = new HttpRequestMessage(httpMethod, route); @@ -191,7 +190,7 @@ public async Task Can_Filter_On_Related_In_Array_Values() // Act var response = await _fixture.Client.SendAsync(request); var body = await response.Content.ReadAsStringAsync(); - var documents = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + var documents = JsonConvert.DeserializeObject(body); var included = documents.Included; // Assert diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs index 4636b9c475..8faae4fbec 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs @@ -43,7 +43,7 @@ public async Task CreateResource_ModelWithEntityFrameworkInheritance_IsCreated() // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); var createdSuperUser = _deserializer.DeserializeSingle(body).Data; - var created = _dbContext.SuperUsers.First(e => e.Id.Equals(createdSuperUser.Id)); + _dbContext.SuperUsers.First(e => e.Id.Equals(createdSuperUser.Id)); } [Fact] @@ -57,7 +57,7 @@ public async Task CreateResource_GuidResource_IsCreated() var todoItemCollection = new TodoItemCollection { Owner = owner }; // Act - var (body, response) = await Post("/api/v1/todoCollections", serializer.Serialize(todoItemCollection)); + var (_, response) = await Post("/api/v1/todoCollections", serializer.Serialize(todoItemCollection)); // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); @@ -73,7 +73,7 @@ public async Task ClientGeneratedId_IntegerIdAndNotEnabled_IsForbidden() todoItem.Id = clientDefinedId; // Act - var (body, response) = await Post("/api/v1/todoItems", serializer.Serialize(todoItem)); + var (_, response) = await Post("/api/v1/todoItems", serializer.Serialize(todoItem)); // Assert AssertEqualStatusCode(HttpStatusCode.Forbidden, response); @@ -216,12 +216,10 @@ public async Task CreateResource_EntityTypeMismatch_IsConflict() { // Arrange var serializer = GetSerializer(e => new { }, e => new { e.Owner }); - var resourceGraph = new ResourceGraphBuilder().AddResource("todoItems").AddResource().AddResource().Build(); - var _deserializer = new ResponseDeserializer(resourceGraph); var content = serializer.Serialize(_todoItemFaker.Generate()).Replace("todoItems", "people"); // Act - var (body, response) = await Post("/api/v1/todoItems", content); + var (_, response) = await Post("/api/v1/todoItems", content); // Assert AssertEqualStatusCode(HttpStatusCode.Conflict, response); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs index e6d4c9ba38..f5c1538721 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs @@ -51,7 +51,6 @@ public SparseFieldSetTests(TestFixture fixture) public async Task Can_Select_Sparse_Fieldsets() { // Arrange - var fields = new List { "Id", "Description", "CreatedDate", "AchievedDate" }; var todoItem = new TodoItem { Description = "description", @@ -61,9 +60,6 @@ public async Task Can_Select_Sparse_Fieldsets() }; _dbContext.TodoItems.Add(todoItem); await _dbContext.SaveChangesAsync(); - var expectedSql = StringExtensions.Normalize($@"SELECT 't'.'Id', 't'.'Description', 't'.'CreatedDate', 't'.'AchievedDate' - FROM 'TodoItems' AS 't' - WHERE 't'.'Id' = {todoItem.Id}"); // Act var query = _dbContext diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs index de8b6011bc..13ffaf063c 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs @@ -78,7 +78,6 @@ public async Task Response400IfUpdatingNotSettableAttribute() var response = await client.SendAsync(request); // Assert - var body = await response.Content.ReadAsStringAsync(); Assert.Equal(422, Convert.ToInt32(response.StatusCode)); } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index f1aec3431c..12d3054801 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -91,8 +91,7 @@ public async Task Can_Update_Cyclic_ToMany_Relationship_By_Patching_Resource() // Act - var response = await client.SendAsync(request); - var body = await response.Content.ReadAsStringAsync(); + await client.SendAsync(request); _context = _fixture.GetService(); var updatedTodoItem = _context.TodoItems.AsNoTracking() @@ -108,7 +107,6 @@ public async Task Can_Update_Cyclic_ToOne_Relationship_By_Patching_Resource() { // Arrange var todoItem = _todoItemFaker.Generate(); - var strayTodoItem = _todoItemFaker.Generate(); _context.TodoItems.Add(todoItem); _context.SaveChanges(); @@ -147,11 +145,9 @@ public async Task Can_Update_Cyclic_ToOne_Relationship_By_Patching_Resource() // Act - var response = await client.SendAsync(request); - var body = await response.Content.ReadAsStringAsync(); + await client.SendAsync(request); _context = _fixture.GetService(); - var updatedTodoItem = _context.TodoItems.AsNoTracking() .Where(ti => ti.Id == todoItem.Id) .Include(ti => ti.DependentOnTodo).First(); @@ -213,11 +209,9 @@ public async Task Can_Update_Both_Cyclic_ToOne_And_ToMany_Relationship_By_Patchi // Act - var response = await client.SendAsync(request); - var body = await response.Content.ReadAsStringAsync(); + await client.SendAsync(request); _context = _fixture.GetService(); - var updatedTodoItem = _context.TodoItems.AsNoTracking() .Where(ti => ti.Id == todoItem.Id) .Include(ti => ti.ParentTodo).First(); @@ -585,12 +579,6 @@ public async Task Can_Delete_ToMany_Relationship_By_Patching_Resource() _context.People.Add(person); _context.SaveChanges(); - var builder = new WebHostBuilder() - .UseStartup(); - - var server = new TestServer(builder); - var client = server.CreateClient(); - var content = new { data = new diff --git a/test/UnitTests/ResourceHooks/DiscoveryTests.cs b/test/UnitTests/ResourceHooks/DiscoveryTests.cs index 1ff192f691..02e97c45ce 100644 --- a/test/UnitTests/ResourceHooks/DiscoveryTests.cs +++ b/test/UnitTests/ResourceHooks/DiscoveryTests.cs @@ -79,7 +79,7 @@ public void HookDiscovery_WronglyUsedLoadDatabaseValueAttribute_ThrowsJsonApiSet Assert.Throws(() => { // Arrange & act - var hookConfig = new HooksDiscovery(MockProvider(new YetAnotherDummyResourceDefinition())); + new HooksDiscovery(MockProvider(new YetAnotherDummyResourceDefinition())); }); } diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs index 0873aee1c9..5fdf18dcb1 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs @@ -42,7 +42,6 @@ public void BeforeDelete() var passportDiscovery = SetDiscoverableHooks(targetHooks, EnableDbValues); var (_, hookExecutor, personResourceMock, todoResourceMock, passportResourceMock) = CreateTestObjects(personDiscovery, todoDiscovery, passportDiscovery, repoDbContextOptions: options); - var todoList = CreateTodoWithOwner(); // Act hookExecutor.BeforeDelete(new List { person }, ResourcePipeline.Delete); @@ -62,7 +61,6 @@ public void BeforeDelete_No_Parent_Hooks() var passportDiscovery = SetDiscoverableHooks(targetHooks, EnableDbValues); var (_, hookExecutor, personResourceMock, todoResourceMock, passportResourceMock) = CreateTestObjects(personDiscovery, todoDiscovery, passportDiscovery, repoDbContextOptions: options); - var todoList = CreateTodoWithOwner(); // Act hookExecutor.BeforeDelete(new List { person }, ResourcePipeline.Delete); @@ -81,7 +79,6 @@ public void BeforeDelete_No_Children_Hooks() var passportDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, personResourceMock, todoResourceMock, passportResourceMock) = CreateTestObjects(personDiscovery, todoDiscovery, passportDiscovery, repoDbContextOptions: options); - var todoList = CreateTodoWithOwner(); // Act hookExecutor.BeforeDelete(new List { person }, ResourcePipeline.Delete); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs index 562a65598d..9e6fa35790 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs @@ -78,7 +78,7 @@ public void OnReturn_Without_Children_Hooks_Implemented() var tagDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, tags) = CreateIdentifiableManyToManyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -97,7 +97,7 @@ public void OnReturn_Without_Grand_Children_Hooks_Implemented() var joinDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, joins, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -116,7 +116,7 @@ public void OnReturn_Without_Any_Descendant_Hooks_Implemented() var joinDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -134,7 +134,7 @@ public void OnReturn_Without_Any_Hook_Implemented() var joinDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs index 2d32e1dfdd..57ad54dd75 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs @@ -48,7 +48,7 @@ public void OnReturn() var articleDiscovery = SetDiscoverableHooks
(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateDummyData(); + var (articles, _, tags) = CreateDummyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -66,7 +66,7 @@ public void OnReturn_Without_Parent_Hook_Implemented() var articleDiscovery = SetDiscoverableHooks
(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateDummyData(); + var (articles, _, tags) = CreateDummyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -83,7 +83,7 @@ public void OnReturn_Without_Children_Hooks_Implemented() var articleDiscovery = SetDiscoverableHooks
(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateDummyData(); + var (articles, _, _) = CreateDummyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); @@ -101,7 +101,7 @@ public void OnReturn_Without_Any_Hook_Implemented() var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateDummyData(); + var (articles, _, _) = CreateDummyData(); // Act hookExecutor.OnReturn(articles, ResourcePipeline.Get); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs index 3cb8a7dc72..8c915f3d42 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Hooks; using JsonApiDotNetCore.Models; using JsonApiDotNetCoreExample.Models; @@ -16,9 +16,7 @@ public void BeforeRead() { // Arrange var todoDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); - var personDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock) = CreateTestObjects(todoDiscovery); - var todoList = CreateTodoWithOwner(); iqMock.Setup(c => c.Get()).Returns(new List>()); // Act @@ -37,7 +35,6 @@ public void BeforeReadWithInclusion() var personDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (iqMock, _, hookExecutor, todoResourceMock, ownerResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner", "assignee", "stakeHolders")); @@ -59,7 +56,6 @@ public void BeforeReadWithNestedInclusion() var passportDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock, ownerResourceMock, passportResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery, passportDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner.passport,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner.passport", "assignee", "stakeHolders")); @@ -83,7 +79,6 @@ public void BeforeReadWithNestedInclusion_No_Parent_Hook_Implemented() var passportDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock, ownerResourceMock, passportResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery, passportDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner.passport,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner.passport", "assignee", "stakeHolders")); @@ -105,7 +100,6 @@ public void BeforeReadWithNestedInclusion_No_Child_Hook_Implemented() var passportDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock, ownerResourceMock, passportResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery, passportDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner.passport,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner.passport", "assignee", "stakeHolders")); @@ -127,7 +121,6 @@ public void BeforeReadWithNestedInclusion_No_Grandchild_Hook_Implemented() var passportDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock, ownerResourceMock, passportResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery, passportDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner.passport,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner.passport", "assignee", "stakeHolders")); @@ -150,7 +143,6 @@ public void BeforeReadWithNestedInclusion_Without_Any_Hook_Implemented() var passportDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (iqMock, hookExecutor, todoResourceMock, ownerResourceMock, passportResourceMock) = CreateTestObjects(todoDiscovery, personDiscovery, passportDiscovery); - var todoList = CreateTodoWithOwner(); // eg a call on api/todoItems?include=owner.passport,assignee,stakeHolders iqMock.Setup(c => c.Get()).Returns(GetIncludedRelationshipsChains("owner.passport", "assignee", "stakeHolders")); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs index 1f7f5f678f..f002136ac9 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs @@ -60,7 +60,7 @@ public void AfterRead_Without_Children_Hooks_Implemented() var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, tags) = CreateIdentifiableManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -79,7 +79,7 @@ public void AfterRead_Without_Grand_Children_Hooks_Implemented() var joinDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, joins, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -98,7 +98,7 @@ public void AfterRead_Without_Any_Descendant_Hooks_Implemented() var joinDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -116,7 +116,7 @@ public void AfterRead_Without_Any_Hook_Implemented() var joinDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, hookExecutor, articleResourceMock, joinResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, joinDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateIdentifiableManyToManyData(); + var (articles, _, _) = CreateIdentifiableManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs index c3860c935e..b94f80655e 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs @@ -18,7 +18,7 @@ public void AfterRead() var articleDiscovery = SetDiscoverableHooks
(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateManyToManyData(); + var (articles, _, tags) = CreateManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -36,7 +36,7 @@ public void AfterRead_Without_Parent_Hook_Implemented() var articleDiscovery = SetDiscoverableHooks
(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateManyToManyData(); + var (articles, _, tags) = CreateManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -53,7 +53,7 @@ public void AfterRead_Without_Children_Hooks_Implemented() var articleDiscovery = SetDiscoverableHooks
(targetHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateManyToManyData(); + var (articles, _, _) = CreateManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); @@ -70,7 +70,7 @@ public void AfterRead_Without_Any_Hook_Implemented() var articleDiscovery = SetDiscoverableHooks
(NoHooks, DisableDbValues); var tagDiscovery = SetDiscoverableHooks(NoHooks, DisableDbValues); var (_, _, hookExecutor, articleResourceMock, tagResourceMock) = CreateTestObjects(articleDiscovery, tagDiscovery); - var (articles, joins, tags) = CreateManyToManyData(); + var (articles, _, _) = CreateManyToManyData(); // Act hookExecutor.AfterRead(articles, ResourcePipeline.Get); diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs index 10a5c1fbb9..f2cb44ddd8 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using System.Collections.Generic; @@ -39,7 +39,7 @@ public void Entity_Has_Cyclic_Relations() { // Arrange var todoDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); - (var contextMock, var hookExecutor, var todoResourceMock) = CreateTestObjects(todoDiscovery); + var (_, hookExecutor, todoResourceMock) = CreateTestObjects(todoDiscovery); var todo = new TodoItem(); todo.ParentTodo = todo; todo.ChildrenTodos = new List { todo }; @@ -58,7 +58,7 @@ public void Entity_Has_Nested_Cyclic_Relations() { // Arrange var todoDiscovery = SetDiscoverableHooks(targetHooks, DisableDbValues); - (var contextMock, var hookExecutor, var todoResourceMock) = CreateTestObjects(todoDiscovery); + var (_, hookExecutor, todoResourceMock) = CreateTestObjects(todoDiscovery); var rootTodo = new TodoItem { Id = 1 }; var child = new TodoItem { ParentTodo = rootTodo, Id = 2 }; rootTodo.ChildrenTodos = new List { child }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs index 39271372cb..4542107549 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs @@ -204,7 +204,6 @@ private bool TodoCheckDiff(IDiffableEntityHashSet entities, string che var diffPair = entities.GetDiffs().Single(); var dbCheck = diffPair.DatabaseValue.Description == checksum; var reqCheck = diffPair.Entity.Description == null; - var diffPairCheck = (dbCheck && reqCheck); var updatedRelationship = entities.GetByRelationship().Single(); var diffCheck = updatedRelationship.Key.PublicRelationshipName == "oneToOnePerson"; diff --git a/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs index f2e5e65929..019a083eac 100644 --- a/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs @@ -15,7 +15,7 @@ public class IncludedResourceObjectBuilderTests : SerializerTestsSetup public void BuildIncluded_DeeplyNestedCircularChainOfSingleData_CanBuild() { // Arrange - var (article, author, authorFood, reviewer, reviewerFood) = GetAuthorChainInstances(); + var (article, author, _, reviewer, _) = GetAuthorChainInstances(); var authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood"); var builder = GetBuilder(); @@ -59,10 +59,10 @@ public void BuildIncluded_OverlappingDeeplyNestedCircularChains_CanBuild() { // Arrange var authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood"); - var (article, author, authorFood, reviewer, reviewerFood) = GetAuthorChainInstances(); + var (article, author, _, reviewer, reviewerFood) = GetAuthorChainInstances(); var sharedBlog = author.Blogs.First(); var sharedBlogAuthor = reviewer; - var (_reviewer, _reviewerSong, _author, _authorSong) = GetReviewerChainInstances(article, sharedBlog, sharedBlogAuthor); + var (_, _, _, authorSong) = GetReviewerChainInstances(article, sharedBlog, sharedBlogAuthor); var reviewerChain = GetIncludedRelationshipsChain("reviewer.blogs.author.favoriteSong"); var builder = GetBuilder(); @@ -81,10 +81,7 @@ public void BuildIncluded_OverlappingDeeplyNestedCircularChains_CanBuild() foreach (var blog in nonOverlappingBlogs) Assert.Single(blog.Relationships.Keys.ToList()); - var sharedAuthorResourceObject = result.Single((ro) => ro.Type == "people" && ro.Id == sharedBlogAuthor.StringId); - var sharedAuthorSongRelation = sharedAuthorResourceObject.Relationships["favoriteSong"].SingleData; - Assert.Equal(_authorSong.StringId, sharedBlogAuthor.FavoriteSong.StringId); - var sharedAuthorFoodRelation = sharedAuthorResourceObject.Relationships["favoriteFood"].SingleData; + Assert.Equal(authorSong.StringId, sharedBlogAuthor.FavoriteSong.StringId); Assert.Equal(reviewerFood.StringId, sharedBlogAuthor.FavoriteFood.StringId); } diff --git a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs index 226b600594..81c2aa50ff 100644 --- a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs +++ b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs @@ -39,7 +39,7 @@ public void DeserializeAttributes_VariousUpdatedMembers_RegistersTargetedFields( public void DeserializeAttributes_UpdatedImmutableMember_ThrowsInvalidOperationException() { // Arrange - SetupFieldsManager(out List attributesToUpdate, out List relationshipsToUpdate); + SetupFieldsManager(out _, out _); var content = new Document { Data = new ResourceObject From 0127ee4047949c4801663bbbc01bf90940fe3a15 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:38:43 +0100 Subject: [PATCH 42/73] Fixed: Method return value is never used --- .../Hooks/Execution/DiffableEntityHashSet.cs | 2 +- .../Serialization/Common/BaseDocumentParser.cs | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs index 7909d00208..7ba800da56 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs @@ -88,7 +88,7 @@ public IEnumerable> GetDiffs() return new HashSet(); } - private HashSet ThrowNoDbValuesError() + private void ThrowNoDbValuesError() { throw new MemberAccessException($"Cannot iterate over the diffs if the ${nameof(LoadDatabaseValues)} option is set to false"); } diff --git a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs index e96c72957c..2ab3e47655 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs @@ -159,8 +159,7 @@ private IIdentifiable ParseResourceObject(ResourceObject data) /// /// /// - /// - private object SetHasOneRelationship(IIdentifiable entity, + private void SetHasOneRelationship(IIdentifiable entity, PropertyInfo[] entityProperties, HasOneAttribute attr, RelationshipEntry relationshipData) @@ -181,8 +180,6 @@ private object SetHasOneRelationship(IIdentifiable entity, // depending on if this base parser is used client-side or server-side, // different additional processing per field needs to be executed. AfterProcessField(entity, attr, relationshipData); - - return entity; } /// @@ -224,9 +221,10 @@ private void SetNavigation(IIdentifiable entity, HasOneAttribute attr, string re /// /// Sets a HasMany relationship. /// - private object SetHasManyRelationship(IIdentifiable entity, - HasManyAttribute attr, - RelationshipEntry relationshipData) + private void SetHasManyRelationship( + IIdentifiable entity, + HasManyAttribute attr, + RelationshipEntry relationshipData) { if (relationshipData.Data != null) { // if the relationship is set to null, no need to set the navigation property to null: this is the default value. @@ -241,8 +239,6 @@ private object SetHasManyRelationship(IIdentifiable entity, } AfterProcessField(entity, attr, relationshipData); - - return entity; } private object ConvertAttrValue(object newValue, Type targetType) From 705882e3e5b8d2fabc441e4e527dd7134b1d1881 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:47:07 +0100 Subject: [PATCH 43/73] Fixed: Constructor is never used --- test/UnitTests/DbSetMock.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/UnitTests/DbSetMock.cs b/test/UnitTests/DbSetMock.cs index f6ad7a2915..4d8afc5cff 100644 --- a/test/UnitTests/DbSetMock.cs +++ b/test/UnitTests/DbSetMock.cs @@ -85,10 +85,6 @@ TResult IAsyncQueryProvider.ExecuteAsync(Expression expression, Cancell internal class TestAsyncEnumerable : EnumerableQuery, IAsyncEnumerable, IQueryable { - public TestAsyncEnumerable(IEnumerable enumerable) - : base(enumerable) - { } - public TestAsyncEnumerable(Expression expression) : base(expression) { } From 8b1d50ad75214657ad919ed14a0976fee4f17ec6 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:50:49 +0100 Subject: [PATCH 44/73] Fixed: shared instance is never used --- src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs | 2 +- src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index 5fe21b7aa3..29b30ff4fc 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Hooks /// internal class HookExecutorHelper : IHookExecutorHelper { - private readonly IdentifiableComparer _comparer = new IdentifiableComparer(); + private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly IJsonApiOptions _options; protected readonly IGenericServiceFactory _genericProcessorFactory; protected readonly Dictionary _hookContainers; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index c5086ec6a7..aef838373c 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Hooks /// internal class ChildNode : INode where TResource : class, IIdentifiable { - private readonly IdentifiableComparer _comparer = new IdentifiableComparer(); + private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; /// public RightType ResourceType { get; private set; } /// diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs index 83f485f5a1..f97a9ee1e7 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Hooks /// internal class RootNode : INode where TResource : class, IIdentifiable { - private readonly IdentifiableComparer _comparer = new IdentifiableComparer(); + private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly RelationshipProxy[] _allRelationshipsToNextLayer; private HashSet _uniqueEntities; public Type ResourceType { get; internal set; } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 54f6407f2f..ff6f5535d7 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -23,7 +23,7 @@ namespace JsonApiDotNetCore.Hooks ///
internal class TraversalHelper : ITraversalHelper { - private readonly IdentifiableComparer _comparer = new IdentifiableComparer(); + private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly IResourceGraph _resourceGraph; private readonly ITargetedFields _targetedFields; /// diff --git a/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs b/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs index 60793829b8..2837cbd8ac 100644 --- a/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs +++ b/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs @@ -9,6 +9,7 @@ namespace JsonApiDotNetCore.Internal public class IdentifiableComparer : IEqualityComparer { internal static readonly IdentifiableComparer Instance = new IdentifiableComparer(); + public bool Equals(IIdentifiable x, IIdentifiable y) { return x.StringId == y.StringId; From ddc43d656ab4b5002fdc7ec89d4884bfc279f4e6 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:52:46 +0100 Subject: [PATCH 45/73] Fixed: Parameter is never used --- .../Middleware/CurrentRequestMiddleware.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index 41852205d6..cd8ecd009f 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -98,9 +98,9 @@ private string GetBasePath(string resourceName = null) var r = _httpContext.Request; if (_options.RelativeLinks) { - return GetNameSpace(resourceName); + return GetNameSpace(); } - var ns = GetNameSpace(resourceName); + var ns = GetNameSpace(); var customRoute = GetCustomRoute(r.Path.Value, resourceName); var toReturn = $"{r.Scheme}://{r.Host}/{ns}"; if (customRoute != null) @@ -127,9 +127,8 @@ private object GetCustomRoute(string path, string resourceName) } } - private string GetNameSpace(string resourceName = null) + private string GetNameSpace() { - return _options.Namespace; } From e654fb1c0c1b43b63354b8694fc74405df162c90 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:54:00 +0100 Subject: [PATCH 46/73] Fixed: Method is never used --- .../Models/Annotation/HasOneAttribute.cs | 18 ------------------ .../Acceptance/Spec/SparseFieldSetTests.cs | 2 -- .../Helpers/Extensions/StringExtensions.cs | 15 --------------- .../Create/BeforeCreate_WithDbValues_Tests.cs | 8 -------- .../Serialization/SerializerTestsSetup.cs | 14 -------------- 5 files changed, 57 deletions(-) delete mode 100644 test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs index e3423c6cf9..da77c4730d 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs @@ -73,23 +73,5 @@ public override void SetValue(object entity, object newValue) } propertyInfo.SetValue(entity, newValue); } - - // HACK: this will likely require boxing - // we should be able to move some of the reflection into the ResourceGraphBuilder - /// - /// Gets the value of the independent identifier (e.g. Article.AuthorId) - /// - /// - /// - /// An instance of dependent resource - /// - /// - /// - /// The property value or null if the property does not exist on the model. - /// - internal object GetIdentifiablePropertyValue(object resource) => resource - .GetType() - .GetProperty(IdentifiablePropertyName) - ?.GetValue(resource); } } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs index f5c1538721..9c385a479a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -14,7 +13,6 @@ using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Xunit; -using StringExtensions = JsonApiDotNetCoreExampleTests.Helpers.Extensions.StringExtensions; using Person = JsonApiDotNetCoreExample.Models.Person; using System.Net; using JsonApiDotNetCore.Serialization.Client; diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs deleted file mode 100644 index dbe6b19feb..0000000000 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.RegularExpressions; - -namespace JsonApiDotNetCoreExampleTests.Helpers.Extensions -{ - public static class StringExtensions - { - public static string Normalize(this string input) - { - return Regex.Replace(input, @"\s+", string.Empty) - .ToUpper() - .Replace("\"", string.Empty) - .Replace("'", string.Empty); - } - } -} diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs index 31246bb210..e52067291d 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs @@ -177,13 +177,5 @@ private bool PersonIdCheck(IEnumerable ids, string checksum) { return ids.Single() == checksum; } - - private bool PersonCheck(string checksum, IRelationshipsDictionary helper) - { - - var entries = helper.GetByRelationship(); - return entries.Single().Value.Single().LastName == checksum; - } } } - diff --git a/test/UnitTests/Serialization/SerializerTestsSetup.cs b/test/UnitTests/Serialization/SerializerTestsSetup.cs index 2d4bd96c22..21930e2212 100644 --- a/test/UnitTests/Serialization/SerializerTestsSetup.cs +++ b/test/UnitTests/Serialization/SerializerTestsSetup.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using JsonApiDotNetCore.Managers.Contracts; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Models.Links; using JsonApiDotNetCore.Query; @@ -76,13 +75,6 @@ protected IMetaBuilder GetMetaBuilder(Dictionary meta = nu return mock.Object; } - protected ICurrentRequest GetRequestManager() where T : class, IIdentifiable - { - var mock = new Mock(); - mock.Setup(m => m.GetRequestResource()).Returns(_resourceGraph.GetResourceContext()); - return mock.Object; - } - protected ILinkBuilder GetLinkBuilder(TopLevelLinks top = null, ResourceLinks resource = null, RelationshipLinks relationship = null) { var mock = new Mock(); @@ -92,12 +84,6 @@ protected ILinkBuilder GetLinkBuilder(TopLevelLinks top = null, ResourceLinks re return mock.Object; } - protected ISparseFieldsService GetFieldsQuery() - { - var mock = new Mock(); - return mock.Object; - } - protected IFieldsToSerialize GetSerializableFields() { var mock = new Mock(); From a2fe29c204aa98c1d330ad291261ac5e8d8d0934 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 11:55:16 +0100 Subject: [PATCH 47/73] Fixed: Initializing field/property by default value is redundant --- .../Models/JsonApiDocuments/ExposableData.cs | 6 +++--- .../JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs index db4b634bd5..738fd04da4 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -44,14 +44,14 @@ public bool ShouldSerializeData() /// Internally used to indicate if the document's primary data is /// "single" or "many". /// - internal bool IsManyData { get; private set; } = false; + internal bool IsManyData { get; private set; } /// /// Internally used to indicate if the document's primary data is /// should still be serialized when it's value is null. This is used when /// a single resource is requested but not present (eg /articles/1/author). /// - internal bool IsPopulated { get; private set; } = false; + internal bool IsPopulated { get; private set; } internal bool HasResource { get { return IsPopulated && ((IsManyData && ManyData.Any()) || SingleData != null); } } diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs index affadfca0a..7bb99db640 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs @@ -68,7 +68,7 @@ public void ReloadDbContext() Context = new AppDbContext(GetService>()); } - private bool disposedValue = false; + private bool disposedValue; protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -88,4 +88,4 @@ public void Dispose() Dispose(true); } } -} \ No newline at end of file +} From d1a620393cc1c6ba877c56ecee8289e1c4ef6286 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:04:03 +0100 Subject: [PATCH 48/73] Fixed: Redundant base constructor call --- test/UnitTests/Serialization/Server/RequestDeserializerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs index 81c2aa50ff..2aad229907 100644 --- a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs +++ b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs @@ -14,7 +14,7 @@ public class RequestDeserializerTests : DeserializerTestsSetup { private readonly RequestDeserializer _deserializer; private readonly Mock _fieldsManagerMock = new Mock(); - public RequestDeserializerTests() : base() + public RequestDeserializerTests() { _deserializer = new RequestDeserializer(_resourceGraph, _fieldsManagerMock.Object); } From 631871e9ed8e525d817ef199e8645865c2ff33c3 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:07:36 +0100 Subject: [PATCH 49/73] Fixed: parameter hides outer local variable with the same name --- src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs | 2 +- test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs index cc5341026a..ca2bbb3268 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs @@ -30,7 +30,7 @@ public virtual void ConfigureServices(IServiceCollection services) { options .EnableSensitiveDataLogging() - .UseNpgsql(GetDbConnectionString(), options => options.SetPostgresVersion(new Version(9,6))); + .UseNpgsql(GetDbConnectionString(), innerOptions => innerOptions.SetPostgresVersion(new Version(9,6))); }, ServiceLifetime.Transient) .AddJsonApi(options => { diff --git a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs index 06908a2fd9..6f9ce979ec 100644 --- a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs +++ b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs @@ -116,7 +116,7 @@ private InvokeConfiguration GetConfiguration(string path, string resourceName = { throw new ArgumentException("Path should start with a '/'"); } - var middleware = new CurrentRequestMiddleware((context) => + var middleware = new CurrentRequestMiddleware(httpContext => { return Task.Run(() => Console.WriteLine("finished")); }); From 9d1fd2e0137e735eb7e2d9f446eb50c42a9b9f58 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:11:31 +0100 Subject: [PATCH 50/73] Fixed: Cannot resolve symbol 'dynamic' --- .../Serialization/Client/IRequestSerializer.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/JsonApiDotNetCore/Serialization/Client/IRequestSerializer.cs b/src/JsonApiDotNetCore/Serialization/Client/IRequestSerializer.cs index 39dbc5f805..f90e7c041a 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/IRequestSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/IRequestSerializer.cs @@ -1,6 +1,5 @@ using System.Collections; using System.Collections.Generic; -using System.Linq.Expressions; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Internal.Contracts; @@ -26,13 +25,13 @@ public interface IRequestSerializer string Serialize(IEnumerable entities); /// /// Sets the attributes that will be included in the serialized payload. - /// You can use + /// You can use /// to conveniently access the desired instances /// public IEnumerable AttributesToSerialize { set; } /// /// Sets the relationships that will be included in the serialized payload. - /// You can use + /// You can use /// to conveniently access the desired instances /// public IEnumerable RelationshipsToSerialize { set; } From 428a182b8515eec3564047988bd9d8309e23ce51 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:14:35 +0100 Subject: [PATCH 51/73] Fixed: Possible unintended reference comparison --- .../Server/Builders/ResponseResourceObjectBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs index 5a16ac5c14..7f0b25d09f 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Builders/ResponseResourceObjectBuilder.cs @@ -43,7 +43,7 @@ protected override RelationshipEntry GetRelationshipData(RelationshipAttribute r { RelationshipEntry relationshipEntry = null; List> relationshipChains = null; - if (relationship == _requestRelationship || ShouldInclude(relationship, out relationshipChains )) + if (Equals(relationship, _requestRelationship) || ShouldInclude(relationship, out relationshipChains )) { relationshipEntry = base.GetRelationshipData(relationship, entity); if (relationshipChains != null && relationshipEntry.HasResource) From 2c0321a91b28fb7292c774cce6516c94491a7221 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:16:57 +0100 Subject: [PATCH 52/73] Fixed: Co-variant array conversion can cause run-time exception on write operation --- test/IntegrationTests/Data/EntityRepositoryTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index 074f57db76..da97640992 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -67,7 +67,7 @@ public async Task Paging_PageNumberIsPositive_ReturnCorrectIdsAtTheFront(int pag // Arrange await using var context = GetContext(); var (repository, _) = Setup(context); - context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9)); + context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9).Cast()); await context.SaveChangesAsync(); // Act @@ -87,7 +87,7 @@ public async Task Paging_PageSizeNonPositive_DoNothing(int pageSize) await using var context = GetContext(); var (repository, _) = Setup(context); var items = TodoItems(2, 3, 1); - context.AddRange(items); + context.AddRange(items.Cast()); await context.SaveChangesAsync(); // Act @@ -104,7 +104,7 @@ public async Task Paging_PageNumberDoesNotExist_ReturnEmptyAQueryable() var items = TodoItems(2, 3, 1); await using var context = GetContext(); var (repository, _) = Setup(context); - context.AddRange(items); + context.AddRange(items.Cast()); // Act var result = await repository.PageAsync(context.Set(), 2, 3); @@ -119,7 +119,7 @@ public async Task Paging_PageNumberIsZero_PretendsItsOne() // Arrange await using var context = GetContext(); var (repository, _) = Setup(context); - context.AddRange(TodoItems(2, 3, 4, 5, 6, 7, 8, 9)); + context.AddRange(TodoItems(2, 3, 4, 5, 6, 7, 8, 9).Cast()); await context.SaveChangesAsync(); // Act @@ -138,7 +138,7 @@ public async Task Paging_PageNumberIsNegative_GiveBackReverseAmountOfIds(int pag // Arrange await using var context = GetContext(); var repository = Setup(context).Repository; - context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9)); + context.AddRange(TodoItems(1, 2, 3, 4, 5, 6, 7, 8, 9).Cast()); context.SaveChanges(); // Act From 87fb6ffab709c6888b3b62a39e5e7ba148cd0adb Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:20:42 +0100 Subject: [PATCH 53/73] Fixed: Return value of pure method is not used --- .../Acceptance/Spec/CreatingDataTests.cs | 3 ++- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs index 8faae4fbec..39c1235206 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs @@ -43,7 +43,8 @@ public async Task CreateResource_ModelWithEntityFrameworkInheritance_IsCreated() // Assert AssertEqualStatusCode(HttpStatusCode.Created, response); var createdSuperUser = _deserializer.DeserializeSingle(body).Data; - _dbContext.SuperUsers.First(e => e.Id.Equals(createdSuperUser.Id)); + var first = _dbContext.SuperUsers.FirstOrDefault(e => e.Id.Equals(createdSuperUser.Id)); + Assert.NotNull(first); } [Fact] diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index 12d3054801..0bc7ace7de 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -98,8 +98,7 @@ public async Task Can_Update_Cyclic_ToMany_Relationship_By_Patching_Resource() .Where(ti => ti.Id == todoItem.Id) .Include(ti => ti.ChildrenTodos).First(); - updatedTodoItem.ChildrenTodos.Any((ti) => ti.Id == todoItem.Id); - Assert.Contains(updatedTodoItem.ChildrenTodos, (ti) => ti.Id == todoItem.Id); + Assert.Contains(updatedTodoItem.ChildrenTodos, ti => ti.Id == todoItem.Id); } [Fact] From 17134f86b88813b2b795060af675c2cb962bfe72 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:35:29 +0100 Subject: [PATCH 54/73] Fixed: Auto-property can be made get-only --- src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs | 6 +++--- .../Hooks/Execution/DiffableEntityHashSet.cs | 4 ++-- src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs | 4 ++-- .../Models/Annotation/HasManyThroughAttribute.cs | 2 +- src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs | 6 +++--- test/NoEntityFrameworkTests/TestFixture.cs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs index a0e7d9120c..9cc8f4b41f 100644 --- a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs @@ -16,9 +16,9 @@ namespace JsonApiDotNetCore.Builders { public class ResourceGraphBuilder : IResourceGraphBuilder { - private List _resources { get; set; } = new List(); - private List _validationResults { get; set; } = new List(); - private IResourceNameFormatter _formatter { get; set; } = new CamelCaseFormatter(); + private List _resources { get; } = new List(); + private List _validationResults { get; } = new List(); + private IResourceNameFormatter _formatter { get; } = new CamelCaseFormatter(); public ResourceGraphBuilder() { } diff --git a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs index 7ba800da56..35e0833db3 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs @@ -109,10 +109,10 @@ public EntityDiffPair(TResource entity, TResource databaseValue) /// /// The resource from the request matching the resource from the database. /// - public TResource Entity { get; private set; } + public TResource Entity { get; } /// /// The resource from the database matching the resource from the request. /// - public TResource DatabaseValue { get; private set; } + public TResource DatabaseValue { get; } } } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index aef838373c..228e6c7e99 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -16,7 +16,7 @@ internal class ChildNode : INode where TResource : class, IIdentifiab { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; /// - public RightType ResourceType { get; private set; } + public RightType ResourceType { get; } /// public RelationshipProxy[] RelationshipsToNextLayer { get; set; } /// diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs index 14423e6007..835f8c555d 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs @@ -28,9 +28,9 @@ public class RelationshipProxy /// For HasManyThrough it is either the ThroughProperty (when the join table is /// Identifiable) or it is the right-hand side (when the join table is not identifiable) /// - public Type RightType { get; private set; } + public Type RightType { get; } public Type LeftType { get { return Attribute.LeftType; } } - public bool IsContextRelation { get; private set; } + public bool IsContextRelation { get; } public RelationshipAttribute Attribute { get; set; } public RelationshipProxy(RelationshipAttribute attr, Type relatedType, bool isContextRelation) diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs index f33276cb35..f906ba59de 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs @@ -132,7 +132,7 @@ public override void SetValue(object entity, object newValue) /// In the `[HasManyThrough("tags", nameof(ArticleTags))]` example /// this would be "ArticleTags". /// - public string InternalThroughName { get; private set; } + public string InternalThroughName { get; } /// /// The join type. diff --git a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs index 96907a880a..2281e14a73 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs @@ -26,18 +26,18 @@ public LinksAttribute(Link topLevelLinks = Link.NotConfigured, Link resourceLink /// Configures which links to show in the /// object for this resource. /// - public Link TopLevelLinks { get; private set; } + public Link TopLevelLinks { get; } /// /// Configures which links to show in the /// object for this resource. /// - public Link ResourceLinks { get; private set; } + public Link ResourceLinks { get; } /// /// Configures which links to show in the /// for all relationships of the resource for which this attribute was instantiated. /// - public Link RelationshipLinks { get; private set; } + public Link RelationshipLinks { get; } } } diff --git a/test/NoEntityFrameworkTests/TestFixture.cs b/test/NoEntityFrameworkTests/TestFixture.cs index 97a1bae837..5196a1d7a8 100644 --- a/test/NoEntityFrameworkTests/TestFixture.cs +++ b/test/NoEntityFrameworkTests/TestFixture.cs @@ -14,8 +14,8 @@ namespace NoEntityFrameworkTests { public class TestFixture : IDisposable { - public AppDbContext Context { get; private set; } - public TestServer Server { get; private set; } + public AppDbContext Context { get; } + public TestServer Server { get; } private readonly IServiceProvider _services; public TestFixture() { From dbf8cbf5d949b705674efb84f840b5c2e52f2ee3 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:37:48 +0100 Subject: [PATCH 55/73] Fixed: Inconsistent body style: use expression-bodied property --- .../JsonApiDotNetCoreExample/Models/TodoItem.cs | 2 +- .../Services/TodoItemService.cs | 8 +------- .../Hooks/Execution/EntityHashSet.cs | 7 ++++--- src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs | 8 +------- .../Hooks/Traversal/RelationshipProxy.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs | 4 ++-- .../Models/JsonApiDocuments/ExposableData.cs | 8 ++++++-- .../Common/QueryParameterService.cs | 2 +- .../QueryParameterServices/PageService.cs | 2 +- test/UnitTests/DbSetMock.cs | 13 ++----------- 10 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs index 815bc52675..e152dbb6fd 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs @@ -32,7 +32,7 @@ public TodoItem() public DateTime? UpdatedDate { get; set; } [Attr(isImmutable: true)] - public string CalculatedValue { get => "calculated"; } + public string CalculatedValue => "calculated"; [Attr] public DateTimeOffset? OffsetDate { get; set; } diff --git a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs index 5f8a21e350..57d9aa1aca 100644 --- a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs +++ b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs @@ -20,13 +20,7 @@ public TodoItemService(IConfiguration config) _connectionString = config.GetValue("Data:DefaultConnection"); } - private IDbConnection Connection - { - get - { - return new NpgsqlConnection(_connectionString); - } - } + private IDbConnection Connection => new NpgsqlConnection(_connectionString); private async Task> QueryAsync(Func>> query) { diff --git a/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs index 93ee588a7a..efe2763455 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Models; using System.Collections; using JsonApiDotNetCore.Internal; @@ -26,7 +26,8 @@ public interface IEntityHashSet : IByAffectedRelationships public class EntityHashSet : HashSet, IEntityHashSet where TResource : class, IIdentifiable { /// - public Dictionary> AffectedRelationships { get => _relationships; } + public Dictionary> AffectedRelationships => _relationships; + private readonly RelationshipsDictionary _relationships; public EntityHashSet(HashSet entities, @@ -61,4 +62,4 @@ public HashSet GetAffected(Expression> Naviga return _relationships.GetAffected(NavigationAction); } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index 228e6c7e99..c4d8d57437 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -29,13 +29,7 @@ public IEnumerable UniqueEntities } /// - public IRelationshipsFromPreviousLayer RelationshipsFromPreviousLayer - { - get - { - return _relationshipsFromPreviousLayer; - } - } + public IRelationshipsFromPreviousLayer RelationshipsFromPreviousLayer => _relationshipsFromPreviousLayer; private readonly RelationshipsFromPreviousLayer _relationshipsFromPreviousLayer; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs index 835f8c555d..0b8094e557 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs @@ -29,7 +29,7 @@ public class RelationshipProxy /// Identifiable) or it is the right-hand side (when the join table is not identifiable) /// public Type RightType { get; } - public Type LeftType { get { return Attribute.LeftType; } } + public Type LeftType => Attribute.LeftType; public bool IsContextRelation { get; } public RelationshipAttribute Attribute { get; set; } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs index f97a9ee1e7..2b21e7e995 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs @@ -17,7 +17,7 @@ internal class RootNode : INode where TResource : class, IIdentifiabl private readonly RelationshipProxy[] _allRelationshipsToNextLayer; private HashSet _uniqueEntities; public Type ResourceType { get; internal set; } - public IEnumerable UniqueEntities { get { return _uniqueEntities; } } + public IEnumerable UniqueEntities => _uniqueEntities; public RelationshipProxy[] RelationshipsToNextLayer { get; } public Dictionary> LeftsToNextLayerByRelationships() @@ -38,7 +38,7 @@ public Dictionary LeftsToNextLayer() /// /// The root node does not have a parent layer and therefore does not have any relationships to any previous layer /// - public IRelationshipsFromPreviousLayer RelationshipsFromPreviousLayer { get { return null; } } + public IRelationshipsFromPreviousLayer RelationshipsFromPreviousLayer => null; public RootNode(IEnumerable uniqueEntities, RelationshipProxy[] populatedRelationships, RelationshipProxy[] allRelationships) { diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs index 738fd04da4..567f24e930 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ExposableData.cs @@ -11,7 +11,11 @@ public class ExposableData where T : class /// see "primary data" in https://jsonapi.org/format/#document-top-level. /// [JsonProperty("data")] - public object Data { get { return GetPrimaryData(); } set { SetPrimaryData(value); } } + public object Data + { + get => GetPrimaryData(); + set => SetPrimaryData(value); + } /// /// see https://www.newtonsoft.com/json/help/html/ConditionalProperties.htm @@ -53,7 +57,7 @@ public bool ShouldSerializeData() /// internal bool IsPopulated { get; private set; } - internal bool HasResource { get { return IsPopulated && ((IsManyData && ManyData.Any()) || SingleData != null); } } + internal bool HasResource => IsPopulated && ((IsManyData && ManyData.Any()) || SingleData != null); /// /// Gets the "single" or "many" data depending on which one was diff --git a/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs index 16cf8145c4..3bf99c7376 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs @@ -35,7 +35,7 @@ protected QueryParameterService() { } /// `?include=some-relationship` /// public class IncludeService : QueryParameterService { /* ... */ } /// - public virtual string Name { get { return GetParameterNameFromType(); } } + public virtual string Name => GetParameterNameFromType(); /// /// Gets the query parameter name from the implementing class name. Trims "Service" diff --git a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs index 95179d85b0..2e10843831 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs @@ -57,7 +57,7 @@ public int CurrentPageSize public int TotalPages => (TotalRecords == null || CurrentPageSize == 0) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, CurrentPageSize)); /// - public bool CanPaginate { get { return TotalPages > 1; } } + public bool CanPaginate => TotalPages > 1; /// public int? TotalRecords { get; set; } diff --git a/test/UnitTests/DbSetMock.cs b/test/UnitTests/DbSetMock.cs index 4d8afc5cff..3d1ad10db0 100644 --- a/test/UnitTests/DbSetMock.cs +++ b/test/UnitTests/DbSetMock.cs @@ -99,10 +99,7 @@ public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToke throw new System.NotImplementedException(); } - IQueryProvider IQueryable.Provider - { - get { return new TestAsyncQueryProvider(this); } - } + IQueryProvider IQueryable.Provider => new TestAsyncQueryProvider(this); } internal class TestAsyncEnumerator : IAsyncEnumerator @@ -119,13 +116,7 @@ public void Dispose() _inner.Dispose(); } - public T Current - { - get - { - return _inner.Current; - } - } + public T Current => _inner.Current; public Task MoveNext(CancellationToken cancellationToken) { From 243f82ff83d071fcc24305815e73bca7beab9882 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:38:51 +0100 Subject: [PATCH 56/73] Fixed: Empty statement is redundant --- .../Extensions/IApplicationBuilderExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs index 2dd6f1e915..5525e74417 100644 --- a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs @@ -49,12 +49,12 @@ public static void UseJsonApi(this IApplicationBuilder app, bool skipRegisterMid if (useAuthentication) { app.UseAuthentication(); - }; + } if (useAuthorization) { app.UseAuthorization(); - }; + } // middleware to run after routing occurs. app.UseMiddleware(); From d4938d5324401140c18dbc4b70e34269e4f1634c Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:41:09 +0100 Subject: [PATCH 57/73] Fixed: Local variable can be declared in inner scope --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 75a7066b6f..3ec2a4504d 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -243,17 +243,15 @@ private static IQueryable CallGenericWhereMethod(IQueryable CallGenericWhereMethod(IQueryable CallGenericSelectMethod(IQueryable(); - Expression bindExpression; foreach (var item in nestedTypesAndProperties) { var nestedProperty = sourceType.GetProperty(item.Key); var nestedPropertyType = nestedProperty.PropertyType; // [HasMany] attribute + Expression bindExpression; if (nestedPropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(nestedPropertyType)) { // Concrete type of Collection From b9d70e8f759134a087c3aa85ad3aa534ce4e928f Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:42:00 +0100 Subject: [PATCH 58/73] Fixed: Join declaration and assignment --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index 3ec2a4504d..5d2befe185 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -302,7 +302,6 @@ private static IQueryable CallGenericWhereMethod(IQueryable CallGenericSelectMethod(IQueryable source, List columns) { - List sourceBindings; var sourceType = typeof(TSource); var parameter = Expression.Parameter(source.ElementType, "x"); var sourceProperties = new List(); @@ -324,7 +323,7 @@ private static IQueryable CallGenericSelectMethod(IQueryable Expression.Bind(sourceType.GetProperty(prop), Expression.PropertyOrField(parameter, prop))).ToList(); + var sourceBindings = sourceProperties.Select(prop => Expression.Bind(sourceType.GetProperty(prop), Expression.PropertyOrField(parameter, prop))).ToList(); // Bind attributes on nested types var nestedBindings = new List(); From 4d83cc326e358559721adbb4bf92e6160cc04a95 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:43:25 +0100 Subject: [PATCH 59/73] Fixed: Convert constructor to protected in abstract class --- test/UnitTests/ResourceHooks/DiscoveryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/ResourceHooks/DiscoveryTests.cs b/test/UnitTests/ResourceHooks/DiscoveryTests.cs index 02e97c45ce..e655ab8222 100644 --- a/test/UnitTests/ResourceHooks/DiscoveryTests.cs +++ b/test/UnitTests/ResourceHooks/DiscoveryTests.cs @@ -41,7 +41,7 @@ public void HookDiscovery_StandardResourceDefinition_CanDiscover() public class AnotherDummy : Identifiable { } public abstract class ResourceDefinitionBase : ResourceDefinition where T : class, IIdentifiable { - public ResourceDefinitionBase(IResourceGraph resourceGraph) : base(resourceGraph) { } + protected ResourceDefinitionBase(IResourceGraph resourceGraph) : base(resourceGraph) { } public override IEnumerable BeforeDelete(IEntityHashSet entities, ResourcePipeline pipeline) { return entities; } public override void AfterDelete(HashSet entities, ResourcePipeline pipeline, bool succeeded) { } } From 51dd093d224d702825d20856aaa1786192151dab Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:44:40 +0100 Subject: [PATCH 60/73] Fixed: Replace with single call to FirstOrDefault/Count --- .../Helpers/Extensions/DocumentExtensions.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs index 470e77b53c..0255fb7e36 100644 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs +++ b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/DocumentExtensions.cs @@ -8,16 +8,14 @@ public static class DocumentExtensions { public static ResourceObject FindResource(this List included, string type, TId id) { - var document = included.Where(documentData => ( - documentData.Type == type - && documentData.Id == id.ToString() - )).FirstOrDefault(); + var document = included.FirstOrDefault(documentData => + documentData.Type == type && documentData.Id == id.ToString()); return document; } public static int CountOfType(this List included, string type) { - return included.Where(documentData => documentData.Type == type).Count(); + return included.Count(documentData => documentData.Type == type); } } } From bea8731960b110a28c84e27004fb424745c5411a Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:45:57 +0100 Subject: [PATCH 61/73] Fixed: Use single deconstruction declaration --- src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs | 2 +- .../QueryParameterServices/FilterService.cs | 4 ++-- .../ResourceHookExecutor/Delete/AfterDeleteTests.cs | 2 +- .../ResourceHookExecutor/Delete/BeforeDeleteTests.cs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index ff6f5535d7..6962d28173 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -81,7 +81,7 @@ public NodeLayer CreateNextLayer(IEnumerable nodes) { // first extract entities by parsing populated relationships in the entities // of previous layer - (var lefts, var rights) = ExtractEntities(nodes); + var (lefts, rights) = ExtractEntities(nodes); // group them conveniently so we can make ChildNodes of them: // there might be several relationship attributes in rights dictionary diff --git a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs index 04e28369be..2a10a698c3 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs @@ -69,7 +69,7 @@ private List GetFilterQueries(KeyValuePair qu if (string.Equals(op, FilterOperation.@in.ToString(), StringComparison.OrdinalIgnoreCase) || string.Equals(op, FilterOperation.nin.ToString(), StringComparison.OrdinalIgnoreCase)) { - (var _, var filterValue) = ParseFilterOperation(queryParameter.Value); + var (_, filterValue) = ParseFilterOperation(queryParameter.Value); queries.Add(new FilterQuery(propertyName, filterValue, op)); } else @@ -77,7 +77,7 @@ private List GetFilterQueries(KeyValuePair qu var values = ((string)queryParameter.Value).Split(QueryConstants.COMMA); foreach (var val in values) { - (var operation, var filterValue) = ParseFilterOperation(val); + var (operation, filterValue) = ParseFilterOperation(val); queries.Add(new FilterQuery(propertyName, filterValue, operation)); } } diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs index 681fa831ef..2ce85c0da3 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs @@ -31,7 +31,7 @@ public void AfterDelete_Without_Any_Hook_Implemented() { // Arrange var discovery = SetDiscoverableHooks(NoHooks, DisableDbValues); - (var _, var hookExecutor, var resourceDefinitionMock) = CreateTestObjects(discovery); + var (_, hookExecutor, resourceDefinitionMock) = CreateTestObjects(discovery); var todoList = CreateTodoWithOwner(); // Act diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs index 35eb20b1b2..631feeed95 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using Xunit; @@ -14,7 +14,7 @@ public void BeforeDelete() { // Arrange var discovery = SetDiscoverableHooks(targetHooks, DisableDbValues); - (var _, var hookExecutor, var resourceDefinitionMock) = CreateTestObjects(discovery); + var (_, hookExecutor, resourceDefinitionMock) = CreateTestObjects(discovery); var todoList = CreateTodoWithOwner(); // Act @@ -30,7 +30,7 @@ public void BeforeDelete_Without_Any_Hook_Implemented() { // Arrange var discovery = SetDiscoverableHooks(NoHooks, DisableDbValues); - (var _, var hookExecutor, var resourceDefinitionMock) = CreateTestObjects(discovery); + var (_, hookExecutor, resourceDefinitionMock) = CreateTestObjects(discovery); var todoList = CreateTodoWithOwner(); // Act From 995e1149b6e6653491d6eac5640edf823d91d2a4 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 12:48:12 +0100 Subject: [PATCH 62/73] Fixed: Removed unused using directives --- .../Acceptance/KebabCaseFormatterTests.cs | 1 - .../Acceptance/Spec/CreatingDataTests.cs | 2 -- 2 files changed, 3 deletions(-) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs index c023ff5676..5932ca25ee 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs @@ -1,4 +1,3 @@ -using System.Linq; using System.Net; using System.Threading.Tasks; using Bogus; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs index 39c1235206..fb363e00c7 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs @@ -4,8 +4,6 @@ using System.Net; using System.Threading.Tasks; using Bogus; -using JsonApiDotNetCore.Builders; -using JsonApiDotNetCore.Serialization.Client; using JsonApiDotNetCoreExample.Models; using JsonApiDotNetCoreExampleTests.Helpers.Models; using Microsoft.EntityFrameworkCore; From 9a1e4b335da389f5da9d80d0f900f3ed254cb783 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 13:02:36 +0100 Subject: [PATCH 63/73] Fixed a few obvious naming violations --- .../Builders/ResourceGraphBuilder.cs | 26 +++++++++---------- .../Data/DefaultResourceRepository.cs | 6 ++--- .../Graph/ServiceDiscoveryFacade.cs | 2 +- .../Hooks/Discovery/HooksDiscovery.cs | 2 +- .../Discovery/LoadDatabaseValuesAttribute.cs | 5 ++-- .../Hooks/Execution/DiffableEntityHashSet.cs | 6 ++--- .../Hooks/Execution/EntityHashSet.cs | 4 +-- .../Execution/RelationshipsDictionary.cs | 6 ++--- .../Internal/ResourceGraph.cs | 10 +++---- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 14 +++++----- .../ServiceDiscoveryFacadeTests.cs | 10 +++---- .../NoHttpDeleteTests.cs | 4 +-- .../NoHttpPatchTests.cs | 4 +-- 13 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs index 9cc8f4b41f..2f98f7e6a7 100644 --- a/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs @@ -16,22 +16,22 @@ namespace JsonApiDotNetCore.Builders { public class ResourceGraphBuilder : IResourceGraphBuilder { - private List _resources { get; } = new List(); - private List _validationResults { get; } = new List(); - private IResourceNameFormatter _formatter { get; } = new CamelCaseFormatter(); + private List Resources { get; } = new List(); + private List ValidationResults { get; } = new List(); + private IResourceNameFormatter Formatter { get; } = new CamelCaseFormatter(); public ResourceGraphBuilder() { } public ResourceGraphBuilder(IResourceNameFormatter formatter) { - _formatter = formatter; + Formatter = formatter; } /// public IResourceGraph Build() { - _resources.ForEach(SetResourceLinksOptions); - var resourceGraph = new ResourceGraph(_resources, _validationResults); + Resources.ForEach(SetResourceLinksOptions); + var resourceGraph = new ResourceGraph(Resources, ValidationResults); return resourceGraph; } @@ -60,13 +60,13 @@ public IResourceGraphBuilder AddResource(Type resourceType, Type idType = null, AssertEntityIsNotAlreadyDefined(resourceType); if (resourceType.Implements()) { - pluralizedTypeName ??= _formatter.FormatResourceName(resourceType); + pluralizedTypeName ??= Formatter.FormatResourceName(resourceType); idType ??= TypeLocator.GetIdType(resourceType); - _resources.Add(GetEntity(pluralizedTypeName, resourceType, idType)); + Resources.Add(GetEntity(pluralizedTypeName, resourceType, idType)); } else { - _validationResults.Add(new ValidationResult(LogLevel.Warning, $"{resourceType} does not implement 'IIdentifiable<>'. ")); + ValidationResults.Add(new ValidationResult(LogLevel.Warning, $"{resourceType} does not implement 'IIdentifiable<>'. ")); } return this; @@ -98,7 +98,7 @@ protected virtual List GetAttributes(Type entityType) { var idAttr = new AttrAttribute { - PublicAttributeName = _formatter.FormatPropertyName(prop), + PublicAttributeName = Formatter.FormatPropertyName(prop), PropertyInfo = prop }; attributes.Add(idAttr); @@ -109,7 +109,7 @@ protected virtual List GetAttributes(Type entityType) if (attribute == null) continue; - attribute.PublicAttributeName ??= _formatter.FormatPropertyName(prop); + attribute.PublicAttributeName ??= Formatter.FormatPropertyName(prop); attribute.PropertyInfo = prop; attributes.Add(attribute); @@ -126,7 +126,7 @@ protected virtual List GetRelationships(Type entityType) var attribute = (RelationshipAttribute)prop.GetCustomAttribute(typeof(RelationshipAttribute)); if (attribute == null) continue; - attribute.PublicRelationshipName ??= _formatter.FormatPropertyName(prop); + attribute.PublicRelationshipName ??= Formatter.FormatPropertyName(prop); attribute.InternalRelationshipName = prop.Name; attribute.RightType = GetRelationshipType(attribute, prop); attribute.LeftType = entityType; @@ -183,7 +183,7 @@ protected virtual Type GetRelationshipType(RelationshipAttribute relation, Prope private void AssertEntityIsNotAlreadyDefined(Type entityType) { - if (_resources.Any(e => e.ResourceType == entityType)) + if (Resources.Any(e => e.ResourceType == entityType)) throw new InvalidOperationException($"Cannot add entity type {entityType} to context resourceGraph, there is already an entity of that type configured."); } } diff --git a/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs b/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs index 582cdc197b..de6fdeeb0b 100644 --- a/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs +++ b/src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs @@ -235,16 +235,16 @@ private object GetTrackedRelationshipValue(RelationshipAttribute relationshipAtt private IList GetTrackedManyRelationshipValue(IEnumerable relationshipValueList, RelationshipAttribute relationshipAttr, ref bool wasAlreadyAttached) { if (relationshipValueList == null) return null; - bool _wasAlreadyAttached = false; + bool newWasAlreadyAttached = false; var trackedPointerCollection = relationshipValueList.Select(pointer => { // convert each element in the value list to relationshipAttr.DependentType. var tracked = AttachOrGetTracked(pointer); - if (tracked != null) _wasAlreadyAttached = true; + if (tracked != null) newWasAlreadyAttached = true; return Convert.ChangeType(tracked ?? pointer, relationshipAttr.RightType); }) .ToList() .Cast(relationshipAttr.RightType); - if (_wasAlreadyAttached) wasAlreadyAttached = true; + if (newWasAlreadyAttached) wasAlreadyAttached = true; return (IList)trackedPointerCollection; } diff --git a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs index 1c668488ae..417b0b1fe5 100644 --- a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs @@ -186,7 +186,7 @@ private void AddRepositories(Assembly assembly, ResourceDescriptor resourceDescr RegisterServiceImplementations(assembly, serviceInterface, resourceDescriptor); } } - public int i = 0; + private void RegisterServiceImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor) { if (resourceDescriptor.IdType == typeof(Guid) && interfaceType.GetTypeInfo().GenericTypeParameters.Length == 1) diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs index 4dec1e95ff..96f7e9a5df 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs @@ -72,7 +72,7 @@ void DiscoverImplementedHooks(Type containerType) throw new JsonApiSetupException("DatabaseValuesAttribute cannot be used on hook" + $"{hook:G} in resource definition {containerType.Name}"); } - var targetList = attr.value ? databaseValuesEnabledHooks : databaseValuesDisabledHooks; + var targetList = attr.Value ? databaseValuesEnabledHooks : databaseValuesDisabledHooks; targetList.Add(hook); } } diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs b/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs index 6a47e9d2a0..296d5d4914 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs @@ -3,10 +3,11 @@ namespace JsonApiDotNetCore.Hooks { public class LoadDatabaseValues : Attribute { - public readonly bool value; + public readonly bool Value; + public LoadDatabaseValues(bool mode = true) { - value = mode; + Value = mode; } } } diff --git a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs index 35e0833db3..22cdcc3873 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs @@ -71,15 +71,15 @@ public IEnumerable> GetDiffs() } /// - public new HashSet GetAffected(Expression> NavigationAction) + public new HashSet GetAffected(Expression> navigationAction) { - var propertyInfo = TypeHelper.ParseNavigationExpression(NavigationAction); + var propertyInfo = TypeHelper.ParseNavigationExpression(navigationAction); var propertyType = propertyInfo.PropertyType; if (propertyType.Inherits(typeof(IEnumerable))) propertyType = TypeHelper.GetTypeOfList(propertyType); if (propertyType.Implements()) { // the navigation action references a relationship. Redirect the call to the relationship dictionary. - return base.GetAffected(NavigationAction); + return base.GetAffected(navigationAction); } else if (_updatedAttributes.TryGetValue(propertyInfo, out HashSet entities)) { diff --git a/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs index efe2763455..a29b30e391 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs @@ -57,9 +57,9 @@ public Dictionary> GetByRelationship - public HashSet GetAffected(Expression> NavigationAction) + public HashSet GetAffected(Expression> navigationAction) { - return _relationships.GetAffected(NavigationAction); + return _relationships.GetAffected(navigationAction); } } } diff --git a/src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs b/src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs index 45b6cd0eca..a40e93a343 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -91,9 +91,9 @@ public Dictionary> GetByRelationship(T } /// - public HashSet GetAffected(Expression> NavigationAction) + public HashSet GetAffected(Expression> navigationAction) { - var property = TypeHelper.ParseNavigationExpression(NavigationAction); + var property = TypeHelper.ParseNavigationExpression(navigationAction); return this.Where(p => p.Key.InternalRelationshipName == property.Name).Select(p => p.Value).SingleOrDefault(); } } diff --git a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs index d1a98a915b..b9f89420a4 100644 --- a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs +++ b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs @@ -13,22 +13,22 @@ namespace JsonApiDotNetCore.Internal public class ResourceGraph : IResourceGraph { internal List ValidationResults { get; } - private List _resources { get; } + private List Resources { get; } public ResourceGraph(List entities, List validationResults = null) { - _resources = entities; + Resources = entities; ValidationResults = validationResults; } /// - public ResourceContext[] GetResourceContexts() => _resources.ToArray(); + public ResourceContext[] GetResourceContexts() => Resources.ToArray(); /// public ResourceContext GetResourceContext(string entityName) - => _resources.SingleOrDefault(e => string.Equals(e.ResourceName, entityName, StringComparison.OrdinalIgnoreCase)); + => Resources.SingleOrDefault(e => string.Equals(e.ResourceName, entityName, StringComparison.OrdinalIgnoreCase)); /// public ResourceContext GetResourceContext(Type entityType) - => _resources.SingleOrDefault(e => e.ResourceType == entityType); + => Resources.SingleOrDefault(e => e.ResourceType == entityType); /// public ResourceContext GetResourceContext() where TResource : class, IIdentifiable => GetResourceContext(typeof(TResource)); diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index 4f02ad4fe6..72e7f6ad95 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -91,32 +91,32 @@ public static Type GetTypeOfList(Type type) /// Gets the property info that is referenced in the NavigationAction expression. /// Credits: https://stackoverflow.com/a/17116267/4441216 /// - public static PropertyInfo ParseNavigationExpression(Expression> NavigationExpression) + public static PropertyInfo ParseNavigationExpression(Expression> navigationExpression) { - MemberExpression Exp; + MemberExpression exp; //this line is necessary, because sometimes the expression comes in as Convert(originalExpression) - if (NavigationExpression.Body is UnaryExpression unaryExpression) + if (navigationExpression.Body is UnaryExpression unaryExpression) { if (unaryExpression.Operand is MemberExpression memberExpression) { - Exp = memberExpression; + exp = memberExpression; } else { throw new ArgumentException(); } } - else if (NavigationExpression.Body is MemberExpression memberExpression) + else if (navigationExpression.Body is MemberExpression memberExpression) { - Exp = memberExpression; + exp = memberExpression; } else { throw new ArgumentException(); } - return (PropertyInfo)Exp.Member; + return (PropertyInfo)exp.Member; } /// diff --git a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs index 30a899d943..4afe430546 100644 --- a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs +++ b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs @@ -42,13 +42,13 @@ public ServiceDiscoveryFacadeTests() _services.AddScoped((_) => new Mock().Object); } - private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade(_services, _resourceGraphBuilder); + private ServiceDiscoveryFacade Facade => new ServiceDiscoveryFacade(_services, _resourceGraphBuilder); [Fact] public void AddAssembly_Adds_All_Resources_To_Graph() { // Arrange, act - _facade.AddAssembly(typeof(Person).Assembly); + Facade.AddAssembly(typeof(Person).Assembly); // Assert var resourceGraph = _resourceGraphBuilder.Build(); @@ -65,7 +65,7 @@ public void AddAssembly_Adds_All_Resources_To_Graph() public void AddCurrentAssembly_Adds_Resources_To_Graph() { // Arrange, act - _facade.AddCurrentAssembly(); + Facade.AddCurrentAssembly(); // Assert var resourceGraph = _resourceGraphBuilder.Build(); @@ -77,7 +77,7 @@ public void AddCurrentAssembly_Adds_Resources_To_Graph() public void AddCurrentAssembly_Adds_Services_To_Container() { // Arrange, act - _facade.AddCurrentAssembly(); + Facade.AddCurrentAssembly(); // Assert var services = _services.BuildServiceProvider(); @@ -89,7 +89,7 @@ public void AddCurrentAssembly_Adds_Services_To_Container() public void AddCurrentAssembly_Adds_Repositories_To_Container() { // Arrange, act - _facade.AddCurrentAssembly(); + Facade.AddCurrentAssembly(); // Assert var services = _services.BuildServiceProvider(); diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs index e7aa542d9a..2d8f3c940f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using JsonApiDotNetCoreExample; @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class nohttpdeleteTests + public class NoHttpDeleteTests { [Fact] public async Task Allows_GET_Requests() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs index 573b8dccf7..94347db048 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using JsonApiDotNetCoreExample; @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class nohttppatchTests + public class NoHttpPatchTests { [Fact] public async Task Allows_GET_Requests() From 6964ca333b31f051ee96c62711051e3616b0c52a Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 15:35:58 +0100 Subject: [PATCH 64/73] Fixed: Virtual member that is never overridden --- .../Controllers/TodoItemsCustomController.cs | 25 ++++++++----------- .../Models/Passport.cs | 8 +++--- .../JsonApiDotNetCoreExample/Models/Person.cs | 18 ++++++------- .../Models/TodoItem.cs | 22 ++++++++-------- .../Models/TodoItemCollection.cs | 4 +-- .../Startups/Startup.cs | 2 +- src/Examples/ReportsExample/Startup.cs | 2 +- .../Hooks/ResourceHookExecutor.cs | 23 +++++++++-------- .../Acceptance/TestFixture.cs | 3 ++- 9 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs index 19e16c26ea..476ae4860b 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs @@ -28,7 +28,7 @@ public CustomJsonApiController( IJsonApiOptions options, IResourceService resourceService, ILoggerFactory loggerFactory) - : base(options, resourceService, loggerFactory) + : base(options, resourceService) { } } @@ -36,23 +36,20 @@ public CustomJsonApiController( public class CustomJsonApiController : ControllerBase where T : class, IIdentifiable { - private readonly ILogger _logger; private readonly IJsonApiOptions _options; private readonly IResourceService _resourceService; - protected IActionResult Forbidden() + private IActionResult Forbidden() { return new StatusCodeResult(403); } public CustomJsonApiController( IJsonApiOptions options, - IResourceService resourceService, - ILoggerFactory loggerFactory) + IResourceService resourceService) { _options = options; _resourceService = resourceService; - _logger = loggerFactory.CreateLogger>(); } public CustomJsonApiController( @@ -62,14 +59,14 @@ public CustomJsonApiController( } [HttpGet] - public virtual async Task GetAsync() + public async Task GetAsync() { var entities = await _resourceService.GetAsync(); return Ok(entities); } [HttpGet("{id}")] - public virtual async Task GetAsync(TId id) + public async Task GetAsync(TId id) { var entity = await _resourceService.GetAsync(id); @@ -80,7 +77,7 @@ public virtual async Task GetAsync(TId id) } [HttpGet("{id}/relationships/{relationshipName}")] - public virtual async Task GetRelationshipsAsync(TId id, string relationshipName) + public async Task GetRelationshipsAsync(TId id, string relationshipName) { var relationship = _resourceService.GetRelationshipAsync(id, relationshipName); if (relationship == null) @@ -90,14 +87,14 @@ public virtual async Task GetRelationshipsAsync(TId id, string re } [HttpGet("{id}/{relationshipName}")] - public virtual async Task GetRelationshipAsync(TId id, string relationshipName) + public async Task GetRelationshipAsync(TId id, string relationshipName) { var relationship = await _resourceService.GetRelationshipAsync(id, relationshipName); return Ok(relationship); } [HttpPost] - public virtual async Task PostAsync([FromBody] T entity) + public async Task PostAsync([FromBody] T entity) { if (entity == null) return UnprocessableEntity(); @@ -111,7 +108,7 @@ public virtual async Task PostAsync([FromBody] T entity) } [HttpPatch("{id}")] - public virtual async Task PatchAsync(TId id, [FromBody] T entity) + public async Task PatchAsync(TId id, [FromBody] T entity) { if (entity == null) return UnprocessableEntity(); @@ -125,14 +122,14 @@ public virtual async Task PatchAsync(TId id, [FromBody] T entity) } [HttpPatch("{id}/relationships/{relationshipName}")] - public virtual async Task PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List relationships) + public async Task PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List relationships) { await _resourceService.UpdateRelationshipsAsync(id, relationshipName, relationships); return Ok(); } [HttpDelete("{id}")] - public virtual async Task DeleteAsync(TId id) + public async Task DeleteAsync(TId id) { var wasDeleted = await _resourceService.DeleteAsync(id); diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs index 8775ecbab5..9aa47a2eca 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs @@ -4,10 +4,10 @@ namespace JsonApiDotNetCoreExample.Models { public class Passport : Identifiable { - public virtual int? SocialSecurityNumber { get; set; } - public virtual bool IsLocked { get; set; } + public int? SocialSecurityNumber { get; set; } + public bool IsLocked { get; set; } [HasOne] - public virtual Person Person { get; set; } + public Person Person { get; set; } } -} \ No newline at end of file +} diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs index c5182aeb9d..a0a1bc8238 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs @@ -24,30 +24,30 @@ public class Person : Identifiable, IIsLockable public int Age { get; set; } [HasMany] - public virtual List TodoItems { get; set; } + public List TodoItems { get; set; } [HasMany] - public virtual List AssignedTodoItems { get; set; } + public List AssignedTodoItems { get; set; } [HasMany] - public virtual List todoCollections { get; set; } + public List todoCollections { get; set; } [HasOne] - public virtual PersonRole Role { get; set; } + public PersonRole Role { get; set; } public int? PersonRoleId { get; set; } [HasOne] - public virtual TodoItem OneToOneTodoItem { get; set; } + public TodoItem OneToOneTodoItem { get; set; } [HasOne] - public virtual TodoItem StakeHolderTodoItem { get; set; } - public virtual int? StakeHolderTodoItemId { get; set; } + public TodoItem StakeHolderTodoItem { get; set; } + public int? StakeHolderTodoItemId { get; set; } [HasOne(links: Link.All, canInclude: false)] - public virtual TodoItem UnIncludeableItem { get; set; } + public TodoItem UnIncludeableItem { get; set; } [HasOne] - public virtual Passport Passport { get; set; } + public Passport Passport { get; set; } public int? PassportId { get; set; } } } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs index e152dbb6fd..5358d6cb11 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs @@ -44,35 +44,35 @@ public TodoItem() public Guid? CollectionId { get; set; } [HasOne] - public virtual Person Owner { get; set; } + public Person Owner { get; set; } [HasOne] - public virtual Person Assignee { get; set; } + public Person Assignee { get; set; } [HasOne] - public virtual Person OneToOnePerson { get; set; } + public Person OneToOnePerson { get; set; } - public virtual int? OneToOnePersonId { get; set; } + public int? OneToOnePersonId { get; set; } [HasMany] - public virtual List StakeHolders { get; set; } + public List StakeHolders { get; set; } [HasOne] - public virtual TodoItemCollection Collection { get; set; } + public TodoItemCollection Collection { get; set; } // cyclical to-one structure - public virtual int? DependentOnTodoId { get; set; } + public int? DependentOnTodoId { get; set; } [HasOne] - public virtual TodoItem DependentOnTodo { get; set; } + public TodoItem DependentOnTodo { get; set; } // cyclical to-many structure - public virtual int? ParentTodoId {get; set;} + public int? ParentTodoId {get; set;} [HasOne] - public virtual TodoItem ParentTodo { get; set; } + public TodoItem ParentTodo { get; set; } [HasMany] - public virtual List ChildrenTodos { get; set; } + public List ChildrenTodos { get; set; } } } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs index 2a251581d4..fb15cdb2e7 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs @@ -11,10 +11,10 @@ public class TodoItemCollection : Identifiable public string Name { get; set; } [HasMany] - public virtual List TodoItems { get; set; } + public List TodoItems { get; set; } [HasOne] - public virtual Person Owner { get; set; } + public Person Owner { get; set; } public int? OwnerId { get; set; } } diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs index ca2bbb3268..5c7a7164b2 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs @@ -44,7 +44,7 @@ public virtual void ConfigureServices(IServiceCollection services) services.AddClientSerialization(); } - public virtual void Configure( + public void Configure( IApplicationBuilder app, AppDbContext context) { diff --git a/src/Examples/ReportsExample/Startup.cs b/src/Examples/ReportsExample/Startup.cs index bafa6f7689..e586ec2273 100644 --- a/src/Examples/ReportsExample/Startup.cs +++ b/src/Examples/ReportsExample/Startup.cs @@ -20,7 +20,7 @@ public Startup(IWebHostEnvironment env) Config = builder.Build(); } - public virtual void ConfigureServices(IServiceCollection services) + public void ConfigureServices(IServiceCollection services) { var mvcBuilder = services.AddMvcCore(); services.AddJsonApi( diff --git a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs index 8b2a258409..0937ac972b 100644 --- a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs +++ b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs @@ -15,13 +15,14 @@ namespace JsonApiDotNetCore.Hooks { /// - internal class ResourceHookExecutor : IResourceHookExecutor + internal sealed class ResourceHookExecutor : IResourceHookExecutor { - internal readonly IHookExecutorHelper _executorHelper; + private readonly IHookExecutorHelper _executorHelper; private readonly ITraversalHelper _traversalHelper; private readonly IIncludeService _includeService; private readonly ITargetedFields _targetedFields; private readonly IResourceGraph _resourceGraph; + public ResourceHookExecutor( IHookExecutorHelper executorHelper, ITraversalHelper traversalHelper, @@ -37,7 +38,7 @@ public ResourceHookExecutor( } /// - public virtual void BeforeRead(ResourcePipeline pipeline, string stringId = null) where TResource : class, IIdentifiable + public void BeforeRead(ResourcePipeline pipeline, string stringId = null) where TResource : class, IIdentifiable { var hookContainer = _executorHelper.GetResourceHookContainer(ResourceHook.BeforeRead); hookContainer?.BeforeRead(pipeline, false, stringId); @@ -47,7 +48,7 @@ public virtual void BeforeRead(ResourcePipeline pipeline, string stri } /// - public virtual IEnumerable BeforeUpdate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public IEnumerable BeforeUpdate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeUpdate, entities, out var container, out var node)) { @@ -64,7 +65,7 @@ public virtual IEnumerable BeforeUpdate(IEnumerable - public virtual IEnumerable BeforeCreate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public IEnumerable BeforeCreate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeCreate, entities, out var container, out var node)) { @@ -78,7 +79,7 @@ public virtual IEnumerable BeforeCreate(IEnumerable - public virtual IEnumerable BeforeDelete(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public IEnumerable BeforeDelete(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeDelete, entities, out var container, out var node)) { @@ -105,7 +106,7 @@ public virtual IEnumerable BeforeDelete(IEnumerable - public virtual IEnumerable OnReturn(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public IEnumerable OnReturn(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.OnReturn, entities, out var container, out var node) && pipeline != ResourcePipeline.GetRelationship) { @@ -125,7 +126,7 @@ public virtual IEnumerable OnReturn(IEnumerable } /// - public virtual void AfterRead(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public void AfterRead(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.AfterRead, entities, out var container, out var node)) { @@ -139,7 +140,7 @@ public virtual void AfterRead(IEnumerable entities, Resour } /// - public virtual void AfterCreate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public void AfterCreate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.AfterCreate, entities, out var container, out var node)) { @@ -152,7 +153,7 @@ public virtual void AfterCreate(IEnumerable entities, Reso } /// - public virtual void AfterUpdate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable + public void AfterUpdate(IEnumerable entities, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.AfterUpdate, entities, out var container, out var node)) { @@ -165,7 +166,7 @@ public virtual void AfterUpdate(IEnumerable entities, Reso } /// - public virtual void AfterDelete(IEnumerable entities, ResourcePipeline pipeline, bool succeeded) where TResource : class, IIdentifiable + public void AfterDelete(IEnumerable entities, ResourcePipeline pipeline, bool succeeded) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.AfterDelete, entities, out var container, out var node)) { diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs index 7bb99db640..4c4b75e3b6 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TestFixture.cs @@ -69,7 +69,8 @@ public void ReloadDbContext() } private bool disposedValue; - protected virtual void Dispose(bool disposing) + + private void Dispose(bool disposing) { if (!disposedValue) { From f0d7c4f69d4cf21c1ddc42812f065aa9b4522fe9 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 15:47:38 +0100 Subject: [PATCH 65/73] Removed DefaultPageSize/RequestedPageSize from IPageService because where the calculated value comes from is an implementation detail and should not be exposed to external code that uses paging. --- .../QueryParameterServices/Contracts/IPageService.cs | 12 ++---------- .../QueryParameterServices/PageService.cs | 4 ++-- .../Serialization/Server/Builders/LinkBuilder.cs | 10 +++++----- .../Services/DefaultResourceService.cs | 6 +++--- test/UnitTests/Builders/LinkBuilderTests.cs | 2 +- test/UnitTests/QueryParameters/PageServiceTests.cs | 4 ++-- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs b/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs index ed840d5694..968ed85958 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs @@ -8,19 +8,11 @@ public interface IPageService : IQueryParameterService /// /// Gets the requested or default page size /// - int CurrentPageSize { get; } - /// - /// Default size to be used in pagination - /// - int DefaultPageSize { get; set; } - /// - /// Currently requested page size to be used in pagination - /// - int? RequestedPageSize { get; set; } + int PageSize { get; } /// /// The page requested. Note that the page number is one-based. /// - int CurrentPage { get; set; } + int CurrentPage { get; } /// /// Total amount of pages for request /// diff --git a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs index 2e10843831..d7da6292ae 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs @@ -29,7 +29,7 @@ internal PageService(IJsonApiOptions options) } /// - public int CurrentPageSize + public int PageSize { get { @@ -54,7 +54,7 @@ public int CurrentPageSize public bool Backwards { get; set; } /// - public int TotalPages => (TotalRecords == null || CurrentPageSize == 0) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, CurrentPageSize)); + public int TotalPages => (TotalRecords == null || PageSize == 0) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize)); /// public bool CanPaginate => TotalPages > 1; diff --git a/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs b/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs index d8b432b959..cf0aea0d36 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/Builders/LinkBuilder.cs @@ -65,19 +65,19 @@ private void SetPageLinks(ResourceContext resourceContext, TopLevelLinks links) { if (_pageService.CurrentPage > 1) { - links.Prev = GetPageLink(resourceContext, _pageService.CurrentPage - 1, _pageService.CurrentPageSize); + links.Prev = GetPageLink(resourceContext, _pageService.CurrentPage - 1, _pageService.PageSize); } if (_pageService.CurrentPage < _pageService.TotalPages) { - links.Next = GetPageLink(resourceContext, _pageService.CurrentPage + 1, _pageService.CurrentPageSize); + links.Next = GetPageLink(resourceContext, _pageService.CurrentPage + 1, _pageService.PageSize); } if (_pageService.TotalPages > 0) { - links.Self = GetPageLink(resourceContext, _pageService.CurrentPage, _pageService.CurrentPageSize); - links.First = GetPageLink(resourceContext, 1, _pageService.CurrentPageSize); - links.Last = GetPageLink(resourceContext, _pageService.TotalPages, _pageService.CurrentPageSize); + links.Self = GetPageLink(resourceContext, _pageService.CurrentPage, _pageService.PageSize); + links.First = GetPageLink(resourceContext, 1, _pageService.PageSize); + links.Last = GetPageLink(resourceContext, _pageService.TotalPages, _pageService.PageSize); } } diff --git a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs index 4c4f33cb87..d1c7c1553a 100644 --- a/src/JsonApiDotNetCore/Services/DefaultResourceService.cs +++ b/src/JsonApiDotNetCore/Services/DefaultResourceService.cs @@ -200,7 +200,7 @@ public virtual async Task UpdateRelationshipsAsync(TId id, string relationshipNa protected virtual async Task> ApplyPageQueryAsync(IQueryable entities) { - if (!(_pageService.CurrentPageSize > 0)) + if (!(_pageService.PageSize > 0)) { return await _repository.ToListAsync(entities); } @@ -212,9 +212,9 @@ protected virtual async Task> ApplyPageQueryAsync(IQuerya } _logger.LogInformation($"Applying paging query. Fetching page {pageOffset} " + - $"with {_pageService.CurrentPageSize} entities"); + $"with {_pageService.PageSize} entities"); - return await _repository.PageAsync(entities, _pageService.CurrentPageSize, pageOffset); + return await _repository.PageAsync(entities, _pageService.PageSize, pageOffset); } /// diff --git a/test/UnitTests/Builders/LinkBuilderTests.cs b/test/UnitTests/Builders/LinkBuilderTests.cs index bf7c628552..71374a8b72 100644 --- a/test/UnitTests/Builders/LinkBuilderTests.cs +++ b/test/UnitTests/Builders/LinkBuilderTests.cs @@ -212,7 +212,7 @@ private IPageService GetPageManager() mock.Setup(m => m.CanPaginate).Returns(true); mock.Setup(m => m.CurrentPage).Returns(2); mock.Setup(m => m.TotalPages).Returns(3); - mock.Setup(m => m.CurrentPageSize).Returns(10); + mock.Setup(m => m.PageSize).Returns(10); return mock.Object; } diff --git a/test/UnitTests/QueryParameters/PageServiceTests.cs b/test/UnitTests/QueryParameters/PageServiceTests.cs index 1d763c8c21..cabeae7c4c 100644 --- a/test/UnitTests/QueryParameters/PageServiceTests.cs +++ b/test/UnitTests/QueryParameters/PageServiceTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.QueryParameters { public class PageServiceTests : QueryParametersUnitTestCollection { - public PageService GetService(int? maximumPageSize = null, int? maximumPageNumber = null) + public IPageService GetService(int? maximumPageSize = null, int? maximumPageNumber = null) { return new PageService(new JsonApiOptions { @@ -52,7 +52,7 @@ public void Parse_PageSize_CanParse(string value, int expectedValue, int? maximu else { service.Parse(query); - Assert.Equal(expectedValue, service.CurrentPageSize); + Assert.Equal(expectedValue, service.PageSize); } } From a50ab4de53d188a883ee9f13546f77949ee663e1 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 15:48:29 +0100 Subject: [PATCH 66/73] Fixed: Initializing property by default value is redundant --- src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index 8f63623eca..d63701cc97 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -50,7 +50,7 @@ public class JsonApiOptions : IJsonApiOptions /// /// Defaults to . /// - public bool LoadDatabaseValues { get; set; } = false; + public bool LoadDatabaseValues { get; set; } /// /// The base URL Namespace From e874f42c029c36e5cdce7e65b4088a7512e14365 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 16:09:22 +0100 Subject: [PATCH 67/73] Reduced accessibility for some non-public types/members --- src/Examples/GettingStarted/Models/Article.cs | 2 +- src/Examples/GettingStarted/Models/Person.cs | 2 +- src/JsonApiDotNetCore/Extensions/TypeExtensions.cs | 2 +- src/JsonApiDotNetCore/Graph/ResourceDescriptor.cs | 4 ++-- src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs | 4 ++-- .../Hooks/Execution/HookExecutorHelper.cs | 8 ++++---- src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs | 2 +- src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs | 2 +- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 6 +++--- src/JsonApiDotNetCore/Internal/ValidationResults.cs | 4 ++-- .../Middleware/CurrentRequestMiddleware.cs | 2 +- src/JsonApiDotNetCore/Models/ResourceAttribute.cs | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Examples/GettingStarted/Models/Article.cs b/src/Examples/GettingStarted/Models/Article.cs index f10c3b175f..96cc704139 100644 --- a/src/Examples/GettingStarted/Models/Article.cs +++ b/src/Examples/GettingStarted/Models/Article.cs @@ -10,4 +10,4 @@ public class Article : Identifiable public Person Author { get; set; } public int AuthorId { get; set; } } -} \ No newline at end of file +} diff --git a/src/Examples/GettingStarted/Models/Person.cs b/src/Examples/GettingStarted/Models/Person.cs index 39b59a44bb..74e19c99be 100644 --- a/src/Examples/GettingStarted/Models/Person.cs +++ b/src/Examples/GettingStarted/Models/Person.cs @@ -10,4 +10,4 @@ public class Person : Identifiable [HasMany] public List
Articles { get; set; } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs index 2e52e58d7b..305e7745be 100644 --- a/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/TypeExtensions.cs @@ -113,7 +113,7 @@ public static bool Implements(this Type concreteType) /// /// Whether or not a type implements an interface. /// - public static bool Implements(this Type concreteType, Type interfaceType) + private static bool Implements(this Type concreteType, Type interfaceType) => interfaceType?.IsAssignableFrom(concreteType) == true; /// diff --git a/src/JsonApiDotNetCore/Graph/ResourceDescriptor.cs b/src/JsonApiDotNetCore/Graph/ResourceDescriptor.cs index 2cb1a8b812..7fd97d3059 100644 --- a/src/JsonApiDotNetCore/Graph/ResourceDescriptor.cs +++ b/src/JsonApiDotNetCore/Graph/ResourceDescriptor.cs @@ -10,8 +10,8 @@ public ResourceDescriptor(Type resourceType, Type idType) IdType = idType; } - public Type ResourceType { get; set; } - public Type IdType { get; set; } + public Type ResourceType { get; } + public Type IdType { get; } internal static ResourceDescriptor Empty => new ResourceDescriptor(null, null); } diff --git a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs index 417b0b1fe5..a9a4e022d6 100644 --- a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Graph { public class ServiceDiscoveryFacade : IServiceDiscoveryFacade { - internal static HashSet ServiceInterfaces = new HashSet { + internal static readonly HashSet ServiceInterfaces = new HashSet { typeof(IResourceService<>), typeof(IResourceService<,>), typeof(IResourceCommandService<>), @@ -37,7 +37,7 @@ public class ServiceDiscoveryFacade : IServiceDiscoveryFacade typeof(IDeleteService<,>) }; - internal static HashSet RepositoryInterfaces = new HashSet { + private static readonly HashSet RepositoryInterfaces = new HashSet { typeof(IResourceRepository<>), typeof(IResourceRepository<,>), typeof(IResourceWriteRepository<>), diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index 29b30ff4fc..bbe4f7840e 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -19,10 +19,10 @@ internal class HookExecutorHelper : IHookExecutorHelper { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly IJsonApiOptions _options; - protected readonly IGenericServiceFactory _genericProcessorFactory; - protected readonly Dictionary _hookContainers; - protected readonly Dictionary _hookDiscoveries; - protected readonly List _targetedHooksForRelatedEntities; + private readonly IGenericServiceFactory _genericProcessorFactory; + private readonly Dictionary _hookContainers; + private readonly Dictionary _hookDiscoveries; + private readonly List _targetedHooksForRelatedEntities; public HookExecutorHelper(IGenericServiceFactory genericProcessorFactory, IJsonApiOptions options) diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index c4d8d57437..26c5bdfdf1 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -18,7 +18,7 @@ internal class ChildNode : INode where TResource : class, IIdentifiab /// public RightType ResourceType { get; } /// - public RelationshipProxy[] RelationshipsToNextLayer { get; set; } + public RelationshipProxy[] RelationshipsToNextLayer { get; } /// public IEnumerable UniqueEntities { diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs index 2b21e7e995..588edb6484 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs @@ -16,7 +16,7 @@ internal class RootNode : INode where TResource : class, IIdentifiabl private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly RelationshipProxy[] _allRelationshipsToNextLayer; private HashSet _uniqueEntities; - public Type ResourceType { get; internal set; } + public Type ResourceType { get; } public IEnumerable UniqueEntities => _uniqueEntities; public RelationshipProxy[] RelationshipsToNextLayer { get; } diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index 72e7f6ad95..4a0be08cb4 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -17,7 +17,7 @@ public static IList ConvertCollection(IEnumerable collection, Type targe list.Add(ConvertType(item, targetType)); return list; } - public static bool IsNullable(Type type) + private static bool IsNullable(Type type) { return (!type.IsValueType || Nullable.GetUnderlyingType(type) != null); } @@ -143,7 +143,7 @@ public static IList ConvertListType(IEnumerable values, Type type) /// Generic type parameters to be used in open type. /// Constructor arguments to be provided in instantiation. /// Open generic type - public static object CreateInstanceOfOpenType(Type openType, Type[] parameters, params object[] constructorArguments) + private static object CreateInstanceOfOpenType(Type openType, Type[] parameters, params object[] constructorArguments) { var parameterizedType = openType.MakeGenericType(parameters); return Activator.CreateInstance(parameterizedType, constructorArguments); @@ -170,7 +170,7 @@ public static Dictionary> ConvertAttributeDicti /// /// Use this overload if you need to instantiate a type that has a internal constructor /// - public static object CreateInstanceOfOpenType(Type openType, Type[] parameters, bool hasInternalConstructor, params object[] constructorArguments) + private static object CreateInstanceOfOpenType(Type openType, Type[] parameters, bool hasInternalConstructor, params object[] constructorArguments) { if (!hasInternalConstructor) return CreateInstanceOfOpenType(openType, parameters, constructorArguments); var parameterizedType = openType.MakeGenericType(parameters); diff --git a/src/JsonApiDotNetCore/Internal/ValidationResults.cs b/src/JsonApiDotNetCore/Internal/ValidationResults.cs index 93fa32c74b..7a07b0256a 100644 --- a/src/JsonApiDotNetCore/Internal/ValidationResults.cs +++ b/src/JsonApiDotNetCore/Internal/ValidationResults.cs @@ -10,7 +10,7 @@ public ValidationResult(LogLevel logLevel, string message) Message = message; } - public LogLevel LogLevel { get; set; } - public string Message { get; set; } + public LogLevel LogLevel { get; } + public string Message { get; } } } diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index cd8ecd009f..8c7f25ae60 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -172,7 +172,7 @@ private bool IsValidAcceptHeader(HttpContext context) return true; } - internal static bool ContainsMediaTypeParameters(string mediaType) + private static bool ContainsMediaTypeParameters(string mediaType) { var incomingMediaTypeSpan = mediaType.AsSpan(); diff --git a/src/JsonApiDotNetCore/Models/ResourceAttribute.cs b/src/JsonApiDotNetCore/Models/ResourceAttribute.cs index 9f17883662..c74396c4c7 100644 --- a/src/JsonApiDotNetCore/Models/ResourceAttribute.cs +++ b/src/JsonApiDotNetCore/Models/ResourceAttribute.cs @@ -9,6 +9,6 @@ public ResourceAttribute(string resourceName) ResourceName = resourceName; } - public string ResourceName { get; set; } + public string ResourceName { get; } } } From 9a3ae135740e36d37516ed49cba4eccad6f1cd2b Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 16:49:14 +0100 Subject: [PATCH 68/73] Fixed: missing checkbox in Solution Configuration Manager --- JsonApiDotnetCore.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/JsonApiDotnetCore.sln b/JsonApiDotnetCore.sln index 69b9367d58..769230390d 100644 --- a/JsonApiDotnetCore.sln +++ b/JsonApiDotnetCore.sln @@ -108,6 +108,7 @@ Global {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.ActiveCfg = Debug|Any CPU {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.Build.0 = Debug|Any CPU {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.Build.0 = Release|Any CPU {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.ActiveCfg = Release|Any CPU {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.Build.0 = Release|Any CPU {DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x86.ActiveCfg = Release|Any CPU From 1771ebd94067bef6fd350a5b0cee38f73f36eb42 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 16:51:22 +0100 Subject: [PATCH 69/73] Made non-public (and a few public) types sealed --- benchmarks/BenchmarkResource.cs | 4 ++-- .../Controllers/ArticlesController.cs | 2 +- .../Controllers/PeopleController.cs | 2 +- src/Examples/GettingStarted/Models/Article.cs | 2 +- src/Examples/GettingStarted/Models/Person.cs | 2 +- .../ResourceDefinitionExample/Model.cs | 2 +- .../ResourceDefinitionExample/ModelsController.cs | 2 +- src/Examples/GettingStarted/Startup.cs | 2 +- .../Controllers/ArticlesController.cs | 2 +- .../Controllers/CamelCasedModelsController.cs | 2 +- .../Controllers/PassportsController.cs | 2 +- .../Controllers/PeopleController.cs | 2 +- .../Controllers/PersonRolesController.cs | 2 +- .../Controllers/TagsController.cs | 2 +- .../Controllers/TodoCollectionsController.cs | 2 +- .../Controllers/TodoItemsController.cs | 2 +- .../Controllers/UsersController.cs | 4 ++-- .../JsonApiDotNetCoreExample/Data/AppDbContext.cs | 2 +- .../JsonApiDotNetCoreExample/Models/Article.cs | 2 +- .../JsonApiDotNetCoreExample/Models/ArticleTag.cs | 4 ++-- .../JsonApiDotNetCoreExample/Models/Author.cs | 2 +- .../JsonApiDotNetCoreExample/Models/Passport.cs | 2 +- .../JsonApiDotNetCoreExample/Models/Person.cs | 4 ++-- .../Models/TodoItemCollection.cs | 2 +- .../JsonApiDotNetCoreExample/Models/User.cs | 2 +- .../Startups/MetaStartup.cs | 4 ++-- .../Startups/NoDefaultPageSizeStartup.cs | 2 +- .../Controllers/TodoItemsController.cs | 2 +- .../NoEntityFrameworkExample/Data/AppDbContext.cs | 2 +- .../NoEntityFrameworkExample/Models/TodoItem.cs | 2 +- .../Services/TodoItemService.cs | 2 +- src/Examples/ReportsExample/Models/Report.cs | 4 ++-- src/Examples/ReportsExample/Startup.cs | 2 +- .../Controllers/DisableQueryAttribute.cs | 4 ++-- .../DisableRoutingConventionAttribute.cs | 4 ++-- .../Controllers/HttpMethodRestrictionFilter.cs | 8 ++++---- src/JsonApiDotNetCore/Data/DbContextResolver.cs | 2 +- .../Formatters/JsonApiInputFormatter.cs | 2 +- .../Formatters/JsonApiOutputFormatter.cs | 2 +- src/JsonApiDotNetCore/Graph/ResourceIdMapper.cs | 4 ++-- .../ResourceNameFormatters/CamelCaseFormatter.cs | 4 ++-- .../ResourceNameFormatters/KebabCaseFormatter.cs | 4 ++-- .../Discovery/LoadDatabaseValuesAttribute.cs | 2 +- .../Hooks/Execution/DiffableEntityHashSet.cs | 4 ++-- .../Hooks/Execution/HookExecutorHelper.cs | 2 +- .../Hooks/Traversal/ChildNode.cs | 2 +- .../Hooks/Traversal/RelationshipGroup.cs | 6 +++--- .../Hooks/Traversal/RelationshipProxy.cs | 2 +- .../Traversal/RelationshipsFromPreviousLayer.cs | 4 ++-- src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs | 2 +- .../Hooks/Traversal/TraversalHelper.cs | 4 ++-- .../Internal/Exceptions/JsonApiSetupException.cs | 4 ++-- .../Internal/Generics/GenericServiceFactory.cs | 2 +- .../Internal/IdentifiableComparer.cs | 2 +- src/JsonApiDotNetCore/Internal/Query/SortQuery.cs | 2 +- .../Internal/Query/SortQueryContext.cs | 1 + .../Internal/ValidationResults.cs | 2 +- .../Middleware/CurrentRequestMiddleware.cs | 4 ++-- .../Middleware/DefaultExceptionFilter.cs | 2 +- .../Middleware/DefaultTypeMatchFilter.cs | 4 ++-- .../Middleware/QueryParameterFilter.cs | 2 +- .../Models/Annotation/AttrAttribute.cs | 4 ++-- .../Models/Annotation/HasManyThroughAttribute.cs | 2 +- .../Models/Annotation/HasOneAttribute.cs | 2 +- .../Models/Annotation/LinksAttribute.cs | 2 +- .../Models/JsonApiDocuments/Document.cs | 2 +- .../Models/JsonApiDocuments/RelationshipEntry.cs | 2 +- .../Models/JsonApiDocuments/RelationshipLinks.cs | 2 +- .../Models/JsonApiDocuments/ResourceLinks.cs | 6 +++--- .../Models/JsonApiDocuments/ResourceObject.cs | 2 +- .../JsonApiDocuments/ResourceObjectComparer.cs | 4 ++-- src/JsonApiDotNetCore/Models/ResourceAttribute.cs | 2 +- .../Models/ResourceDefinition.cs | 4 ++-- .../RequestServices/CurrentRequest.cs | 2 +- .../RequestServices/TargetedFields.cs | 4 ++-- .../Serialization/Client/DeserializedResponse.cs | 4 ++-- .../Common/ResourceObjectBuilderSettings.cs | 2 +- .../ResourceObjectBuilderSettingsProvider.cs | 2 +- .../Services/ResourceDefinitionProvider.cs | 4 ++-- .../Services/ScopedServiceProvider.cs | 2 +- .../DiscoveryTests/ServiceDiscoveryFacadeTests.cs | 4 ++-- .../Data/EntityRepositoryTests.cs | 4 ++-- .../Extensibility/CustomControllerTests.cs | 2 +- .../NullValuedAttributeHandlingTests.cs | 2 +- .../Acceptance/Extensibility/RequestMetaTests.cs | 2 +- .../HttpMethodRestrictions/HttpReadOnlyTests.cs | 2 +- .../HttpMethodRestrictions/NoHttpDeleteTests.cs | 2 +- .../HttpMethodRestrictions/NoHttpPatchTests.cs | 2 +- .../HttpMethodRestrictions/NoHttpPostTests.cs | 4 ++-- .../Acceptance/KebabCaseFormatterTests.cs | 2 +- .../Acceptance/ManyToManyTests.cs | 2 +- .../ResourceDefinitions/QueryFiltersTests.cs | 2 +- .../ResourceDefinitionTests.cs | 2 +- .../Acceptance/Spec/AttributeFilterTests.cs | 2 +- .../Acceptance/Spec/AttributeSortTests.cs | 2 +- .../Acceptance/Spec/ContentNegotiation.cs | 2 +- .../Acceptance/Spec/CreatingDataTests.cs | 4 ++-- .../Acceptance/Spec/DeeplyNestedInclusionTests.cs | 2 +- .../Acceptance/Spec/DeletingDataTests.cs | 2 +- .../Acceptance/Spec/DocumentTests/Included.cs | 2 +- .../Acceptance/Spec/DocumentTests/Meta.cs | 2 +- .../Spec/DocumentTests/Relationships.cs | 2 +- .../Acceptance/Spec/FetchingDataTests.cs | 2 +- .../Acceptance/Spec/FetchingRelationshipsTests.cs | 2 +- .../Acceptance/Spec/NestedResourceTests.cs | 4 ++-- .../Acceptance/Spec/PagingTests.cs | 4 ++-- .../Acceptance/Spec/QueryParameters.cs | 2 +- .../Acceptance/Spec/SparseFieldSetTests.cs | 2 +- .../Acceptance/Spec/UpdatingDataTests.cs | 2 +- .../Acceptance/Spec/UpdatingRelationshipsTests.cs | 2 +- .../Acceptance/TodoItemsControllerTests.cs | 2 +- .../Extensibility/NoEntityFrameworkTests.cs | 2 +- .../TestScopedServiceProvider.cs | 2 +- test/NoEntityFrameworkTests/TestStartup.cs | 2 +- .../Builders/ContextGraphBuilder_Tests.cs | 12 +++++++----- test/UnitTests/Builders/LinkBuilderTests.cs | 2 +- test/UnitTests/Builders/LinkTests.cs | 2 +- .../Controllers/BaseJsonApiController_Tests.cs | 6 +++--- .../Controllers/JsonApiControllerMixin_Tests.cs | 2 +- .../UnitTests/Data/DefaultEntityRepositoryTest.cs | 2 +- test/UnitTests/DbSetMock.cs | 6 +++--- .../IServiceCollectionExtensionsTests.cs | 4 ++-- test/UnitTests/Extensions/TypeExtensions_Tests.cs | 4 ++-- test/UnitTests/Graph/TypeLocator_Tests.cs | 8 ++++---- test/UnitTests/Internal/JsonApiException_Test.cs | 2 +- .../Internal/ResourceGraphBuilder_Tests.cs | 2 +- test/UnitTests/Internal/TypeHelper_Tests.cs | 4 ++-- .../Middleware/CurrentRequestMiddlewareTests.cs | 4 ++-- test/UnitTests/Models/AttributesEqualsTests.cs | 2 +- test/UnitTests/Models/IdentifiableTests.cs | 4 ++-- test/UnitTests/Models/LinkTests.cs | 4 ++-- test/UnitTests/Models/RelationshipDataTests.cs | 4 ++-- test/UnitTests/Models/ResourceDefinitionTests.cs | 4 ++-- .../QueryParameters/FilterServiceTests.cs | 2 +- .../QueryParameters/IncludeServiceTests.cs | 2 +- .../QueryParameters/OmitDefaultService.cs | 2 +- test/UnitTests/QueryParameters/OmitNullService.cs | 2 +- .../UnitTests/QueryParameters/PageServiceTests.cs | 2 +- .../UnitTests/QueryParameters/SortServiceTests.cs | 2 +- .../QueryParameters/SparseFieldsServiceTests.cs | 2 +- .../ResourceHooks/AffectedEntitiesHelperTests.cs | 8 ++++---- test/UnitTests/ResourceHooks/DiscoveryTests.cs | 10 +++++----- .../Create/AfterCreateTests.cs | 4 ++-- .../Create/BeforeCreateTests.cs | 4 ++-- .../Create/BeforeCreate_WithDbValues_Tests.cs | 2 +- .../Delete/AfterDeleteTests.cs | 2 +- .../Delete/BeforeDeleteTests.cs | 2 +- .../Delete/BeforeDelete_WithDbValue_Tests.cs | 3 +-- .../IdentifiableManyToMany_OnReturnTests.cs | 2 +- .../ManyToMany_OnReturnTests.cs | 2 +- .../ResourceHookExecutor/Read/BeforeReadTests.cs | 2 +- .../Read/IdentifiableManyToMany_AfterReadTests.cs | 2 +- .../Read/ManyToMany_AfterReadTests.cs | 2 +- .../ResourceHookExecutor/ScenarioTests.cs | 2 +- .../Update/AfterUpdateTests.cs | 4 ++-- .../Update/BeforeUpdateTests.cs | 4 ++-- .../Update/BeforeUpdate_WithDbValues_Tests.cs | 2 +- .../Client/RequestSerializerTests.cs | 2 +- .../Client/ResponseDeserializerTests.cs | 2 +- .../Serialization/Common/DocumentBuilderTests.cs | 2 +- .../Serialization/Common/DocumentParserTests.cs | 2 +- .../Common/ResourceObjectBuilderTests.cs | 2 +- .../Serialization/DeserializerTestsSetup.cs | 2 +- .../Serialization/SerializerTestsSetup.cs | 2 +- .../Server/IncludedResourceObjectBuilderTests.cs | 2 +- .../Server/RequestDeserializerTests.cs | 2 +- .../Server/ResponseResourceObjectBuilderTests.cs | 2 +- .../Server/ResponseSerializerTests.cs | 4 ++-- .../Services/EntityResourceService_Tests.cs | 2 +- test/UnitTests/TestModels.cs | 15 +++++++-------- test/UnitTests/TestScopedServiceProvider.cs | 2 +- 171 files changed, 246 insertions(+), 245 deletions(-) diff --git a/benchmarks/BenchmarkResource.cs b/benchmarks/BenchmarkResource.cs index 0d3ae2c8bf..6fe5eea7ca 100644 --- a/benchmarks/BenchmarkResource.cs +++ b/benchmarks/BenchmarkResource.cs @@ -2,7 +2,7 @@ namespace Benchmarks { - public class BenchmarkResource : Identifiable + public sealed class BenchmarkResource : Identifiable { [Attr(BenchmarkResourcePublicNames.NameAttr)] public string Name { get; set; } @@ -17,7 +17,7 @@ public class SubResource : Identifiable public string Value { get; set; } } - public static class BenchmarkResourcePublicNames + internal static class BenchmarkResourcePublicNames { public const string NameAttr = "full-name"; public const string Type = "simple-types"; diff --git a/src/Examples/GettingStarted/Controllers/ArticlesController.cs b/src/Examples/GettingStarted/Controllers/ArticlesController.cs index fec9d3e38d..c25e740825 100644 --- a/src/Examples/GettingStarted/Controllers/ArticlesController.cs +++ b/src/Examples/GettingStarted/Controllers/ArticlesController.cs @@ -6,7 +6,7 @@ namespace GettingStarted { - public class ArticlesController : JsonApiController
+ public sealed class ArticlesController : JsonApiController
{ public ArticlesController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/GettingStarted/Controllers/PeopleController.cs b/src/Examples/GettingStarted/Controllers/PeopleController.cs index 68ff5932ea..e6a9a2a4ff 100644 --- a/src/Examples/GettingStarted/Controllers/PeopleController.cs +++ b/src/Examples/GettingStarted/Controllers/PeopleController.cs @@ -6,7 +6,7 @@ namespace GettingStarted { - public class PeopleController : JsonApiController + public sealed class PeopleController : JsonApiController { public PeopleController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/GettingStarted/Models/Article.cs b/src/Examples/GettingStarted/Models/Article.cs index 96cc704139..e8bf99fcaf 100644 --- a/src/Examples/GettingStarted/Models/Article.cs +++ b/src/Examples/GettingStarted/Models/Article.cs @@ -2,7 +2,7 @@ namespace GettingStarted.Models { - public class Article : Identifiable + public sealed class Article : Identifiable { [Attr] public string Title { get; set; } diff --git a/src/Examples/GettingStarted/Models/Person.cs b/src/Examples/GettingStarted/Models/Person.cs index 74e19c99be..3c5cff596c 100644 --- a/src/Examples/GettingStarted/Models/Person.cs +++ b/src/Examples/GettingStarted/Models/Person.cs @@ -3,7 +3,7 @@ namespace GettingStarted.Models { - public class Person : Identifiable + public sealed class Person : Identifiable { [Attr] public string Name { get; set; } diff --git a/src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs b/src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs index 44a421e112..c12d8946f8 100644 --- a/src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs +++ b/src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs @@ -2,7 +2,7 @@ namespace GettingStarted.ResourceDefinitionExample { - public class Model : Identifiable + public sealed class Model : Identifiable { [Attr] public string DoNotExpose { get; set; } diff --git a/src/Examples/GettingStarted/ResourceDefinitionExample/ModelsController.cs b/src/Examples/GettingStarted/ResourceDefinitionExample/ModelsController.cs index 52478823f8..3b2d83e8c8 100644 --- a/src/Examples/GettingStarted/ResourceDefinitionExample/ModelsController.cs +++ b/src/Examples/GettingStarted/ResourceDefinitionExample/ModelsController.cs @@ -5,7 +5,7 @@ namespace GettingStarted.ResourceDefinitionExample { - public class ModelsController : JsonApiController + public sealed class ModelsController : JsonApiController { public ModelsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/GettingStarted/Startup.cs b/src/Examples/GettingStarted/Startup.cs index c467b9cccd..6c46707d1d 100644 --- a/src/Examples/GettingStarted/Startup.cs +++ b/src/Examples/GettingStarted/Startup.cs @@ -5,7 +5,7 @@ namespace GettingStarted { - public class Startup + public sealed class Startup { public void ConfigureServices(IServiceCollection services) { diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs index ab64bf2c45..4ae287c670 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class ArticlesController : JsonApiController
+ public sealed class ArticlesController : JsonApiController
{ public ArticlesController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/CamelCasedModelsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/CamelCasedModelsController.cs index 588b474c28..3f1ac5e2ed 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/CamelCasedModelsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/CamelCasedModelsController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class KebabCasedModelsController : JsonApiController + public sealed class KebabCasedModelsController : JsonApiController { public KebabCasedModelsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs index 1f38c6aee6..d2268ac09e 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class PassportsController : JsonApiController + public sealed class PassportsController : JsonApiController { public PassportsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs index 85a00aaa02..eae404b7bc 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class PeopleController : JsonApiController + public sealed class PeopleController : JsonApiController { public PeopleController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs index f11e2cee5a..4dfb9232b0 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class PersonRolesController : JsonApiController + public sealed class PersonRolesController : JsonApiController { public PersonRolesController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs index 24a5de6931..d9e1382c33 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class TagsController : JsonApiController + public sealed class TagsController : JsonApiController { public TagsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs index 8bf3a95539..7fea8dc083 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class TodoCollectionsController : JsonApiController + public sealed class TodoCollectionsController : JsonApiController { readonly IDbContextResolver _dbResolver; diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs index ea8dbf8359..d21f6c016d 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class TodoItemsController : JsonApiController + public sealed class TodoItemsController : JsonApiController { public TodoItemsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/UsersController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/UsersController.cs index e96bed2517..e07456cc90 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/UsersController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/UsersController.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCoreExample.Controllers { - public class UsersController : JsonApiController + public sealed class UsersController : JsonApiController { public UsersController( IJsonApiOptions jsonApiOptions, @@ -16,7 +16,7 @@ public UsersController( { } } - public class SuperUsersController : JsonApiController + public sealed class SuperUsersController : JsonApiController { public SuperUsersController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs b/src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs index 17815f9778..cb8876b36a 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs @@ -3,7 +3,7 @@ namespace JsonApiDotNetCoreExample.Data { - public class AppDbContext : DbContext + public sealed class AppDbContext : DbContext { public DbSet TodoItems { get; set; } public DbSet Passports { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Article.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Article.cs index d8fd68c886..7a4a3ca56b 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Article.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Article.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCoreExample.Models { - public class Article : Identifiable + public sealed class Article : Identifiable { [Attr] public string Name { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs b/src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs index 22a63459c7..c1f8ebbf82 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCoreExample.Models { - public class ArticleTag + public sealed class ArticleTag { public int ArticleId { get; set; } public Article Article { get; set; } @@ -24,4 +24,4 @@ public class IdentifiableArticleTag : Identifiable public string SomeMetaData { get; set; } } -} \ No newline at end of file +} diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Author.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Author.cs index fce4e7f9c3..0696b037e3 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Author.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Author.cs @@ -3,7 +3,7 @@ namespace JsonApiDotNetCoreExample.Models { - public class Author : Identifiable + public sealed class Author : Identifiable { [Attr] public string Name { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs index 9aa47a2eca..e7d9336ac9 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCoreExample.Models { - public class Passport : Identifiable + public sealed class Passport : Identifiable { public int? SocialSecurityNumber { get; set; } public bool IsLocked { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs b/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs index a0a1bc8238..58e2c8c67b 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/Person.cs @@ -4,13 +4,13 @@ namespace JsonApiDotNetCoreExample.Models { - public class PersonRole : Identifiable + public sealed class PersonRole : Identifiable { [HasOne] public Person Person { get; set; } } - public class Person : Identifiable, IIsLockable + public sealed class Person : Identifiable, IIsLockable { public bool IsLocked { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs index fb15cdb2e7..3b33a0fc1f 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/TodoItemCollection.cs @@ -5,7 +5,7 @@ namespace JsonApiDotNetCoreExample.Models { [Resource("todoCollections")] - public class TodoItemCollection : Identifiable + public sealed class TodoItemCollection : Identifiable { [Attr] public string Name { get; set; } diff --git a/src/Examples/JsonApiDotNetCoreExample/Models/User.cs b/src/Examples/JsonApiDotNetCoreExample/Models/User.cs index ddf706540b..ef65054c89 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Models/User.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Models/User.cs @@ -8,7 +8,7 @@ public class User : Identifiable [Attr] public string Password { get; set; } } - public class SuperUser : User + public sealed class SuperUser : User { [Attr] public int SecurityLevel { get; set; } } diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs index 192534787d..f074be15bc 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startups/MetaStartup.cs @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExample /// This should be in JsonApiDotNetCoreExampleTests project but changes in .net core 3.0 /// do no longer allow that. See https://github.com/aspnet/AspNetCore/issues/15373. /// - public class MetaStartup : Startup + public sealed class MetaStartup : Startup { public MetaStartup(IWebHostEnvironment env) : base(env) { } @@ -20,7 +20,7 @@ public override void ConfigureServices(IServiceCollection services) } } - public class MetaService : IRequestMeta + public sealed class MetaService : IRequestMeta { public Dictionary GetMeta() { diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs index facfd2bb42..2d990ce784 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs @@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExample /// This should be in JsonApiDotNetCoreExampleTests project but changes in .net core 3.0 /// do no longer allow that. See https://github.com/aspnet/AspNetCore/issues/15373. /// - public class NoDefaultPageSizeStartup : Startup + public sealed class NoDefaultPageSizeStartup : Startup { public NoDefaultPageSizeStartup(IWebHostEnvironment env) : base(env) { } diff --git a/src/Examples/NoEntityFrameworkExample/Controllers/TodoItemsController.cs b/src/Examples/NoEntityFrameworkExample/Controllers/TodoItemsController.cs index c21ee5a837..79b487d721 100644 --- a/src/Examples/NoEntityFrameworkExample/Controllers/TodoItemsController.cs +++ b/src/Examples/NoEntityFrameworkExample/Controllers/TodoItemsController.cs @@ -6,7 +6,7 @@ namespace NoEntityFrameworkExample.Controllers { - public class TodoItemsController : JsonApiController + public sealed class TodoItemsController : JsonApiController { public TodoItemsController( IJsonApiOptions jsonApiOptions, diff --git a/src/Examples/NoEntityFrameworkExample/Data/AppDbContext.cs b/src/Examples/NoEntityFrameworkExample/Data/AppDbContext.cs index e7247108dd..383041c6be 100644 --- a/src/Examples/NoEntityFrameworkExample/Data/AppDbContext.cs +++ b/src/Examples/NoEntityFrameworkExample/Data/AppDbContext.cs @@ -3,7 +3,7 @@ namespace NoEntityFrameworkExample.Data { - public class AppDbContext : DbContext + public sealed class AppDbContext : DbContext { public AppDbContext(DbContextOptions options) : base(options) diff --git a/src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs b/src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs index 7836ecdd58..8e9c7c8674 100644 --- a/src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs +++ b/src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs @@ -3,7 +3,7 @@ namespace NoEntityFrameworkExample.Models { - public class TodoItem : Identifiable + public sealed class TodoItem : Identifiable { public TodoItem() { diff --git a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs index 57d9aa1aca..bbf430060f 100644 --- a/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs +++ b/src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs @@ -11,7 +11,7 @@ namespace NoEntityFrameworkExample.Services { - public class TodoItemService : IResourceService + public sealed class TodoItemService : IResourceService { private readonly string _connectionString; diff --git a/src/Examples/ReportsExample/Models/Report.cs b/src/Examples/ReportsExample/Models/Report.cs index 5bc93edb49..6a682f3dc1 100644 --- a/src/Examples/ReportsExample/Models/Report.cs +++ b/src/Examples/ReportsExample/Models/Report.cs @@ -2,7 +2,7 @@ namespace ReportsExample.Models { - public class Report : Identifiable + public sealed class Report : Identifiable { [Attr] public string Title { get; set; } @@ -11,7 +11,7 @@ public class Report : Identifiable public ComplexType ComplexType { get; set; } } - public class ComplexType + public sealed class ComplexType { public string CompoundPropertyName { get; set; } } diff --git a/src/Examples/ReportsExample/Startup.cs b/src/Examples/ReportsExample/Startup.cs index e586ec2273..6940d2f94d 100644 --- a/src/Examples/ReportsExample/Startup.cs +++ b/src/Examples/ReportsExample/Startup.cs @@ -5,7 +5,7 @@ namespace ReportsExample { - public class Startup + public sealed class Startup { public readonly IConfiguration Config; diff --git a/src/JsonApiDotNetCore/Controllers/DisableQueryAttribute.cs b/src/JsonApiDotNetCore/Controllers/DisableQueryAttribute.cs index d28bd06faf..0dbc45f49a 100644 --- a/src/JsonApiDotNetCore/Controllers/DisableQueryAttribute.cs +++ b/src/JsonApiDotNetCore/Controllers/DisableQueryAttribute.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Controllers { - public class DisableQueryAttribute : Attribute + public sealed class DisableQueryAttribute : Attribute { /// /// Disabled one of the native query parameters for a controller. @@ -26,4 +26,4 @@ public DisableQueryAttribute(string customQueryParams) public string QueryParams { get; } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Controllers/DisableRoutingConventionAttribute.cs b/src/JsonApiDotNetCore/Controllers/DisableRoutingConventionAttribute.cs index a0812007e3..8e23b3fb99 100644 --- a/src/JsonApiDotNetCore/Controllers/DisableRoutingConventionAttribute.cs +++ b/src/JsonApiDotNetCore/Controllers/DisableRoutingConventionAttribute.cs @@ -2,6 +2,6 @@ namespace JsonApiDotNetCore.Controllers { - public class DisableRoutingConventionAttribute : Attribute + public sealed class DisableRoutingConventionAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs b/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs index 58cc56a2d0..35341781dc 100644 --- a/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs +++ b/src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs @@ -27,22 +27,22 @@ private bool CanExecuteAction(string requestMethod) } } - public class HttpReadOnlyAttribute : HttpRestrictAttribute + public sealed class HttpReadOnlyAttribute : HttpRestrictAttribute { protected override string[] Methods { get; } = new string[] { "POST", "PATCH", "DELETE" }; } - public class NoHttpPostAttribute : HttpRestrictAttribute + public sealed class NoHttpPostAttribute : HttpRestrictAttribute { protected override string[] Methods { get; } = new string[] { "POST" }; } - public class NoHttpPatchAttribute : HttpRestrictAttribute + public sealed class NoHttpPatchAttribute : HttpRestrictAttribute { protected override string[] Methods { get; } = new string[] { "PATCH" }; } - public class NoHttpDeleteAttribute : HttpRestrictAttribute + public sealed class NoHttpDeleteAttribute : HttpRestrictAttribute { protected override string[] Methods { get; } = new string[] { "DELETE" }; } diff --git a/src/JsonApiDotNetCore/Data/DbContextResolver.cs b/src/JsonApiDotNetCore/Data/DbContextResolver.cs index 39c1cd8c97..628f44e2ca 100644 --- a/src/JsonApiDotNetCore/Data/DbContextResolver.cs +++ b/src/JsonApiDotNetCore/Data/DbContextResolver.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Data { - public class DbContextResolver : IDbContextResolver + public sealed class DbContextResolver : IDbContextResolver where TContext : DbContext { private readonly TContext _context; diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiInputFormatter.cs b/src/JsonApiDotNetCore/Formatters/JsonApiInputFormatter.cs index f556b7433d..017c5751e0 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiInputFormatter.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiInputFormatter.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Formatters { - public class JsonApiInputFormatter : IInputFormatter + public sealed class JsonApiInputFormatter : IInputFormatter { public bool CanRead(InputFormatterContext context) { diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiOutputFormatter.cs b/src/JsonApiDotNetCore/Formatters/JsonApiOutputFormatter.cs index 6facec6a6a..aed26685d2 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiOutputFormatter.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiOutputFormatter.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Formatters { - public class JsonApiOutputFormatter : IOutputFormatter + public sealed class JsonApiOutputFormatter : IOutputFormatter { public bool CanWriteResult(OutputFormatterCanWriteContext context) { diff --git a/src/JsonApiDotNetCore/Graph/ResourceIdMapper.cs b/src/JsonApiDotNetCore/Graph/ResourceIdMapper.cs index 7252d5c710..4aa9f5b010 100644 --- a/src/JsonApiDotNetCore/Graph/ResourceIdMapper.cs +++ b/src/JsonApiDotNetCore/Graph/ResourceIdMapper.cs @@ -19,9 +19,9 @@ public interface IRelatedIdMapper } /// - public class DefaultRelatedIdMapper : IRelatedIdMapper + public sealed class DefaultRelatedIdMapper : IRelatedIdMapper { /// public string GetRelatedIdPropertyName(string propertyName) => propertyName + "Id"; } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/CamelCaseFormatter.cs b/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/CamelCaseFormatter.cs index 17a94cdcde..8ea50e5dd7 100644 --- a/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/CamelCaseFormatter.cs +++ b/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/CamelCaseFormatter.cs @@ -1,4 +1,4 @@ -using str = JsonApiDotNetCore.Extensions.StringExtensions; +using str = JsonApiDotNetCore.Extensions.StringExtensions; namespace JsonApiDotNetCore.Graph { @@ -31,7 +31,7 @@ namespace JsonApiDotNetCore.Graph /// // > "todoItem" /// /// - public class CamelCaseFormatter: BaseResourceNameFormatter + public sealed class CamelCaseFormatter: BaseResourceNameFormatter { /// public override string ApplyCasingConvention(string properName) => str.Camelize(properName); diff --git a/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/KebabCaseFormatter.cs b/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/KebabCaseFormatter.cs index 42a48a8572..dbf7f1ab86 100644 --- a/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/KebabCaseFormatter.cs +++ b/src/JsonApiDotNetCore/Graph/ResourceNameFormatters/KebabCaseFormatter.cs @@ -1,4 +1,4 @@ -using str = JsonApiDotNetCore.Extensions.StringExtensions; +using str = JsonApiDotNetCore.Extensions.StringExtensions; namespace JsonApiDotNetCore.Graph { @@ -31,7 +31,7 @@ namespace JsonApiDotNetCore.Graph /// // > "todo-item" /// /// - public class KebabCaseFormatter : BaseResourceNameFormatter + public sealed class KebabCaseFormatter : BaseResourceNameFormatter { /// public override string ApplyCasingConvention(string properName) => str.Dasherize(properName); diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs b/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs index 296d5d4914..ebf816d3eb 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs @@ -1,7 +1,7 @@ using System; namespace JsonApiDotNetCore.Hooks { - public class LoadDatabaseValues : Attribute + public sealed class LoadDatabaseValues : Attribute { public readonly bool Value; diff --git a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs index 22cdcc3873..cb1ecbdb64 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/DiffableEntityHashSet.cs @@ -29,7 +29,7 @@ public interface IDiffableEntityHashSet : IEntityHashSet w } /// - public class DiffableEntityHashSet : EntityHashSet, IDiffableEntityHashSet where TResource : class, IIdentifiable + public sealed class DiffableEntityHashSet : EntityHashSet, IDiffableEntityHashSet where TResource : class, IIdentifiable { private readonly HashSet _databaseValues; private readonly bool _databaseValuesLoaded; @@ -98,7 +98,7 @@ private void ThrowNoDbValuesError() /// A wrapper that contains an entity that is affected by the request, /// matched to its current database value /// - public class EntityDiffPair where TResource : class, IIdentifiable + public sealed class EntityDiffPair where TResource : class, IIdentifiable { public EntityDiffPair(TResource entity, TResource databaseValue) { diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index bbe4f7840e..1d14e4264d 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -15,7 +15,7 @@ namespace JsonApiDotNetCore.Hooks { /// - internal class HookExecutorHelper : IHookExecutorHelper + internal sealed class HookExecutorHelper : IHookExecutorHelper { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly IJsonApiOptions _options; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs index 26c5bdfdf1..80c83b4a34 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/ChildNode.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCore.Hooks /// Child node in the tree /// /// - internal class ChildNode : INode where TResource : class, IIdentifiable + internal sealed class ChildNode : INode where TResource : class, IIdentifiable { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; /// diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipGroup.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipGroup.cs index 6f34f1fb7b..c3febd7a3b 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipGroup.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipGroup.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Models; namespace JsonApiDotNetCore.Hooks @@ -9,7 +9,7 @@ internal interface IRelationshipGroup HashSet LeftEntities { get; } } - internal class RelationshipGroup : IRelationshipGroup where TRight : class, IIdentifiable + internal sealed class RelationshipGroup : IRelationshipGroup where TRight : class, IIdentifiable { public RelationshipProxy Proxy { get; } public HashSet LeftEntities { get; } @@ -21,4 +21,4 @@ public RelationshipGroup(RelationshipProxy proxy, HashSet leftEnt RightEntities = rightEntities; } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs index 0b8094e557..3881ebe167 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs @@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Hooks /// it and fire hooks for it, if defined) or not (in which case we skip /// ArticleTags and go directly to Tags. /// - public class RelationshipProxy + internal sealed class RelationshipProxy { readonly bool _isHasManyThrough; readonly bool _skipJoinTable; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs index 2068fa8652..d2085dc2dd 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; using JsonApiDotNetCore.Models; @@ -22,7 +22,7 @@ internal interface IRelationshipsFromPreviousLayer Dictionary GetLeftEntities(); } - internal class RelationshipsFromPreviousLayer : IRelationshipsFromPreviousLayer, IEnumerable> where TRightResource : class, IIdentifiable + internal sealed class RelationshipsFromPreviousLayer : IRelationshipsFromPreviousLayer, IEnumerable> where TRightResource : class, IIdentifiable { readonly IEnumerable> _collection; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs index 588edb6484..f346cdffc7 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RootNode.cs @@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Hooks /// The root node class of the breadth-first-traversal of entity data structures /// as performed by the /// - internal class RootNode : INode where TResource : class, IIdentifiable + internal sealed class RootNode : INode where TResource : class, IIdentifiable { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly RelationshipProxy[] _allRelationshipsToNextLayer; diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 6962d28173..7b14e842b2 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -21,7 +21,7 @@ namespace JsonApiDotNetCore.Hooks /// Typically, the first layer is homogeneous (all entities have the same type), /// and further nodes can be mixed. /// - internal class TraversalHelper : ITraversalHelper + internal sealed class TraversalHelper : ITraversalHelper { private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance; private readonly IResourceGraph _resourceGraph; @@ -314,7 +314,7 @@ IRelationshipGroup CreateRelationshipGroupInstance(Type thisLayerType, Relations /// A helper class that represents all entities in the current layer that /// are being traversed for which hooks will be executed (see IResourceHookExecutor) /// - internal class NodeLayer : IEnumerable + internal sealed class NodeLayer : IEnumerable { readonly List _collection; diff --git a/src/JsonApiDotNetCore/Internal/Exceptions/JsonApiSetupException.cs b/src/JsonApiDotNetCore/Internal/Exceptions/JsonApiSetupException.cs index 34765066be..5ab6400b65 100644 --- a/src/JsonApiDotNetCore/Internal/Exceptions/JsonApiSetupException.cs +++ b/src/JsonApiDotNetCore/Internal/Exceptions/JsonApiSetupException.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Internal { - public class JsonApiSetupException : Exception + public sealed class JsonApiSetupException : Exception { public JsonApiSetupException(string message) : base(message) { } @@ -10,4 +10,4 @@ public JsonApiSetupException(string message) public JsonApiSetupException(string message, Exception innerException) : base(message, innerException) { } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Internal/Generics/GenericServiceFactory.cs b/src/JsonApiDotNetCore/Internal/Generics/GenericServiceFactory.cs index bc834f4733..acd3f88b06 100644 --- a/src/JsonApiDotNetCore/Internal/Generics/GenericServiceFactory.cs +++ b/src/JsonApiDotNetCore/Internal/Generics/GenericServiceFactory.cs @@ -31,7 +31,7 @@ public interface IGenericServiceFactory TInterface Get(Type openGenericType, Type resourceType, Type keyType); } - public class GenericServiceFactory : IGenericServiceFactory + public sealed class GenericServiceFactory : IGenericServiceFactory { private readonly IServiceProvider _serviceProvider; diff --git a/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs b/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs index 2837cbd8ac..fbec8f67cb 100644 --- a/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs +++ b/src/JsonApiDotNetCore/Internal/IdentifiableComparer.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Internal /// /// Compares `IIdentifiable` with each other based on ID /// - public class IdentifiableComparer : IEqualityComparer + public sealed class IdentifiableComparer : IEqualityComparer { internal static readonly IdentifiableComparer Instance = new IdentifiableComparer(); diff --git a/src/JsonApiDotNetCore/Internal/Query/SortQuery.cs b/src/JsonApiDotNetCore/Internal/Query/SortQuery.cs index 840de80ddb..36c703e71b 100644 --- a/src/JsonApiDotNetCore/Internal/Query/SortQuery.cs +++ b/src/JsonApiDotNetCore/Internal/Query/SortQuery.cs @@ -1,4 +1,4 @@ -namespace JsonApiDotNetCore.Internal.Query +namespace JsonApiDotNetCore.Internal.Query { /// /// Internal representation of the raw articles?sort[field] query from the URL. diff --git a/src/JsonApiDotNetCore/Internal/Query/SortQueryContext.cs b/src/JsonApiDotNetCore/Internal/Query/SortQueryContext.cs index ce1395102d..68d591e5e9 100644 --- a/src/JsonApiDotNetCore/Internal/Query/SortQueryContext.cs +++ b/src/JsonApiDotNetCore/Internal/Query/SortQueryContext.cs @@ -7,6 +7,7 @@ namespace JsonApiDotNetCore.Internal.Query public class SortQueryContext : BaseQueryContext { public SortQueryContext(SortQuery sortQuery) : base(sortQuery) { } + public SortDirection Direction => Query.Direction; } } diff --git a/src/JsonApiDotNetCore/Internal/ValidationResults.cs b/src/JsonApiDotNetCore/Internal/ValidationResults.cs index 7a07b0256a..d13b5c65da 100644 --- a/src/JsonApiDotNetCore/Internal/ValidationResults.cs +++ b/src/JsonApiDotNetCore/Internal/ValidationResults.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Internal { - public class ValidationResult + public sealed class ValidationResult { public ValidationResult(LogLevel logLevel, string message) { diff --git a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs index 8c7f25ae60..6b7adf2c20 100644 --- a/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs +++ b/src/JsonApiDotNetCore/Middleware/CurrentRequestMiddleware.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Middleware /// /// This sets all necessary parameters relating to the HttpContext for JADNC /// - public class CurrentRequestMiddleware + public sealed class CurrentRequestMiddleware { private readonly RequestDelegate _next; private HttpContext _httpContext; @@ -132,7 +132,7 @@ private string GetNameSpace() return _options.Namespace; } - protected bool PathIsRelationship() + private bool PathIsRelationship() { var actionName = (string)_routeValues["action"]; return actionName.ToLower().Contains("relationships"); diff --git a/src/JsonApiDotNetCore/Middleware/DefaultExceptionFilter.cs b/src/JsonApiDotNetCore/Middleware/DefaultExceptionFilter.cs index 195e38a9e4..9ba23becdf 100644 --- a/src/JsonApiDotNetCore/Middleware/DefaultExceptionFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/DefaultExceptionFilter.cs @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.Middleware /// /// Global exception filter that wraps any thrown error with a JsonApiException. /// - public class DefaultExceptionFilter : ActionFilterAttribute, IExceptionFilter + public sealed class DefaultExceptionFilter : ActionFilterAttribute, IExceptionFilter { private readonly ILogger _logger; diff --git a/src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs b/src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs index 8ba43dbc26..5e428fa772 100644 --- a/src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Internal.Contracts; @@ -10,7 +10,7 @@ namespace JsonApiDotNetCore.Middleware /// /// Action filter used to verify the incoming type matches the target type, else return a 409 /// - public class DefaultTypeMatchFilter : IActionFilter + public sealed class DefaultTypeMatchFilter : IActionFilter { private readonly IResourceContextProvider _provider; diff --git a/src/JsonApiDotNetCore/Middleware/QueryParameterFilter.cs b/src/JsonApiDotNetCore/Middleware/QueryParameterFilter.cs index 9e66363da2..863bf7ad3a 100644 --- a/src/JsonApiDotNetCore/Middleware/QueryParameterFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/QueryParameterFilter.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Middleware { - public class QueryParameterActionFilter : IAsyncActionFilter, IQueryParameterActionFilter + public sealed class QueryParameterActionFilter : IAsyncActionFilter, IQueryParameterActionFilter { private readonly IQueryParameterDiscovery _queryParser; public QueryParameterActionFilter(IQueryParameterDiscovery queryParser) => _queryParser = queryParser; diff --git a/src/JsonApiDotNetCore/Models/Annotation/AttrAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/AttrAttribute.cs index 211d94a174..7e7dacbb7d 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/AttrAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/AttrAttribute.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCore.Models { - public class AttrAttribute : Attribute, IResourceField + public sealed class AttrAttribute : Attribute, IResourceField { /// /// Defines a public attribute exposed by the API @@ -123,7 +123,7 @@ private PropertyInfo GetResourceProperty(object resource) /// /// Whether or not the provided exposed name is equivalent to the one defined in on the model /// - public virtual bool Is(string publicRelationshipName) + public bool Is(string publicRelationshipName) => string.Equals(publicRelationshipName, PublicAttributeName, StringComparison.OrdinalIgnoreCase); } } diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs index f906ba59de..84ff0cfcfa 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs @@ -26,7 +26,7 @@ namespace JsonApiDotNetCore.Models /// public List<ArticleTag> ArticleTags { get; set; } /// /// - public class HasManyThroughAttribute : HasManyAttribute + public sealed class HasManyThroughAttribute : HasManyAttribute { /// /// Create a HasMany relationship through a many-to-many join relationship. diff --git a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs index da77c4730d..7e7152f1e8 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCore.Models { - public class HasOneAttribute : RelationshipAttribute + public sealed class HasOneAttribute : RelationshipAttribute { /// /// Create a HasOne relational link to another entity diff --git a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs index 2281e14a73..b677769744 100644 --- a/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs +++ b/src/JsonApiDotNetCore/Models/Annotation/LinksAttribute.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCore.Models.Links { [AttributeUsage(AttributeTargets.Class, Inherited = false)] - public class LinksAttribute : Attribute + public sealed class LinksAttribute : Attribute { public LinksAttribute(Link topLevelLinks = Link.NotConfigured, Link resourceLinks = Link.NotConfigured, Link relationshipLinks = Link.NotConfigured) { diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/Document.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/Document.cs index 0b74574ee9..b42bb75766 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/Document.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/Document.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.Models /// /// https://jsonapi.org/format/#document-structure /// - public class Document : ExposableData + public sealed class Document : ExposableData { /// /// see "meta" in https://jsonapi.org/format/#document-top-level diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipEntry.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipEntry.cs index d0c718b721..5a19067f49 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipEntry.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipEntry.cs @@ -3,7 +3,7 @@ namespace JsonApiDotNetCore.Models { - public class RelationshipEntry : ExposableData + public sealed class RelationshipEntry : ExposableData { [JsonProperty("links", NullValueHandling = NullValueHandling.Ignore)] public RelationshipLinks Links { get; set; } diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipLinks.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipLinks.cs index c728df6777..e8076af318 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipLinks.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/RelationshipLinks.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Models.Links { - public class RelationshipLinks + public sealed class RelationshipLinks { /// /// see "links" bulletin at https://jsonapi.org/format/#document-resource-object-relationships diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceLinks.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceLinks.cs index ea701f7681..0ff07ad7e5 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceLinks.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceLinks.cs @@ -1,8 +1,8 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace JsonApiDotNetCore.Models.Links { - public class ResourceLinks + public sealed class ResourceLinks { /// /// https://jsonapi.org/format/#document-resource-object-links @@ -10,4 +10,4 @@ public class ResourceLinks [JsonProperty("self", NullValueHandling = NullValueHandling.Ignore)] public string Self { get; set; } } -} \ No newline at end of file +} diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObject.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObject.cs index 55dc096adb..e46525755b 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObject.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObject.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCore.Models { - public class ResourceObject : ResourceIdentifierObject + public sealed class ResourceObject : ResourceIdentifierObject { [JsonProperty("attributes", NullValueHandling = NullValueHandling.Ignore)] public Dictionary Attributes { get; set; } diff --git a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObjectComparer.cs b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObjectComparer.cs index e7da59bb98..442a918687 100644 --- a/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObjectComparer.cs +++ b/src/JsonApiDotNetCore/Models/JsonApiDocuments/ResourceObjectComparer.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Models; namespace JsonApiDotNetCore.Builders { - class ResourceObjectComparer : IEqualityComparer + internal sealed class ResourceObjectComparer : IEqualityComparer { public bool Equals(ResourceObject x, ResourceObject y) { diff --git a/src/JsonApiDotNetCore/Models/ResourceAttribute.cs b/src/JsonApiDotNetCore/Models/ResourceAttribute.cs index c74396c4c7..7b618ea654 100644 --- a/src/JsonApiDotNetCore/Models/ResourceAttribute.cs +++ b/src/JsonApiDotNetCore/Models/ResourceAttribute.cs @@ -2,7 +2,7 @@ namespace JsonApiDotNetCore.Models { - public class ResourceAttribute : Attribute + public sealed class ResourceAttribute : Attribute { public ResourceAttribute(string resourceName) { diff --git a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs index 78201ec14d..07a71edaf2 100644 --- a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs +++ b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs @@ -127,7 +127,7 @@ public virtual void BeforeImplicitUpdateRelationship(IRelationshipsDictionary for usage details. /// - public class QueryFilters : Dictionary, FilterQuery, IQueryable>> { } + public sealed class QueryFilters : Dictionary, FilterQuery, IQueryable>> { } /// /// Define a the default sort order if no sort key is provided. @@ -166,6 +166,6 @@ public class QueryFilters : Dictionary, Filte /// method signature. /// See for usage details. /// - public class PropertySortOrder : List<(Expression>, SortDirection)> { } + public sealed class PropertySortOrder : List<(Expression>, SortDirection)> { } } } diff --git a/src/JsonApiDotNetCore/RequestServices/CurrentRequest.cs b/src/JsonApiDotNetCore/RequestServices/CurrentRequest.cs index 053cf39cfb..a5bbc31a1b 100644 --- a/src/JsonApiDotNetCore/RequestServices/CurrentRequest.cs +++ b/src/JsonApiDotNetCore/RequestServices/CurrentRequest.cs @@ -4,7 +4,7 @@ namespace JsonApiDotNetCore.Managers { - class CurrentRequest : ICurrentRequest + internal sealed class CurrentRequest : ICurrentRequest { private ResourceContext _resourceContext; public string BasePath { get; set; } diff --git a/src/JsonApiDotNetCore/RequestServices/TargetedFields.cs b/src/JsonApiDotNetCore/RequestServices/TargetedFields.cs index b5a4ee18d8..d5e3d2919a 100644 --- a/src/JsonApiDotNetCore/RequestServices/TargetedFields.cs +++ b/src/JsonApiDotNetCore/RequestServices/TargetedFields.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Models; namespace JsonApiDotNetCore.Serialization { /// - public class TargetedFields : ITargetedFields + public sealed class TargetedFields : ITargetedFields { /// public List Attributes { get; set; } = new List(); diff --git a/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs b/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs index 2851d6a382..6bae9a9370 100644 --- a/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs +++ b/src/JsonApiDotNetCore/Serialization/Client/DeserializedResponse.cs @@ -20,7 +20,7 @@ public abstract class DeserializedResponseBase /// Represents a deserialized document with "single data". /// /// Type of the resource in the primary data - public class DeserializedSingleResponse : DeserializedResponseBase where TResource : class, IIdentifiable + public sealed class DeserializedSingleResponse : DeserializedResponseBase where TResource : class, IIdentifiable { public TResource Data { get; set; } } @@ -29,7 +29,7 @@ public class DeserializedSingleResponse : DeserializedResponseBase wh /// Represents a deserialized document with "many data". /// /// Type of the resource(s) in the primary data - public class DeserializedListResponse : DeserializedResponseBase where TResource : class, IIdentifiable + public sealed class DeserializedListResponse : DeserializedResponseBase where TResource : class, IIdentifiable { public List Data { get; set; } } diff --git a/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilderSettings.cs b/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilderSettings.cs index e64578e333..2e84b7988e 100644 --- a/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilderSettings.cs +++ b/src/JsonApiDotNetCore/Serialization/Common/ResourceObjectBuilderSettings.cs @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Serialization /// Options used to configure how fields of a model get serialized into /// a json:api . /// - public class ResourceObjectBuilderSettings + public sealed class ResourceObjectBuilderSettings { /// Omit null values from attributes /// Omit default values from attributes diff --git a/src/JsonApiDotNetCore/Serialization/Server/ResourceObjectBuilderSettingsProvider.cs b/src/JsonApiDotNetCore/Serialization/Server/ResourceObjectBuilderSettingsProvider.cs index 9e4541c201..eaddf81891 100644 --- a/src/JsonApiDotNetCore/Serialization/Server/ResourceObjectBuilderSettingsProvider.cs +++ b/src/JsonApiDotNetCore/Serialization/Server/ResourceObjectBuilderSettingsProvider.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.Serialization.Server /// This implementation of the behaviour provider reads the query params that /// can, if provided, override the settings in . /// - public class ResourceObjectBuilderSettingsProvider : IResourceObjectBuilderSettingsProvider + public sealed class ResourceObjectBuilderSettingsProvider : IResourceObjectBuilderSettingsProvider { private readonly IOmitDefaultService _defaultAttributeValues; private readonly IOmitNullService _nullAttributeValues; diff --git a/src/JsonApiDotNetCore/Services/ResourceDefinitionProvider.cs b/src/JsonApiDotNetCore/Services/ResourceDefinitionProvider.cs index 5a9e4b655c..32005a984d 100644 --- a/src/JsonApiDotNetCore/Services/ResourceDefinitionProvider.cs +++ b/src/JsonApiDotNetCore/Services/ResourceDefinitionProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using JsonApiDotNetCore.Internal.Contracts; using JsonApiDotNetCore.Models; using JsonApiDotNetCore.Services; @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Query { /// - internal class ResourceDefinitionProvider : IResourceDefinitionProvider + internal sealed class ResourceDefinitionProvider : IResourceDefinitionProvider { private readonly IResourceGraph _resourceContextProvider; private readonly IScopedServiceProvider _serviceProvider; diff --git a/src/JsonApiDotNetCore/Services/ScopedServiceProvider.cs b/src/JsonApiDotNetCore/Services/ScopedServiceProvider.cs index 51248f7593..975c87029c 100644 --- a/src/JsonApiDotNetCore/Services/ScopedServiceProvider.cs +++ b/src/JsonApiDotNetCore/Services/ScopedServiceProvider.cs @@ -14,7 +14,7 @@ public interface IScopedServiceProvider : IServiceProvider { } /// /// A service provider that uses the current HttpContext request scope /// - public class RequestScopedServiceProvider : IScopedServiceProvider + public sealed class RequestScopedServiceProvider : IScopedServiceProvider { private readonly IHttpContextAccessor _httpContextAccessor; diff --git a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs index 4afe430546..9a62c99457 100644 --- a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs +++ b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs @@ -22,7 +22,7 @@ namespace DiscoveryTests { - public class ServiceDiscoveryFacadeTests + public sealed class ServiceDiscoveryFacadeTests { private readonly IServiceCollection _services = new ServiceCollection(); private readonly ResourceGraphBuilder _resourceGraphBuilder = new ResourceGraphBuilder(); @@ -96,7 +96,7 @@ public void AddCurrentAssembly_Adds_Repositories_To_Container() Assert.IsType(services.GetService>()); } - public class TestModel : Identifiable { } + public sealed class TestModel : Identifiable { } public class TestModelService : DefaultResourceService { diff --git a/test/IntegrationTests/Data/EntityRepositoryTests.cs b/test/IntegrationTests/Data/EntityRepositoryTests.cs index da97640992..033cd3a399 100644 --- a/test/IntegrationTests/Data/EntityRepositoryTests.cs +++ b/test/IntegrationTests/Data/EntityRepositoryTests.cs @@ -15,7 +15,7 @@ namespace JADNC.IntegrationTests.Data { - public class EntityRepositoryTests + public sealed class EntityRepositoryTests { [Fact] public async Task UpdateAsync_AttributesUpdated_ShouldHaveSpecificallyThoseAttributesUpdated() @@ -176,7 +176,7 @@ private static TodoItem[] TodoItems(params int[] ids) return ids.Select(id => new TodoItem { Id = id }).ToArray(); } - private class IdComparer : IEqualityComparer + private sealed class IdComparer : IEqualityComparer where T : IIdentifiable { public bool Equals(T x, T y) => x?.StringId == y?.StringId; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs index a9f0d15da4..a5dacd3921 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs @@ -15,7 +15,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility { [Collection("WebHostCollection")] - public class CustomControllerTests + public sealed class CustomControllerTests { private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NullValuedAttributeHandlingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NullValuedAttributeHandlingTests.cs index baeb5deef7..1aaa56a309 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NullValuedAttributeHandlingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NullValuedAttributeHandlingTests.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility { [Collection("WebHostCollection")] - public class NullValuedAttributeHandlingTests : IAsyncLifetime + public sealed class NullValuedAttributeHandlingTests : IAsyncLifetime { private readonly TestFixture _fixture; private readonly AppDbContext _dbContext; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs index 57d6840cbf..46128676c5 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility { [Collection("WebHostCollection")] - public class RequestMetaTests + public sealed class RequestMetaTests { private readonly TestFixture _fixture; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/HttpReadOnlyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/HttpReadOnlyTests.cs index 0d3de444ee..3171eddace 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/HttpReadOnlyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/HttpReadOnlyTests.cs @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class HttpReadOnlyTests + public sealed class HttpReadOnlyTests { [Fact] public async Task Allows_GET_Requests() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs index 2d8f3c940f..0702a77c25 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpDeleteTests.cs @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class NoHttpDeleteTests + public sealed class NoHttpDeleteTests { [Fact] public async Task Allows_GET_Requests() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs index 94347db048..97975c505a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPatchTests.cs @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class NoHttpPatchTests + public sealed class NoHttpPatchTests { [Fact] public async Task Allows_GET_Requests() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPostTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPostTests.cs index b1dda90c29..8aa2be9c0f 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPostTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/HttpMethodRestrictions/NoHttpPostTests.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using JsonApiDotNetCoreExample; @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class NoHttpPostTests + public sealed class NoHttpPostTests { [Fact] public async Task Allows_GET_Requests() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs index 5932ca25ee..2aaf4ef4dd 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/KebabCaseFormatterTests.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { - public class KebabCaseFormatterTests : FunctionalTestCollection + public sealed class KebabCaseFormatterTests : FunctionalTestCollection { private readonly Faker _faker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs index 883c1073e8..0a2a86afd5 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs @@ -18,7 +18,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class ManyToManyTests + public sealed class ManyToManyTests { private static readonly Faker
_articleFaker = new Faker
() .RuleFor(a => a.Name, f => f.Random.AlphaNumeric(10)) diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs index 25131b9ae8..6c312ddd3d 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/QueryFiltersTests.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class QueryFiltersTests + public sealed class QueryFiltersTests { private readonly TestFixture _fixture; private readonly AppDbContext _context; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs index 206ab5472b..4dc6c68228 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ResourceDefinitions/ResourceDefinitionTests.cs @@ -17,7 +17,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class ResourceDefinitionTests + public sealed class ResourceDefinitionTests { private readonly TestFixture _fixture; private readonly AppDbContext _context; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs index b5c2a2138a..2f77e2f9bb 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs @@ -16,7 +16,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class AttributeFilterTests + public sealed class AttributeFilterTests { private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs index 84e2adcdc2..7998df3431 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeSortTests.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class AttributeSortTests + public sealed class AttributeSortTests { private readonly TestFixture _fixture; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs index e6b67a78ed..dc026a6fd1 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ContentNegotiation.cs @@ -10,7 +10,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class ContentNegotiation + public sealed class ContentNegotiation { [Fact] public async Task Server_Sends_Correct_ContentType_Header() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs index fb363e00c7..d1acf36c65 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { - public class CreatingDataTests : FunctionalTestCollection + public sealed class CreatingDataTests : FunctionalTestCollection { private readonly Faker _todoItemFaker; private readonly Faker _personFaker; @@ -282,7 +282,7 @@ public async Task CreateRelationship_ToManyWithImplicitRemove_IsCreated() } - public class CreatingDataWithClientEnabledIdTests : FunctionalTestCollection + public sealed class CreatingDataWithClientEnabledIdTests : FunctionalTestCollection { private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs index d513280175..4a2dd5a3ed 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeeplyNestedInclusionTests.cs @@ -17,7 +17,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class DeeplyNestedInclusionTests + public sealed class DeeplyNestedInclusionTests { private readonly TestFixture _fixture; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs index 625882667b..eb18ce542d 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DeletingDataTests.cs @@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class DeletingDataTests + public sealed class DeletingDataTests { private readonly AppDbContext _context; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs index bfd5d10c04..0c844e0d23 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs @@ -17,7 +17,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests { [Collection("WebHostCollection")] - public class Included + public sealed class Included { private readonly AppDbContext _context; private readonly Faker _personFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs index 6a61ab092f..71b3559965 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs @@ -15,7 +15,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests { [Collection("WebHostCollection")] - public class Meta + public sealed class Meta { private readonly TestFixture _fixture; private readonly AppDbContext _context; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs index 3df536b3e5..96b6d3d6fa 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Relationships.cs @@ -15,7 +15,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests { [Collection("WebHostCollection")] - public class Relationships + public sealed class Relationships { private readonly AppDbContext _context; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs index 5973fc2c8a..40b5bd0f71 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs @@ -16,7 +16,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class FetchingDataTests + public sealed class FetchingDataTests { private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs index 8812d49383..3c816d1ec4 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class FetchingRelationshipsTests + public sealed class FetchingRelationshipsTests { private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/NestedResourceTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/NestedResourceTests.cs index e023590da5..222ec684cd 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/NestedResourceTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/NestedResourceTests.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Net; using System.Threading.Tasks; using Bogus; @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { - public class NestedResourceTests : FunctionalTestCollection + public sealed class NestedResourceTests : FunctionalTestCollection { private readonly Faker _todoItemFaker; private readonly Faker _personFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs index 7538831918..d7fb0d11fc 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/PagingTests.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class PagingTests : TestFixture + public sealed class PagingTests : TestFixture { private readonly TestFixture _fixture; private readonly Faker _todoItemFaker; @@ -138,7 +138,7 @@ public async Task Pagination_OnGivenPage_DisplaysCorrectTopLevelLinks(int pageNu } } - private class IdComparer : IEqualityComparer + private sealed class IdComparer : IEqualityComparer where T : IIdentifiable { public bool Equals(T x, T y) => x?.StringId == y?.StringId; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs index 7efe3f594f..2cacb7c302 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/QueryParameters.cs @@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class QueryParameters + public sealed class QueryParameters { [Fact] public async Task Server_Returns_400_ForUnknownQueryParam() diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs index 9c385a479a..558268aa44 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/SparseFieldSetTests.cs @@ -23,7 +23,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class SparseFieldSetTests + public sealed class SparseFieldSetTests { private readonly AppDbContext _dbContext; private readonly IResourceGraph _resourceGraph; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs index 13ffaf063c..bbe645d17c 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs @@ -19,7 +19,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class UpdatingDataTests : EndToEndTest + public sealed class UpdatingDataTests : EndToEndTest { private readonly AppDbContext _context; private readonly Faker _todoItemFaker; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs index 0bc7ace7de..d2c0a46ba0 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingRelationshipsTests.cs @@ -18,7 +18,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec { [Collection("WebHostCollection")] - public class UpdatingRelationshipsTests + public sealed class UpdatingRelationshipsTests { private readonly TestFixture _fixture; private AppDbContext _context; diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs index 7e1b6cbe53..2825371b7a 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs @@ -20,7 +20,7 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance { [Collection("WebHostCollection")] - public class TodoItemControllerTests + public sealed class TodoItemControllerTests { private readonly TestFixture _fixture; private readonly AppDbContext _context; diff --git a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs index bd9036b0bf..ca21468d76 100644 --- a/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs +++ b/test/NoEntityFrameworkTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs @@ -12,7 +12,7 @@ namespace NoEntityFrameworkTests.Acceptance.Extensibility { - public class NoEntityFrameworkTests : IClassFixture + public sealed class NoEntityFrameworkTests : IClassFixture { private readonly TestFixture _fixture; diff --git a/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs b/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs index 1800efe8a5..6d209dc491 100644 --- a/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs +++ b/test/NoEntityFrameworkTests/TestScopedServiceProvider.cs @@ -5,7 +5,7 @@ namespace NoEntityFrameworkTests { - public class TestScopedServiceProvider : IScopedServiceProvider + public sealed class TestScopedServiceProvider : IScopedServiceProvider { private readonly IServiceProvider _serviceProvider; private readonly Mock _httpContextAccessorMock = new Mock(); diff --git a/test/NoEntityFrameworkTests/TestStartup.cs b/test/NoEntityFrameworkTests/TestStartup.cs index ad0022a197..986706c9db 100644 --- a/test/NoEntityFrameworkTests/TestStartup.cs +++ b/test/NoEntityFrameworkTests/TestStartup.cs @@ -5,7 +5,7 @@ namespace NoEntityFrameworkTests { - public class TestStartup : Startup + public sealed class TestStartup : Startup { public TestStartup(IWebHostEnvironment env) : base(env) { } diff --git a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs index abfea6b890..bb42e1a4fc 100644 --- a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs +++ b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs @@ -14,10 +14,12 @@ namespace UnitTests { - public class ResourceGraphBuilder_Tests + public sealed class ResourceGraphBuilder_Tests { - class NonDbResource : Identifiable { } - class DbResource : Identifiable { } + sealed class NonDbResource : Identifiable { } + + sealed class DbResource : Identifiable { } + class TestContext : DbContext { public DbSet DbResources { get; set; } @@ -118,7 +120,7 @@ public void Relationships_Without_Names_Specified_Will_Use_Default_Formatter() Assert.Equal("relatedResources", resource.Relationships.Single(r => r.IsHasMany).PublicRelationshipName); } - public class TestResource : Identifiable + public sealed class TestResource : Identifiable { [Attr] public string CompoundAttribute { get; set; } [HasOne] public RelatedResource RelatedResource { get; set; } @@ -127,7 +129,7 @@ public class TestResource : Identifiable public class RelatedResource : Identifiable { } - public class CamelCaseNameFormatter : IResourceNameFormatter + public sealed class CamelCaseNameFormatter : IResourceNameFormatter { public string ApplyCasingConvention(string properName) => ToCamelCase(properName); diff --git a/test/UnitTests/Builders/LinkBuilderTests.cs b/test/UnitTests/Builders/LinkBuilderTests.cs index 71374a8b72..1867c31b08 100644 --- a/test/UnitTests/Builders/LinkBuilderTests.cs +++ b/test/UnitTests/Builders/LinkBuilderTests.cs @@ -13,7 +13,7 @@ namespace UnitTests { - public class LinkBuilderTests + public sealed class LinkBuilderTests { private readonly IPageService _pageService; private readonly Mock _provider = new Mock(); diff --git a/test/UnitTests/Builders/LinkTests.cs b/test/UnitTests/Builders/LinkTests.cs index 96d49b2f22..df1504930c 100644 --- a/test/UnitTests/Builders/LinkTests.cs +++ b/test/UnitTests/Builders/LinkTests.cs @@ -3,7 +3,7 @@ namespace UnitTests.Builders { - public class LinkTests + public sealed class LinkTests { [Theory] [InlineData(Link.All, Link.Self, true)] diff --git a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs index ea61a83b0c..aec9a5a438 100644 --- a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs +++ b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs @@ -13,14 +13,14 @@ namespace UnitTests { - public class BaseJsonApiController_Tests + public sealed class BaseJsonApiController_Tests { - public class Resource : Identifiable + public sealed class Resource : Identifiable { [Attr] public string TestAttribute { get; set; } } - public class ResourceController : BaseJsonApiController + public sealed class ResourceController : BaseJsonApiController { public ResourceController( IJsonApiOptions jsonApiOptions, diff --git a/test/UnitTests/Controllers/JsonApiControllerMixin_Tests.cs b/test/UnitTests/Controllers/JsonApiControllerMixin_Tests.cs index 00f265daed..51fb451c42 100644 --- a/test/UnitTests/Controllers/JsonApiControllerMixin_Tests.cs +++ b/test/UnitTests/Controllers/JsonApiControllerMixin_Tests.cs @@ -6,7 +6,7 @@ namespace UnitTests { - public class JsonApiControllerMixin_Tests : JsonApiControllerMixin + public sealed class JsonApiControllerMixin_Tests : JsonApiControllerMixin { [Fact] diff --git a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs index 8461d2cc9f..3633000a70 100644 --- a/test/UnitTests/Data/DefaultEntityRepositoryTest.cs +++ b/test/UnitTests/Data/DefaultEntityRepositoryTest.cs @@ -12,7 +12,7 @@ namespace UnitTests.Data { - public class DefaultEntityRepositoryTest + public sealed class DefaultEntityRepositoryTest { [Fact] diff --git a/test/UnitTests/DbSetMock.cs b/test/UnitTests/DbSetMock.cs index 3d1ad10db0..2921a8247b 100644 --- a/test/UnitTests/DbSetMock.cs +++ b/test/UnitTests/DbSetMock.cs @@ -37,7 +37,7 @@ public static Mock> AsDbSetMock(this List list) where T : class } } -internal class TestAsyncQueryProvider : IAsyncQueryProvider +internal sealed class TestAsyncQueryProvider : IAsyncQueryProvider { private readonly IQueryProvider _inner; @@ -83,7 +83,7 @@ TResult IAsyncQueryProvider.ExecuteAsync(Expression expression, Cancell } } -internal class TestAsyncEnumerable : EnumerableQuery, IAsyncEnumerable, IQueryable +internal sealed class TestAsyncEnumerable : EnumerableQuery, IAsyncEnumerable, IQueryable { public TestAsyncEnumerable(Expression expression) : base(expression) @@ -102,7 +102,7 @@ public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToke IQueryProvider IQueryable.Provider => new TestAsyncQueryProvider(this); } -internal class TestAsyncEnumerator : IAsyncEnumerator +internal sealed class TestAsyncEnumerator : IAsyncEnumerator { private readonly IEnumerator _inner; diff --git a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs index 80fc27167c..d42be16de5 100644 --- a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs +++ b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs @@ -22,7 +22,7 @@ namespace UnitTests.Extensions { - public class IServiceCollectionExtensionsTests + public sealed class IServiceCollectionExtensionsTests { [Fact] public void AddJsonApiInternals_Adds_All_Required_Services() @@ -154,7 +154,7 @@ public void AddJsonApi_With_Context_Uses_Resource_Type_Name_If_NoOtherSpecified( Assert.Equal("intResources", resource.ResourceName); } - public class IntResource : Identifiable { } + public sealed class IntResource : Identifiable { } public class GuidResource : Identifiable { } private class IntResourceService : IResourceService diff --git a/test/UnitTests/Extensions/TypeExtensions_Tests.cs b/test/UnitTests/Extensions/TypeExtensions_Tests.cs index b473ceb5e3..849b80d1f6 100644 --- a/test/UnitTests/Extensions/TypeExtensions_Tests.cs +++ b/test/UnitTests/Extensions/TypeExtensions_Tests.cs @@ -6,7 +6,7 @@ namespace UnitTests.Extensions { - public class TypeExtensions_Tests + public sealed class TypeExtensions_Tests { [Fact] public void GetCollection_Creates_List_If_T_Implements_Interface() @@ -63,7 +63,7 @@ public void Implements_Returns_False_If_Type_DoesNot_Implement_Interface() Assert.False(result); } - private class Model : IIdentifiable + private sealed class Model : IIdentifiable { public string StringId { get; set; } } diff --git a/test/UnitTests/Graph/TypeLocator_Tests.cs b/test/UnitTests/Graph/TypeLocator_Tests.cs index ca70b32581..dfd4e723c4 100644 --- a/test/UnitTests/Graph/TypeLocator_Tests.cs +++ b/test/UnitTests/Graph/TypeLocator_Tests.cs @@ -5,7 +5,7 @@ namespace UnitTests.Internal { - public class TypeLocator_Tests + public sealed class TypeLocator_Tests { [Fact] public void GetGenericInterfaceImplementation_Gets_Implementation() @@ -139,11 +139,11 @@ public void TryGetResourceDescriptor_Returns_False_If_Type_Is_IIdentifiable() public interface IGenericInterface { } - public class Implementation : IGenericInterface { } + public sealed class Implementation : IGenericInterface { } public class BaseType { } - public class DerivedType : BaseType { } + public sealed class DerivedType : BaseType { } - public class Model : Identifiable { } + public sealed class Model : Identifiable { } } diff --git a/test/UnitTests/Internal/JsonApiException_Test.cs b/test/UnitTests/Internal/JsonApiException_Test.cs index 57ac29d480..989db27ef3 100644 --- a/test/UnitTests/Internal/JsonApiException_Test.cs +++ b/test/UnitTests/Internal/JsonApiException_Test.cs @@ -3,7 +3,7 @@ namespace UnitTests.Internal { - public class JsonApiException_Test + public sealed class JsonApiException_Test { [Fact] public void Can_GetStatusCode() diff --git a/test/UnitTests/Internal/ResourceGraphBuilder_Tests.cs b/test/UnitTests/Internal/ResourceGraphBuilder_Tests.cs index e765004ac5..e6475f242d 100644 --- a/test/UnitTests/Internal/ResourceGraphBuilder_Tests.cs +++ b/test/UnitTests/Internal/ResourceGraphBuilder_Tests.cs @@ -7,7 +7,7 @@ namespace UnitTests.Internal { - public class ResourceGraphBuilder_Tests + public sealed class ResourceGraphBuilder_Tests { [Fact] public void AddDbContext_Does_Not_Throw_If_Context_Contains_Members_That_DoNot_Implement_IIdentifiable() diff --git a/test/UnitTests/Internal/TypeHelper_Tests.cs b/test/UnitTests/Internal/TypeHelper_Tests.cs index 287444aea4..387d0cfdc3 100644 --- a/test/UnitTests/Internal/TypeHelper_Tests.cs +++ b/test/UnitTests/Internal/TypeHelper_Tests.cs @@ -5,7 +5,7 @@ namespace UnitTests.Internal { - public class TypeHelper_Tests + public sealed class TypeHelper_Tests { [Fact] public void Can_Convert_DateTimeOffsets() @@ -136,7 +136,7 @@ private enum TestEnum Test = 1 } - private class ComplexType : BaseType + private sealed class ComplexType : BaseType { public int Property { get; set; } } diff --git a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs index 6f9ce979ec..120c0cd41d 100644 --- a/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs +++ b/test/UnitTests/Middleware/CurrentRequestMiddlewareTests.cs @@ -15,7 +15,7 @@ namespace UnitTests.Middleware { - public class CurrentRequestMiddlewareTests + public sealed class CurrentRequestMiddlewareTests { [Fact] public async Task ParseUrlBase_ObfuscatedIdClass_ShouldSetIdCorrectly() @@ -92,7 +92,7 @@ public async Task ParseUrlBase_UrlHasIncorrectBaseIdSet_ShouldThrowException(str Assert.Contains(baseId, exception.Message); } - class InvokeConfiguration + private sealed class InvokeConfiguration { public CurrentRequestMiddleware MiddleWare; public HttpContext HttpContext; diff --git a/test/UnitTests/Models/AttributesEqualsTests.cs b/test/UnitTests/Models/AttributesEqualsTests.cs index 39ca127372..5aa4ba1bd1 100644 --- a/test/UnitTests/Models/AttributesEqualsTests.cs +++ b/test/UnitTests/Models/AttributesEqualsTests.cs @@ -3,7 +3,7 @@ namespace UnitTests.Models { - public class AttributesEqualsTests + public sealed class AttributesEqualsTests { [Fact] public void HasManyAttribute_Equals_Returns_True_When_Same_Name() diff --git a/test/UnitTests/Models/IdentifiableTests.cs b/test/UnitTests/Models/IdentifiableTests.cs index 954daedb8d..971a936e39 100644 --- a/test/UnitTests/Models/IdentifiableTests.cs +++ b/test/UnitTests/Models/IdentifiableTests.cs @@ -3,7 +3,7 @@ namespace UnitTests.Models { - public class IdentifiableTests + public sealed class IdentifiableTests { [Fact] public void Can_Set_StringId_To_Value_Type() @@ -27,7 +27,7 @@ public void GetStringId_Returns_EmptyString_If_Object_Is_Null() Assert.Equal(string.Empty, stringId); } - private class IntId : Identifiable { + private sealed class IntId : Identifiable { public string ExposedGetStringId(object value) => GetStringId(value); } } diff --git a/test/UnitTests/Models/LinkTests.cs b/test/UnitTests/Models/LinkTests.cs index a1b64e1ea6..69ef23d577 100644 --- a/test/UnitTests/Models/LinkTests.cs +++ b/test/UnitTests/Models/LinkTests.cs @@ -1,9 +1,9 @@ -using JsonApiDotNetCore.Models.Links; +using JsonApiDotNetCore.Models.Links; using Xunit; namespace UnitTests.Models { - public class LinkTests + public sealed class LinkTests { [Fact] public void All_Contains_All_Flags_Except_None() diff --git a/test/UnitTests/Models/RelationshipDataTests.cs b/test/UnitTests/Models/RelationshipDataTests.cs index eaa52440e6..8eb271ff52 100644 --- a/test/UnitTests/Models/RelationshipDataTests.cs +++ b/test/UnitTests/Models/RelationshipDataTests.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; +using System.Collections.Generic; using JsonApiDotNetCore.Models; using Newtonsoft.Json.Linq; using Xunit; namespace UnitTests.Models { - public class RelationshipDataTests + public sealed class RelationshipDataTests { [Fact] public void Setting_ExposeData_To_List_Sets_ManyData() diff --git a/test/UnitTests/Models/ResourceDefinitionTests.cs b/test/UnitTests/Models/ResourceDefinitionTests.cs index d7e635b8eb..67f7fdf40f 100644 --- a/test/UnitTests/Models/ResourceDefinitionTests.cs +++ b/test/UnitTests/Models/ResourceDefinitionTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.Models { - public class ResourceDefinition_Scenario_Tests + public sealed class ResourceDefinition_Scenario_Tests { [Fact] public void Request_Filter_Uses_Member_Expression() @@ -43,7 +43,7 @@ public class Model : Identifiable [Attr] public string Prop { get; set; } } - public class RequestFilteredResource : ResourceDefinition + public sealed class RequestFilteredResource : ResourceDefinition { // this constructor will be resolved from the container // that means you can take on any dependency that is also defined in the container diff --git a/test/UnitTests/QueryParameters/FilterServiceTests.cs b/test/UnitTests/QueryParameters/FilterServiceTests.cs index 68937ee793..df7390124a 100644 --- a/test/UnitTests/QueryParameters/FilterServiceTests.cs +++ b/test/UnitTests/QueryParameters/FilterServiceTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.QueryParameters { - public class FilterServiceTests : QueryParametersUnitTestCollection + public sealed class FilterServiceTests : QueryParametersUnitTestCollection { public FilterService GetService() { diff --git a/test/UnitTests/QueryParameters/IncludeServiceTests.cs b/test/UnitTests/QueryParameters/IncludeServiceTests.cs index 33ad5ac671..d2eef40f9c 100644 --- a/test/UnitTests/QueryParameters/IncludeServiceTests.cs +++ b/test/UnitTests/QueryParameters/IncludeServiceTests.cs @@ -8,7 +8,7 @@ namespace UnitTests.QueryParameters { - public class IncludeServiceTests : QueryParametersUnitTestCollection + public sealed class IncludeServiceTests : QueryParametersUnitTestCollection { public IncludeService GetService(ResourceContext resourceContext = null) diff --git a/test/UnitTests/QueryParameters/OmitDefaultService.cs b/test/UnitTests/QueryParameters/OmitDefaultService.cs index 497942e4f9..32b5aa0976 100644 --- a/test/UnitTests/QueryParameters/OmitDefaultService.cs +++ b/test/UnitTests/QueryParameters/OmitDefaultService.cs @@ -6,7 +6,7 @@ namespace UnitTests.QueryParameters { - public class OmitDefaultServiceTests : QueryParametersUnitTestCollection + public sealed class OmitDefaultServiceTests : QueryParametersUnitTestCollection { public OmitDefaultService GetService(bool @default, bool @override) { diff --git a/test/UnitTests/QueryParameters/OmitNullService.cs b/test/UnitTests/QueryParameters/OmitNullService.cs index 448971d129..98758cd171 100644 --- a/test/UnitTests/QueryParameters/OmitNullService.cs +++ b/test/UnitTests/QueryParameters/OmitNullService.cs @@ -6,7 +6,7 @@ namespace UnitTests.QueryParameters { - public class OmitNullServiceTests : QueryParametersUnitTestCollection + public sealed class OmitNullServiceTests : QueryParametersUnitTestCollection { public OmitNullService GetService(bool @default, bool @override) { diff --git a/test/UnitTests/QueryParameters/PageServiceTests.cs b/test/UnitTests/QueryParameters/PageServiceTests.cs index cabeae7c4c..d157d1efda 100644 --- a/test/UnitTests/QueryParameters/PageServiceTests.cs +++ b/test/UnitTests/QueryParameters/PageServiceTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.QueryParameters { - public class PageServiceTests : QueryParametersUnitTestCollection + public sealed class PageServiceTests : QueryParametersUnitTestCollection { public IPageService GetService(int? maximumPageSize = null, int? maximumPageNumber = null) { diff --git a/test/UnitTests/QueryParameters/SortServiceTests.cs b/test/UnitTests/QueryParameters/SortServiceTests.cs index efbb078f70..ca86183626 100644 --- a/test/UnitTests/QueryParameters/SortServiceTests.cs +++ b/test/UnitTests/QueryParameters/SortServiceTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.QueryParameters { - public class SortServiceTests : QueryParametersUnitTestCollection + public sealed class SortServiceTests : QueryParametersUnitTestCollection { public SortService GetService() { diff --git a/test/UnitTests/QueryParameters/SparseFieldsServiceTests.cs b/test/UnitTests/QueryParameters/SparseFieldsServiceTests.cs index 6b0df9e779..c615854066 100644 --- a/test/UnitTests/QueryParameters/SparseFieldsServiceTests.cs +++ b/test/UnitTests/QueryParameters/SparseFieldsServiceTests.cs @@ -8,7 +8,7 @@ namespace UnitTests.QueryParameters { - public class SparseFieldsServiceTests : QueryParametersUnitTestCollection + public sealed class SparseFieldsServiceTests : QueryParametersUnitTestCollection { public SparseFieldsService GetService(ResourceContext resourceContext = null) { diff --git a/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs b/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs index 7b450c4351..34be2b6ea8 100644 --- a/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs +++ b/test/UnitTests/ResourceHooks/AffectedEntitiesHelperTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks.AffectedEntities { - public class Dummy : Identifiable + public sealed class Dummy : Identifiable { public string SomeUpdatedProperty { get; set; } public string SomeNotUpdatedProperty { get; set; } @@ -21,10 +21,10 @@ public class Dummy : Identifiable } public class NotTargeted : Identifiable { } - public class ToMany : Identifiable { } - public class ToOne : Identifiable { } + public sealed class ToMany : Identifiable { } + public sealed class ToOne : Identifiable { } - public class RelationshipDictionaryTests + public sealed class RelationshipDictionaryTests { public readonly HasOneAttribute FirstToOneAttr; public readonly HasOneAttribute SecondToOneAttr; diff --git a/test/UnitTests/ResourceHooks/DiscoveryTests.cs b/test/UnitTests/ResourceHooks/DiscoveryTests.cs index e655ab8222..de8319c314 100644 --- a/test/UnitTests/ResourceHooks/DiscoveryTests.cs +++ b/test/UnitTests/ResourceHooks/DiscoveryTests.cs @@ -10,10 +10,10 @@ namespace UnitTests.ResourceHooks { - public class DiscoveryTests + public sealed class DiscoveryTests { public class Dummy : Identifiable { } - public class DummyResourceDefinition : ResourceDefinition + public sealed class DummyResourceDefinition : ResourceDefinition { public DummyResourceDefinition() : base(new ResourceGraphBuilder().AddResource().Build()) { } @@ -46,7 +46,7 @@ protected ResourceDefinitionBase(IResourceGraph resourceGraph) : base(resourceGr public override void AfterDelete(HashSet entities, ResourcePipeline pipeline, bool succeeded) { } } - public class AnotherDummyResourceDefinition : ResourceDefinitionBase + public sealed class AnotherDummyResourceDefinition : ResourceDefinitionBase { public AnotherDummyResourceDefinition() : base(new ResourceGraphBuilder().AddResource().Build()) { } } @@ -62,7 +62,7 @@ public void HookDiscovery_InheritanceSubclass_CanDiscover() } public class YetAnotherDummy : Identifiable { } - public class YetAnotherDummyResourceDefinition : ResourceDefinition + public sealed class YetAnotherDummyResourceDefinition : ResourceDefinition { public YetAnotherDummyResourceDefinition() : base(new ResourceGraphBuilder().AddResource().Build()) { } @@ -94,7 +94,7 @@ public void HookDiscovery_InheritanceWithGenericSubclass_CanDiscover() Assert.Contains(ResourceHook.AfterDelete, hookConfig.ImplementedHooks); } - public class GenericDummyResourceDefinition : ResourceDefinition where TResource : class, IIdentifiable + public sealed class GenericDummyResourceDefinition : ResourceDefinition where TResource : class, IIdentifiable { public GenericDummyResourceDefinition() : base(new ResourceGraphBuilder().AddResource().Build()) { } diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/AfterCreateTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/AfterCreateTests.cs index d91231280e..4dafef66a4 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/AfterCreateTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/AfterCreateTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using System.Collections.Generic; @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class AfterCreateTests : HooksTestsSetup + public sealed class AfterCreateTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.AfterCreate, ResourceHook.AfterUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreateTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreateTests.cs index a5438b624d..64c2e24e9b 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreateTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreateTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using System.Collections.Generic; @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeCreateTests : HooksTestsSetup + public sealed class BeforeCreateTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeCreate, ResourceHook.BeforeUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs index e52067291d..c5ca7ac86f 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreate_WithDbValues_Tests.cs @@ -9,7 +9,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeCreate_WithDbValues_Tests : HooksTestsSetup + public sealed class BeforeCreate_WithDbValues_Tests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeCreate, ResourceHook.BeforeImplicitUpdateRelationship, ResourceHook.BeforeUpdateRelationship }; private readonly ResourceHook[] targetHooksNoImplicit = { ResourceHook.BeforeCreate, ResourceHook.BeforeUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs index 2ce85c0da3..b029e89043 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class AfterDeleteTests : HooksTestsSetup + public sealed class AfterDeleteTests : HooksTestsSetup { readonly ResourceHook[] targetHooks = { ResourceHook.AfterDelete }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs index 631feeed95..d6493c2f61 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDeleteTests.cs @@ -5,7 +5,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeDeleteTests : HooksTestsSetup + public sealed class BeforeDeleteTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeDelete }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs index 5fdf18dcb1..032af05430 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/BeforeDelete_WithDbValue_Tests.cs @@ -7,10 +7,9 @@ using System.Linq; using Xunit; - namespace UnitTests.ResourceHooks { - public class BeforeDelete_WithDbValues_Tests : HooksTestsSetup + public sealed class BeforeDelete_WithDbValues_Tests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeDelete, ResourceHook.BeforeImplicitUpdateRelationship, ResourceHook.BeforeUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs index 9e6fa35790..d14dcdc3f5 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/IdentifiableManyToMany_OnReturnTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks { - public class IdentifiableManyToMany_OnReturnTests : HooksTestsSetup + public sealed class IdentifiableManyToMany_OnReturnTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.OnReturn }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs index 57ad54dd75..378fe22606 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks { - public class ManyToMany_OnReturnTests : HooksTestsSetup + public sealed class ManyToMany_OnReturnTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.OnReturn }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs index 8c915f3d42..19748c2c0d 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/BeforeReadTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeReadTests : HooksTestsSetup + public sealed class BeforeReadTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeRead }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs index f002136ac9..c2a1fd8e1b 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/IdentifiableManyToMany_AfterReadTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks { - public class IdentifiableManyToMany_AfterReadTests : HooksTestsSetup + public sealed class IdentifiableManyToMany_AfterReadTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.AfterRead }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs index b94f80655e..19039e2ff2 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Read/ManyToMany_AfterReadTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.ResourceHooks { - public class ManyToMany_AfterReadTests : HooksTestsSetup + public sealed class ManyToMany_AfterReadTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.AfterRead }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs index f2cb44ddd8..9cdec75f65 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ScenarioTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class SameEntityTypeTests : HooksTestsSetup + public sealed class SameEntityTypeTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.OnReturn }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/AfterUpdateTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/AfterUpdateTests.cs index 148c80cf68..3979a124e6 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/AfterUpdateTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/AfterUpdateTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using System.Collections.Generic; @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class AfterUpdateTests : HooksTestsSetup + public sealed class AfterUpdateTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.AfterUpdate, ResourceHook.AfterUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdateTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdateTests.cs index 65047e81c2..a4fcdd22e2 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdateTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdateTests.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Hooks; +using JsonApiDotNetCore.Hooks; using JsonApiDotNetCoreExample.Models; using Moq; using System.Collections.Generic; @@ -6,7 +6,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeUpdateTests : HooksTestsSetup + public sealed class BeforeUpdateTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeUpdate, ResourceHook.BeforeUpdateRelationship }; diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs index 4542107549..05f6108041 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Update/BeforeUpdate_WithDbValues_Tests.cs @@ -9,7 +9,7 @@ namespace UnitTests.ResourceHooks { - public class BeforeUpdate_WithDbValues_Tests : HooksTestsSetup + public sealed class BeforeUpdate_WithDbValues_Tests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.BeforeUpdate, ResourceHook.BeforeImplicitUpdateRelationship, ResourceHook.BeforeUpdateRelationship }; private readonly ResourceHook[] targetHooksNoImplicit = { ResourceHook.BeforeUpdate, ResourceHook.BeforeUpdateRelationship }; diff --git a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs index 3f038c70ef..783c49c11a 100644 --- a/test/UnitTests/Serialization/Client/RequestSerializerTests.cs +++ b/test/UnitTests/Serialization/Client/RequestSerializerTests.cs @@ -8,7 +8,7 @@ namespace UnitTests.Serialization.Client { - public class RequestSerializerTests : SerializerTestsSetup + public sealed class RequestSerializerTests : SerializerTestsSetup { private readonly RequestSerializer _serializer; diff --git a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs index 0ef49c5069..fa9436d699 100644 --- a/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs +++ b/test/UnitTests/Serialization/Client/ResponseDeserializerTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.Serialization.Client { - public class ResponseDeserializerTests : DeserializerTestsSetup + public sealed class ResponseDeserializerTests : DeserializerTestsSetup { private readonly Dictionary _linkValues = new Dictionary(); private readonly ResponseDeserializer _deserializer; diff --git a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs index 169968ad9d..69b7f17d75 100644 --- a/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentBuilderTests.cs @@ -7,7 +7,7 @@ namespace UnitTests.Serialization.Serializer { - public class BaseDocumentBuilderTests : SerializerTestsSetup + public sealed class BaseDocumentBuilderTests : SerializerTestsSetup { private readonly TestDocumentBuilder _builder; diff --git a/test/UnitTests/Serialization/Common/DocumentParserTests.cs b/test/UnitTests/Serialization/Common/DocumentParserTests.cs index 6695a1e51e..360cb2c775 100644 --- a/test/UnitTests/Serialization/Common/DocumentParserTests.cs +++ b/test/UnitTests/Serialization/Common/DocumentParserTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.Serialization.Deserializer { - public class BaseDocumentParserTests : DeserializerTestsSetup + public sealed class BaseDocumentParserTests : DeserializerTestsSetup { private readonly TestDocumentParser _deserializer; diff --git a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs index 4b14f884c3..0aded6e7f9 100644 --- a/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Common/ResourceObjectBuilderTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.Serialization.Serializer { - public class ResourceObjectBuilderTests : SerializerTestsSetup + public sealed class ResourceObjectBuilderTests : SerializerTestsSetup { private readonly ResourceObjectBuilder _builder; diff --git a/test/UnitTests/Serialization/DeserializerTestsSetup.cs b/test/UnitTests/Serialization/DeserializerTestsSetup.cs index d8f9dcea20..79d1a83666 100644 --- a/test/UnitTests/Serialization/DeserializerTestsSetup.cs +++ b/test/UnitTests/Serialization/DeserializerTestsSetup.cs @@ -7,7 +7,7 @@ namespace UnitTests.Serialization { public class DeserializerTestsSetup : SerializationTestsSetupBase { - protected class TestDocumentParser : BaseDocumentParser + protected sealed class TestDocumentParser : BaseDocumentParser { public TestDocumentParser(IResourceGraph resourceGraph) : base(resourceGraph) { } diff --git a/test/UnitTests/Serialization/SerializerTestsSetup.cs b/test/UnitTests/Serialization/SerializerTestsSetup.cs index 21930e2212..3b7ac36d81 100644 --- a/test/UnitTests/Serialization/SerializerTestsSetup.cs +++ b/test/UnitTests/Serialization/SerializerTestsSetup.cs @@ -105,7 +105,7 @@ protected IIncludeService GetIncludedRelationships(List - protected class TestDocumentBuilder : BaseDocumentBuilder + protected sealed class TestDocumentBuilder : BaseDocumentBuilder { public TestDocumentBuilder(IResourceObjectBuilder resourceObjectBuilder) : base(resourceObjectBuilder) { } diff --git a/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs index 019a083eac..e0dca46bd8 100644 --- a/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Server/IncludedResourceObjectBuilderTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.Serialization.Server { - public class IncludedResourceObjectBuilderTests : SerializerTestsSetup + public sealed class IncludedResourceObjectBuilderTests : SerializerTestsSetup { [Fact] public void BuildIncluded_DeeplyNestedCircularChainOfSingleData_CanBuild() diff --git a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs index 2aad229907..d1c47e6dca 100644 --- a/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs +++ b/test/UnitTests/Serialization/Server/RequestDeserializerTests.cs @@ -10,7 +10,7 @@ namespace UnitTests.Serialization.Server { - public class RequestDeserializerTests : DeserializerTestsSetup + public sealed class RequestDeserializerTests : DeserializerTestsSetup { private readonly RequestDeserializer _deserializer; private readonly Mock _fieldsManagerMock = new Mock(); diff --git a/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs b/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs index 7795990eff..f26d6234a7 100644 --- a/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseResourceObjectBuilderTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.Serialization.Server { - public class ResponseResourceObjectBuilderTests : SerializerTestsSetup + public sealed class ResponseResourceObjectBuilderTests : SerializerTestsSetup { private readonly List _relationshipsForBuild; private const string _relationshipName = "dependents"; diff --git a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs index 7412a0479b..a93e2a242d 100644 --- a/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs +++ b/test/UnitTests/Serialization/Server/ResponseSerializerTests.cs @@ -9,7 +9,7 @@ namespace UnitTests.Serialization.Server { - public class ResponseSerializerTests : SerializerTestsSetup + public sealed class ResponseSerializerTests : SerializerTestsSetup { [Fact] public void SerializeSingle_ResourceWithDefaultTargetFields_CanSerialize() @@ -476,7 +476,7 @@ public void SerializeError_CustomError_CanSerialize() Assert.Equal(expectedJson, result); } - class CustomError : Error + private sealed class CustomError : Error { public CustomError(int status, string title, string detail, string myProp) : base(status, title, detail) diff --git a/test/UnitTests/Services/EntityResourceService_Tests.cs b/test/UnitTests/Services/EntityResourceService_Tests.cs index f0a99df980..7f0cedffd6 100644 --- a/test/UnitTests/Services/EntityResourceService_Tests.cs +++ b/test/UnitTests/Services/EntityResourceService_Tests.cs @@ -16,7 +16,7 @@ namespace UnitTests.Services { - public class EntityResourceService_Tests + public sealed class EntityResourceService_Tests { private readonly Mock> _repositoryMock = new Mock>(); private readonly IResourceGraph _resourceGraph; diff --git a/test/UnitTests/TestModels.cs b/test/UnitTests/TestModels.cs index 8abcc84b8e..208c323e61 100644 --- a/test/UnitTests/TestModels.cs +++ b/test/UnitTests/TestModels.cs @@ -4,8 +4,7 @@ namespace UnitTests.TestModels { - - public class TestResource : Identifiable + public sealed class TestResource : Identifiable { [Attr] public string StringField { get; set; } [Attr] public DateTime DateTimeField { get; set; } @@ -27,24 +26,24 @@ public class ComplexType public string CompoundName { get; set; } } - public class OneToOnePrincipal : IdentifiableWithAttribute + public sealed class OneToOnePrincipal : IdentifiableWithAttribute { [HasOne] public OneToOneDependent Dependent { get; set; } } - public class OneToOneDependent : IdentifiableWithAttribute + public sealed class OneToOneDependent : IdentifiableWithAttribute { [HasOne] public OneToOnePrincipal Principal { get; set; } public int? PrincipalId { get; set; } } - public class OneToOneRequiredDependent : IdentifiableWithAttribute + public sealed class OneToOneRequiredDependent : IdentifiableWithAttribute { [HasOne] public OneToOnePrincipal Principal { get; set; } public int PrincipalId { get; set; } } - public class OneToManyDependent : IdentifiableWithAttribute + public sealed class OneToManyDependent : IdentifiableWithAttribute { [HasOne] public OneToManyPrincipal Principal { get; set; } public int? PrincipalId { get; set; } @@ -56,7 +55,7 @@ public class OneToManyRequiredDependent : IdentifiableWithAttribute public int PrincipalId { get; set; } } - public class OneToManyPrincipal : IdentifiableWithAttribute + public sealed class OneToManyPrincipal : IdentifiableWithAttribute { [HasMany] public List Dependents { get; set; } } @@ -66,7 +65,7 @@ public class IdentifiableWithAttribute : Identifiable [Attr] public string AttributeMember { get; set; } } - public class MultipleRelationshipsPrincipalPart : IdentifiableWithAttribute + public sealed class MultipleRelationshipsPrincipalPart : IdentifiableWithAttribute { [HasOne] public OneToOneDependent PopulatedToOne { get; set; } [HasOne] public OneToOneDependent EmptyToOne { get; set; } diff --git a/test/UnitTests/TestScopedServiceProvider.cs b/test/UnitTests/TestScopedServiceProvider.cs index 6e73079bb6..c770ce681e 100644 --- a/test/UnitTests/TestScopedServiceProvider.cs +++ b/test/UnitTests/TestScopedServiceProvider.cs @@ -5,7 +5,7 @@ namespace UnitTests { - public class TestScopedServiceProvider : IScopedServiceProvider + public sealed class TestScopedServiceProvider : IScopedServiceProvider { private readonly IServiceProvider _serviceProvider; private readonly Mock _httpContextAccessorMock = new Mock(); From e96260f365438d216ce2fb32a2a508479660159e Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 16:55:05 +0100 Subject: [PATCH 70/73] =?UTF-8?q?Fixed:=20=EF=BB=BFInconsistent=20modifier?= =?UTF-8?q?s=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/Program.cs | 4 +-- .../Controllers/TodoCollectionsController.cs | 2 +- src/JsonApiDotNetCore/Graph/TypeLocator.cs | 2 +- .../Hooks/Discovery/HooksDiscovery.cs | 2 +- .../Hooks/Execution/HookExecutorHelper.cs | 13 ++++---- .../Hooks/ResourceHookExecutor.cs | 30 +++++++++---------- .../Hooks/Traversal/RelationshipProxy.cs | 4 +-- .../RelationshipsFromPreviousLayer.cs | 2 +- .../Hooks/Traversal/TraversalHelper.cs | 28 ++++++++--------- .../QueryParameterServices/SortService.cs | 2 +- .../Builders/ContextGraphBuilder_Tests.cs | 6 ++-- .../Delete/AfterDeleteTests.cs | 2 +- .../ManyToMany_OnReturnTests.cs | 2 +- .../ResourceHooks/ResourceHooksTestsSetup.cs | 14 ++++----- 14 files changed, 56 insertions(+), 57 deletions(-) diff --git a/benchmarks/Program.cs b/benchmarks/Program.cs index 474bb5725c..396f8786cb 100644 --- a/benchmarks/Program.cs +++ b/benchmarks/Program.cs @@ -5,9 +5,9 @@ namespace Benchmarks { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { var switcher = new BenchmarkSwitcher(new[] { diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs index 7fea8dc083..ccdcb088ca 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs @@ -14,7 +14,7 @@ namespace JsonApiDotNetCoreExample.Controllers { public sealed class TodoCollectionsController : JsonApiController { - readonly IDbContextResolver _dbResolver; + private readonly IDbContextResolver _dbResolver; public TodoCollectionsController( IJsonApiOptions jsonApiOptions, diff --git a/src/JsonApiDotNetCore/Graph/TypeLocator.cs b/src/JsonApiDotNetCore/Graph/TypeLocator.cs index 557a518703..9fd4f5a458 100644 --- a/src/JsonApiDotNetCore/Graph/TypeLocator.cs +++ b/src/JsonApiDotNetCore/Graph/TypeLocator.cs @@ -10,7 +10,7 @@ namespace JsonApiDotNetCore.Graph /// /// Used to locate types and facilitate auto-resource discovery /// - static class TypeLocator + internal static class TypeLocator { private static readonly Dictionary> _identifiableTypeCache = new Dictionary>(); diff --git a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs index 96f7e9a5df..6505ccef97 100644 --- a/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs +++ b/src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs @@ -46,7 +46,7 @@ public HooksDiscovery(IServiceProvider provider) /// Discovers the implemented hooks for a model. ///
/// The implemented hooks for model. - void DiscoverImplementedHooks(Type containerType) + private void DiscoverImplementedHooks(Type containerType) { if (containerType == null || containerType == _boundResourceDefinitionType) { diff --git a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs index 1d14e4264d..22a0dc9956 100644 --- a/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs @@ -105,21 +105,20 @@ public bool ShouldLoadDbValues(Type entityType, ResourceHook hook) return _options.LoadDatabaseValues; } - bool ShouldExecuteHook(RightType entityType, ResourceHook hook) + private bool ShouldExecuteHook(RightType entityType, ResourceHook hook) { var discovery = GetHookDiscovery(entityType); return discovery.ImplementedHooks.Contains(hook); } - - void CheckForTargetHookExistence() + private void CheckForTargetHookExistence() { if (!_targetedHooksForRelatedEntities.Any()) throw new InvalidOperationException("Something is not right in the breadth first traversal of resource hook: " + "trying to get meta information when no allowed hooks are set"); } - IHooksDiscovery GetHookDiscovery(Type entityType) + private IHooksDiscovery GetHookDiscovery(Type entityType) { if (!_hookDiscoveries.TryGetValue(entityType, out IHooksDiscovery discovery)) { @@ -129,7 +128,7 @@ IHooksDiscovery GetHookDiscovery(Type entityType) return discovery; } - IEnumerable GetWhereAndInclude(IEnumerable ids, RelationshipAttribute[] relationshipsToNextLayer) where TResource : class, IIdentifiable + private IEnumerable GetWhereAndInclude(IEnumerable ids, RelationshipAttribute[] relationshipsToNextLayer) where TResource : class, IIdentifiable { var repo = GetRepository(); var query = repo.Get().Where(e => ids.Contains(e.Id)); @@ -140,7 +139,7 @@ IEnumerable GetWhereAndInclude(IEnumerable ids, return query.ToList(); } - IResourceReadRepository GetRepository() where TResource : class, IIdentifiable + private IResourceReadRepository GetRepository() where TResource : class, IIdentifiable { return _genericProcessorFactory.Get>(typeof(IResourceReadRepository<,>), typeof(TResource), typeof(TId)); } @@ -189,7 +188,7 @@ public Dictionary LoadImplicitlyAffected( return implicitlyAffected.ToDictionary(kvp => kvp.Key, kvp => TypeHelper.CreateHashSetFor(kvp.Key.RightType, kvp.Value)); } - bool IsHasManyThrough(KeyValuePair kvp, + private bool IsHasManyThrough(KeyValuePair kvp, out IEnumerable entities, out RelationshipAttribute attr) { diff --git a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs index 0937ac972b..54ac1c5053 100644 --- a/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs +++ b/src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs @@ -182,7 +182,7 @@ public void AfterDelete(IEnumerable entities, ResourcePipe /// Along the way, creates a traversable node from the root entity set. ///
/// true, if hook was implemented, false otherwise. - bool GetHook(ResourceHook target, IEnumerable entities, + private bool GetHook(ResourceHook target, IEnumerable entities, out IResourceHookContainer container, out RootNode node) where TResource : class, IIdentifiable { @@ -194,7 +194,7 @@ bool GetHook(ResourceHook target, IEnumerable entities, /// /// Traverses the nodes in a . /// - void Traverse(NodeLayer currentLayer, ResourceHook target, Action action) + private void Traverse(NodeLayer currentLayer, ResourceHook target, Action action) { if (!currentLayer.AnyEntities()) return; foreach (INode node in currentLayer) @@ -213,7 +213,7 @@ void Traverse(NodeLayer currentLayer, ResourceHook target, Action - void RecursiveBeforeRead(List relationshipChain, ResourcePipeline pipeline, List calledContainers) + private void RecursiveBeforeRead(List relationshipChain, ResourcePipeline pipeline, List calledContainers) { var relationship = relationshipChain.First(); if (!calledContainers.Contains(relationship.RightType)) @@ -238,7 +238,7 @@ void RecursiveBeforeRead(List relationshipChain, Resource /// First the BeforeUpdateRelationship should be for owner1, then the /// BeforeImplicitUpdateRelationship hook should be fired for /// owner2, and lastly the BeforeImplicitUpdateRelationship for article2. - void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer layer) + private void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer layer) { foreach (INode node in layer) { @@ -318,7 +318,7 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer layer) /// with its inverse relationship attribute. /// /// Entities grouped by relationship attribute - Dictionary ReplaceKeysWithInverseRelationships(Dictionary entitiesByRelationship) + private Dictionary ReplaceKeysWithInverseRelationships(Dictionary entitiesByRelationship) { // when Article has one Owner (HasOneAttribute:owner) is set, there is no guarantee // that the inverse attribute was also set (Owner has one Article: HasOneAttr:article). @@ -332,7 +332,7 @@ Dictionary ReplaceKeysWithInverseRelationshi /// Given a source of entities, gets the implicitly affected entities /// from the database and calls the BeforeImplicitUpdateRelationship hook. /// - void FireForAffectedImplicits(Type entityTypeToInclude, Dictionary implicitsTarget, ResourcePipeline pipeline, IEnumerable existingImplicitEntities = null) + private void FireForAffectedImplicits(Type entityTypeToInclude, Dictionary implicitsTarget, ResourcePipeline pipeline, IEnumerable existingImplicitEntities = null) { var container = _executorHelper.GetResourceHookContainer(entityTypeToInclude, ResourceHook.BeforeImplicitUpdateRelationship); if (container == null) return; @@ -349,7 +349,7 @@ void FireForAffectedImplicits(Type entityTypeToInclude, Dictionary /// The collection returned from the hook /// The pipeline from which the hook was fired - void ValidateHookResponse(IEnumerable returnedList, ResourcePipeline pipeline = 0) + private void ValidateHookResponse(IEnumerable returnedList, ResourcePipeline pipeline = 0) { if (pipeline == ResourcePipeline.GetSingle && returnedList.Count() > 1) { @@ -361,7 +361,7 @@ void ValidateHookResponse(IEnumerable returnedList, ResourcePipeline pipel /// /// A helper method to call a hook on reflectively. /// - IEnumerable CallHook(IResourceHookContainer container, ResourceHook hook, object[] arguments) + private IEnumerable CallHook(IResourceHookContainer container, ResourceHook hook, object[] arguments) { var method = container.GetType().GetMethod(hook.ToString("G")); // note that some of the hooks return "void". When these hooks, the @@ -373,7 +373,7 @@ IEnumerable CallHook(IResourceHookContainer container, ResourceHook hook, object /// /// If the method, unwrap and throw the actual exception. /// - object ThrowJsonApiExceptionOnError(Func action) + private object ThrowJsonApiExceptionOnError(Func action) { try { @@ -390,7 +390,7 @@ object ThrowJsonApiExceptionOnError(Func action) /// If are included, the values of the entries in need to be replaced with these values. /// /// The relationship helper. - IRelationshipsDictionary CreateRelationshipHelper(RightType entityType, Dictionary prevLayerRelationships, IEnumerable dbValues = null) + private IRelationshipsDictionary CreateRelationshipHelper(RightType entityType, Dictionary prevLayerRelationships, IEnumerable dbValues = null) { if (dbValues != null) prevLayerRelationships = ReplaceWithDbValues(prevLayerRelationships, dbValues.Cast()); return (IRelationshipsDictionary)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipsDictionary<>), entityType, true, prevLayerRelationships); @@ -400,7 +400,7 @@ IRelationshipsDictionary CreateRelationshipHelper(RightType entityType, Dictiona /// Replaces the entities in the values of the prevLayerRelationships dictionary /// with the corresponding entities loaded from the db. /// - Dictionary ReplaceWithDbValues(Dictionary prevLayerRelationships, IEnumerable dbValues) + private Dictionary ReplaceWithDbValues(Dictionary prevLayerRelationships, IEnumerable dbValues) { foreach (var key in prevLayerRelationships.Keys.ToList()) { @@ -414,7 +414,7 @@ Dictionary ReplaceWithDbValues(Dictionary. /// - HashSet GetAllowedEntities(IEnumerable source, IEnumerable allowedIds) + private HashSet GetAllowedEntities(IEnumerable source, IEnumerable allowedIds) { return new HashSet(source.Cast().Where(ue => allowedIds.Contains(ue.StringId))); } @@ -429,7 +429,7 @@ HashSet GetAllowedEntities(IEnumerable source, IEnumerableThe hook in which the db values will be displayed. /// Relationships from to the next layer: /// this indicates which relationships will be included on . - IEnumerable LoadDbValues(Type entityType, IEnumerable uniqueEntities, ResourceHook targetHook, RelationshipAttribute[] relationshipsToNextLayer) + private IEnumerable LoadDbValues(Type entityType, IEnumerable uniqueEntities, ResourceHook targetHook, RelationshipAttribute[] relationshipsToNextLayer) { // We only need to load database values if the target hook of this hook execution // cycle is compatible with displaying database values and has this option enabled. @@ -440,7 +440,7 @@ IEnumerable LoadDbValues(Type entityType, IEnumerable uniqueEntities, ResourceHo /// /// Fires the AfterUpdateRelationship hook /// - void FireAfterUpdateRelationship(IResourceHookContainer container, INode node, ResourcePipeline pipeline) + private void FireAfterUpdateRelationship(IResourceHookContainer container, INode node, ResourcePipeline pipeline) { Dictionary currentEntitiesGrouped = node.RelationshipsFromPreviousLayer.GetRightEntities(); @@ -457,7 +457,7 @@ void FireAfterUpdateRelationship(IResourceHookContainer container, INode node, R /// /// The ids. /// IIdentifiable entities. - HashSet GetIds(IEnumerable entities) + private HashSet GetIds(IEnumerable entities) { return new HashSet(entities.Cast().Select(e => e.StringId)); } diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs index 3881ebe167..8e8201151e 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs @@ -19,8 +19,8 @@ namespace JsonApiDotNetCore.Hooks /// internal sealed class RelationshipProxy { - readonly bool _isHasManyThrough; - readonly bool _skipJoinTable; + private readonly bool _isHasManyThrough; + private readonly bool _skipJoinTable; /// /// The target type for this relationship attribute. diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs index d2085dc2dd..386cf75e9f 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/RelationshipsFromPreviousLayer.cs @@ -24,7 +24,7 @@ internal interface IRelationshipsFromPreviousLayer internal sealed class RelationshipsFromPreviousLayer : IRelationshipsFromPreviousLayer, IEnumerable> where TRightResource : class, IIdentifiable { - readonly IEnumerable> _collection; + private readonly IEnumerable> _collection; public RelationshipsFromPreviousLayer(IEnumerable> collection) { diff --git a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs index 7b14e842b2..b380f8f0ae 100644 --- a/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs +++ b/src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs @@ -113,7 +113,7 @@ public NodeLayer CreateNextLayer(IEnumerable nodes) /// iterates through the dictionary and groups the values /// by matching right type of the keys (which are relationship attributes) /// - Dictionary>>> GroupByRightTypeOfRelationship(Dictionary> relationships) + private Dictionary>>> GroupByRightTypeOfRelationship(Dictionary> relationships) { return relationships.GroupBy(kvp => kvp.Key.RightType).ToDictionary(gdc => gdc.Key, gdc => gdc.ToList()); } @@ -122,7 +122,7 @@ Dictionary>> /// Extracts the entities for the current layer by going through all populated relationships /// of the (left entities of the previous layer. /// - (Dictionary>, Dictionary>) ExtractEntities(IEnumerable leftNodes) + private (Dictionary>, Dictionary>) ExtractEntities(IEnumerable leftNodes) { var leftEntitiesGrouped = new Dictionary>(); // RelationshipAttr_prevLayer->currentLayer => prevLayerEntities var rightEntitiesGrouped = new Dictionary>(); // RelationshipAttr_prevLayer->currentLayer => currentLayerEntities @@ -173,7 +173,7 @@ Dictionary>> /// left type to any right type /// /// The relationships. - RelationshipProxy[] GetPopulatedRelationships(LeftType leftType, IEnumerable lefts) + private RelationshipProxy[] GetPopulatedRelationships(LeftType leftType, IEnumerable lefts) { var relationshipsFromLeftToRight = _relationshipProxies.Select(entry => entry.Value).Where(proxy => proxy.LeftType == leftType); return relationshipsFromLeftToRight.Where(proxy => proxy.IsContextRelation || lefts.Any(p => proxy.GetValue(p) != null)).ToArray(); @@ -185,7 +185,7 @@ RelationshipProxy[] GetPopulatedRelationships(LeftType leftType, IEnumerableThe entities. /// Incoming entities. /// The 1st type parameter. - HashSet ProcessEntities(IEnumerable incomingEntities) where TResource : class, IIdentifiable + private HashSet ProcessEntities(IEnumerable incomingEntities) where TResource : class, IIdentifiable { Type type = typeof(TResource); var newEntities = UniqueInTree(incomingEntities, type); @@ -198,7 +198,7 @@ HashSet ProcessEntities(IEnumerable incomingEnt /// other models in the resource resourceGraphs by constructing RelationshipProxies . /// /// The type to parse - void RegisterRelationshipProxies(RightType type) + private void RegisterRelationshipProxies(RightType type) { foreach (RelationshipAttribute attr in _resourceGraph.GetRelationships(type)) { @@ -220,7 +220,7 @@ void RegisterRelationshipProxies(RightType type) /// /// Entities to register /// Entity type. - void RegisterProcessedEntities(IEnumerable entities, Type entityType) + private void RegisterProcessedEntities(IEnumerable entities, Type entityType) { var processedEntities = GetProcessedEntities(entityType); processedEntities.UnionWith(new HashSet(entities)); @@ -231,7 +231,7 @@ void RegisterProcessedEntities(IEnumerable entities, Type entityT /// /// The processed entities. /// Entity type. - HashSet GetProcessedEntities(Type entityType) + private HashSet GetProcessedEntities(Type entityType) { if (!_processedEntities.TryGetValue(entityType, out HashSet processedEntities)) { @@ -248,7 +248,7 @@ HashSet GetProcessedEntities(Type entityType) /// The in tree. /// Entities. /// Entity type. - HashSet UniqueInTree(IEnumerable entities, Type entityType) where TResource : class, IIdentifiable + private HashSet UniqueInTree(IEnumerable entities, Type entityType) where TResource : class, IIdentifiable { var newEntities = entities.Except(GetProcessedEntities(entityType), _comparer).Cast(); return new HashSet(newEntities); @@ -262,7 +262,7 @@ HashSet UniqueInTree(IEnumerable entities, Type /// /// The target type for traversal /// Relationship attribute - RightType GetRightTypeFromRelationship(RelationshipAttribute attr) + private RightType GetRightTypeFromRelationship(RelationshipAttribute attr) { if (attr is HasManyThroughAttribute throughAttr && throughAttr.ThroughType.Inherits(typeof(IIdentifiable))) { @@ -271,7 +271,7 @@ RightType GetRightTypeFromRelationship(RelationshipAttribute attr) return attr.RightType; } - void AddToRelationshipGroup(Dictionary> target, RelationshipProxy proxy, IEnumerable newEntities) + private void AddToRelationshipGroup(Dictionary> target, RelationshipProxy proxy, IEnumerable newEntities) { if (!target.TryGetValue(proxy, out List entities)) { @@ -284,7 +284,7 @@ void AddToRelationshipGroup(Dictionary> t /// /// Reflective helper method to create an instance of ; /// - INode CreateNodeInstance(RightType nodeType, RelationshipProxy[] relationshipsToNext, IEnumerable relationshipsFromPrev) + private INode CreateNodeInstance(RightType nodeType, RelationshipProxy[] relationshipsToNext, IEnumerable relationshipsFromPrev) { IRelationshipsFromPreviousLayer prev = CreateRelationshipsFromInstance(nodeType, relationshipsFromPrev); return (INode)TypeHelper.CreateInstanceOfOpenType(typeof(ChildNode<>), nodeType, relationshipsToNext, prev); @@ -293,7 +293,7 @@ INode CreateNodeInstance(RightType nodeType, RelationshipProxy[] relationshipsTo /// /// Reflective helper method to create an instance of ; /// - IRelationshipsFromPreviousLayer CreateRelationshipsFromInstance(RightType nodeType, IEnumerable relationshipsFromPrev) + private IRelationshipsFromPreviousLayer CreateRelationshipsFromInstance(RightType nodeType, IEnumerable relationshipsFromPrev) { var cast = relationshipsFromPrev.Cast(relationshipsFromPrev.First().GetType()); return (IRelationshipsFromPreviousLayer)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipsFromPreviousLayer<>), nodeType, cast); @@ -302,7 +302,7 @@ IRelationshipsFromPreviousLayer CreateRelationshipsFromInstance(RightType nodeTy /// /// Reflective helper method to create an instance of ; /// - IRelationshipGroup CreateRelationshipGroupInstance(Type thisLayerType, RelationshipProxy proxy, List leftEntities, List rightEntities) + private IRelationshipGroup CreateRelationshipGroupInstance(Type thisLayerType, RelationshipProxy proxy, List leftEntities, List rightEntities) { var rightEntitiesHashed = TypeHelper.CreateInstanceOfOpenType(typeof(HashSet<>), thisLayerType, rightEntities.Cast(thisLayerType)); return (IRelationshipGroup)TypeHelper.CreateInstanceOfOpenType(typeof(RelationshipGroup<>), @@ -316,7 +316,7 @@ IRelationshipGroup CreateRelationshipGroupInstance(Type thisLayerType, Relations /// internal sealed class NodeLayer : IEnumerable { - readonly List _collection; + private readonly List _collection; public bool AnyEntities() { diff --git a/src/JsonApiDotNetCore/QueryParameterServices/SortService.cs b/src/JsonApiDotNetCore/QueryParameterServices/SortService.cs index 6373f92ac4..fe136993eb 100644 --- a/src/JsonApiDotNetCore/QueryParameterServices/SortService.cs +++ b/src/JsonApiDotNetCore/QueryParameterServices/SortService.cs @@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Query /// public class SortService : QueryParameterService, ISortService { - const char DESCENDING_SORT_OPERATOR = '-'; + private const char DESCENDING_SORT_OPERATOR = '-'; private readonly IResourceDefinitionProvider _resourceDefinitionProvider; private List _queries; diff --git a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs index bb42e1a4fc..ccb8eb2ad9 100644 --- a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs +++ b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs @@ -16,11 +16,11 @@ namespace UnitTests { public sealed class ResourceGraphBuilder_Tests { - sealed class NonDbResource : Identifiable { } + private sealed class NonDbResource : Identifiable { } - sealed class DbResource : Identifiable { } + private sealed class DbResource : Identifiable { } - class TestContext : DbContext + private class TestContext : DbContext { public DbSet DbResources { get; set; } } diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs index b029e89043..0da8920138 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/Delete/AfterDeleteTests.cs @@ -8,7 +8,7 @@ namespace UnitTests.ResourceHooks { public sealed class AfterDeleteTests : HooksTestsSetup { - readonly ResourceHook[] targetHooks = { ResourceHook.AfterDelete }; + private readonly ResourceHook[] targetHooks = { ResourceHook.AfterDelete }; [Fact] public void AfterDelete() diff --git a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs index 378fe22606..c1abacdfc2 100644 --- a/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs +++ b/test/UnitTests/ResourceHooks/ResourceHookExecutor/ManyToMany_OnReturnTests.cs @@ -11,7 +11,7 @@ public sealed class ManyToMany_OnReturnTests : HooksTestsSetup { private readonly ResourceHook[] targetHooks = { ResourceHook.OnReturn }; - (List
, List, List) CreateDummyData() + private (List
, List, List) CreateDummyData() { var tagsSubset = _tagFaker.Generate(3).ToList(); var joinsSubSet = _articleTagFaker.Generate(3).ToList(); diff --git a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs index d21541688c..a040c72551 100644 --- a/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs +++ b/test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs @@ -141,7 +141,7 @@ protected List CreateTodoWithOwner() public class HooksTestsSetup : HooksDummyData { - (Mock, Mock, Mock, IJsonApiOptions) CreateMocks() + private (Mock, Mock, Mock, IJsonApiOptions) CreateMocks() { var pfMock = new Mock(); var ufMock = new Mock(); @@ -268,7 +268,7 @@ protected DbContextOptions InitInMemoryDb(Action seeder return options; } - void MockHooks(Mock> resourceDefinition) where TModel : class, IIdentifiable + private void MockHooks(Mock> resourceDefinition) where TModel : class, IIdentifiable { resourceDefinition .Setup(rd => rd.BeforeCreate(It.IsAny>(), It.IsAny())) @@ -310,7 +310,7 @@ void MockHooks(Mock> resourceDefinition) .Verifiable(); } - void SetupProcessorFactoryForResourceDefinition( + private void SetupProcessorFactoryForResourceDefinition( Mock processorFactory, IResourceHookContainer modelResource, IHooksDiscovery discovery, @@ -340,7 +340,7 @@ void SetupProcessorFactoryForResourceDefinition( } } - IResourceReadRepository CreateTestRepository( + private IResourceReadRepository CreateTestRepository( AppDbContext dbContext ) where TModel : class, IIdentifiable { @@ -348,19 +348,19 @@ AppDbContext dbContext return new DefaultResourceRepository(null, resolver, null, null, NullLoggerFactory.Instance); } - IDbContextResolver CreateTestDbResolver(AppDbContext dbContext) where TModel : class, IIdentifiable + private IDbContextResolver CreateTestDbResolver(AppDbContext dbContext) where TModel : class, IIdentifiable { var mock = new Mock(); mock.Setup(r => r.GetContext()).Returns(dbContext); return mock.Object; } - void ResolveInverseRelationships(AppDbContext context) + private void ResolveInverseRelationships(AppDbContext context) { new InverseRelationships(_resourceGraph, new DbContextResolver(context)).Resolve(); } - Mock> CreateResourceDefinition + private Mock> CreateResourceDefinition (IHooksDiscovery discovery ) where TModel : class, IIdentifiable From f20d1e9f231d2ce4f2070ec2940bac9cadc113f9 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 18:01:57 +0100 Subject: [PATCH 71/73] Removed reference to xunit from benchmarks project, so that 'dotnet test' does not try to run tests from it --- benchmarks/Benchmarks.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/benchmarks/Benchmarks.csproj b/benchmarks/Benchmarks.csproj index 02bfbf378d..72ff3a78cf 100644 --- a/benchmarks/Benchmarks.csproj +++ b/benchmarks/Benchmarks.csproj @@ -6,7 +6,6 @@ - From dd10241b09da133d6b1b4c6cff02711450e91a16 Mon Sep 17 00:00:00 2001 From: Bart Koelman Date: Mon, 17 Feb 2020 19:42:40 +0100 Subject: [PATCH 72/73] Empty commit to retry cibuild From 72842043ba896c89e494dc3b573b6234531ac450 Mon Sep 17 00:00:00 2001 From: Maurits Moeys Date: Tue, 24 Mar 2020 16:11:44 +0100 Subject: [PATCH 73/73] Update IQueryableExtensions.cs --- src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs index d1bce613fb..68505d6c56 100644 --- a/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs @@ -245,7 +245,8 @@ private static IQueryable CallGenericWhereMethod(IQueryable CallGenericWhereMethod(IQueryable