-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add example projects and tests #4
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
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
99e7d50
Add example projects and tests
mrnkr c53096a
throw proper error when fetching relationships
mrnkr b42b381
relationship creation tests
mrnkr c815c29
fix: unsupported relationships message
mrnkr c3f9dcf
test to-many relationship creation
mrnkr f348ff9
test unsupported filters
mrnkr 1b49d01
test for readonly attributes
mrnkr fc94301
suggested changes to validation and IModel implementation
mrnkr ab7fed5
cleanup last commit
mrnkr 970692b
remove unnecessary MongoDBRefs
mrnkr 3ec805d
added update relationship tests
mrnkr 0a3604e
address review comments
mrnkr ca2588d
update README.md
mrnkr 1bcef1f
address review comments
mrnkr e384b4e
bring latest changes in IntegrationTestContext
mrnkr aa140cb
Fixed handling DateTimes with ambiguous kind.
310b972
Added test for resource meta
f3e63b2
Cleanup solution: Move GettingStarted to the root and make it the def…
09456b0
Simplified code
465d720
fix README.md
mrnkr 054501b
remove unnecessary test for sparse fieldsets
mrnkr 2446ae4
remove unnecessary tests from CreateResourceTests
mrnkr a7b8713
address review comments
mrnkr c97d773
fix: custom query parameter support
mrnkr 78f058c
fix: sort on HasMany test passing
mrnkr 72430bc
added tests for relationship support in SparseFieldSetTests
mrnkr 99192c1
remove unnecessary ReadWrite tests
mrnkr afb71a5
fix: sort ids descending test
mrnkr a3742bd
cleanup sparse fieldset tests
mrnkr 5341ba9
move MongoDatabaseExtensions to test project
mrnkr 27f72f7
fix: sparse fieldset test
mrnkr e4b94bd
cleanup tests
mrnkr aae4eeb
latest requested changes minus ReadWrite tests
mrnkr 0f3272b
add missing ReadWrite tests
mrnkr a9e1bc8
Fixed failing tests
4e5bf56
address review comments
mrnkr 33add8b
Fixed: do not return relationship links in response json
2a73164
Fixed: the Task returned from Collection.InsertOneAsync was not await…
11646fc
address review comments
mrnkr 461eb32
Cleanup IoC registrations to properly detect when non-string IDs are …
4e50bc3
Removed unused types
d7c7520
Updated example
3451619
rename public static class ServiceCollectionExtensions.cs to ServiceC…
mrnkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Examples/GettingStarted/Controllers/BooksController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using GettingStarted.Models; | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Controllers; | ||
using JsonApiDotNetCore.Services; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GettingStarted.Controllers | ||
{ | ||
public sealed class BooksController : JsonApiController<Book, string> | ||
{ | ||
public BooksController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Book, string> resourceService) | ||
: base(options, loggerFactory, resourceService) | ||
{ | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>$(NetCoreAppVersion)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="JsonApiDotNetCore" Version="$(JsonApiDotNetCoreVersion)" /> | ||
<PackageReference Include="MongoDB.Driver" Version="$(MongoDBDriverVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\JsonApiDotNetCore.MongoDb\JsonApiDotNetCore.MongoDb.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using JsonApiDotNetCore.MongoDb.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace GettingStarted.Models | ||
{ | ||
public sealed class Book : MongoDbIdentifiable | ||
{ | ||
[Attr] | ||
public string Title { get; set; } | ||
|
||
[Attr] | ||
public int PublishYear { get; set; } | ||
|
||
[Attr] | ||
public string Author { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace GettingStarted | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
private static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Examples/GettingStarted/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:52498", | ||
"sslPort": 44343 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": false, | ||
"launchUrl": "api/books", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Kestrel": { | ||
"commandName": "Project", | ||
"launchBrowser": false, | ||
"launchUrl": "api/books", | ||
"applicationUrl": "http://localhost:14141", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Sample project | ||
|
||
## Usage | ||
|
||
`dotnet run` to run the project | ||
|
||
You can verify the project is running by checking this endpoint: | ||
`localhost:14141/api/people` | ||
|
||
For further documentation and implementation of a JsonApiDotnetCore Application see the documentation or GitHub page: | ||
|
||
Repository: https://github.com/json-api-dotnet/JsonApiDotNetCore | ||
|
||
Documentation: http://www.jsonapi.net |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using GettingStarted.Models; | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.MongoDb.Repositories; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MongoDB.Driver; | ||
using Newtonsoft.Json; | ||
|
||
namespace GettingStarted | ||
{ | ||
public sealed class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
private IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddSingleton(sp => | ||
{ | ||
var client = new MongoClient(Configuration.GetSection("DatabaseSettings:ConnectionString").Value); | ||
return client.GetDatabase(Configuration.GetSection("DatabaseSettings:Database").Value); | ||
}); | ||
|
||
services.AddJsonApi( | ||
ConfigureJsonApiOptions, | ||
resources: builder => | ||
{ | ||
builder.Add<Book, string>(); | ||
}); | ||
|
||
services.AddResourceRepository<MongoDbRepository<Book>>(); | ||
} | ||
|
||
private void ConfigureJsonApiOptions(JsonApiOptions options) | ||
{ | ||
options.Namespace = "api"; | ||
options.UseRelativeLinks = true; | ||
options.IncludeTotalResourceCount = true; | ||
options.SerializerSettings.Formatting = Formatting.Indented; | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
CreateSampleData(app.ApplicationServices.GetService<IMongoDatabase>()); | ||
|
||
app.UseRouting(); | ||
app.UseJsonApi(); | ||
app.UseEndpoints(endpoints => endpoints.MapControllers()); | ||
} | ||
|
||
private static void CreateSampleData(IMongoDatabase db) | ||
{ | ||
db.GetCollection<Book>(nameof(Book)).InsertMany(new [] | ||
{ | ||
new Book | ||
{ | ||
Title = "Frankenstein", | ||
PublishYear = 1818, | ||
Author = "Mary Shelley" | ||
}, new Book | ||
{ | ||
Title = "Robinson Crusoe", | ||
PublishYear = 1719, | ||
Author = "Daniel Defoe" | ||
}, new Book | ||
{ | ||
Title = "Gulliver's Travels", | ||
PublishYear = 1726, | ||
Author = "Jonathan Swift" | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"DatabaseSettings": { | ||
"ConnectionString": "mongodb://localhost:27017", | ||
"Database": "JsonApiDotNetCoreMongoDbGettingStarted" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.