Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 27062ed

Browse filesBrowse files
committed
Updating packages and Code review
1 parent ac89822 commit 27062ed
Copy full SHA for 27062ed
Expand file treeCollapse file tree

16 files changed

+224
-251
lines changed

‎src/Unosquare.Swan.AspNetCore.Sample/Controllers/ProductController.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Controllers/ProductController.cs
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
23
using System.Collections.Generic;
34
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
65
using Unosquare.Swan.AspNetCore.Sample.Database;
7-
using Microsoft.AspNetCore.Authorization;
86

97
namespace Unosquare.Swan.AspNetCore.Sample.Controllers
108
{

‎src/Unosquare.Swan.AspNetCore.Sample/Controllers/ValuesController.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Controllers/ValuesController.cs
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
1+
using Microsoft.AspNetCore.Mvc;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
63

74
namespace Unosquare.Swan.AspNetCore.Sample.Controllers
85
{

‎src/Unosquare.Swan.AspNetCore.Sample/Database/AuditTrailEntry.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Database/AuditTrailEntry.cs
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.DataAnnotations;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Unosquare.Swan.AspNetCore.Models;
7-
8-
namespace Unosquare.Swan.AspNetCore.Sample.Database
1+
namespace Unosquare.Swan.AspNetCore.Sample.Database
92
{
3+
using System;
4+
using System.ComponentModel.DataAnnotations;
5+
using Models;
6+
107
public class AuditTrailEntry :IAuditTrailEntry
118
{
129
[Key]

‎src/Unosquare.Swan.AspNetCore.Sample/Database/Product.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Database/Product.cs
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.DataAnnotations;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
7-
namespace Unosquare.Swan.AspNetCore.Sample.Database
1+
namespace Unosquare.Swan.AspNetCore.Sample.Database
82
{
3+
using System.ComponentModel.DataAnnotations;
4+
95
public class Product
106
{
117
[Key]

‎src/Unosquare.Swan.AspNetCore.Sample/Startup.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Startup.cs
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace Unosquare.Swan.AspNetCore.Sample
22
{
3-
using AspNetCore;
43
using Database;
54
using Microsoft.AspNetCore.Builder;
65
using Microsoft.AspNetCore.Hosting;
@@ -46,7 +45,7 @@ public Startup(IHostingEnvironment env)
4645
}
4746

4847
public IConfigurationRoot Configuration { get; }
49-
private TokenValidationParameters ValidationParameters { get; set; }
48+
private TokenValidationParameters ValidationParameters { get; }
5049

5150
// This method gets called by the runtime. Use this method to add services to the container
5251
public void ConfigureServices(IServiceCollection services)

‎src/Unosquare.Swan.AspNetCore.Sample/Unosquare.Swan.AspNetCore.Sample.csproj

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore.Sample/Unosquare.Swan.AspNetCore.Sample.csproj
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.0.0" />
21-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.0" />
22-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
24-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
27-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
20+
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.0.1" />
21+
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.1" />
22+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.1" />
23+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
24+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
26+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
27+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
2828
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
2929
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
3030
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
3131
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
3232
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
3333
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
3434
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
35-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
35+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
3636
</ItemGroup>
3737

3838
<ItemGroup>

‎src/Unosquare.Swan.AspNetCore/AuditTrailController.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore/AuditTrailController.cs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using Unosquare.Swan.AspNetCore.Models;
8-
using Unosquare.Swan.Formatters;
7+
using Models;
8+
using Formatters;
99

1010
/// <summary>
1111
/// Represents an AuditTrail controller to use with BusinessDbContext

‎src/Unosquare.Swan.AspNetCore/BusinessRuleAttribute.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore/BusinessRuleAttribute.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class BusinessRuleAttribute : Attribute
4343
/// <param name="actionFlags">The action flags.</param>
4444
public BusinessRuleAttribute(ActionFlags actionFlags)
4545
{
46-
this.Action = actionFlags;
46+
Action = actionFlags;
4747
}
4848

4949
/// <summary>
@@ -53,8 +53,8 @@ public BusinessRuleAttribute(ActionFlags actionFlags)
5353
/// <param name="actionFlags">The action flags.</param>
5454
public BusinessRuleAttribute(Type[] entityTypes, ActionFlags actionFlags)
5555
{
56-
this.EntityTypes = entityTypes;
57-
this.Action = actionFlags;
56+
EntityTypes = entityTypes;
57+
Action = actionFlags;
5858
}
5959

6060
/// <summary>

‎src/Unosquare.Swan.AspNetCore/BusinessRulesController.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore/BusinessRulesController.cs
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public void RunBusinessRules()
9292

9393
private void ExecuteBusinessRulesMethods(EntityState state, ActionFlags action, MethodInfo[] methodInfoSet)
9494
{
95-
var selfTrackingEntries = Context.ChangeTracker.Entries().Where(x => x.State == state).ToList();
95+
var selfTrackingEntries = Context.ChangeTracker.Entries()
96+
.Where(x => x.State == state)
97+
.ToList();
9698

9799
foreach (var entry in selfTrackingEntries)
98100
{
@@ -103,12 +105,12 @@ private void ExecuteBusinessRulesMethods(EntityState state, ActionFlags action,
103105
var methods = methodInfoSet.Where(m => m.GetCustomAttributes(typeof(BusinessRuleAttribute), true)
104106
.Select(a => a as BusinessRuleAttribute)
105107
.Any(b => b != null && (b.EntityTypes == null ||
106-
b.EntityTypes.Any(t => t == entityType)) &&
107-
b.Action == action));
108+
b.EntityTypes.Any(t => t == entityType)) &&
109+
b.Action == action));
108110

109111
foreach (var methodInfo in methods)
110112
{
111-
methodInfo.Invoke(this, new[] { entity });
113+
methodInfo.Invoke(this, new[] {entity});
112114
}
113115
}
114116
}

‎src/Unosquare.Swan.AspNetCore/TokenProviderMiddleware.cs

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore/TokenProviderMiddleware.cs
+57-63Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,63 @@ public Task Invoke(HttpContext context)
8585
return _next(context);
8686
}
8787

88+
private static void ThrowIfInvalidOptions(TokenProviderOptions options)
89+
{
90+
if (string.IsNullOrEmpty(options.Path))
91+
{
92+
throw new ArgumentNullException(nameof(TokenProviderOptions.Path));
93+
}
94+
95+
if (string.IsNullOrEmpty(options.Issuer))
96+
{
97+
throw new ArgumentNullException(nameof(TokenProviderOptions.Issuer));
98+
}
99+
100+
if (string.IsNullOrEmpty(options.Audience))
101+
{
102+
throw new ArgumentNullException(nameof(TokenProviderOptions.Audience));
103+
}
104+
105+
if (options.Expiration == TimeSpan.Zero)
106+
{
107+
throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(TokenProviderOptions.Expiration));
108+
}
109+
110+
if (options.IdentityResolver == null)
111+
{
112+
throw new ArgumentNullException(nameof(TokenProviderOptions.IdentityResolver));
113+
}
114+
115+
if (options.SigningCredentials == null)
116+
{
117+
throw new ArgumentNullException(nameof(TokenProviderOptions.SigningCredentials));
118+
}
119+
120+
if (options.NonceGenerator == null)
121+
{
122+
throw new ArgumentNullException(nameof(TokenProviderOptions.NonceGenerator));
123+
}
124+
125+
if (options.IdentityResolver == null)
126+
{
127+
throw new ArgumentNullException(nameof(TokenProviderOptions.IdentityResolver));
128+
}
129+
130+
if (options.BearerTokenResolver == null)
131+
{
132+
throw new ArgumentNullException(nameof(TokenProviderOptions.BearerTokenResolver));
133+
}
134+
}
135+
136+
private static string SerializeError(string description, string error = "invalid_grant")
137+
{
138+
return Json.Serialize(new
139+
{
140+
error,
141+
error_description = description
142+
});
143+
}
144+
88145
private async Task GenerateToken(HttpContext context)
89146
{
90147
JwtSecurityToken jwt;
@@ -178,68 +235,5 @@ private async Task GenerateToken(HttpContext context)
178235

179236
await context.Response.WriteAsync(Json.Serialize(await _options.BearerTokenResolver(identity, responseInfo)));
180237
}
181-
182-
private static void ThrowIfInvalidOptions(TokenProviderOptions options)
183-
{
184-
if (string.IsNullOrEmpty(options.Path))
185-
{
186-
throw new ArgumentNullException(nameof(TokenProviderOptions.Path));
187-
}
188-
189-
if (string.IsNullOrEmpty(options.Issuer))
190-
{
191-
throw new ArgumentNullException(nameof(TokenProviderOptions.Issuer));
192-
}
193-
194-
if (string.IsNullOrEmpty(options.Audience))
195-
{
196-
throw new ArgumentNullException(nameof(TokenProviderOptions.Audience));
197-
}
198-
199-
if (options.Expiration == TimeSpan.Zero)
200-
{
201-
throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(TokenProviderOptions.Expiration));
202-
}
203-
204-
if (options.IdentityResolver == null)
205-
{
206-
throw new ArgumentNullException(nameof(TokenProviderOptions.IdentityResolver));
207-
}
208-
209-
if (options.SigningCredentials == null)
210-
{
211-
throw new ArgumentNullException(nameof(TokenProviderOptions.SigningCredentials));
212-
}
213-
214-
if (options.NonceGenerator == null)
215-
{
216-
throw new ArgumentNullException(nameof(TokenProviderOptions.NonceGenerator));
217-
}
218-
219-
if (options.IdentityResolver == null)
220-
{
221-
throw new ArgumentNullException(nameof(TokenProviderOptions.IdentityResolver));
222-
}
223-
224-
if (options.BearerTokenResolver == null)
225-
{
226-
throw new ArgumentNullException(nameof(TokenProviderOptions.BearerTokenResolver));
227-
}
228-
}
229-
230-
/// <summary>
231-
/// Serializes the error.
232-
/// </summary>
233-
/// <param name="description">The description.</param>
234-
/// <param name="error">The error.</param>
235-
/// <returns>The error in JSON format</returns>
236-
private static string SerializeError(string description, string error = "invalid_grant")
237-
{
238-
return Json.Serialize(new
239-
{
240-
error,
241-
error_description = description
242-
});
243-
}
244238
}
245239
}

‎src/Unosquare.Swan.AspNetCore/Unosquare.Swan.AspNetCore.csproj

Copy file name to clipboardExpand all lines: src/Unosquare.Swan.AspNetCore/Unosquare.Swan.AspNetCore.csproj
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>Bearer Token and logging to fast start any ASP.NET Core project</Description>
55
<Copyright>Copyright (c) 2016-2017 - Unosquare</Copyright>
66
<AssemblyTitle>Unosquare SWAN AspNet Core</AssemblyTitle>
7-
<VersionPrefix>0.9.2</VersionPrefix>
7+
<VersionPrefix>0.9.3</VersionPrefix>
88
<TargetFrameworks>netstandard2.0</TargetFrameworks>
99
<DebugType>Full</DebugType>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -17,16 +17,16 @@
1717
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
1818
<PrivateAssets>All</PrivateAssets>
1919
</PackageReference>
20-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
21-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.0.0" />
22-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
20+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.1" />
21+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.0.1" />
22+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.1" />
23+
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.1" />
24+
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
2626
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
2727
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.1.4" />
2828
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.1.4" />
29-
<PackageReference Include="Unosquare.Swan" Version="0.15.0" />
29+
<PackageReference Include="Unosquare.Swan" Version="0.18.0" />
3030
</ItemGroup>
3131

3232
</Project>

‎test/Unosquare.Swan.AspNetCore.Test/AuditTrailTest.cs

Copy file name to clipboardExpand all lines: test/Unosquare.Swan.AspNetCore.Test/AuditTrailTest.cs
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[TestFixture]
1010
class AuditTrailTest
1111
{
12-
private ProductMock product;
12+
private ProductMock _product;
1313

1414
private BusinessDbContextMock SetupDatabase(string name)
1515
{
@@ -22,15 +22,15 @@ private BusinessDbContextMock SetupDatabase(string name)
2222
[SetUp]
2323
public void SetUp()
2424
{
25-
product = ProductMock.GetProduct();
25+
_product = ProductMock.GetProduct();
2626
}
2727

2828
[Test]
2929
public async Task SaveChangesEntityTestAsync()
3030
{
3131
using (var context = SetupDatabase(nameof(SaveChangesEntityTestAsync)))
3232
{
33-
context.Add(product);
33+
context.Add(_product);
3434
await context.SaveChangesAsync();
3535

3636
var audit = context.AuditTrailEntries.Last();
@@ -46,7 +46,7 @@ public void SaveChangesEntityTest()
4646
using (var context = SetupDatabase(nameof(SaveChangesEntityTest)))
4747
{
4848

49-
context.Add(product);
49+
context.Add(_product);
5050
context.SaveChanges();
5151

5252
var audit = context.AuditTrailEntries.Last();
@@ -61,10 +61,10 @@ public void UpdatedChangesEntityTest()
6161
{
6262
using (var context = SetupDatabase(nameof(UpdatedChangesEntityTest)))
6363
{
64-
context.Add(product);
64+
context.Add(_product);
6565
context.SaveChanges();
6666

67-
context.Update(product);
67+
context.Update(_product);
6868
context.SaveChanges();
6969

7070
var audit = context.AuditTrailEntries.Last();
@@ -79,10 +79,10 @@ public void DeleteChangesEntityTest()
7979
{
8080
using (var context = SetupDatabase(nameof(DeleteChangesEntityTest)))
8181
{
82-
context.Add(product);
82+
context.Add(_product);
8383
context.SaveChanges();
8484

85-
context.Remove(product);
85+
context.Remove(_product);
8686
context.SaveChanges();
8787

8888
var audit = context.AuditTrailEntries.Last();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.