Skip to content

.NET Core 2.2 -> 3.0 #597

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 50 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
24a2ef3
merge: merge into correct email:
wisepotato Oct 23, 2019
adf845b
Merge branch 'feat/upgrade-2.2' into feat/upgrade-2.2-real
wisepotato Oct 23, 2019
4124aa9
feat: upgrade to 2.2
wisepotato Oct 23, 2019
fb6aa66
chore: merge fixes
wisepotato Oct 23, 2019
17f0c8c
chore: spacing fix
wisepotato Oct 23, 2019
10ea6cb
chore: revert silencing error
wisepotato Oct 23, 2019
0a4e322
chore: small spacing fix
wisepotato Oct 23, 2019
9697449
chore: remove unneeeded dependencies
wisepotato Oct 23, 2019
931c97c
chore: fix framework dependencies
wisepotato Oct 23, 2019
dd37d8e
chore: updates
wisepotato Oct 23, 2019
aaa7655
merge: merge from dev-v4
wisepotato Oct 23, 2019
13bfdeb
chore: test fixes
wisepotato Oct 23, 2019
5b10565
chore: start integration tests
wisepotato Oct 23, 2019
487728e
chore: cleanup name of dertest
wisepotato Oct 23, 2019
80ea141
chore: start of getRepostory
wisepotato Oct 23, 2019
754e2e3
chore: upgrade testsdk version + xunit version
wisepotato Oct 23, 2019
19349ae
feat: use template in version control of packages in integrationTests
wisepotato Oct 23, 2019
7617445
feat: unit test assemblyinfo add, port old test to integration (attri…
wisepotato Oct 23, 2019
bc5c1df
docs: add version compatibility
wisepotato Oct 24, 2019
70dd35d
chore: add asterisk for version number
wisepotato Oct 24, 2019
9f11631
feat: port defaultentityrepositorytests to integration tests
wisepotato Oct 24, 2019
67dd3eb
chore: should add logging, done.
wisepotato Oct 24, 2019
15a9402
tests: bad response from tests
wisepotato Oct 24, 2019
153f9cb
chore: fixes for lang version and making ifs more noticable
wisepotato Oct 24, 2019
9e6c36b
fix: fix routing issue with upgrade to enableendpointrouting
wisepotato Oct 24, 2019
bf72324
chore: HostEnvironment -> IWebHostEnvironment
wisepotato Oct 24, 2019
07840c4
chore: act -> Act, assert -> Assert, arrange -> Arrange
wisepotato Oct 24, 2019
9ee71f5
chore: fix tests
wisepotato Oct 24, 2019
9000421
chore: re-add unit test for defaultentityrepository for test IAsyncQu…
wisepotato Oct 24, 2019
2843111
refactor: make if statements more conscise
wisepotato Oct 24, 2019
d6f763f
chore: final stretch
wisepotato Oct 24, 2019
98b1119
tests: revert for good tests
wisepotato Oct 24, 2019
cd7e19c
Revert "tests: revert for good tests"
maurei Oct 29, 2019
90ebfca
Revert "chore: final stretch"
maurei Oct 29, 2019
5f7d330
fix: client generated id tests
maurei Oct 29, 2019
f149bc9
fix: create data tests with workaround for efcore 3.0 bug
maurei Oct 29, 2019
f8e9523
refactor: DetachRelationships usage of is operator
maurei Oct 29, 2019
9ff0709
fix: move MetaStartup to other assembly as .net core 3 bug workaround
maurei Oct 29, 2019
9b2ecdf
fix: UpdatingRelationshipTests locally evaluated queries error
maurei Oct 29, 2019
57c5da1
feat: reintroduced generic processor (RepositoryRelationshipUpdateHel…
maurei Oct 29, 2019
7faa500
feat: full sql support for UpdateRelationshipsAsync using expression …
maurei Oct 29, 2019
73f43e9
fix: DeletingDataTest
maurei Oct 29, 2019
fe67998
fix: paging test
maurei Oct 29, 2019
82005ec
fix: paging unit tests
maurei Oct 29, 2019
4a3296e
chore: remove RE-split models, duplicate models to NoEntityFrameworkE…
maurei Oct 29, 2019
e83abfd
fix: NoEntityFrameworkExample tests fixed by workaround assembly problem
maurei Oct 29, 2019
a81b6ac
fix: connection string e2e test projects
maurei Oct 29, 2019
518e4d0
chore: minor cleanup
maurei Oct 29, 2019
7845250
chore: minor cleanup
maurei Oct 29, 2019
6e8ddf4
chore: cleanup
maurei Oct 29, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Dictionary<string, object> GetMeta()
{
return new Dictionary<string, object> {
{ "copyright", "Copyright 2015 Example Corp." },
{ "authors", new string[] { "Jared Nance", "Maurits Moeys" } }
{ "authors", new string[] { "Jared Nance", "Maurits Moeys", "Harro van der Kroft" } }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because why not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really appreciate your work. Thank you all.

};
}
}
Expand Down
47 changes: 35 additions & 12 deletions src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Serialization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.Extensions.Logging;

namespace JsonApiDotNetCore.Data
Expand Down Expand Up @@ -298,21 +299,43 @@ public virtual IQueryable<TResource> Include(IQueryable<TResource> entities, IEn
/// <inheritdoc />
public virtual async Task<IEnumerable<TResource>> PageAsync(IQueryable<TResource> entities, int pageSize, int pageNumber)
{
// the IQueryable returned from the hook executor is sometimes consumed here.
// In this case, it does not support .ToListAsync(), so we use the method below.
if (pageNumber >= 0)
{
// the IQueryable returned from the hook executor is sometimes consumed here.
// In this case, it does not support .ToListAsync(), so we use the method below.
return await this.ToListAsync(entities.PageForward(pageSize, pageNumber));
entities = entities.PageForward(pageSize, pageNumber);
if (entities is IAsyncQueryProvider)
{
return await entities.ToListAsync();
}
else
{
return entities.ToList();
}
}
else
{
if (!(entities is IAsyncQueryProvider))
{
entities = entities.Reverse();
int firstIndex = pageSize * Math.Abs(pageNumber) - 1;
int numberOfElementsInPage = Math.Min(pageSize, firstIndex + pageSize);

return entities.Skip(firstIndex).Take(numberOfElementsInPage);
}
else
{
// since EntityFramework does not support IQueryable.Reverse(), we need to know the number of queried entities
var totalCount = await entities.CountAsync();

int virtualFirstIndex = totalCount - pageSize * Math.Abs(pageNumber);
int numberOfElementsInPage = Math.Min(pageSize, virtualFirstIndex + pageSize);

return await ToListAsync(entities
.Skip(virtualFirstIndex)
.Take(numberOfElementsInPage));
}
}
// since EntityFramework does not support IQueryable.Reverse(), we need to know the number of queried entities
var totalCount = await entities.CountAsync();
// may be negative
int virtualFirstIndex = totalCount - pageSize * Math.Abs(pageNumber);
int numberOfElementsInPage = Math.Min(pageSize, virtualFirstIndex + pageSize);

return await ToListAsync(entities
.Skip(virtualFirstIndex)
.Take(numberOfElementsInPage));
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,20 @@ public async Task Can_Paginate_TodoItems_From_End()
var totalCount = expectedEntitiesPerPage * 2;
var person = new Person();
var todoItems = _todoItemFaker.Generate(totalCount).ToList();

foreach (var todoItem in todoItems)
todoItem.Owner = person;
todoItems.ForEach(ti => ti.Owner = person);

Context.TodoItems.RemoveRange(Context.TodoItems);
Context.TodoItems.AddRange(todoItems);
Context.SaveChanges();

var route = $"/api/v1/todo-items?page[size]={expectedEntitiesPerPage}&page[number]=-1";

// Act
var response = await Client.GetAsync(route);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var body = await response.Content.ReadAsStringAsync();

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var deserializedBody = _fixture.GetDeserializer().DeserializeList<TodoItem>(body).Data;

var expectedTodoItems = new[] { todoItems[totalCount - 2], todoItems[totalCount - 1] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task Response400IfUpdatingNotSettableAttribute()
public async Task Respond_404_If_EntityDoesNotExist()
{
// Arrange
var maxPersonId = _context.TodoItems.LastOrDefault()?.Id ?? 0;
var maxPersonId = _context.TodoItems.ToList().LastOrDefault()?.Id ?? 0;
var todoItem = _todoItemFaker.Generate();
todoItem.Id = maxPersonId + 100;
todoItem.CreatedDate = DateTime.Now;
Expand All @@ -95,7 +95,7 @@ public async Task Respond_404_If_EntityDoesNotExist()
public async Task Respond_422_If_IdNotInAttributeList()
{
// Arrange
var maxPersonId = _context.TodoItems.LastOrDefault()?.Id ?? 0;
var maxPersonId = _context.TodoItems.ToList().LastOrDefault()?.Id ?? 0;
var todoItem = _todoItemFaker.Generate();
todoItem.CreatedDate = DateTime.Now;
var builder = new WebHostBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using JsonApiDotNetCoreExample;
using JsonApiDotNetCoreExample.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Newtonsoft.Json;
using Xunit;

Expand Down Expand Up @@ -74,7 +77,6 @@ public async Task Can_Create_TodoItems()
{
// Arrange
var description = Guid.NewGuid().ToString();
var client = _fixture.Server.CreateClient();
var httpMethod = new HttpMethod("POST");
var route = $"/api/v1/custom-todo-items/";
var content = new
Expand All @@ -94,6 +96,11 @@ public async Task Can_Create_TodoItems()
request.Content = new StringContent(JsonConvert.SerializeObject(content));
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.api+json");

var builder = new WebHostBuilder()
.UseStartup<Startup>();
var server = new TestServer(builder);
var client = server.CreateClient();

// Act
var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
Expand Down
3 changes: 2 additions & 1 deletion test/NoEntityFrameworkTests/TestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JsonApiDotNetCore.Builders;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Serialization.Client;
using JsonApiDotNetCoreExample;
using JsonApiDotNetCoreExample.Data;
using JsonApiDotNetCoreExample.Models;
using JsonApiDotNetCoreExampleTests.Helpers.Extensions;
Expand All @@ -19,7 +20,7 @@ public class TestFixture : IDisposable
private IServiceProvider _services;
public TestFixture()
{
var builder = new WebHostBuilder().UseStartup<TestStartup>();
var builder = new WebHostBuilder().UseStartup<Startup>();
Server = new TestServer(builder);
Context = Server.GetService<AppDbContext>();
Context.Database.EnsureCreated();
Expand Down
74 changes: 74 additions & 0 deletions test/UnitTests/Data/DefaultEntityRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 Xunit;

namespace UnitTests.Data
{
public class DefaultEntityRepositoryTest
{

[Fact]
public async Task PageAsync_IQueryableIsAListAndPageNumberPositive_CanStillCount()
{
// If IQueryable is actually a list (this can happen after a filter or hook)
// It needs to not do CountAsync, because well.. its not asynchronous.

// Arrange
var repository = Setup();
var todoItems = new List<TodoItem>() {
new TodoItem{ Id = 1 },
new TodoItem{ Id = 2 }
};

// Act
var result = await repository.PageAsync(todoItems.AsQueryable(), pageSize: 1, pageNumber: 2);

// Assert
Assert.True(result.ElementAt(0).Id == todoItems[1].Id);
}

[Fact]
public async Task PageAsync_IQueryableIsAListAndPageNumberNegative_CanStillCount()
{
// If IQueryable is actually a list (this can happen after a filter or hook)
// It needs to not do CountAsync, because well.. its not asynchronous.

// Arrange
var repository = Setup();
var todoItems = new List<TodoItem>() {
new TodoItem{ Id = 1 },
new TodoItem{ Id = 2 },
new TodoItem{ Id = 3 },
new TodoItem{ Id = 4 }
};

// Act
var result = await repository.PageAsync(todoItems.AsQueryable(), pageSize: 1, pageNumber: -2);

// Assert
Assert.True(result.First().Id == 3);
}

private DefaultResourceRepository<TodoItem> Setup()
{
var contextResolverMock = new Mock<IDbContextResolver>();
contextResolverMock.Setup(m => m.GetContext()).Returns(new Mock<DbContext>().Object);
var resourceGraph = new Mock<IResourceGraph>();
var targetedFields = new Mock<ITargetedFields>();
var repository = new DefaultResourceRepository<TodoItem>(targetedFields.Object, contextResolverMock.Object, resourceGraph.Object, null);
return repository;
}

}
}
81 changes: 0 additions & 81 deletions test/UnitTests/Data/DefaultEntityRepositoryTests.cs

This file was deleted.

1 change: 1 addition & 0 deletions test/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Repositories\" />
<Folder Include="Serialization\Common\" />
<Folder Include="Serialization\Client\" />
<Folder Include="Serialization\Server\" />
Expand Down