Skip to content

Commit

Permalink
Fix more pragma warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Apr 8, 2024
1 parent f02d3dc commit 74bc61f
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Backend.Tests/Backend.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AnalysisMode>Recommended</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CA1305;CS1591</NoWarn>
<NoWarn>$(NoWarn);CA1305;CA1859;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
Expand Down
4 changes: 3 additions & 1 deletion Backend.Tests/Controllers/LiftControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,11 @@ public void TestRoundtrip(RoundTripObj roundTripObj)
}
}

private class MockLogger : ILogger<LiftController>
private sealed class MockLogger : ILogger<LiftController>
{
#pragma warning disable CS8633
public IDisposable BeginScope<TState>(TState state)
#pragma warning restore CS8633
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/BannerRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Backend.Tests.Mocks
{
public class BannerRepositoryMock : IBannerRepository
internal sealed class BannerRepositoryMock : IBannerRepository
{
private Dictionary<BannerType, Banner> _banners;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/EmailServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Backend.Tests.Mocks
{
internal class EmailServiceMock : IEmailService
internal sealed class EmailServiceMock : IEmailService
{
public Task<bool> SendEmail(MimeMessage msg)
{
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/MergeBlacklistRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Backend.Tests.Mocks
{
public class MergeBlacklistRepositoryMock : IMergeBlacklistRepository
internal sealed class MergeBlacklistRepositoryMock : IMergeBlacklistRepository
{
private readonly List<MergeWordSet> _mergeBlacklist;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/MergeGraylistRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Backend.Tests.Mocks
{
public class MergeGraylistRepositoryMock : IMergeGraylistRepository
internal sealed class MergeGraylistRepositoryMock : IMergeGraylistRepository
{
private readonly List<MergeWordSet> _mergeGraylist;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/PasswordResetServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Backend.Tests.Mocks
{
internal class PasswordResetServiceMock : IPasswordResetService
internal sealed class PasswordResetServiceMock : IPasswordResetService
{
public Task<PasswordReset> CreatePasswordReset(string email)
{
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/PermissionServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Backend.Tests.Mocks
{
internal class PermissionServiceMock : IPermissionService
internal sealed class PermissionServiceMock : IPermissionService
{
private readonly IUserRepository _userRepo;
private const string NoHttpContextAvailable = "NO_HTTP_CONTEXT_AVAILABLE";
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/ProjectRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Backend.Tests.Mocks
{
public class ProjectRepositoryMock : IProjectRepository
internal sealed class ProjectRepositoryMock : IProjectRepository
{
private readonly List<Project> _projects;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/SemanticDomainRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Backend.Tests.Mocks
{
public class SemanticDomainRepositoryMock : ISemanticDomainRepository
internal sealed class SemanticDomainRepositoryMock : ISemanticDomainRepository
{
private object? _responseObj;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/SpeakerRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Backend.Tests.Mocks
{
public class SpeakerRepositoryMock : ISpeakerRepository
internal sealed class SpeakerRepositoryMock : ISpeakerRepository
{
private readonly List<Speaker> _speakers;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/StatisticsServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Backend.Tests.Mocks
{
internal class StatisticsServiceMock : IStatisticsService
internal sealed class StatisticsServiceMock : IStatisticsService
{
public Task<List<SemanticDomainCount>> GetSemanticDomainCounts(string projectId, string lang)
{
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/UserEditRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Backend.Tests.Mocks
{
public class UserEditRepositoryMock : IUserEditRepository
internal sealed class UserEditRepositoryMock : IUserEditRepository
{
private readonly List<UserEdit> _userEdits;

Expand Down
10 changes: 5 additions & 5 deletions Backend.Tests/Mocks/UserRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Backend.Tests.Mocks
{
public class UserRepositoryMock : IUserRepository
internal sealed class UserRepositoryMock : IUserRepository
{
private readonly List<User> _users;

Expand Down Expand Up @@ -57,21 +57,21 @@ public Task<bool> Delete(string userId)

public Task<User?> GetUserByEmail(string email, bool sanitize = true)
{
var user = _users.Find(u => u.Email.ToLowerInvariant() == email.ToLowerInvariant());
var user = _users.Find(u => u.Email.Equals(email, StringComparison.OrdinalIgnoreCase));
return Task.FromResult(user);
}

public Task<User?> GetUserByEmailOrUsername(string emailOrUsername, bool sanitize = true)
{
var user = _users.Find(u =>
u.Email.ToLowerInvariant() == emailOrUsername.ToLowerInvariant() ||
u.Username.ToLowerInvariant() == emailOrUsername.ToLowerInvariant());
u.Email.Equals(emailOrUsername, StringComparison.OrdinalIgnoreCase) ||
u.Username.Equals(emailOrUsername, StringComparison.OrdinalIgnoreCase));
return Task.FromResult(user);
}

public Task<User?> GetUserByUsername(string username, bool sanitize = true)
{
var user = _users.Find(u => u.Username.ToLowerInvariant() == username.ToLowerInvariant());
var user = _users.Find(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase));
return Task.FromResult(user);
}

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/UserRoleRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Backend.Tests.Mocks
{
public class UserRoleRepositoryMock : IUserRoleRepository
internal sealed class UserRoleRepositoryMock : IUserRoleRepository
{
private readonly List<UserRole> _userRoles;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Mocks/WordRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Backend.Tests.Mocks
{
public class WordRepositoryMock : IWordRepository
internal sealed class WordRepositoryMock : IWordRepository
{
private readonly List<Word> _words;
private readonly List<Word> _frontier;
Expand Down
3 changes: 1 addition & 2 deletions Backend/Helper/DuplicateFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BackendFramework.Interfaces;
using BackendFramework.Models;

namespace BackendFramework.Helper
{
public class DuplicateFinder
{
private readonly IEditDistance _editDist;
private readonly LevenshteinDistance _editDist;
private readonly int _maxInList;
private readonly int _maxLists;
private readonly int _maxScore;
Expand Down
13 changes: 7 additions & 6 deletions Backend/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task<bool> Delete(string userId)
public async Task<User?> GetUserByEmail(string email, bool sanitize = true)
{
var user = (await _userDatabase.Users.FindAsync(
x => x.Email.ToLowerInvariant() == email.ToLowerInvariant())).FirstOrDefault();
x => x.Email.Equals(email, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
if (sanitize && user is not null)
{
user.Sanitize();
Expand All @@ -131,8 +131,9 @@ public async Task<bool> Delete(string userId)
public async Task<User?> GetUserByEmailOrUsername(string emailOrUsername, bool sanitize = true)
{
var lower = emailOrUsername.ToLowerInvariant();
var user = (await _userDatabase.Users.FindAsync(
u => u.Username.ToLowerInvariant() == lower || u.Email.ToLowerInvariant() == lower)).FirstOrDefault();
var user = (await _userDatabase.Users.FindAsync(u =>
u.Username.Equals(emailOrUsername, StringComparison.OrdinalIgnoreCase) ||
u.Email.Equals(emailOrUsername, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
if (sanitize && user is not null)
{
user.Sanitize();
Expand All @@ -145,7 +146,7 @@ public async Task<bool> Delete(string userId)
public async Task<User?> GetUserByUsername(string username, bool sanitize = true)
{
var user = (await _userDatabase.Users.FindAsync(
x => x.Username.ToLowerInvariant() == username.ToLowerInvariant())).FirstOrDefault();
x => x.Username.Equals(username, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
if (sanitize && user is not null)
{
user.Sanitize();
Expand All @@ -171,12 +172,12 @@ public async Task<ResultOfUpdate> Update(string userId, User user, bool updateIs
}

// Confirm that email and username aren't taken by another user.
if (user.Email.ToLowerInvariant() != oldUser.Email.ToLowerInvariant()
if (!user.Email.Equals(oldUser.Email, StringComparison.OrdinalIgnoreCase)
&& await GetUserByEmail(user.Email) is not null)
{
return ResultOfUpdate.Failed;
}
if (user.Username.ToLowerInvariant() != oldUser.Username.ToLowerInvariant()
if (!user.Username.Equals(oldUser.Username, StringComparison.OrdinalIgnoreCase)
&& await GetUserByUsername(user.Username) is not null)
{
return ResultOfUpdate.Failed;
Expand Down
2 changes: 1 addition & 1 deletion Backend/Services/PasswordResetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<bool> ResetPassword(string token, string password)
return false;
}
var user = (await _userRepo.GetAllUsers()).Single(u =>
u.Email.ToLowerInvariant() == request.Email.ToLowerInvariant());
u.Email.Equals(request.Email, StringComparison.OrdinalIgnoreCase));
await _userRepo.ChangePassword(user.Id, password);
await ExpirePasswordReset(request.Email);
return true;
Expand Down
11 changes: 4 additions & 7 deletions Backend/Services/StatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,11 @@ public async Task<ChartRootData> GetProgressEstimationLineChartRoot(string proje
{
LineChartData.Dates.Add(workshopSchedule[i]);
var day = workshopSchedule[i];
totalCountDictionary.TryGetValue(day, out today);
if (LineChartData.Datasets.Count == 0)
{
runningTotal = totalCountDictionary.ContainsKey(day) ? totalCountDictionary[day] : 0;
today = yesterday = runningTotal;
LineChartData.Datasets.Add(new Dataset(
"Daily Total", totalCountDictionary.ContainsKey(day) ? totalCountDictionary[day] : 0));
runningTotal = yesterday = today;
LineChartData.Datasets.Add(new Dataset("Daily Total", today));
LineChartData.Datasets.Add(new Dataset("Average", averageValue));
LineChartData.Datasets.Add(new Dataset("Running Total", runningTotal));
LineChartData.Datasets.Add(new Dataset("Projection", projection));
Expand All @@ -216,7 +215,6 @@ public async Task<ChartRootData> GetProgressEstimationLineChartRoot(string proje
// not generate data after the current date for "Daily Total", "Average" and "Running Total"
if (ParseDateTimePermissivelyWithException(day).CompareTo(DateTime.Now) <= 0)
{
today = totalCountDictionary.ContainsKey(day) ? totalCountDictionary[day] : 0;
runningTotal += today;
LineChartData.Datasets.Find(element => element.UserName == "Daily Total")?.Data.Add(today);
LineChartData.Datasets.Find(element => element.UserName == "Average")?.Data.Add(averageValue);
Expand Down Expand Up @@ -330,9 +328,8 @@ public async Task<List<SemanticDomainUserCount>> GetSemanticDomainUserCounts(str
}

// update DomainCount
if (!domainUserValue.DomainSet.Contains(domainName))
if (domainUserValue.DomainSet.Add(domainName))
{
domainUserValue.DomainSet.Add(domainName);
domainUserValue.DomainCount++;
}
// update WordCount
Expand Down
6 changes: 4 additions & 2 deletions Backend/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ public void ConfigureServices(IServiceCollection services)
options =>
{
var connectionStringKey = IsInContainer() ? "ContainerConnectionString" : "ConnectionString";
options.ConnectionString = Configuration[$"MongoDB:{connectionStringKey}"];
options.CombineDatabase = Configuration["MongoDB:CombineDatabase"];
options.ConnectionString = Configuration[$"MongoDB:{connectionStringKey}"]
?? throw new EnvironmentNotConfiguredException();
options.CombineDatabase = Configuration["MongoDB:CombineDatabase"]
?? throw new EnvironmentNotConfiguredException();

const string emailServiceFailureMessage = "Email services will not work.";
options.SmtpServer = CheckedEnvironmentVariable(
Expand Down

0 comments on commit 74bc61f

Please sign in to comment.