diff --git a/.gitignore b/.gitignore
index f22fd045..3636aa8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,3 +109,5 @@
/BlogWebApp/Blog.Web/ClientApp/.angular/cache/20.0.1/BlogAngular
/BlogWebApp/Blog.Web/ClientApp/dist/BlogAngular
/Clients/BlogRazor/bin/Debug/net9.0
+/BlogWebApp/BlogBlazor/bin/Debug/net9.0
+/BlogWebApp/BlogBlazor/obj
diff --git a/BlogWebApp/Blog.Web/Cache/CachedAttribute.cs b/BlogWebApp/Blog.Web/Cache/CachedAttribute.cs
index 34c7b8e6..498a8ab6 100644
--- a/BlogWebApp/Blog.Web/Cache/CachedAttribute.cs
+++ b/BlogWebApp/Blog.Web/Cache/CachedAttribute.cs
@@ -19,13 +19,13 @@
///
/// Initializes a new instance of the class.
///
-/// The life time seconds.
+/// The lifetime seconds.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CachedAttribute(int lifeTimeSeconds)
: Attribute, IAsyncActionFilter
{
///
- /// The life time seconds.
+ /// The lifetime seconds.
///
private readonly int _lifeTimeSeconds = lifeTimeSeconds;
diff --git a/BlogWebApp/Blog.Web/Controllers/V1/AccountsController.cs b/BlogWebApp/Blog.Web/Controllers/V1/AccountsController.cs
index 7093b72d..c65286a7 100644
--- a/BlogWebApp/Blog.Web/Controllers/V1/AccountsController.cs
+++ b/BlogWebApp/Blog.Web/Controllers/V1/AccountsController.cs
@@ -222,7 +222,7 @@ public async Task CreateAsync([FromBody] RegistrationRequest mode
return Bad(result);
}
- model.Roles ??= new[] {"User"};
+ model.Roles ??= ["User"];
foreach(var role in model.Roles)
{
diff --git a/BlogWebApp/Blog.Web/Controllers/V1/CommentsController.cs b/BlogWebApp/Blog.Web/Controllers/V1/CommentsController.cs
index 88815c55..a383646b 100644
--- a/BlogWebApp/Blog.Web/Controllers/V1/CommentsController.cs
+++ b/BlogWebApp/Blog.Web/Controllers/V1/CommentsController.cs
@@ -183,7 +183,7 @@ public async Task CreateAsync([FromBody] CreateCommentRequest req
comment.CreatedAt = Now;
await _commentService.InsertAsync(comment);
var response = new CreatedResponse {Id = comment.Id};
- var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
+ var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
var locationUrl = baseUrl + "/" +
ApiRoutes.CommentsController.Comments + "/" +
ApiRoutes.CommentsController.GetComment + "/" + comment.Id;
diff --git a/BlogWebApp/Blog.Web/Controllers/V1/PostsController.cs b/BlogWebApp/Blog.Web/Controllers/V1/PostsController.cs
index 5b38f15b..796930a3 100644
--- a/BlogWebApp/Blog.Web/Controllers/V1/PostsController.cs
+++ b/BlogWebApp/Blog.Web/Controllers/V1/PostsController.cs
@@ -223,7 +223,7 @@ public async Task CreateAsync([FromBody] CreatePostRequest model)
var response = new CreatedResponse { Id = postToCreate.Id };
- var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
+ var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
var locationUrl = baseUrl + "/" + ApiRoutes.PostsController.Show.Replace("{id}", postToCreate.Id.ToString());
return Created(locationUrl, response);
diff --git a/BlogWebApp/Blog.Web/Controllers/V1/TagsController.cs b/BlogWebApp/Blog.Web/Controllers/V1/TagsController.cs
index c67f32f0..69bb53e5 100644
--- a/BlogWebApp/Blog.Web/Controllers/V1/TagsController.cs
+++ b/BlogWebApp/Blog.Web/Controllers/V1/TagsController.cs
@@ -85,6 +85,9 @@ public async Task GetTags()
[Cached(600)]
public async Task GetTagsByFilter([FromBody] SearchParametersRequest searchParameters = null)
{
+ if (searchParameters == null)
+ return BadRequest();
+
searchParameters.SortParameters ??= new SortParametersRequest();
searchParameters.SortParameters.OrderBy ??= "asc";
@@ -179,12 +182,7 @@ public async Task TagsActivity()
[Authorize]
public async Task CreateAsync([FromBody] CreateTagRequest model)
{
- if (!ModelState.IsValid)
- {
- return Bad(ModelState);
- }
-
- if (await _tagsService.AnyAsync(new TagSpecification(x => x.Title.ToLower().Equals(model.Title.ToLower()))))
+ if (!ModelState.IsValid || await _tagsService.AnyAsync(new TagSpecification(x => x.Title.ToLower().Equals(model.Title.ToLower()))))
{
return Bad(ModelState);
}
@@ -194,7 +192,7 @@ public async Task CreateAsync([FromBody] CreateTagRequest model)
var response = new CreatedResponse { Id = tag.Id };
- var baseUrl = $@"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
+ var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
var locationUrl = baseUrl + "/" + ApiRoutes.TagsController.GetTag.Replace("{id}", tag.Id.ToString());
return Created(locationUrl, response);
diff --git a/BlogWebApp/Blog.Web/Factories/CategoryRequestFactory.cs b/BlogWebApp/Blog.Web/Factories/CategoryRequestFactory.cs
index 22facc14..27ed9f81 100644
--- a/BlogWebApp/Blog.Web/Factories/CategoryRequestFactory.cs
+++ b/BlogWebApp/Blog.Web/Factories/CategoryRequestFactory.cs
@@ -49,7 +49,7 @@ public override CreateCategoryRequest GenerateForCreate() =>
public override UpdateCategoryRequest GenerateForUpdate(int id)
{
var category = _unitOfWork.GetRepository().FirstOrDefault(new CategorySpecification(x => x.Id == id))
- ?? throw new MicroserviceArgumentNullException();;
+ ?? throw new MicroserviceArgumentNullException();
var mapped = _mapper.Map(category);
diff --git a/BlogWebApp/Blog.Web/Filters/SwaggerFilters/LowercaseDocumentFilter.cs b/BlogWebApp/Blog.Web/Filters/SwaggerFilters/LowercaseDocumentFilter.cs
index 80cd74d0..e4ca9b3c 100644
--- a/BlogWebApp/Blog.Web/Filters/SwaggerFilters/LowercaseDocumentFilter.cs
+++ b/BlogWebApp/Blog.Web/Filters/SwaggerFilters/LowercaseDocumentFilter.cs
@@ -17,7 +17,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
}
///
- /// Lowercase the everything but parameters.
+ /// Lowercase everything but parameters.
///
/// The key.
/// string.
diff --git a/BlogWebApp/Blog.Web/Filters/SwaggerFilters/SwaggerGroupOperationFilter.cs b/BlogWebApp/Blog.Web/Filters/SwaggerFilters/SwaggerGroupOperationFilter.cs
index 1d7294cd..ad40481f 100644
--- a/BlogWebApp/Blog.Web/Filters/SwaggerFilters/SwaggerGroupOperationFilter.cs
+++ b/BlogWebApp/Blog.Web/Filters/SwaggerFilters/SwaggerGroupOperationFilter.cs
@@ -24,11 +24,11 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
if (attributes.Any())
{
var groupNameAttribute = attributes.First();
- operation.Tags = new[] { new OpenApiTag { Name = groupNameAttribute.GroupName } };
+ operation.Tags = [new OpenApiTag { Name = groupNameAttribute.GroupName }];
}
else
{
- operation.Tags = new[] { new OpenApiTag { Name = controllerActionDescriptor.RouteValues["controller"] } };
+ operation.Tags = [new OpenApiTag { Name = controllerActionDescriptor.RouteValues["controller"] }];
}
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/AuthenticationAndAuthorizationInstaller.cs b/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/AuthenticationAndAuthorizationInstaller.cs
index ee6177ab..51fe24f0 100644
--- a/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/AuthenticationAndAuthorizationInstaller.cs
+++ b/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/AuthenticationAndAuthorizationInstaller.cs
@@ -102,15 +102,15 @@ public void InstallServices(IServiceCollection services, IConfiguration configur
});
services.AddCors(options =>
{
- options.AddPolicy("AllowAll", bilder =>
+ options.AddPolicy("AllowAll", builder =>
{
- bilder.AllowAnyOrigin()
+ builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
- options.AddPolicy("AllowAllBlazor", bilder =>
+ options.AddPolicy("AllowAllBlazor", builder =>
{
- bilder.WithOrigins("https://localhost:44390").AllowAnyOrigin()
+ builder.WithOrigins("https://localhost:44390").AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
diff --git a/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/CorsInstaller.cs b/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/CorsInstaller.cs
index fc0c77e2..121e4ac6 100644
--- a/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/CorsInstaller.cs
+++ b/BlogWebApp/Blog.Web/StartupConfigureServicesInstallers/CorsInstaller.cs
@@ -29,7 +29,7 @@ public void InstallServices(IServiceCollection services, IConfiguration configur
{
builder.AllowAnyHeader();
builder.AllowAnyMethod();
- builder.SetIsOriginAllowed(host => true);
+ builder.SetIsOriginAllowed(_ => true);
builder.AllowCredentials();
}
else
diff --git a/BlogWebApp/Blog.Web/StartupConfigures/ConfigureSpa.cs b/BlogWebApp/Blog.Web/StartupConfigures/ConfigureSpa.cs
index 06e60c8e..e19f9016 100644
--- a/BlogWebApp/Blog.Web/StartupConfigures/ConfigureSpa.cs
+++ b/BlogWebApp/Blog.Web/StartupConfigures/ConfigureSpa.cs
@@ -26,7 +26,7 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
- spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); ;
+ spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
}
else
{
diff --git a/BlogWebApp/Blog.Web/SwaggerExamples/Responses/CreatedResponseExample.cs b/BlogWebApp/Blog.Web/SwaggerExamples/Responses/CreatedResponseExample.cs
index 28205945..a5e62539 100644
--- a/BlogWebApp/Blog.Web/SwaggerExamples/Responses/CreatedResponseExample.cs
+++ b/BlogWebApp/Blog.Web/SwaggerExamples/Responses/CreatedResponseExample.cs
@@ -6,7 +6,9 @@
///
/// Created response example.
///
-///
+///
+/// IExamplesProvider{CreatedResponse{int}}
+///
public class CreatedResponseExample : IExamplesProvider>
{
///
diff --git a/BlogWebApp/Blog.Web/VIewModels/AspNetUser/TwoFactorAuthenticationViewModel.cs b/BlogWebApp/Blog.Web/VIewModels/AspNetUser/TwoFactorAuthenticationViewModel.cs
index d9d00036..43635da8 100644
--- a/BlogWebApp/Blog.Web/VIewModels/AspNetUser/TwoFactorAuthenticationViewModel.cs
+++ b/BlogWebApp/Blog.Web/VIewModels/AspNetUser/TwoFactorAuthenticationViewModel.cs
@@ -1,7 +1,7 @@
namespace BLog.Web.ViewModels.AspNetUser;
///
-/// Two factor authentication view model
+/// Two-factor authentication view model
///
public class TwoFactorAuthenticationViewModel
{
diff --git a/BlogWebApp/Blog.sln.DotSettings.user b/BlogWebApp/Blog.sln.DotSettings.user
index f0d73571..419787f0 100644
--- a/BlogWebApp/Blog.sln.DotSettings.user
+++ b/BlogWebApp/Blog.sln.DotSettings.user
@@ -1,4 +1,7 @@
+ <AssemblyExplorer>
+ <Assembly Path="C:\Users\user\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll" />
+</AssemblyExplorer>
<SessionState ContinuousTestingMode="0" Name="PostTagRelationsServiceTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
<TestAncestor>
<TestId>xUnit::8AE98490-2264-4CBC-8B61-62DA16A2EC82::net5.0::Blog.ServicesTests.EntityServices.PostTagRelationsServiceTests</TestId>
diff --git a/BlogWebApp/Blog.slnLaunch.user b/BlogWebApp/Blog.slnLaunch.user
new file mode 100644
index 00000000..2890067f
--- /dev/null
+++ b/BlogWebApp/Blog.slnLaunch.user
@@ -0,0 +1,15 @@
+[
+ {
+ "Name": "New Profile",
+ "Projects": [
+ {
+ "Path": "Blog.Web\\Blog.Web.csproj",
+ "Action": "Start"
+ },
+ {
+ "Path": "BlogBlazor\\BlogBlazor.csproj",
+ "Action": "Start"
+ }
+ ]
+ }
+]
\ No newline at end of file
diff --git a/BlogWebApp/Data/Blog.Data.Core/Entity.cs b/BlogWebApp/Data/Blog.Data.Core/Entity.cs
index 7320381b..b3457a07 100644
--- a/BlogWebApp/Data/Blog.Data.Core/Entity.cs
+++ b/BlogWebApp/Data/Blog.Data.Core/Entity.cs
@@ -4,8 +4,8 @@
namespace Blog.Data.Core;
-using System;
using Blog.Core;
+using System;
///
/// Entity.
@@ -74,13 +74,13 @@ public virtual bool Equals(Entity other)
var otherType = other.GetUnproxiedType();
var thisType = this.GetUnproxiedType();
- return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType);
+ return otherType != null && (thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType));
}
///
public override int GetHashCode()
{
- return Equals(this.Id, default(int)) ? base.GetHashCode() : this.Id.GetHashCode();
+ return Equals(this.Id, 0) ? base.GetHashCode() : this.Id.GetHashCode();
}
///
@@ -90,7 +90,7 @@ public override int GetHashCode()
/// bool.
private static bool IsTransient(Entity obj)
{
- return obj != null && Equals(obj.Id, default(int));
+ return obj != null && Equals(obj.Id, 0);
}
///
diff --git a/BlogWebApp/Data/Blog.Data.Core/Models/BaseDeletableModel.cs b/BlogWebApp/Data/Blog.Data.Core/Models/BaseDeletableModel.cs
index f4f2f8f0..ff974d05 100644
--- a/BlogWebApp/Data/Blog.Data.Core/Models/BaseDeletableModel.cs
+++ b/BlogWebApp/Data/Blog.Data.Core/Models/BaseDeletableModel.cs
@@ -4,9 +4,9 @@
namespace Blog.Data.Core.Models;
-using System;
using Blog.Core;
using Interfaces;
+using System;
///
/// Base deletable model.
@@ -89,13 +89,13 @@ public virtual bool Equals(BaseDeletableModel other)
var otherType = other.GetUnproxiedType();
var thisType = this.GetUnproxiedType();
- return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType);
+ return otherType != null && (thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType));
}
///
public override int GetHashCode()
{
- return Equals(this.Id, default(int)) ? base.GetHashCode() : this.Id.GetHashCode();
+ return Equals(this.Id, 0) ? base.GetHashCode() : this.Id.GetHashCode();
}
///
@@ -105,7 +105,7 @@ public override int GetHashCode()
/// bool.
private static bool IsTransient(BaseDeletableModel obj)
{
- return obj != null && Equals(obj.Id, default(int));
+ return obj != null && Equals(obj.Id, 0);
}
///
diff --git a/BlogWebApp/Data/Blog.Data.Core/Models/BaseModel.cs b/BlogWebApp/Data/Blog.Data.Core/Models/BaseModel.cs
index 659fea0a..b26295a6 100644
--- a/BlogWebApp/Data/Blog.Data.Core/Models/BaseModel.cs
+++ b/BlogWebApp/Data/Blog.Data.Core/Models/BaseModel.cs
@@ -4,26 +4,22 @@
namespace Blog.Data.Core.Models;
+using Interfaces;
using System;
using System.ComponentModel.DataAnnotations;
-using Interfaces;
///
/// Base model.
///
/// TKey.
-public abstract class BaseModel : IAuditInfo
+public abstract class BaseModel(TKey id)
+ : IAuditInfo
{
- protected BaseModel(TKey id)
- {
- Id = id;
- }
-
///
/// Gets or sets id.
///
[Key]
- public TKey Id { get; }
+ public TKey Id { get; } = id;
///
/// Gets or sets created on.
diff --git a/BlogWebApp/Data/Blog.Data.Models/ApplicationUser.cs b/BlogWebApp/Data/Blog.Data.Models/ApplicationUser.cs
index 7c560108..3280dd5b 100644
--- a/BlogWebApp/Data/Blog.Data.Models/ApplicationUser.cs
+++ b/BlogWebApp/Data/Blog.Data.Models/ApplicationUser.cs
@@ -4,11 +4,11 @@
namespace Blog.Data.Models;
-using System;
-using System.Collections.Generic;
using Blog.Core;
using Blog.Data.Core.Models.Interfaces;
using Microsoft.AspNetCore.Identity;
+using System;
+using System.Collections.Generic;
///
/// Application user entity.
diff --git a/BlogWebApp/Data/Blog.Data.Models/Message.cs b/BlogWebApp/Data/Blog.Data.Models/Message.cs
index 0879c24b..8be9cf9f 100644
--- a/BlogWebApp/Data/Blog.Data.Models/Message.cs
+++ b/BlogWebApp/Data/Blog.Data.Models/Message.cs
@@ -2,10 +2,9 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
-using Blog.Core.Enums;
-
namespace Blog.Data.Models;
+using Blog.Core.Enums;
using Core;
///
diff --git a/BlogWebApp/Data/Blog.Data.Models/Post.cs b/BlogWebApp/Data/Blog.Data.Models/Post.cs
index 19b189a7..3f898cfd 100644
--- a/BlogWebApp/Data/Blog.Data.Models/Post.cs
+++ b/BlogWebApp/Data/Blog.Data.Models/Post.cs
@@ -2,8 +2,8 @@
namespace Blog.Data.Models;
-using System;
using Core;
+using System;
///
/// Post entity.
diff --git a/BlogWebApp/Data/Blog.Data.Models/PostsTagsRelations.cs b/BlogWebApp/Data/Blog.Data.Models/PostsTagsRelations.cs
index 1326b2f1..af99f115 100644
--- a/BlogWebApp/Data/Blog.Data.Models/PostsTagsRelations.cs
+++ b/BlogWebApp/Data/Blog.Data.Models/PostsTagsRelations.cs
@@ -7,7 +7,7 @@ namespace Blog.Data.Models;
using Core;
///
-/// Posts Tags Many to Many Relations entity.
+/// Posts Tags Many-to-Many Relations entity.
///
///
public class PostsTagsRelations : Entity
diff --git a/BlogWebApp/Data/Blog.Data.Models/Setting.cs b/BlogWebApp/Data/Blog.Data.Models/Setting.cs
index d84e2326..9aafa547 100644
--- a/BlogWebApp/Data/Blog.Data.Models/Setting.cs
+++ b/BlogWebApp/Data/Blog.Data.Models/Setting.cs
@@ -9,7 +9,6 @@ namespace Blog.Data.Models;
///
/// Setting.
///
-
public class Setting : Entity
{
///
diff --git a/BlogWebApp/Data/Blog.Data/ApplicationDbContext.cs b/BlogWebApp/Data/Blog.Data/ApplicationDbContext.cs
index fab6f270..8d7ceb3d 100644
--- a/BlogWebApp/Data/Blog.Data/ApplicationDbContext.cs
+++ b/BlogWebApp/Data/Blog.Data/ApplicationDbContext.cs
@@ -4,15 +4,15 @@
namespace Blog.Data;
+using Blog.Data.Core.Models.Interfaces;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore;
+using Models;
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
-using Blog.Data.Core.Models.Interfaces;
-using Models;
-using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore;
///
/// Application database context.
@@ -159,7 +159,7 @@ protected override void OnModelCreating(ModelBuilder builder)
foreach (var deletableEntityType in deletableEntityTypes)
{
var method = SetIsDeletedQueryFilterMethod.MakeGenericMethod(deletableEntityType.ClrType);
- method.Invoke(null, new object[] { builder });
+ method.Invoke(null, [builder]);
}
// Disable cascade delete
diff --git a/BlogWebApp/Data/Blog.Data/ApplicationDbContextSeeder.cs b/BlogWebApp/Data/Blog.Data/ApplicationDbContextSeeder.cs
index 19de9e5d..c31f4db0 100644
--- a/BlogWebApp/Data/Blog.Data/ApplicationDbContextSeeder.cs
+++ b/BlogWebApp/Data/Blog.Data/ApplicationDbContextSeeder.cs
@@ -2,14 +2,16 @@
// Copyright (c) BLog. All rights reserved.
//
+using static System.ArgumentNullException;
+
namespace Blog.Data;
-using System;
-using System.Linq;
using Blog.Core;
-using Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
+using Models;
+using System;
+using System.Linq;
///
/// Application database context seeder.
@@ -23,15 +25,8 @@ public static class ApplicationDbContextSeeder
/// serviceProvider.
public static void Seed(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
{
- if (dbContext == null)
- {
- throw new ArgumentNullException(nameof(dbContext));
- }
-
- if (serviceProvider == null)
- {
- throw new ArgumentNullException(nameof(serviceProvider));
- }
+ ThrowIfNull(nameof(dbContext));
+ ThrowIfNull(nameof(serviceProvider));
var roleManager = serviceProvider.GetRequiredService>();
Seed(dbContext, roleManager);
@@ -44,15 +39,8 @@ public static void Seed(ApplicationDbContext dbContext, IServiceProvider service
/// roleManager.
public static void Seed(ApplicationDbContext dbContext, RoleManager roleManager)
{
- if (dbContext == null)
- {
- throw new ArgumentNullException(nameof(dbContext));
- }
-
- if (roleManager == null)
- {
- throw new ArgumentNullException(nameof(roleManager));
- }
+ ThrowIfNull(nameof(dbContext));
+ ThrowIfNull(nameof(roleManager));
SeedRoles(roleManager);
}
diff --git a/BlogWebApp/Data/Blog.Data/ApplicationUserStore.cs b/BlogWebApp/Data/Blog.Data/ApplicationUserStore.cs
index ae28a811..8899f7c9 100644
--- a/BlogWebApp/Data/Blog.Data/ApplicationUserStore.cs
+++ b/BlogWebApp/Data/Blog.Data/ApplicationUserStore.cs
@@ -4,10 +4,10 @@
namespace Blog.Data;
-using System.Security.Claims;
-using Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Models;
+using System.Security.Claims;
///
/// Application user store.
@@ -64,7 +64,7 @@ protected override IdentityUserClaim CreateUserClaim(ApplicationUser use
/// login.
/// IdentityUserLogin.
protected override IdentityUserLogin CreateUserLogin(ApplicationUser user, UserLoginInfo login) =>
- new ()
+ new()
{
UserId = user.Id,
ProviderKey = login.ProviderKey,
@@ -93,6 +93,7 @@ protected override IdentityUserToken CreateUserToken(
Name = name,
Value = value,
};
+
return token;
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Data/Blog.Data/Repositories/EfRepository.cs b/BlogWebApp/Data/Blog.Data/Repositories/EfRepository.cs
index 1916585e..10733dfb 100644
--- a/BlogWebApp/Data/Blog.Data/Repositories/EfRepository.cs
+++ b/BlogWebApp/Data/Blog.Data/Repositories/EfRepository.cs
@@ -89,7 +89,7 @@ public Task> SearchAsync(SearchQuery searchQue
throw new NotImplementedException();
}
- public Task> SearchBySquenceAsync(SearchQuery searchQuery, IQueryable sequence)
+ public Task> SearchBySequenceAsync(SearchQuery searchQuery, IQueryable sequence)
{
throw new NotImplementedException();
}
diff --git a/BlogWebApp/Data/Blog.Data/Repository.cs b/BlogWebApp/Data/Blog.Data/Repository.cs
index 5e92b157..d2566254 100644
--- a/BlogWebApp/Data/Blog.Data/Repository.cs
+++ b/BlogWebApp/Data/Blog.Data/Repository.cs
@@ -4,17 +4,17 @@
namespace Blog.Data;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.EntityFrameworkCore;
using Blog.Core;
using Blog.Core.Infrastructure;
using Blog.Core.Infrastructure.Pagination;
using Blog.Core.TableFilters;
-using Specifications.Base;
+using Microsoft.EntityFrameworkCore;
using Repository;
+using Specifications.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
///
/// Table methods.
@@ -40,7 +40,7 @@ public class Repository : IRepository
public virtual IQueryable TableNoTracking =>
// AsNoTracking method temporarily doesn't work, it's a bug in EF Core 2.1 (details in https://github.com/aspnet/EntityFrameworkCore/issues/11689)
- // Update - I checked this functionality and it is working fine, that's why I returned
+ // Update - I checked this functionality, and it is working fine, that's why I returned
this.Entities.AsNoTracking();
///
@@ -109,7 +109,7 @@ public virtual async Task> SearchAsync(SearchQuery
- public virtual async Task> SearchBySquenceAsync(SearchQuery searchQuery, IQueryable sequence)
+ public virtual async Task> SearchBySequenceAsync(SearchQuery searchQuery, IQueryable sequence)
{
// Applying filters
sequence = this.ManageFilters(searchQuery, sequence);
@@ -350,10 +350,7 @@ public async Task DeleteAsync(IEnumerable entities)
///
public bool Any(ISpecification specification)
{
- if (specification.Filter == null)
- {
- throw new ArgumentNullException(nameof(specification));
- }
+ ArgumentNullException.ThrowIfNull(nameof(specification));
return this.Entities.Any(specification.Filter);
}
diff --git a/BlogWebApp/Data/Blog.Data/Repository/IRepository.cs b/BlogWebApp/Data/Blog.Data/Repository/IRepository.cs
index 45e1bc33..c1c2d258 100644
--- a/BlogWebApp/Data/Blog.Data/Repository/IRepository.cs
+++ b/BlogWebApp/Data/Blog.Data/Repository/IRepository.cs
@@ -4,13 +4,13 @@
namespace Blog.Data.Repository;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Blog.Core;
using Blog.Core.Infrastructure.Pagination;
using Blog.Core.TableFilters;
using Specifications.Base;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
///
/// Repository interface.
@@ -82,7 +82,7 @@ public interface IRepository
/// searchQuery.
/// sequence.
/// Task.
- Task> SearchBySquenceAsync(SearchQuery searchQuery, IQueryable sequence);
+ Task> SearchBySequenceAsync(SearchQuery searchQuery, IQueryable sequence);
///
/// Generate query.
diff --git a/BlogWebApp/Data/Blog.Data/Specifications/Base/ISpecification.cs b/BlogWebApp/Data/Blog.Data/Specifications/Base/ISpecification.cs
index 1c8663c1..589ead1b 100644
--- a/BlogWebApp/Data/Blog.Data/Specifications/Base/ISpecification.cs
+++ b/BlogWebApp/Data/Blog.Data/Specifications/Base/ISpecification.cs
@@ -28,5 +28,5 @@ public interface ISpecification
///
/// The includes.
///
- List>> Includes { get; }
+ List>> Includes { get; }
}
\ No newline at end of file
diff --git a/BlogWebApp/Data/Blog.Data/Specifications/MessageSpecification.cs b/BlogWebApp/Data/Blog.Data/Specifications/MessageSpecification.cs
index a5fe72fe..1faa3a61 100644
--- a/BlogWebApp/Data/Blog.Data/Specifications/MessageSpecification.cs
+++ b/BlogWebApp/Data/Blog.Data/Specifications/MessageSpecification.cs
@@ -4,10 +4,10 @@
namespace Blog.Data.Specifications;
+using Base;
+using Models;
using System;
using System.Linq.Expressions;
-using Models;
-using Base;
///
/// Message specification.
@@ -15,13 +15,6 @@ namespace Blog.Data.Specifications;
///
public class MessageSpecification : BaseSpecification
{
- ///
- /// Initializes a new instance of the class.
- ///
- public MessageSpecification()
- {
- }
-
///
/// Initializes a new instance of the class.
///
diff --git a/BlogWebApp/Data/Blog.Data/Specifications/ProfileSpecification.cs b/BlogWebApp/Data/Blog.Data/Specifications/ProfileSpecification.cs
index 3cd534de..30d733a4 100644
--- a/BlogWebApp/Data/Blog.Data/Specifications/ProfileSpecification.cs
+++ b/BlogWebApp/Data/Blog.Data/Specifications/ProfileSpecification.cs
@@ -4,10 +4,10 @@
namespace Blog.Data.Specifications;
+using Base;
+using Models;
using System;
using System.Linq.Expressions;
-using Models;
-using Base;
///
/// Profile specification.
@@ -15,13 +15,6 @@ namespace Blog.Data.Specifications;
///
public class ProfileSpecification : BaseSpecification
{
- ///
- /// Initializes a new instance of the class.
- ///
- public ProfileSpecification()
- {
- }
-
///
/// Initializes a new instance of the class.
///
diff --git a/BlogWebApp/Data/Blog.Data/Specifications/TagSpecification.cs b/BlogWebApp/Data/Blog.Data/Specifications/TagSpecification.cs
index be61de09..018a4a3a 100644
--- a/BlogWebApp/Data/Blog.Data/Specifications/TagSpecification.cs
+++ b/BlogWebApp/Data/Blog.Data/Specifications/TagSpecification.cs
@@ -4,10 +4,10 @@
namespace Blog.Data.Specifications;
+using Base;
+using Models;
using System;
using System.Linq.Expressions;
-using Models;
-using Base;
///
/// Tag specification.
@@ -15,13 +15,6 @@ namespace Blog.Data.Specifications;
///
public class TagSpecification : BaseSpecification
{
- ///
- /// Initializes a new instance of the class.
- ///
- public TagSpecification()
- {
- }
-
///
/// Initializes a new instance of the class.
///
diff --git a/BlogWebApp/Data/Blog.Data/UnitOfWork/IUnitOfWork.cs b/BlogWebApp/Data/Blog.Data/UnitOfWork/IUnitOfWork.cs
index 97bb782e..3f5c1592 100644
--- a/BlogWebApp/Data/Blog.Data/UnitOfWork/IUnitOfWork.cs
+++ b/BlogWebApp/Data/Blog.Data/UnitOfWork/IUnitOfWork.cs
@@ -1,12 +1,12 @@
namespace Blog.Data.UnitOfWork;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
+using Blog.Core;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Storage;
-using Blog.Core;
using Repository;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
///
/// Unit of work interface.
@@ -96,7 +96,7 @@ IQueryable FromSqlRaw(string sql, params object[] parameters)
///
/// The type of the context.
///
-public interface IUnitOfWork : IUnitOfWork
+public interface IUnitOfWork : IUnitOfWork
where TContext : Microsoft.EntityFrameworkCore.DbContext
{
///
diff --git a/BlogWebApp/Data/Blog.Data/UnitOfWork/UnitOfWork.cs b/BlogWebApp/Data/Blog.Data/UnitOfWork/UnitOfWork.cs
index 85029cae..960899fa 100644
--- a/BlogWebApp/Data/Blog.Data/UnitOfWork/UnitOfWork.cs
+++ b/BlogWebApp/Data/Blog.Data/UnitOfWork/UnitOfWork.cs
@@ -1,18 +1,18 @@
namespace Blog.Data.UnitOfWork;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
+using Blog.Core;
using EntityFrameworkCore.AutoHistory.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
-using Blog.Core;
using Repository;
using RepositoryFactory;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
///
/// Unit of work.
@@ -41,7 +41,7 @@ public sealed class UnitOfWork :
/// Initializes a new instance of the class.
///
/// The context.
- /// context
+ /// context.
public UnitOfWork(TContext context)
{
var context1 = context;
@@ -98,7 +98,7 @@ public IDbContextTransaction BeginTransaction(bool useIfExists = false)
/// Sets the automatic detect changes.
///
/// if set to true [value].
- public void SetAutoDetectChanges(bool value)
+ public void SetAutoDetectChanges(bool value)
=> this.DbContext.ChangeTracker.AutoDetectChangesEnabled = value;
///
@@ -107,7 +107,7 @@ public void SetAutoDetectChanges(bool value)
///
/// The last save changes result.
///
- public SaveChangesResult LastSaveChangesResult { get; private set; }
+ public SaveChangesResult LastSaveChangesResult { get; }
///
/// Executes the SQL command.
@@ -248,15 +248,15 @@ public IRepository GetRepository(bool hasCustomRepository) whe
}
var key = typeof(TEntity);
- if (_repositories.ContainsKey(key))
+ if (_repositories.TryGetValue(key, out var repository))
{
- return (IRepository)_repositories[key];
+ return (IRepository)repository;
}
var dbContext = this.DbContext;
if (dbContext != null)
{
- this._repositories[key] = new Repository((DbContext)dbContext) as object;
+ this._repositories[key] = new Repository((DbContext)dbContext);
}
return (IRepository)this._repositories[key];
diff --git a/BlogWebApp/Services/Blog.CommonServices/ActiveDirectoryService.cs b/BlogWebApp/Services/Blog.CommonServices/ActiveDirectoryService.cs
index fa70b62e..2c820bf2 100644
--- a/BlogWebApp/Services/Blog.CommonServices/ActiveDirectoryService.cs
+++ b/BlogWebApp/Services/Blog.CommonServices/ActiveDirectoryService.cs
@@ -1,21 +1,28 @@
-using System.Collections.Generic;
-using Blog.CommonServices.Interfaces;
+using Blog.CommonServices.Interfaces;
using Blog.Services.Core.Dtos.User;
+using System.Collections.Generic;
namespace Blog.CommonServices;
+///
+/// Active Directory service.
+///
+///
public class ActiveDirectoryService : IActiveDirectoryService
{
+ ///
public ActiveDirectoryUserDto GetActiveDirectoryUserByIdentity(string identity)
{
throw new System.NotImplementedException();
}
+ ///
public ActiveDirectoryUserDto GetActiveDirectoryUserByEmployeeId(string employeeId)
{
throw new System.NotImplementedException();
}
+ ///
public List GetActiveDirectoryUsersByGroup(string groupName)
{
throw new System.NotImplementedException();
diff --git a/BlogWebApp/Services/Blog.CommonServices/Interfaces/IActiveDirectoryService.cs b/BlogWebApp/Services/Blog.CommonServices/Interfaces/IActiveDirectoryService.cs
index 5d889c25..b17b4ede 100644
--- a/BlogWebApp/Services/Blog.CommonServices/Interfaces/IActiveDirectoryService.cs
+++ b/BlogWebApp/Services/Blog.CommonServices/Interfaces/IActiveDirectoryService.cs
@@ -4,12 +4,32 @@
namespace Blog.CommonServices.Interfaces;
-using System.Collections.Generic;
using Blog.Services.Core.Dtos.User;
+using System.Collections.Generic;
+///
+/// The Active Directory service interface.
+///
public interface IActiveDirectoryService
{
+ ///
+ /// Gets Active Directory User by identity.
+ ///
+ /// The identity.
+ /// ActiveDirectoryUserDto.
ActiveDirectoryUserDto GetActiveDirectoryUserByIdentity(string identity);
+
+ ///
+ /// Gets Active Directory User by employee id.
+ ///
+ /// The employee id.
+ /// ActiveDirectoryUserDto.
ActiveDirectoryUserDto GetActiveDirectoryUserByEmployeeId(string employeeId);
+
+ ///
+ /// Gets Active Directory Users by group.
+ ///
+ /// The group name.
+ /// ActiveDirectoryUserDto.
List GetActiveDirectoryUsersByGroup(string groupName);
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Caching/MemoryCacheManager.cs b/BlogWebApp/Services/Blog.Services.Core/Caching/MemoryCacheManager.cs
index 42144c0d..1faad455 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Caching/MemoryCacheManager.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Caching/MemoryCacheManager.cs
@@ -4,13 +4,13 @@
namespace Blog.Services.Core.Caching;
+using Interfaces;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
-using Microsoft.Extensions.Caching.Memory;
-using Microsoft.Extensions.Primitives;
-using Interfaces;
///
/// Memory cache manager.
@@ -145,7 +145,7 @@ protected static string AddKey(string key)
protected static void TryRemoveKey(string key)
{
// try to remove key from dictionary
- if (!AllKeys.TryRemove(key, out var _))
+ if (!AllKeys.TryRemove(key, out _))
{
// if not possible to remove key from dictionary, then try to mark key as not existing in cache
AllKeys.TryUpdate(key, false, false);
diff --git a/BlogWebApp/Services/Blog.Services.Core/Caching/RedisCacheManager.cs b/BlogWebApp/Services/Blog.Services.Core/Caching/RedisCacheManager.cs
index 72e18b4f..70dbd56e 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Caching/RedisCacheManager.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Caching/RedisCacheManager.cs
@@ -4,13 +4,13 @@
namespace Blog.Services.Core.Caching;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
using Blog.Core.Configuration;
+using Interfaces;
using Newtonsoft.Json;
using StackExchange.Redis;
-using Interfaces;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
///
/// Redis cache manager.
@@ -143,14 +143,14 @@ protected virtual async Task GetAsync(string key)
var serializedItem = await this.db.StringGetAsync(key);
if (!serializedItem.HasValue)
{
- return default(T);
+ return default;
}
// deserialize item
var item = JsonConvert.DeserializeObject(serializedItem);
if (item == null)
{
- return default(T);
+ return default;
}
// set item in the per-request cache
diff --git a/BlogWebApp/Services/Blog.Services.Core/Caching/RedisConnectionWrapper.cs b/BlogWebApp/Services/Blog.Services.Core/Caching/RedisConnectionWrapper.cs
index eedf9cbb..1502da09 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Caching/RedisConnectionWrapper.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Caching/RedisConnectionWrapper.cs
@@ -4,14 +4,15 @@
namespace Blog.Services.Core.Caching;
-using System;
-using System.Linq;
-using System.Net;
+using Blog.Core.Configuration;
+using Interfaces;
using RedLockNet.SERedis;
using RedLockNet.SERedis.Configuration;
using StackExchange.Redis;
-using Blog.Core.Configuration;
-using Interfaces;
+using System;
+using System.Linq;
+using System.Net;
+using System.Threading;
///
/// Redis connection wrapper.
@@ -31,7 +32,7 @@ public class RedisConnectionWrapper : IRedisConnectionWrapper, ILocker
///
/// Lock object.
///
- private readonly object @lock = new ();
+ private readonly Lock @lock = new();
///
/// RedLock factory.
@@ -110,6 +111,7 @@ public bool PerformActionWithLock(string resource, TimeSpan expirationTime, Acti
{
// use RedLock library
using var redisLock = this.redisLockFactory.CreateLock(resource, expirationTime);
+
// ensure that lock is acquired
if (!redisLock.IsAcquired)
{
diff --git a/BlogWebApp/Services/Blog.Services.Core/Dtos/User/ActiveDirectoryUserDto.cs b/BlogWebApp/Services/Blog.Services.Core/Dtos/User/ActiveDirectoryUserDto.cs
index 5d07796d..98e6161b 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Dtos/User/ActiveDirectoryUserDto.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Dtos/User/ActiveDirectoryUserDto.cs
@@ -1,13 +1,43 @@
-using System.Collections.Generic;
+//
+// Copyright (c) PlaceholderCompany. All rights reserved.
+//
namespace Blog.Services.Core.Dtos.User;
+using System.Collections.Generic;
+
+///
+/// The Active directory user dto.
+///
public class ActiveDirectoryUserDto
{
+ ///
+ /// The gets or sets first name.
+ ///
public string FirstName { get; set; }
+
+ ///
+ /// The gets or sets last name.
+ ///
public string LastName { get; set; }
+
+ ///
+ /// The gets or sets email.
+ ///
public string Email { get; set; }
+
+ ///
+ /// The gets or sets identity.
+ ///
public string Identity { get; set; }
+
+ ///
+ /// The gets or sets display name.
+ ///
public string DisplayName { get; set; }
+
+ ///
+ /// The gets or sets groups.
+ ///
public List Groups { get; set; } = [];
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/JwtFactory.cs b/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/JwtFactory.cs
index 5528dc6c..e01c27b1 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/JwtFactory.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/JwtFactory.cs
@@ -4,6 +4,10 @@
namespace Blog.Services.Core.Identity.Auth;
+using Blog.Core;
+using Data.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
@@ -11,10 +15,6 @@ namespace Blog.Services.Core.Identity.Auth;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.Identity;
-using Microsoft.Extensions.Options;
-using Blog.Core;
-using Data.Models;
using Utilities;
///
@@ -57,8 +57,7 @@ public JwtFactory(
///
public async Task GenerateEncodedToken(string userName, ClaimsIdentity identity)
{
- var claims = new List(new[]
- {
+ var claims = new List([
new Claim(JwtRegisteredClaimNames.Sub, userName),
new Claim(JwtRegisteredClaimNames.Jti, await this.jwtOptions.JtiGenerator()),
new Claim(
@@ -72,8 +71,8 @@ public async Task GenerateEncodedToken(string userName, ClaimsIdentity i
identity.FindFirst(JwtClaimTypes.Email),
identity.FindFirst(JwtClaimTypes.PhoneNumber),
identity.FindFirst(JwtClaimTypes.IsEmailVerified),
- identity.FindFirst(JwtClaimTypes.ProfileId),
- });
+ identity.FindFirst(JwtClaimTypes.ProfileId)
+ ]);
var user = await this.userManager.FindByNameAsync(userName);
@@ -160,14 +159,7 @@ private static void ThrowIfInvalidOptions(JwtIssuerOptions options)
throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(JwtIssuerOptions.ValidFor));
}
- if (options.SigningCredentials == null)
- {
- throw new ArgumentNullException(nameof(JwtIssuerOptions.SigningCredentials));
- }
-
- if (options.JtiGenerator == null)
- {
- throw new ArgumentNullException(nameof(JwtIssuerOptions.JtiGenerator));
- }
+ ArgumentNullException.ThrowIfNull(nameof(JwtIssuerOptions.SigningCredentials));
+ ArgumentNullException.ThrowIfNull(nameof(JwtIssuerOptions.JtiGenerator));
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/Tokens.cs b/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/Tokens.cs
index cff90a31..bf6083e6 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/Tokens.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Identity/Auth/Tokens.cs
@@ -4,9 +4,9 @@
namespace Blog.Services.Core.Identity.Auth;
+using Newtonsoft.Json;
using System.Security.Claims;
using System.Threading.Tasks;
-using Newtonsoft.Json;
///
/// Tokens.
@@ -34,6 +34,7 @@ public static async Task GenerateJwt(ClaimsIdentity identity, IJwtFactor
};
var json = JsonConvert.SerializeObject(response, serializerSettings);
+
return json;
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Identity/User/ViewModelToEntityMappingUser.cs b/BlogWebApp/Services/Blog.Services.Core/Identity/User/ViewModelToEntityMappingUser.cs
index 08b9cddd..f807696c 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Identity/User/ViewModelToEntityMappingUser.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Identity/User/ViewModelToEntityMappingUser.cs
@@ -4,11 +4,11 @@
namespace Blog.Services.Core.Identity.User;
-using System.Linq;
+using Blog.Services.Core.Dtos.User;
using Contracts.V1.Requests.UsersRequests;
using Contracts.V1.Responses.UsersResponses;
using Data.Models;
-using Blog.Services.Core.Dtos.User;
+using System.Linq;
///
/// View model to entity mapping user.
diff --git a/BlogWebApp/Services/Blog.Services.Core/QueryableExtensions.cs b/BlogWebApp/Services/Blog.Services.Core/QueryableExtensions.cs
index 3c3b7d7a..acdb33d3 100644
--- a/BlogWebApp/Services/Blog.Services.Core/QueryableExtensions.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/QueryableExtensions.cs
@@ -4,13 +4,13 @@
namespace Blog.Services.Core;
+using Dtos;
using System;
using System.Linq;
using System.Linq.Expressions;
-using Dtos;
///
-/// Queriable extensions.
+/// Queryable extensions.
///
public static class QueryableExtensions
{
@@ -36,6 +36,7 @@ public static IQueryable OrderBy(this IQueryable source, SortParameters
[source.ElementType, selector.Type],
expression,
Expression.Quote(Expression.Lambda(selector, parameter)));
+
return source.Provider.CreateQuery(expression);
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeHandler.cs b/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeHandler.cs
index 1b3acaed..1ecb3ca2 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeHandler.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeHandler.cs
@@ -4,9 +4,9 @@
namespace Blog.Services.Core.Security;
+using Microsoft.AspNetCore.Authorization;
using System.Linq;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authorization;
///
/// Has scope handler.
@@ -26,7 +26,7 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte
var scopes = context.User.FindFirst(c => c.Type == "scope" && c.Issuer == requirement.Issuer)?.Value.Split(' ');
// Succeed if the scope array contains the required scope
- if (scopes.Any(s => s == requirement.Scope))
+ if (scopes != null && scopes.Any(s => s == requirement.Scope))
{
context.Succeed(requirement);
}
diff --git a/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeRequirement.cs b/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeRequirement.cs
index af08106e..e0b9b468 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeRequirement.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Security/HasScopeRequirement.cs
@@ -1,11 +1,11 @@
-//
+//
// Copyright (c) PlaceholderCompany. All rights reserved.
//
namespace Blog.Services.Core.Security;
-using System;
using Microsoft.AspNetCore.Authorization;
+using System;
///
/// Has scope requirement.
diff --git a/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.DateTime.cs b/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.DateTime.cs
index 564770c7..00d365a0 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.DateTime.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.DateTime.cs
@@ -22,11 +22,12 @@ public static long ToUnixTimeStamp(this DateTime dateTime)
var universalTime = dateTime.ToUniversalTime();
var delta = Math.Round((universalTime - offset).TotalSeconds);
+
return (long)delta;
}
///
- /// Convert DateTime to To user time.
+ /// Convert DateTime to user time.
///
/// dt.
/// sourceDateTimeKind.
@@ -51,6 +52,6 @@ public static DateTime ConvertToUserTime(this DateTime dt, DateTimeKind sourceDa
/// string.
public static string ToSafeFileName(this DateTime dateTime)
{
- return $"{dateTime.Day.ToString("00")}{dateTime.Month.ToString("00")}{dateTime.Year}";
+ return $"{dateTime.Day:00}{dateTime.Month:00}{dateTime.Year}";
}
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.String.cs b/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.String.cs
index 1850760a..5708bcae 100644
--- a/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.String.cs
+++ b/BlogWebApp/Services/Blog.Services.Core/Utilities/Extensions.String.cs
@@ -14,9 +14,9 @@ namespace Blog.Services.Core.Utilities;
///
public static partial class Extensions
{
- private static readonly Regex WebUrlExpression = new Regex(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)", RegexOptions.Singleline | RegexOptions.Compiled);
- private static readonly Regex EmailExpression = new Regex(@"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", RegexOptions.Singleline | RegexOptions.Compiled);
- private static readonly Regex StripHtmlExpression = new Regex("<\\S[^><]*>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
+ private static readonly Regex WebUrlExpression = new(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)", RegexOptions.Singleline | RegexOptions.Compiled);
+ private static readonly Regex EmailExpression = new("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", RegexOptions.Singleline | RegexOptions.Compiled);
+ private static readonly Regex StripHtmlExpression = new("<\\S[^><]*>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
///
/// Convert string to int.
@@ -27,6 +27,7 @@ public static int ToInt(this string input)
{
// int result = 0;
int.TryParse(input, out var result);
+
return result;
}
@@ -39,6 +40,7 @@ public static bool ToBool(this string input)
{
// int result = 0;
bool.TryParse(input, out var result);
+
return result;
}
@@ -51,6 +53,7 @@ public static bool ToBool(this string input)
public static Guid ToGuid(this string value)
{
Guid.TryParse(value, out var result);
+
return result;
}
diff --git a/BlogWebApp/Services/Blog.Services/CommentsService.cs b/BlogWebApp/Services/Blog.Services/CommentsService.cs
index 38a3d207..cf528de8 100644
--- a/BlogWebApp/Services/Blog.Services/CommentsService.cs
+++ b/BlogWebApp/Services/Blog.Services/CommentsService.cs
@@ -135,11 +135,9 @@ public async Task GetPagedCommentsByPostId(int postId, SortPara
///
public async Task GetCommentAsync(int id)
- {
- return await this.Repository.Table
+ => await this.Repository.Table
.Where(new CommentSpecification(x => x.Id.Equals(id)).Filter)
.FirstOrDefaultAsync();
- }
///
public async Task GetCommentsActivity()
diff --git a/BlogWebApp/Services/Blog.Services/ControllerContext/IControllerContext.cs b/BlogWebApp/Services/Blog.Services/ControllerContext/IControllerContext.cs
index 960234d1..6f97f735 100644
--- a/BlogWebApp/Services/Blog.Services/ControllerContext/IControllerContext.cs
+++ b/BlogWebApp/Services/Blog.Services/ControllerContext/IControllerContext.cs
@@ -2,10 +2,10 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
-using Blog.Data.Models;
-
namespace Blog.EntityServices.ControllerContext;
+using Data.Models;
+
///
/// Controller context interface.
///
diff --git a/BlogWebApp/Services/Blog.Services/GeneralService/GeneralService.cs b/BlogWebApp/Services/Blog.Services/GeneralService/GeneralService.cs
index d0d10fcd..404bddb5 100644
--- a/BlogWebApp/Services/Blog.Services/GeneralService/GeneralService.cs
+++ b/BlogWebApp/Services/Blog.Services/GeneralService/GeneralService.cs
@@ -4,16 +4,16 @@
namespace Blog.EntityServices.GeneralService;
+using Blog.Data.Core;
+using Core.Infrastructure.Pagination;
+using Core.TableFilters;
+using Data.Repository;
+using Data.Specifications.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
-using Core.Infrastructure.Pagination;
-using Core.TableFilters;
-using Blog.Data.Core;
-using Data.Repository;
-using Data.Specifications.Base;
///
/// General service.
@@ -114,7 +114,7 @@ public async Task> SearchAsync(SearchQuery searchQuery)
public async Task> SearchBySequenceAsync(
SearchQuery searchQuery,
IQueryable sequence)
- => await this.Repository.SearchBySquenceAsync(searchQuery, sequence);
+ => await this.Repository.SearchBySequenceAsync(searchQuery, sequence);
///
public ICollection GetAll()
diff --git a/BlogWebApp/Services/Blog.Services/GeneralService/IGeneralService.cs b/BlogWebApp/Services/Blog.Services/GeneralService/IGeneralService.cs
index 734e75b8..204e00d3 100644
--- a/BlogWebApp/Services/Blog.Services/GeneralService/IGeneralService.cs
+++ b/BlogWebApp/Services/Blog.Services/GeneralService/IGeneralService.cs
@@ -2,14 +2,14 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
+namespace Blog.EntityServices.GeneralService;
+
+using Core.Infrastructure.Pagination;
+using Core.TableFilters;
+using Data.Specifications.Base;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Blog.Core.Infrastructure.Pagination;
-using Blog.Core.TableFilters;
-using Blog.Data.Specifications.Base;
-
-namespace Blog.EntityServices.GeneralService;
///
/// General service interface.
@@ -195,7 +195,7 @@ Task> SearchBySequenceAsync(
T FirstOrDefault(ISpecification specification);
///
- /// Lasts the or default.
+ /// Last or default.
///
/// The specification.
/// T.
diff --git a/BlogWebApp/Services/Blog.Services/Identity/Auth/IAuthService.cs b/BlogWebApp/Services/Blog.Services/Identity/Auth/IAuthService.cs
index f79a05c8..207647af 100644
--- a/BlogWebApp/Services/Blog.Services/Identity/Auth/IAuthService.cs
+++ b/BlogWebApp/Services/Blog.Services/Identity/Auth/IAuthService.cs
@@ -2,12 +2,12 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
+namespace Blog.EntityServices.Identity.Auth;
+
+using Data.Models;
+using Microsoft.AspNetCore.Identity;
using System.Security.Claims;
using System.Threading.Tasks;
-using Blog.Data.Models;
-using Microsoft.AspNetCore.Identity;
-
-namespace Blog.EntityServices.Identity.Auth;
///
/// Auth service.
diff --git a/BlogWebApp/Services/Blog.Services/Identity/Registration/IRegistrationService.cs b/BlogWebApp/Services/Blog.Services/Identity/Registration/IRegistrationService.cs
index ef8b972a..890e8a45 100644
--- a/BlogWebApp/Services/Blog.Services/Identity/Registration/IRegistrationService.cs
+++ b/BlogWebApp/Services/Blog.Services/Identity/Registration/IRegistrationService.cs
@@ -2,12 +2,12 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
-using System.Threading.Tasks;
-using Blog.Data.Models;
-using Microsoft.AspNetCore.Identity;
-
namespace Blog.EntityServices.Identity.Registration;
+using Data.Models;
+using Microsoft.AspNetCore.Identity;
+using System.Threading.Tasks;
+
///
/// Registration service interface.
///
diff --git a/BlogWebApp/Services/Blog.Services/Identity/User/IUserService.cs b/BlogWebApp/Services/Blog.Services/Identity/User/IUserService.cs
index bc166626..1d40ef9a 100644
--- a/BlogWebApp/Services/Blog.Services/Identity/User/IUserService.cs
+++ b/BlogWebApp/Services/Blog.Services/Identity/User/IUserService.cs
@@ -2,15 +2,15 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
+namespace Blog.EntityServices.Identity.User;
+
+using Contracts.V1.Responses.Chart;
+using Core.Infrastructure.Pagination;
+using Core.TableFilters;
+using Data.Models;
+using Microsoft.AspNetCore.Identity;
using System.Collections.Generic;
using System.Threading.Tasks;
-using Blog.Contracts.V1.Responses.Chart;
-using Blog.Core.Infrastructure.Pagination;
-using Blog.Core.TableFilters;
-using Blog.Data.Models;
-using Microsoft.AspNetCore.Identity;
-
-namespace Blog.EntityServices.Identity.User;
///
/// User service interface.
diff --git a/BlogWebApp/Services/Blog.Services/Identity/User/UserService.cs b/BlogWebApp/Services/Blog.Services/Identity/User/UserService.cs
index 255fa167..1fa7fa2f 100644
--- a/BlogWebApp/Services/Blog.Services/Identity/User/UserService.cs
+++ b/BlogWebApp/Services/Blog.Services/Identity/User/UserService.cs
@@ -4,9 +4,6 @@
namespace Blog.EntityServices.Identity.User;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using AutoMapper;
using Contracts.V1.Responses.Chart;
using Core.Infrastructure.Pagination;
@@ -15,6 +12,9 @@ namespace Blog.EntityServices.Identity.User;
using Data.Repository;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
///
/// User service.
@@ -214,12 +214,12 @@ public async Task> GetAllFilteredUsersAsync(Tab
{
var sequence = this.applicationUserRepository.Table;
- return await this.applicationUserRepository.SearchBySquenceAsync(this.AddFilter(tableFilter), sequence);
+ return await this.applicationUserRepository.SearchBySequenceAsync(this.AddFilter(tableFilter), sequence);
}
///
public async Task GetUsersActivity()
- => new ()
+ => new()
{
Name = "Posts",
Series = await applicationUserRepository.TableNoTracking
diff --git a/BlogWebApp/Services/Blog.Services/PostsService.cs b/BlogWebApp/Services/Blog.Services/PostsService.cs
index ef22ba61..3189c506 100644
--- a/BlogWebApp/Services/Blog.Services/PostsService.cs
+++ b/BlogWebApp/Services/Blog.Services/PostsService.cs
@@ -4,27 +4,25 @@
namespace Blog.EntityServices;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Data;
-using System.Linq;
-using System.Threading.Tasks;
using AutoMapper;
-using Blog.CommonServices.Interfaces;
+using Blog.Services.Core;
+using Blog.Services.Core.Dtos;
+using Blog.Services.Core.Dtos.Posts;
+using Blog.Services.Core.Dtos.User;
using Contracts.V1.Responses.Chart;
using Core.Helpers;
using Data.Models;
using Data.Repository;
using Data.Specifications;
-using Blog.Services.Core;
-using Blog.Services.Core.Dtos;
-using Blog.Services.Core.Dtos.Exports;
-using Blog.Services.Core.Dtos.Posts;
-using Blog.Services.Core.Dtos.User;
using GeneralService;
using Interfaces;
using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Data;
+using System.Linq;
+using System.Threading.Tasks;
///
/// Posts service.
@@ -278,7 +276,7 @@ public async Task InsertAsync(Post post, IEnumerable tags)
///
public async Task GetPostsActivity()
- => new ()
+ => new()
{
Name = "Posts",
Series = await Repository.TableNoTracking
diff --git a/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsPolicyProvider.cs b/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsPolicyProvider.cs
index 83bf69e6..4eb7d29b 100644
--- a/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsPolicyProvider.cs
+++ b/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsPolicyProvider.cs
@@ -4,11 +4,11 @@
namespace Blog.EntityServices.Security.Authorization;
-using System;
-using System.Threading.Tasks;
+using Core.Consts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
-using Core.Consts;
+using System;
+using System.Threading.Tasks;
///
/// Permissions policy provider.
@@ -44,7 +44,7 @@ public class PermissionsPolicyProvider(IOptions options)
public Task GetPolicyAsync(string policyName)
{
if (!policyName.StartsWith(this.policyPrefix, StringComparison.OrdinalIgnoreCase) ||
- string.IsNullOrWhiteSpace(policyName.Substring(this.policyPrefix.Length)))
+ string.IsNullOrWhiteSpace(policyName[this.policyPrefix.Length..]))
{
return this.FallbackPolicyProvider.GetPolicyAsync(policyName);
}
diff --git a/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsRequirement.cs b/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsRequirement.cs
index 171baf05..13efa42e 100644
--- a/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsRequirement.cs
+++ b/BlogWebApp/Services/Blog.Services/Security/Authorization/PermissionsRequirement.cs
@@ -2,10 +2,10 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
//
-using Microsoft.AspNetCore.Authorization;
-
namespace Blog.EntityServices.Security.Authorization;
+using Microsoft.AspNetCore.Authorization;
+
///
/// Permissions requirement.
///
diff --git a/BlogWebApp/Services/Blog.Services/Security/EncryptionService.cs b/BlogWebApp/Services/Blog.Services/Security/EncryptionService.cs
index 26c65c50..5226b928 100644
--- a/BlogWebApp/Services/Blog.Services/Security/EncryptionService.cs
+++ b/BlogWebApp/Services/Blog.Services/Security/EncryptionService.cs
@@ -21,25 +21,24 @@ public class EncryptionService : IEncryptionService
public virtual string CreateSaltKey(int size)
{
// generate a cryptographic random number
- using (var provider = new RNGCryptoServiceProvider())
- {
- var buff = new byte[size];
- provider.GetBytes(buff);
+ using var provider = new RNGCryptoServiceProvider();
- // Return a Base64 string representation of the random number
- return Convert.ToBase64String(buff);
- }
+ var buff = new byte[size];
+ provider.GetBytes(buff);
+
+ // Return a Base64 string representation of the random number
+ return Convert.ToBase64String(buff);
}
///
/// Create a password hash.
///
/// Password.
- /// Salk key.
+ /// Salt key.
/// Password format (hash algorithm).
/// Password hash
- public virtual string CreatePasswordHash(string password, string saltkey, string passwordFormat)
- => this.CreateHash(Encoding.UTF8.GetBytes(string.Concat(password, saltkey)), passwordFormat);
+ public virtual string CreatePasswordHash(string password, string saltKey, string passwordFormat)
+ => this.CreateHash(Encoding.UTF8.GetBytes(string.Concat(password, saltKey)), passwordFormat);
///
/// Create a data hash.
diff --git a/BlogWebApp/Services/Blog.Services/Security/IEncryptionService.cs b/BlogWebApp/Services/Blog.Services/Security/IEncryptionService.cs
index e73148bd..1f7c4770 100644
--- a/BlogWebApp/Services/Blog.Services/Security/IEncryptionService.cs
+++ b/BlogWebApp/Services/Blog.Services/Security/IEncryptionService.cs
@@ -5,47 +5,47 @@
namespace Blog.EntityServices.Security;
///
-/// Encryption service
+/// Encryption service.
///
public interface IEncryptionService
{
///
- /// Create salt key
+ /// Create salt key.
///
- /// Key size
- /// Salt key
+ /// Key size.
+ /// Salt key.
string CreateSaltKey(int size);
///
- /// Create a password hash
+ /// Create a password hash.
///
- /// Password
- /// Salk key
- /// Password format (hash algorithm)
- /// Password hash
- string CreatePasswordHash(string password, string saltkey, string passwordFormat);
+ /// Password.
+ /// Salt key.
+ /// Password format (hash algorithm).
+ /// Password hash.
+ string CreatePasswordHash(string password, string saltKey, string passwordFormat);
///
- /// Create a data hash
+ /// Create a data hash.
///
- /// The data for calculating the hash
- /// Hash algorithm
- /// Data hash
+ /// The data for calculating the hash.
+ /// Hash algorithm.
+ /// Data hash.
string CreateHash(byte[] data, string hashAlgorithm);
///
- /// Encrypt text
+ /// Encrypt text.
///
- /// Text to encrypt
- /// Encryption private key
- /// Encrypted text
+ /// Text to encrypt.
+ /// Encryption private key.
+ /// Encrypted text.
string EncryptText(string plainText, string encryptionPrivateKey = "");
///
- /// Decrypt text
+ /// Decrypt text.
///
- /// Text to decrypt
- /// Encryption private key
- /// Decrypted text
+ /// Text to decrypt.
+ /// Encryption private key.
+ /// Decrypted text.
string DecryptText(string cipherText, string encryptionPrivateKey = "");
}
\ No newline at end of file
diff --git a/BlogWebApp/Services/Blog.Services/Security/PermissionService.cs b/BlogWebApp/Services/Blog.Services/Security/PermissionService.cs
index 337fd4d6..6ffc20f3 100644
--- a/BlogWebApp/Services/Blog.Services/Security/PermissionService.cs
+++ b/BlogWebApp/Services/Blog.Services/Security/PermissionService.cs
@@ -52,16 +52,15 @@ public bool Authorize()
return this.Authorize(this.workContext.CurrentUser);
}
+ ///
+ /// The authorization.
+ ///
private bool Authorize(ApplicationUser user)
- {
- if (this.CheckIsUserAdmin(user))
- {
- return true;
- }
-
- return true;
- }
+ => this.CheckIsUserAdmin(user) || true;
+ ///
+ /// The check if user is admin.
+ ///
private bool CheckIsUserAdmin(ApplicationUser user)
{
var systemAdminKey = string.Format("Admin", user.Id);
diff --git a/BlogWebApp/TestResults/2715d5b6-d117-4900-b1f8-ae27b053d7fb/user_USER_2023-12-08.23_04_51.coverage b/BlogWebApp/TestResults/2715d5b6-d117-4900-b1f8-ae27b053d7fb/user_USER_2023-12-08.23_04_51.coverage
new file mode 100644
index 00000000..b207bffa
Binary files /dev/null and b/BlogWebApp/TestResults/2715d5b6-d117-4900-b1f8-ae27b053d7fb/user_USER_2023-12-08.23_04_51.coverage differ
diff --git a/BlogWebApp/TestResults/c10d3eb3-22ff-4902-9617-2d2c6c43059c/user_USER_2025-03-07.10_09_36.coverage b/BlogWebApp/TestResults/c10d3eb3-22ff-4902-9617-2d2c6c43059c/user_USER_2025-03-07.10_09_36.coverage
new file mode 100644
index 00000000..58e786f5
Binary files /dev/null and b/BlogWebApp/TestResults/c10d3eb3-22ff-4902-9617-2d2c6c43059c/user_USER_2025-03-07.10_09_36.coverage differ
diff --git a/BlogWebApp/TestResults/f8a3d9fb-e298-40fd-8dd7-d2e3b9010615/user_USER_2023-09-22.11_56_30.coverage b/BlogWebApp/TestResults/f8a3d9fb-e298-40fd-8dd7-d2e3b9010615/user_USER_2023-09-22.11_56_30.coverage
new file mode 100644
index 00000000..005697ff
Binary files /dev/null and b/BlogWebApp/TestResults/f8a3d9fb-e298-40fd-8dd7-d2e3b9010615/user_USER_2023-09-22.11_56_30.coverage differ
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs
index 7dec1841..9689e487 100644
--- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs
+++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs
@@ -152,7 +152,7 @@ public void GetAll_WhenCommentsExists_ShouldReturnComments(int notEqualCount)
///
/// Get all comments.
- /// Should return nothing when comments does not exists.
+ /// Should return nothing when comments does not exist.
///
[Fact]
public void GetAll_WhenCommentsDoesNotExists_ShouldReturnNothing()
@@ -238,7 +238,7 @@ public async Task GetAllAsync_WhenCommentsExists_ShouldReturnComments(int notEqu
///
/// Get all async comments.
- /// Should return nothing when comments does not exists.
+ /// Should return nothing when comments does not exist.
///
[Fact]
public async Task GetAllAsync_WhenCommentsDoesNotExists_ShouldReturnNothing()
@@ -359,7 +359,7 @@ public void GetAll_WithEqualsSpecification_WhenCommentsExists_ShouldReturnCommen
///
/// Get all comments with specification.
- /// Should return nothing with when comments does not exists.
+ /// Should return nothing with when comments does not exist.
///
/// The equal count.
/// The CommentBody search.
@@ -389,7 +389,7 @@ public void GetAll_WithEqualSpecification_WhenCommentsExists_ShouldReturnNothing
///
/// Get all comments.
- /// Should return nothing with when comments does not exists.
+ /// Should return nothing with when comments does not exist.
///
/// The CommentBody search.
[Theory]
@@ -451,12 +451,11 @@ public void GetAll_WithContainsSpecification_WhenSpecificationIsNull_ShouldRetur
.With(x => x.CommentBody, commentBodySearch)
.CreateMany(random.Next(100));
- CommentSpecification specification = null;
_commentsRepositoryMock.Setup(x => x.GetAll(It.IsAny()))
.Returns(() => commentsList.Where(x => x.CommentBody.Contains(commentBodySearch)).AsQueryable());
//Act
- var comments = _commentsService.GetAll(specification);
+ var comments = _commentsService.GetAll(null);
//Assert
Assert.NotNull(comments);
@@ -572,7 +571,7 @@ public async Task GetAllAsync_WithEqualsSpecification_WhenCommentsExists_ShouldR
///
/// Get all async comments with specification.
- /// Should return nothing with when comments does not exists.
+ /// Should return nothing with when comments does not exist.
///
/// The equal count.
/// The CommentBody search.
@@ -602,7 +601,7 @@ public async Task GetAllAsync_WithEqualSpecification_WhenCommentsExists_ShouldRe
///
/// Get all async comments.
- /// Should return nothing with when comments does not exists.
+ /// Should return nothing with when comments does not exist.
///
/// The CommentBody search.
[Theory]
@@ -666,12 +665,11 @@ public async Task GetAllAsync_WithContainsSpecification_WhenSpecificationIsNull_
.With(x => x.CommentBody, commentBodySearch)
.CreateMany(random.Next(100));
- CommentSpecification specification = null;
_commentsRepositoryMock.Setup(x => x.GetAllAsync(It.IsAny()))
.ReturnsAsync(() => commentsList.Where(x => x.CommentBody.Contains(commentBodySearch)).ToList());
//Act
- var comments = await _commentsService.GetAllAsync(specification);
+ var comments = await _commentsService.GetAllAsync(null);
//Assert
Assert.NotNull(comments);
@@ -744,7 +742,7 @@ public void Find_WhenCommentExists_ShouldReturnComment()
///
/// Find comment.
- /// Should return nothing when comment does not exists.
+ /// Should return nothing when comment does not exist.
///
[Fact]
public void Find_WhenCommentDoesNotExists_ShouldReturnNothing()
@@ -824,7 +822,7 @@ public async Task FindAsync_WhenCommentExists_ShouldReturnComment()
///
/// Async find comment.
- /// Should return nothing when comment does not exists.
+ /// Should return nothing when comment does not exist.
///
/// Task.
[Fact]
@@ -978,7 +976,7 @@ public void InsertEnumerable_WhenCommentsExists_ShouldReturnComments()
{
//Arrange
var random = new Random();
- var commentId = _fixture.Create(); ;
+ var commentId = _fixture.Create();
var itemsCount = random.Next(10);
var newComments =
SetupCommentFixture()
@@ -1583,7 +1581,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro
#region Delete By Id function
///
- /// Verify that function Delete By Id has been called.
+ /// Verify that function Delete By ID has been called.
///
[Fact]
public void Verify_FunctionDeleteById_HasBeenCalled()
@@ -1596,7 +1594,7 @@ public void Verify_FunctionDeleteById_HasBeenCalled()
//Act
_commentsService.Insert(newComment);
- var comment = _commentsService.Find(commentId);
+ _commentsService.Find(commentId);
_commentsService.Delete(commentId);
_commentsRepositoryMock.Setup(x => x.GetById(commentId))
.Returns(() => null);
@@ -1607,7 +1605,7 @@ public void Verify_FunctionDeleteById_HasBeenCalled()
}
///
- /// Delete By Id comment.
+ /// Delete By ID comment.
/// Should return nothing when comment is deleted.
///
[Fact]
@@ -1627,7 +1625,7 @@ public void DeleteById_WhenCommentIsDeleted_ShouldReturnNothing()
//Act
_commentsService.Insert(newComment);
- var comment = _commentsService.Find(commentId);
+ _commentsService.Find(commentId);
_commentsService.Delete(commentId);
_commentsRepositoryMock.Setup(x => x.GetById(commentId))
.Returns(() => null);
@@ -1637,6 +1635,24 @@ public void DeleteById_WhenCommentIsDeleted_ShouldReturnNothing()
Assert.Null(deletedComment);
}
+ ///
+ /// Delete By ID comment.
+ /// When repository throws exception should throw exception.
+ ///
+ [Fact]
+ public void DeleteById_WhenRepositoryThrowsException_ShouldThrowException()
+ {
+ //Arrange
+ var comment = SetupCommentFixture().Create();
+ _commentsRepositoryMock.Setup(x => x.GetById(It.IsAny