Skip to content

Commit 8e7fbb9

Browse files
authored
Merge pull request #103 from lakatoshv/v3.7.3_AddExceptionTestsForDeleteMethodsAndCodeRefactoringToAspNet10
V3.7.3 add exception tests for delete methods and code refactoring to asp net10
2 parents ba219ba + 0aacbfc commit 8e7fbb9

File tree

100 files changed

+1309
-660
lines changed

Some content is hidden

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

100 files changed

+1309
-660
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@
109109
/BlogWebApp/Blog.Web/ClientApp/.angular/cache/20.0.1/BlogAngular
110110
/BlogWebApp/Blog.Web/ClientApp/dist/BlogAngular
111111
/Clients/BlogRazor/bin/Debug/net9.0
112+
/BlogWebApp/BlogBlazor/bin/Debug/net9.0
113+
/BlogWebApp/BlogBlazor/obj

BlogWebApp/Blog.Web/Cache/CachedAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
/// <remarks>
2020
/// Initializes a new instance of the <see cref="CachedAttribute"/> class.
2121
/// </remarks>
22-
/// <param name="lifeTimeSeconds">The life time seconds.</param>
22+
/// <param name="lifeTimeSeconds">The lifetime seconds.</param>
2323
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
2424
public class CachedAttribute(int lifeTimeSeconds)
2525
: Attribute, IAsyncActionFilter
2626
{
2727
/// <summary>
28-
/// The life time seconds.
28+
/// The lifetime seconds.
2929
/// </summary>
3030
private readonly int _lifeTimeSeconds = lifeTimeSeconds;
3131

BlogWebApp/Blog.Web/Controllers/V1/AccountsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public async Task<IActionResult> CreateAsync([FromBody] RegistrationRequest mode
222222
return Bad(result);
223223
}
224224

225-
model.Roles ??= new[] {"User"};
225+
model.Roles ??= ["User"];
226226

227227
foreach(var role in model.Roles)
228228
{

BlogWebApp/Blog.Web/Controllers/V1/CommentsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public async Task<IActionResult> CreateAsync([FromBody] CreateCommentRequest req
183183
comment.CreatedAt = Now;
184184
await _commentService.InsertAsync(comment);
185185
var response = new CreatedResponse<int> {Id = comment.Id};
186-
var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
186+
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
187187
var locationUrl = baseUrl + "/" +
188188
ApiRoutes.CommentsController.Comments + "/" +
189189
ApiRoutes.CommentsController.GetComment + "/" + comment.Id;

BlogWebApp/Blog.Web/Controllers/V1/PostsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public async Task<IActionResult> CreateAsync([FromBody] CreatePostRequest model)
223223

224224
var response = new CreatedResponse<int> { Id = postToCreate.Id };
225225

226-
var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
226+
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
227227
var locationUrl = baseUrl + "/" + ApiRoutes.PostsController.Show.Replace("{id}", postToCreate.Id.ToString());
228228

229229
return Created(locationUrl, response);

BlogWebApp/Blog.Web/Controllers/V1/TagsController.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public async Task<ActionResult> GetTags()
8585
[Cached(600)]
8686
public async Task<ActionResult> GetTagsByFilter([FromBody] SearchParametersRequest searchParameters = null)
8787
{
88+
if (searchParameters == null)
89+
return BadRequest();
90+
8891
searchParameters.SortParameters ??= new SortParametersRequest();
8992

9093
searchParameters.SortParameters.OrderBy ??= "asc";
@@ -179,12 +182,7 @@ public async Task<ActionResult> TagsActivity()
179182
[Authorize]
180183
public async Task<IActionResult> CreateAsync([FromBody] CreateTagRequest model)
181184
{
182-
if (!ModelState.IsValid)
183-
{
184-
return Bad(ModelState);
185-
}
186-
187-
if (await _tagsService.AnyAsync(new TagSpecification(x => x.Title.ToLower().Equals(model.Title.ToLower()))))
185+
if (!ModelState.IsValid || await _tagsService.AnyAsync(new TagSpecification(x => x.Title.ToLower().Equals(model.Title.ToLower()))))
188186
{
189187
return Bad(ModelState);
190188
}
@@ -194,7 +192,7 @@ public async Task<IActionResult> CreateAsync([FromBody] CreateTagRequest model)
194192

195193
var response = new CreatedResponse<int> { Id = tag.Id };
196194

197-
var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
195+
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
198196
var locationUrl = baseUrl + "/" + ApiRoutes.TagsController.GetTag.Replace("{id}", tag.Id.ToString());
199197

200198
return Created(locationUrl, response);

BlogWebApp/Blog.Web/Factories/CategoryRequestFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public override CreateCategoryRequest GenerateForCreate() =>
4949
public override UpdateCategoryRequest GenerateForUpdate(int id)
5050
{
5151
var category = _unitOfWork.GetRepository<Category>().FirstOrDefault(new CategorySpecification(x => x.Id == id))
52-
?? throw new MicroserviceArgumentNullException();;
52+
?? throw new MicroserviceArgumentNullException();
5353

5454

5555
var mapped = _mapper.Map<UpdateCategoryRequest>(category);

BlogWebApp/Blog.Web/Filters/SwaggerFilters/LowercaseDocumentFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
1717
}
1818

1919
/// <summary>
20-
/// Lowercase the everything but parameters.
20+
/// Lowercase everything but parameters.
2121
/// </summary>
2222
/// <param name="key">The key.</param>
2323
/// <returns>string.</returns>

BlogWebApp/Blog.Web/Filters/SwaggerFilters/SwaggerGroupOperationFilter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
2424
if (attributes.Any())
2525
{
2626
var groupNameAttribute = attributes.First();
27-
operation.Tags = new[] { new OpenApiTag { Name = groupNameAttribute.GroupName } };
27+
operation.Tags = [new OpenApiTag { Name = groupNameAttribute.GroupName }];
2828
}
2929
else
3030
{
31-
operation.Tags = new[] { new OpenApiTag { Name = controllerActionDescriptor.RouteValues["controller"] } };
31+
operation.Tags = [new OpenApiTag { Name = controllerActionDescriptor.RouteValues["controller"] }];
3232
}
3333
}
3434
}

BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/AuthenticationAndAuthorizationInstaller.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public void InstallServices(IServiceCollection services, IConfiguration configur
102102
});
103103
services.AddCors(options =>
104104
{
105-
options.AddPolicy("AllowAll", bilder =>
105+
options.AddPolicy("AllowAll", builder =>
106106
{
107-
bilder.AllowAnyOrigin()
107+
builder.AllowAnyOrigin()
108108
.AllowAnyHeader()
109109
.AllowAnyMethod();
110110
});
111-
options.AddPolicy("AllowAllBlazor", bilder =>
111+
options.AddPolicy("AllowAllBlazor", builder =>
112112
{
113-
bilder.WithOrigins("https://localhost:44390").AllowAnyOrigin()
113+
builder.WithOrigins("https://localhost:44390").AllowAnyOrigin()
114114
.AllowAnyHeader()
115115
.AllowAnyMethod();
116116
});

0 commit comments

Comments
 (0)