Skip to content

Removal of obsolete methods #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public JsonApiDeserializer_Benchmarks() {
jsonApiOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions);

var genericProcessorFactoryMock = new Mock<IGenericProcessorFactory>();

_jsonApiDeSerializer = new JsonApiDeSerializer(jsonApiContextMock.Object, genericProcessorFactoryMock.Object);
_jsonApiDeSerializer = new JsonApiDeSerializer(jsonApiContextMock.Object);
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override async Task<IActionResult> PatchAsync(Guid id, [FromBody] TodoIte
if (entity.Name == "PRE-ATTACH-TEST")
{
var targetTodoId = entity.TodoItems.First().Id;
var todoItemContext = _dbResolver.GetDbSet<TodoItem>();
var todoItemContext = _dbResolver.GetContext().Set<TodoItem>();
await todoItemContext.Where(ti => ti.Id == targetTodoId).FirstOrDefaultAsync();
}
return await base.PatchAsync(id, entity);
Expand Down
6 changes: 0 additions & 6 deletions src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ public class JsonApiOptions
/// </example>
public bool ValidateModelState { get; set; }

[Obsolete("JsonContract resolver can now be set on SerializerSettings.")]
public IContractResolver JsonContractResolver
{
get => SerializerSettings.ContractResolver;
set => SerializerSettings.ContractResolver = value;
}
public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Data/DbContextResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DbContextResolver(TContext context)

public DbContext GetContext() => _context;

public DbSet<TEntity> GetDbSet<TEntity>() where TEntity : class
=> _context.GetDbSet<TEntity>();
public DbSet<TEntity> GetDbSet<TEntity>() where TEntity : class => null;

}
}
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public DefaultEntityRepository(
ResourceDefinition<TEntity> resourceDefinition = null)
{
_context = contextResolver.GetContext();
_dbSet = contextResolver.GetDbSet<TEntity>();
_dbSet = _context.Set<TEntity>();
_jsonApiContext = jsonApiContext;
_genericProcessorFactory = _jsonApiContext.GenericProcessorFactory;
_resourceDefinition = resourceDefinition;
Expand All @@ -69,7 +69,7 @@ public DefaultEntityRepository(
ResourceDefinition<TEntity> resourceDefinition = null)
{
_context = contextResolver.GetContext();
_dbSet = contextResolver.GetDbSet<TEntity>();
_dbSet = _context.Set<TEntity>();
_jsonApiContext = jsonApiContext;
_logger = loggerFactory.CreateLogger<DefaultEntityRepository<TEntity, TId>>();
_genericProcessorFactory = _jsonApiContext.GenericProcessorFactory;
Expand Down
3 changes: 3 additions & 0 deletions src/JsonApiDotNetCore/Data/IDbContextResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using Microsoft.EntityFrameworkCore;

namespace JsonApiDotNetCore.Data
{
public interface IDbContextResolver
{
DbContext GetContext();

[Obsolete("Use DbContext.Set<TEntity>() instead", error: true)]
DbSet<TEntity> GetDbSet<TEntity>()
where TEntity : class;
}
Expand Down
9 changes: 0 additions & 9 deletions src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ private static MethodInfo ContainsMethod
}
}

[Obsolete("Use overload Sort<T>(IJsonApiContext, List<SortQuery>) instead.", error: true)]
public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, List<SortQuery> sortQueries) => null;

[Obsolete("Use overload Sort<T>(IJsonApiContext, SortQuery) instead.", error: true)]
public static IOrderedQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, SortQuery sortQuery) => null;

[Obsolete("Use overload Sort<T>(IJsonApiContext, SortQuery) instead.", error: true)]
public static IOrderedQueryable<TSource> Sort<TSource>(this IOrderedQueryable<TSource> source, SortQuery sortQuery) => null;

public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, IJsonApiContext jsonApiContext, List<SortQuery> sortQueries)
{
if (sortQueries == null || sortQueries.Count == 0)
Expand Down
20 changes: 0 additions & 20 deletions src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@ namespace JsonApiDotNetCore.Extensions
{
public static class ModelStateExtensions
{
[Obsolete("Use Generic Method ConvertToErrorCollection<T>(IResourceGraph resourceGraph) instead for full validation errors")]
public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState)
{
ErrorCollection collection = new ErrorCollection();
foreach (var entry in modelState)
{
if (entry.Value.Errors.Any() == false)
continue;

foreach (var modelError in entry.Value.Errors)
{
if (modelError.Exception is JsonApiException jex)
collection.Errors.AddRange(jex.GetError().Errors);
else
collection.Errors.Add(new Error(400, entry.Key, modelError.ErrorMessage, modelError.Exception != null ? ErrorMeta.FromException(modelError.Exception) : null));
}
}

return collection;
}
public static ErrorCollection ConvertToErrorCollection<T>(this ModelStateDictionary modelState, IResourceGraph resourceGraph)
{
ErrorCollection collection = new ErrorCollection();
Expand Down
15 changes: 0 additions & 15 deletions src/JsonApiDotNetCore/Internal/ContextGraph.cs

This file was deleted.

22 changes: 1 addition & 21 deletions src/JsonApiDotNetCore/Internal/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ namespace JsonApiDotNetCore.Internal
{
public class Error
{
public Error()
{ }

[Obsolete("Use Error constructors with int typed status")]
public Error(string status, string title, ErrorMeta meta = null, object source = null)
{
Status = status;
Title = title;
Meta = meta;
Source = source;
}
public Error() { }

public Error(int status, string title, ErrorMeta meta = null, object source = null)
{
Expand All @@ -29,16 +19,6 @@ public Error(int status, string title, ErrorMeta meta = null, object source = nu
Source = source;
}

[Obsolete("Use Error constructors with int typed status")]
public Error(string status, string title, string detail, ErrorMeta meta = null, object source = null)
{
Status = status;
Title = title;
Detail = detail;
Meta = meta;
Source = source;
}

public Error(int status, string title, string detail, ErrorMeta meta = null, object source = null)
{
Status = status.ToString();
Expand Down
12 changes: 1 addition & 11 deletions src/JsonApiDotNetCore/Internal/JsonApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ public JsonApiException(ErrorCollection errorCollection)

public JsonApiException(Error error)
: base(error.Title) => _errors.Add(error);

[Obsolete("Use int statusCode overload instead")]
public JsonApiException(string statusCode, string message, string source = null)
: base(message)
=> _errors.Add(new Error(statusCode, message, null, GetMeta(), source));

[Obsolete("Use int statusCode overload instead")]
public JsonApiException(string statusCode, string message, string detail, string source = null)
: base(message)
=> _errors.Add(new Error(statusCode, message, detail, GetMeta(), source));


public JsonApiException(int statusCode, string message, string source = null)
: base(message)
=> _errors.Add(new Error(statusCode, message, null, GetMeta(), source));
Expand Down
5 changes: 0 additions & 5 deletions src/JsonApiDotNetCore/Internal/Query/AttrFilterQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public AttrFilterQuery(

if (Attribute.IsFilterable == false)
throw new JsonApiException(400, $"Filter is not allowed for attribute '{Attribute.PublicAttributeName}'.");

FilteredAttribute = Attribute;
}

[Obsolete("Use " + nameof(BaseAttrQuery.Attribute) + " instead.")]
public AttrAttribute FilteredAttribute { get; set; }
}
}
3 changes: 0 additions & 3 deletions src/JsonApiDotNetCore/Internal/Query/FilterQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ public class FilterQuery : BaseQuery
public FilterQuery(string attribute, string value, string operation)
: base(attribute)
{
Key = attribute.ToProperCase();
Value = value;
Operation = operation;
}

[Obsolete("Key has been replaced by '" + nameof(Attribute) + "'. Members should be located by their public name, not by coercing the provided value to the internal name.")]
public string Key { get; set; }
public string Value { get; set; }
public string Operation { get; set; }

Expand Down
10 changes: 1 addition & 9 deletions src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ public RelatedAttrFilterQuery(

if (Attribute.IsFilterable == false)
throw new JsonApiException(400, $"Filter is not allowed for attribute '{Attribute.PublicAttributeName}'.");

FilteredRelationship = Relationship;
FilteredAttribute = Attribute;

}

[Obsolete("Use " + nameof(Attribute) + " instead.")]
public AttrAttribute FilteredAttribute { get; set; }

[Obsolete("Use " + nameof(Relationship) + " instead.")]
public RelationshipAttribute FilteredRelationship { get; set; }
}
}
7 changes: 0 additions & 7 deletions src/JsonApiDotNetCore/Internal/Query/SortQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace JsonApiDotNetCore.Internal.Query
/// </summary>
public class SortQuery : BaseQuery
{
[Obsolete("Use constructor overload (SortDirection, string) instead. The string should be the publicly exposed attribute name.", error: true)]
public SortQuery(SortDirection direction, AttrAttribute sortedAttribute)
: base(sortedAttribute.PublicAttributeName) { }

public SortQuery(SortDirection direction, string attribute)
: base(attribute)
{
Expand All @@ -22,8 +18,5 @@ public SortQuery(SortDirection direction, string attribute)
/// Direction the sort should be applied
/// </summary>
public SortDirection Direction { get; set; }

[Obsolete("Use string based Attribute instead.", error: true)]
public AttrAttribute SortedAttribute { get; set; }
}
}
6 changes: 0 additions & 6 deletions src/JsonApiDotNetCore/Models/Identifiable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,5 @@ protected virtual T GetTypedId(string value)
var convertedValue = TypeHelper.ConvertType(value, typeof(T));
return convertedValue == null ? default : (T)convertedValue;
}

[Obsolete("Use GetTypedId instead")]
protected virtual object GetConcreteId(string value)
{
return TypeHelper.ConvertType(value, typeof(T));
}
}
}
10 changes: 0 additions & 10 deletions src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ public class JsonApiDeSerializer : IJsonApiDeSerializer
{
private readonly IJsonApiContext _jsonApiContext;

[Obsolete(
"The deserializer no longer depends on the IGenericProcessorFactory",
error: false)]
public JsonApiDeSerializer(
IJsonApiContext jsonApiContext,
IGenericProcessorFactory genericProcessorFactory)
{
_jsonApiContext = jsonApiContext;
}

public JsonApiDeSerializer(IJsonApiContext jsonApiContext)
{
_jsonApiContext = jsonApiContext;
Expand Down
6 changes: 0 additions & 6 deletions src/JsonApiDotNetCore/Services/IJsonApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ public interface IJsonApiRequest : IJsonApiApplication, IUpdateRequest, IQueryRe
/// If the request is on the `{id}/relationships/{relationshipName}` route
/// </summary>
bool IsRelationshipPath { get; }

[Obsolete("Use `IsRelationshipPath` instead.")]
bool IsRelationshipData { get; set; }
}

public interface IJsonApiContext : IJsonApiRequest
Expand All @@ -150,9 +147,6 @@ public interface IJsonApiContext : IJsonApiRequest
IMetaBuilder MetaBuilder { get; set; }
IGenericProcessorFactory GenericProcessorFactory { get; set; }

[Obsolete("Use the proxied method IControllerContext.GetControllerAttribute instead.")]
TAttribute GetControllerAttribute<TAttribute>() where TAttribute : Attribute;

/// <summary>
/// **_Experimental_**: do not use. It is likely to change in the future.
///
Expand Down
4 changes: 0 additions & 4 deletions src/JsonApiDotNetCore/Services/JsonApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ private PageManager GetPageManager()
};
}

[Obsolete("Use the proxied method IControllerContext.GetControllerAttribute instead.")]
public TAttribute GetControllerAttribute<TAttribute>() where TAttribute : Attribute
=> _controllerContext.GetControllerAttribute<TAttribute>();

public void BeginOperation()
{
IncludedRelationships = new List<string>();
Expand Down
14 changes: 12 additions & 2 deletions test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JsonApiDotNetCore.Graph;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;
Expand All @@ -14,7 +15,16 @@ namespace DiscoveryTests
public class ServiceDiscoveryFacadeTests
{
private readonly IServiceCollection _services = new ServiceCollection();
private readonly ResourceGraphBuilder _graphBuilder = new ResourceGraphBuilder();
private readonly ResourceGraphBuilder _graphBuilder = new ResourceGraphBuilder();

public ServiceDiscoveryFacadeTests()
{
var contextMock = new Mock<DbContext>();
var dbResolverMock = new Mock<IDbContextResolver>();
dbResolverMock.Setup(m => m.GetContext()).Returns(new Mock<DbContext>().Object);
TestModelRepository._dbContextResolver = dbResolverMock.Object;
}

private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade(_services, _graphBuilder);

[Fact]
Expand Down Expand Up @@ -79,7 +89,7 @@ public TestModelService() : base(_jsonApiContext, _repo) { }

public class TestModelRepository : DefaultEntityRepository<TestModel>
{
private static IDbContextResolver _dbContextResolver = new Mock<IDbContextResolver>().Object;
internal static IDbContextResolver _dbContextResolver;
private static IJsonApiContext _jsonApiContext = new Mock<IJsonApiContext>().Object;
public TestModelRepository() : base(_jsonApiContext, _dbContextResolver) { }
}
Expand Down
9 changes: 5 additions & 4 deletions test/UnitTests/Data/DefaultEntityRepository_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ public async Task UpdateAsync_Updates_Attributes_In_AttributesToUpdate()

private DefaultEntityRepository<TodoItem> GetRepository()
{

_contextMock
.Setup(m => m.Set<TodoItem>())
.Returns(_dbSetMock.Object);

_contextResolverMock
.Setup(m => m.GetContext())
.Returns(_contextMock.Object);

_contextResolverMock
.Setup(m => m.GetDbSet<TodoItem>())
.Returns(_dbSetMock.Object);

_jsonApiContextMock
.Setup(m => m.AttributesToUpdate)
.Returns(_attrsToUpdate);
Expand Down
1 change: 0 additions & 1 deletion test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ IDbContextResolver CreateTestDbResolver<TModel>(AppDbContext dbContext) where TM
{
var mock = new Mock<IDbContextResolver>();
mock.Setup(r => r.GetContext()).Returns(dbContext);
mock.Setup(r => r.GetDbSet<TModel>()).Returns(dbContext.Set<TModel>());
return mock.Object;
}

Expand Down