aboutsummaryrefslogtreecommitdiff
path: root/src/Web
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-15 19:06:14 +0200
committertranstrike <transtrike@gmail.com>2021-02-15 19:06:14 +0200
commit4c03712af14c37718b7be5b23fcadeb86f2a2191 (patch)
tree0c6b5a592244e5b2574afa9e4919d4a3111eea34 /src/Web
parent09fc4603e82f69c926f9457085aa3fa48bb3939c (diff)
downloadDevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.tar
DevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.tar.gz
DevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.zip
Code Analyzer added to all csproj; Removed unnessessary code; Fixed formatting
Diffstat (limited to 'src/Web')
-rw-r--r--src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs (renamed from src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs)5
-rw-r--r--src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs4
-rw-r--r--src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj8
-rw-r--r--src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs1
-rw-r--r--src/Web/DevHive.Web.Tests/CommentController.Tests.cs35
-rw-r--r--src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj11
-rw-r--r--src/Web/DevHive.Web.Tests/LanguageController.Tests.cs4
-rw-r--r--src/Web/DevHive.Web.Tests/PostController.Tests.cs29
-rw-r--r--src/Web/DevHive.Web.Tests/RoleController.Tests.cs4
-rw-r--r--src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs4
-rw-r--r--src/Web/DevHive.Web.Tests/UserController.Tests.cs46
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs5
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs2
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs (renamed from src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs)6
-rw-r--r--src/Web/DevHive.Web/DevHive.Web.csproj21
-rw-r--r--src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs14
16 files changed, 89 insertions, 110 deletions
diff --git a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs
index 5ecb41a..c452499 100644
--- a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs
+++ b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs
@@ -1,9 +1,8 @@
-using System;
using System.ComponentModel.DataAnnotations;
namespace DevHive.Web.Models.Attributes
{
- public class GoodPassword : ValidationAttribute
+ public class GoodPasswordAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
@@ -11,7 +10,7 @@ namespace DevHive.Web.Models.Attributes
for (int i = 0; i < stringValue.Length; i++)
{
- if (Char.IsDigit(stringValue[i]))
+ if (char.IsDigit(stringValue[i]))
{
base.ErrorMessage = "Password must be atleast 5 characters long!";
return stringValue.Length >= 5;
diff --git a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs
index 0f6adb1..faaeee4 100644
--- a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs
+++ b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace DevHive.Web.Models.Attributes
{
- public class OnlyLetters : ValidationAttribute
+ public class OnlyLettersAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
@@ -11,7 +11,7 @@ namespace DevHive.Web.Models.Attributes
foreach (char ch in stringValue)
{
- if (!Char.IsLetter(ch))
+ if (!char.IsLetter(ch))
return false;
}
return true;
diff --git a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj
index ca49b8c..64d0bd0 100644
--- a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj
+++ b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj
@@ -3,10 +3,10 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
- <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj" />
+ <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj"/>
</ItemGroup>
-
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
+ <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2"/>
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/>
</ItemGroup>
-</Project>
+</Project> \ No newline at end of file
diff --git a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
index 8238f47..3ae93aa 100644
--- a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
+++ b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
@@ -21,6 +21,5 @@ namespace DevHive.Web.Models.Post
public List<IdModel> Comments { get; set; }
public List<string> FileUrls { get; set; }
- // public List<FileContentResult> Files { get; set; }
}
}
diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs
index 3a03f1a..98397e7 100644
--- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs
@@ -35,11 +35,11 @@ namespace DevHive.Web.Tests
public void AddComment_ReturnsOkObjectResult_WhenCommentIsSuccessfullyCreated()
{
Guid id = Guid.NewGuid();
- CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel
+ CreateCommentWebModel createCommentWebModel = new()
{
Message = MESSAGE
};
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
+ CreateCommentServiceModel createCommentServiceModel = new()
{
Message = MESSAGE
};
@@ -67,11 +67,11 @@ namespace DevHive.Web.Tests
public void AddComment_ReturnsBadRequestObjectResult_WhenCommentIsNotCreatedSuccessfully()
{
Guid id = Guid.NewGuid();
- CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel
+ CreateCommentWebModel createCommentWebModel = new()
{
Message = MESSAGE
};
- CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel
+ CreateCommentServiceModel createCommentServiceModel = new()
{
Message = MESSAGE
};
@@ -86,8 +86,8 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<BadRequestObjectResult>(result);
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
+ BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequestObjectResult.Value.ToString();
Assert.AreEqual(errorMessage, resultMessage);
}
@@ -95,8 +95,7 @@ namespace DevHive.Web.Tests
[Test]
public void AddComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized()
{
- Guid id = Guid.NewGuid();
- CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel
+ CreateCommentWebModel createCommentWebModel = new()
{
Message = MESSAGE
};
@@ -115,11 +114,11 @@ namespace DevHive.Web.Tests
{
Guid id = Guid.NewGuid();
- ReadCommentServiceModel readCommentServiceModel = new ReadCommentServiceModel
+ ReadCommentServiceModel readCommentServiceModel = new()
{
Message = MESSAGE
};
- ReadCommentWebModel readCommentWebModel = new ReadCommentWebModel
+ ReadCommentWebModel readCommentWebModel = new()
{
Message = MESSAGE
};
@@ -132,7 +131,7 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<OkObjectResult>(result);
OkObjectResult okObjectResult = result as OkObjectResult;
- ReadCommentWebModel resultModel = okObjectResult.Value as Models.Comment.ReadCommentWebModel;
+ ReadCommentWebModel resultModel = okObjectResult.Value as ReadCommentWebModel;
Assert.AreEqual(MESSAGE, resultModel.Message);
}
@@ -143,11 +142,11 @@ namespace DevHive.Web.Tests
public void Update_ShouldReturnOkResult_WhenCommentIsUpdatedSuccessfully()
{
Guid id = Guid.NewGuid();
- UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel
+ UpdateCommentWebModel updateCommentWebModel = new()
{
NewMessage = MESSAGE
};
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
+ UpdateCommentServiceModel updateCommentServiceModel = new()
{
NewMessage = MESSAGE
};
@@ -171,11 +170,11 @@ namespace DevHive.Web.Tests
public void Update_ShouldReturnBadObjectResult_WhenCommentIsNotUpdatedSuccessfully()
{
string message = "Unable to update comment!";
- UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel
+ UpdateCommentWebModel updateCommentWebModel = new()
{
NewMessage = MESSAGE
};
- UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel
+ UpdateCommentServiceModel updateCommentServiceModel = new()
{
NewMessage = MESSAGE
};
@@ -196,7 +195,7 @@ namespace DevHive.Web.Tests
[Test]
public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized()
{
- UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel
+ UpdateCommentWebModel updateCommentWebModel = new()
{
NewMessage = MESSAGE
};
@@ -224,7 +223,7 @@ namespace DevHive.Web.Tests
}
[Test]
- public void DeletComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully()
+ public void DeleteComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully()
{
string message = "Could not delete Comment";
Guid id = Guid.NewGuid();
@@ -243,7 +242,7 @@ namespace DevHive.Web.Tests
}
[Test]
- public void DeletComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized()
+ public void DeleteComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized()
{
this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false));
diff --git a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj
index f8390de..465698c 100644
--- a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj
+++ b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj
@@ -4,13 +4,14 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Moq" Version="4.16.0" />
- <PackageReference Include="NUnit" Version="3.13.1" />
- <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
+ <PackageReference Include="Moq" Version="4.16.0"/>
+ <PackageReference Include="NUnit" Version="3.13.1"/>
+ <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/>
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj" />
+ <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj"/>
</ItemGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs
index 7c8d64e..af4672a 100644
--- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs
@@ -81,8 +81,8 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<BadRequestObjectResult>(result);
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
+ BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequestObjectResult.Value.ToString();
Assert.AreEqual(errorMessage, resultMessage);
}
diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs
index 96b0356..f10f8dd 100644
--- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs
@@ -32,11 +32,11 @@ namespace DevHive.Web.Tests
[Test]
public void CreatePost_ReturnsOkObjectResult_WhenPostIsSuccessfullyCreated()
{
- CreatePostWebModel createPostWebModel = new CreatePostWebModel
+ CreatePostWebModel createPostWebModel = new()
{
Message = MESSAGE
};
- CreatePostServiceModel createPostServiceModel = new CreatePostServiceModel
+ CreatePostServiceModel createPostServiceModel = new()
{
Message = MESSAGE
};
@@ -64,11 +64,11 @@ namespace DevHive.Web.Tests
[Test]
public void CreatePost_ReturnsBadRequestObjectResult_WhenPostIsNotCreatedSuccessfully()
{
- CreatePostWebModel createTechnologyWebModel = new CreatePostWebModel
+ CreatePostWebModel createTechnologyWebModel = new()
{
Message = MESSAGE
};
- CreatePostServiceModel createTechnologyServiceModel = new CreatePostServiceModel
+ CreatePostServiceModel createTechnologyServiceModel = new()
{
Message = MESSAGE
};
@@ -83,8 +83,8 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<BadRequestObjectResult>(result);
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
+ BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequestObjectResult.Value.ToString();
Assert.AreEqual(errorMessage, resultMessage);
}
@@ -92,8 +92,7 @@ namespace DevHive.Web.Tests
[Test]
public void CreatePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized()
{
- Guid id = Guid.NewGuid();
- CreatePostWebModel createPostWebModel = new CreatePostWebModel
+ CreatePostWebModel createPostWebModel = new()
{
Message = MESSAGE
};
@@ -112,11 +111,11 @@ namespace DevHive.Web.Tests
{
Guid id = Guid.NewGuid();
- ReadPostServiceModel readPostServiceModel = new ReadPostServiceModel
+ ReadPostServiceModel readPostServiceModel = new()
{
Message = MESSAGE
};
- ReadPostWebModel readPostWebModel = new ReadPostWebModel
+ ReadPostWebModel readPostWebModel = new()
{
Message = MESSAGE
};
@@ -140,11 +139,11 @@ namespace DevHive.Web.Tests
public void Update_ShouldReturnOkResult_WhenPostIsUpdatedSuccessfully()
{
Guid id = Guid.NewGuid();
- UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel
+ UpdatePostWebModel updatePostWebModel = new()
{
NewMessage = MESSAGE
};
- UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel
+ UpdatePostServiceModel updatePostServiceModel = new()
{
NewMessage = MESSAGE
};
@@ -163,11 +162,11 @@ namespace DevHive.Web.Tests
{
Guid id = Guid.NewGuid();
string message = "Could not update post!";
- UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel
+ UpdatePostWebModel updatePostWebModel = new()
{
NewMessage = MESSAGE
};
- UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel
+ UpdatePostServiceModel updatePostServiceModel = new()
{
NewMessage = MESSAGE
};
@@ -188,7 +187,7 @@ namespace DevHive.Web.Tests
[Test]
public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized()
{
- UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel
+ UpdatePostWebModel updatePostWebModel = new()
{
NewMessage = MESSAGE
};
diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs
index 64e3f11..ff80dc0 100644
--- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs
@@ -81,8 +81,8 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<BadRequestObjectResult>(result);
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
+ BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequestObjectResult.Value.ToString();
Assert.AreEqual(errorMessage, resultMessage);
}
diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs
index 164bcbf..a00f1db 100644
--- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs
@@ -84,8 +84,8 @@ namespace DevHive.Web.Tests
Assert.IsInstanceOf<BadRequestObjectResult>(result);
- BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult;
- string resultMessage = badRequsetObjectResult.Value.ToString();
+ BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult;
+ string resultMessage = badRequestObjectResult.Value.ToString();
Assert.AreEqual(errorMessage, resultMessage);
}
diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs
index 7457ad7..13f618e 100644
--- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs
+++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs
@@ -33,17 +33,17 @@ namespace DevHive.Web.Tests
public void LoginUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyLoggedIn()
{
Guid id = Guid.NewGuid();
- LoginWebModel loginWebModel = new LoginWebModel
+ LoginWebModel loginWebModel = new()
{
UserName = USERNAME
};
- LoginServiceModel loginServiceModel = new LoginServiceModel
+ LoginServiceModel loginServiceModel = new()
{
UserName = USERNAME
};
string token = "goshotrapov";
- TokenModel tokenModel = new TokenModel(token);
- TokenWebModel tokenWebModel = new TokenWebModel(token);
+ TokenModel tokenModel = new(token);
+ TokenWebModel tokenWebModel = new(token);
this.MapperMock.Setup(p => p.Map<LoginServiceModel>(It.IsAny<LoginWebModel>())).Returns(loginServiceModel);
this.MapperMock.Setup(p => p.Map<TokenWebModel>(It.IsAny<TokenModel>())).Returns(tokenWebModel);
@@ -61,18 +61,17 @@ namespace DevHive.Web.Tests
[Test]
public void RegisterUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyRegistered()
{
- Guid id = Guid.NewGuid();
- RegisterWebModel registerWebModel = new RegisterWebModel
+ RegisterWebModel registerWebModel = new()
{
UserName = USERNAME
};
- RegisterServiceModel registerServiceModel = new RegisterServiceModel
+ RegisterServiceModel registerServiceModel = new()
{
UserName = USERNAME
};
string token = "goshotrapov";
- TokenModel tokenModel = new TokenModel(token);
- TokenWebModel tokenWebModel = new TokenWebModel(token);
+ TokenModel tokenModel = new(token);
+ TokenWebModel tokenWebModel = new(token);
this.MapperMock.Setup(p => p.Map<RegisterServiceModel>(It.IsAny<RegisterWebModel>())).Returns(registerServiceModel);
this.MapperMock.Setup(p => p.Map<TokenWebModel>(It.IsAny<TokenModel>())).Returns(tokenWebModel);
@@ -95,11 +94,11 @@ namespace DevHive.Web.Tests
{
Guid id = Guid.NewGuid();
- UserServiceModel userServiceModel = new UserServiceModel
+ UserServiceModel userServiceModel = new()
{
UserName = USERNAME
};
- UserWebModel userWebModel = new UserWebModel
+ UserWebModel userWebModel = new()
{
UserName = USERNAME
};
@@ -121,12 +120,6 @@ namespace DevHive.Web.Tests
[Test]
public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized()
{
- Guid id = Guid.NewGuid();
- UserWebModel userWebModel = new UserWebModel
- {
- UserName = USERNAME
- };
-
this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false));
IActionResult result = this.UserController.GetById(Guid.NewGuid(), null).Result;
@@ -137,12 +130,11 @@ namespace DevHive.Web.Tests
[Test]
public void GetUser_ReturnsTheUser_WhenItExists()
{
- Guid id = Guid.NewGuid();
- UserWebModel userWebModel = new UserWebModel
+ UserWebModel userWebModel = new()
{
UserName = USERNAME
};
- UserServiceModel userServiceModel = new UserServiceModel
+ UserServiceModel userServiceModel = new()
{
UserName = USERNAME
};
@@ -166,15 +158,15 @@ namespace DevHive.Web.Tests
public void Update_ShouldReturnOkResult_WhenUserIsUpdatedSuccessfully()
{
Guid id = Guid.NewGuid();
- UpdateUserWebModel updateUserWebModel = new UpdateUserWebModel
+ UpdateUserWebModel updateUserWebModel = new()
{
UserName = USERNAME
};
- UpdateUserServiceModel updateUserServiceModel = new UpdateUserServiceModel
+ UpdateUserServiceModel updateUserServiceModel = new()
{
UserName = USERNAME
};
- UserServiceModel userServiceModel = new UserServiceModel
+ UserServiceModel userServiceModel = new()
{
UserName = USERNAME
};
@@ -192,13 +184,13 @@ namespace DevHive.Web.Tests
public void UpdateProfilePicture_ShouldReturnOkObjectResult_WhenProfilePictureIsUpdatedSuccessfully()
{
string profilePictureURL = "goshotrapov";
- UpdateProfilePictureWebModel updateProfilePictureWebModel = new UpdateProfilePictureWebModel();
- UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new UpdateProfilePictureServiceModel();
- ProfilePictureServiceModel profilePictureServiceModel = new ProfilePictureServiceModel
+ UpdateProfilePictureWebModel updateProfilePictureWebModel = new();
+ UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new();
+ ProfilePictureServiceModel profilePictureServiceModel = new()
{
ProfilePictureURL = profilePictureURL
};
- ProfilePictureWebModel profilePictureWebModel = new ProfilePictureWebModel
+ ProfilePictureWebModel profilePictureWebModel = new()
{
ProfilePictureURL = profilePictureURL
};
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
index 8b7d657..0b8194e 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
@@ -1,6 +1,5 @@
using System;
using AutoMapper;
-//using AutoMapper.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
@@ -15,10 +14,10 @@ namespace DevHive.Web.Configurations.Extensions
public static void UseAutoMapperConfiguration(this IApplicationBuilder app)
{
- var config = new MapperConfiguration(cfg =>
+ _ = new MapperConfiguration(cfg =>
{
cfg.AllowNullCollections = true;
});
}
}
-} \ No newline at end of file
+}
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs
index 286727f..c017a8c 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs
@@ -6,8 +6,6 @@ namespace DevHive.Web.Configurations.Extensions
{
public static class ConfigureExceptionHandlerMiddleware
{
- public static void ExceptionHandlerMiddlewareConfiguration(this IServiceCollection services) { }
-
public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app)
{
app.UseMiddleware<ExceptionMiddleware>();
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs
index d422bc8..03d4b11 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs
@@ -8,11 +8,11 @@ using Microsoft.IdentityModel.Tokens;
namespace DevHive.Web.Configurations.Extensions
{
- public static class JWTExtensions
+ public static class ConfigureJwt
{
public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration)
{
- services.AddSingleton(new JWTOptions(configuration
+ services.AddSingleton(new JwtOptions(configuration
.GetSection("AppSettings")
.GetSection("Secret")
.Value));
@@ -51,4 +51,4 @@ namespace DevHive.Web.Configurations.Extensions
});
}
}
-} \ No newline at end of file
+}
diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj
index 6f78b69..6511c37 100644
--- a/src/Web/DevHive.Web/DevHive.Web.csproj
+++ b/src/Web/DevHive.Web/DevHive.Web.csproj
@@ -7,21 +7,22 @@
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605" />
- <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605" />
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605"/>
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
- <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
- <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.5" />
- <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
- <PackageReference Include="AutoMapper" Version="10.1.1" />
- <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
+ <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2"/>
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.5"/>
+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1"/>
+ <PackageReference Include="AutoMapper" Version="10.1.1"/>
+ <PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3"/>
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj" />
- <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj" />
+ <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj"/>
+ <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj"/>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs
index cb6d4ca..f159b69 100644
--- a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs
+++ b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs
@@ -9,18 +9,11 @@ namespace DevHive.Web.Middleware
public class ExceptionMiddleware
{
private readonly RequestDelegate _next;
- // private readonly ILogger _logger;
public ExceptionMiddleware(RequestDelegate next)
{
this._next = next;
- // this._logger = logger;
}
- // public ExceptionMiddleware(RequestDelegate next, ILogger logger)
- // {
- // this._logger = logger;
- // this._next = next;
- // }
public async Task InvokeAsync(HttpContext httpContext)
{
@@ -30,20 +23,19 @@ namespace DevHive.Web.Middleware
}
catch (Exception ex)
{
- // this._logger.LogError($"Something went wrong: {ex}");
await HandleExceptionAsync(httpContext, ex);
}
}
- private Task HandleExceptionAsync(HttpContext context, Exception exception)
+ private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
return context.Response.WriteAsync(new
{
- StatusCode = context.Response.StatusCode,
- Message = exception.Message
+ context.Response.StatusCode,
+ exception.Message
}.ToString());
}
}