Skip to content

Commit 07840c4

Browse files
committed
chore: act -> Act, assert -> Assert, arrange -> Arrange
1 parent bf72324 commit 07840c4

File tree

82 files changed

+1202
-1155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1202
-1155
lines changed

src/Examples/GettingStarted/Startup.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.EntityFrameworkCore;
@@ -21,11 +21,10 @@ public void ConfigureServices(IServiceCollection services)
2121
discover => discover.AddCurrentAssembly(), mvcBuilder: mvcBuilder);
2222
}
2323

24-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, SampleDbContext context)
24+
public void Configure(IApplicationBuilder app, SampleDbContext context)
2525
{
2626
context.Database.EnsureDeleted(); // indicies need to be reset
2727
context.Database.EnsureCreated();
28-
2928
app.UseJsonApi();
3029
}
3130
}

src/Examples/JsonApiDotNetCoreExample/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public Startup(IWebHostEnvironment env)
2121
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
2222
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
2323
.AddEnvironmentVariables();
24-
2524
Config = builder.Build();
2625
}
2726

src/Examples/ReportsExample/Startup.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Startup
1111
{
1212
public readonly IConfiguration Config;
1313

14-
public Startup(IHostingEnvironment env)
14+
public Startup(IWebHostEnvironment env)
1515
{
1616
var builder = new ConfigurationBuilder()
1717
.SetBasePath(env.ContentRootPath)
@@ -29,10 +29,5 @@ public virtual void ConfigureServices(IServiceCollection services)
2929
opt => opt.Namespace = "api",
3030
discovery => discovery.AddCurrentAssembly(), mvcBuilder: mvcBuilder);
3131
}
32-
33-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
34-
{
35-
app.UseMvc();
36-
}
3732
}
3833
}
Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,105 @@
1-
using System.Collections.Generic;
2-
using GettingStarted.Models;
3-
using GettingStarted.ResourceDefinitionExample;
4-
using JsonApiDotNetCore.Builders;
1+
using System.Collections.Generic;
2+
using GettingStarted.Models;
3+
using GettingStarted.ResourceDefinitionExample;
4+
using JsonApiDotNetCore.Builders;
55
using JsonApiDotNetCore.Configuration;
6-
using JsonApiDotNetCore.Data;
7-
using JsonApiDotNetCore.Graph;
6+
using JsonApiDotNetCore.Data;
7+
using JsonApiDotNetCore.Graph;
88
using JsonApiDotNetCore.Hooks;
99
using JsonApiDotNetCore.Internal.Contracts;
1010
using JsonApiDotNetCore.Internal.Generics;
1111
using JsonApiDotNetCore.Managers.Contracts;
12-
using JsonApiDotNetCore.Models;
12+
using JsonApiDotNetCore.Models;
1313
using JsonApiDotNetCore.Query;
1414
using JsonApiDotNetCore.Serialization;
1515
using JsonApiDotNetCore.Serialization.Server.Builders;
16-
using JsonApiDotNetCore.Services;
16+
using JsonApiDotNetCore.Services;
1717
using Microsoft.EntityFrameworkCore;
18-
using Microsoft.Extensions.DependencyInjection;
18+
using Microsoft.Extensions.DependencyInjection;
1919
using Microsoft.Extensions.Logging;
20-
using Moq;
21-
using Xunit;
22-
23-
namespace DiscoveryTests
24-
{
25-
public class ServiceDiscoveryFacadeTests
26-
{
27-
private readonly IServiceCollection _services = new ServiceCollection();
20+
using Moq;
21+
using Xunit;
22+
23+
namespace DiscoveryTests
24+
{
25+
public class ServiceDiscoveryFacadeTests
26+
{
27+
private readonly IServiceCollection _services = new ServiceCollection();
2828
private readonly ResourceGraphBuilder _resourceGraphBuilder = new ResourceGraphBuilder();
2929

3030
public ServiceDiscoveryFacadeTests()
3131
{
32-
var contextMock = new Mock<DbContext>();
33-
var dbResolverMock = new Mock<IDbContextResolver>();
34-
dbResolverMock.Setup(m => m.GetContext()).Returns(new Mock<DbContext>().Object);
32+
var contextMock = new Mock<DbContext>();
33+
var dbResolverMock = new Mock<IDbContextResolver>();
34+
dbResolverMock.Setup(m => m.GetContext()).Returns(new Mock<DbContext>().Object);
3535
TestModelRepository._dbContextResolver = dbResolverMock.Object;
36-
_services.AddSingleton<IJsonApiOptions>(new JsonApiOptions());
36+
_services.AddSingleton<IJsonApiOptions>(new JsonApiOptions());
3737
_services.AddScoped((_) => new Mock<ILinkBuilder>().Object);
38-
_services.AddScoped((_) => new Mock<ICurrentRequest>().Object);
39-
_services.AddScoped((_) => new Mock<ITargetedFields>().Object);
38+
_services.AddScoped((_) => new Mock<ICurrentRequest>().Object);
39+
_services.AddScoped((_) => new Mock<ITargetedFields>().Object);
4040
_services.AddScoped((_) => new Mock<IResourceGraph>().Object);
4141
_services.AddScoped((_) => new Mock<IGenericServiceFactory>().Object);
4242
_services.AddScoped((_) => new Mock<IResourceContextProvider>().Object);
4343
}
4444

45-
private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade(_services, _resourceGraphBuilder);
46-
47-
[Fact]
48-
public void AddAssembly_Adds_All_Resources_To_Graph()
49-
{
50-
// arrange, act
51-
_facade.AddAssembly(typeof(Person).Assembly);
52-
53-
// assert
54-
var resourceGraph = _resourceGraphBuilder.Build();
55-
var personResource = resourceGraph.GetResourceContext(typeof(Person));
56-
var articleResource = resourceGraph.GetResourceContext(typeof(Article));
57-
var modelResource = resourceGraph.GetResourceContext(typeof(Model));
58-
59-
Assert.NotNull(personResource);
60-
Assert.NotNull(articleResource);
61-
Assert.NotNull(modelResource);
62-
}
63-
64-
[Fact]
65-
public void AddCurrentAssembly_Adds_Resources_To_Graph()
66-
{
67-
// arrange, act
68-
_facade.AddCurrentAssembly();
69-
70-
// assert
71-
var resourceGraph = _resourceGraphBuilder.Build();
72-
var testModelResource = resourceGraph.GetResourceContext(typeof(TestModel));
73-
Assert.NotNull(testModelResource);
74-
}
75-
76-
[Fact]
77-
public void AddCurrentAssembly_Adds_Services_To_Container()
45+
private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade(_services, _resourceGraphBuilder);
46+
47+
[Fact]
48+
public void AddAssembly_Adds_All_Resources_To_Graph()
49+
{
50+
// Arrange, act
51+
_facade.AddAssembly(typeof(Person).Assembly);
52+
53+
// Assert
54+
var resourceGraph = _resourceGraphBuilder.Build();
55+
var personResource = resourceGraph.GetResourceContext(typeof(Person));
56+
var articleResource = resourceGraph.GetResourceContext(typeof(Article));
57+
var modelResource = resourceGraph.GetResourceContext(typeof(Model));
58+
59+
Assert.NotNull(personResource);
60+
Assert.NotNull(articleResource);
61+
Assert.NotNull(modelResource);
62+
}
63+
64+
[Fact]
65+
public void AddCurrentAssembly_Adds_Resources_To_Graph()
66+
{
67+
// Arrange, act
68+
_facade.AddCurrentAssembly();
69+
70+
// Assert
71+
var resourceGraph = _resourceGraphBuilder.Build();
72+
var testModelResource = resourceGraph.GetResourceContext(typeof(TestModel));
73+
Assert.NotNull(testModelResource);
74+
}
75+
76+
[Fact]
77+
public void AddCurrentAssembly_Adds_Services_To_Container()
78+
{
79+
// Arrange, act
80+
_facade.AddCurrentAssembly();
81+
82+
// Assert
83+
var services = _services.BuildServiceProvider();
84+
var service = services.GetService<IResourceService<TestModel>>();
85+
Assert.IsType<TestModelService>(service);
86+
}
87+
88+
[Fact]
89+
public void AddCurrentAssembly_Adds_Repositories_To_Container()
90+
{
91+
// Arrange, act
92+
_facade.AddCurrentAssembly();
93+
94+
// Assert
95+
var services = _services.BuildServiceProvider();
96+
Assert.IsType<TestModelRepository>(services.GetService<IResourceRepository<TestModel>>());
97+
}
98+
99+
public class TestModel : Identifiable { }
100+
101+
public class TestModelService : DefaultResourceService<TestModel>
78102
{
79-
// arrange, act
80-
_facade.AddCurrentAssembly();
81-
82-
// assert
83-
var services = _services.BuildServiceProvider();
84-
var service = services.GetService<IResourceService<TestModel>>();
85-
Assert.IsType<TestModelService>(service);
86-
}
87-
88-
[Fact]
89-
public void AddCurrentAssembly_Adds_Repositories_To_Container()
90-
{
91-
// arrange, act
92-
_facade.AddCurrentAssembly();
93-
94-
// assert
95-
var services = _services.BuildServiceProvider();
96-
Assert.IsType<TestModelRepository>(services.GetService<IResourceRepository<TestModel>>());
97-
}
98-
99-
public class TestModel : Identifiable { }
100-
101-
public class TestModelService : DefaultResourceService<TestModel>
102-
{
103103
private static IResourceRepository<TestModel> _repo = new Mock<IResourceRepository<TestModel>>().Object;
104104

105105
public TestModelService(IEnumerable<IQueryParameterService> queryParameters,
@@ -109,16 +109,16 @@ public TestModelService(IEnumerable<IQueryParameterService> queryParameters,
109109
IResourceHookExecutor hookExecutor = null,
110110
ILoggerFactory loggerFactory = null)
111111
: base(queryParameters, options, repository, provider, hookExecutor, loggerFactory) { }
112-
}
113-
114-
public class TestModelRepository : DefaultResourceRepository<TestModel>
115-
{
112+
}
113+
114+
public class TestModelRepository : DefaultResourceRepository<TestModel>
115+
{
116116
internal static IDbContextResolver _dbContextResolver;
117117

118118
public TestModelRepository(ITargetedFields targetedFields,
119119
IResourceGraph resourceGraph,
120120
IGenericServiceFactory genericServiceFactory)
121121
: base(targetedFields, _dbContextResolver, resourceGraph, genericServiceFactory) { }
122-
}
123-
}
124-
}
122+
}
123+
}
124+
}

test/JsonApiDotNetCoreExampleTests/Acceptance/CamelCasedModelsControllerTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ public async Task Can_Get_CamelCasedModels_ById()
6666

6767
var httpMethod = new HttpMethod("GET");
6868
var route = $"api/v1/camelCasedModels/{model.Id}";
69+
var request = new HttpRequestMessage(httpMethod, route);
70+
71+
// unnecessary, will fix in 4.1
6972
var builder = new WebHostBuilder()
70-
.UseStartup<Startup>();
73+
.UseStartup<Startup>();
7174
var server = new TestServer(builder);
7275
var client = server.CreateClient();
73-
var request = new HttpRequestMessage(httpMethod, route);
7476

7577
// Act
7678
var response = await client.SendAsync(request);

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CustomControllerTests(TestFixture<TestStartup> fixture)
3535
[Fact]
3636
public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes()
3737
{
38-
// arrange
38+
// Arrange
3939
var builder = new WebHostBuilder()
4040
.UseStartup<Startup>();
4141
var httpMethod = new HttpMethod("GET");
@@ -45,10 +45,10 @@ public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes()
4545
var client = server.CreateClient();
4646
var request = new HttpRequestMessage(httpMethod, route);
4747

48-
// act
48+
// Act
4949
var response = await client.SendAsync(request);
5050

51-
// assert
51+
// Assert
5252
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
5353
}
5454

@@ -65,10 +65,10 @@ public async Task CustomRouteControllers_Uses_Dasherized_Collection_Route()
6565
var client = server.CreateClient();
6666
var request = new HttpRequestMessage(httpMethod, route);
6767

68-
// act
68+
// Act
6969
var response = await client.SendAsync(request);
7070

71-
// assert
71+
// Assert
7272
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
7373
}
7474

@@ -92,10 +92,10 @@ public async Task CustomRouteControllers_Uses_Dasherized_Item_Route()
9292
var client = server.CreateClient();
9393
var request = new HttpRequestMessage(httpMethod, route);
9494

95-
// act
95+
// Act
9696
var response = await client.SendAsync(request);
9797

98-
// assert
98+
// Assert
9999
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
100100
}
101101

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NullValuedAttributeHandlingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public async Task CheckNullBehaviorCombination(bool? omitNullValuedAttributes, b
8686
var route = $"/api/v1/todo-items/{_todoItem.Id}?include=owner{queryString}";
8787
var request = new HttpRequestMessage(httpMethod, route);
8888

89-
// act
89+
// Act
9090
var response = await _fixture.Client.SendAsync(request);
9191
var body = await response.Content.ReadAsStringAsync();
9292
var deserializeBody = JsonConvert.DeserializeObject<Document>(body);
9393

94-
// assert: does response contain a null valued attribute?
94+
// Assert: does response contain a null valued attribute?
9595
Assert.Equal(omitsNulls, !deserializeBody.SingleData.Attributes.ContainsKey("description"));
9696
Assert.Equal(omitsNulls, !deserializeBody.Included[0].Attributes.ContainsKey("last-name"));
9797

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/RequestMetaTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public RequestMetaTests(TestFixture<TestStartup> fixture)
2626
[Fact]
2727
public async Task Injecting_IRequestMeta_Adds_Meta_Data()
2828
{
29-
// arrange
29+
// Arrange
3030
var builder = new WebHostBuilder()
3131
.UseStartup<MetaStartup>();
3232

@@ -38,12 +38,12 @@ public async Task Injecting_IRequestMeta_Adds_Meta_Data()
3838
var request = new HttpRequestMessage(httpMethod, route);
3939
var expectedMeta = (_fixture.GetService<ResourceDefinition<Person>>() as IHasMeta).GetMeta();
4040

41-
// act
41+
// Act
4242
var response = await client.SendAsync(request);
4343
var body = await response.Content.ReadAsStringAsync();
4444
var meta = _fixture.GetDeserializer().DeserializeList<Person>(body).Meta;
4545

46-
// assert
46+
// Assert
4747
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
4848
Assert.NotNull(meta);
4949
Assert.NotNull(expectedMeta);

0 commit comments

Comments
 (0)