refactor (readonly for static objects in tests and file-scoped namespaces
This commit is contained in:
		| @@ -3,17 +3,16 @@ using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models; | ||||
| using VisaApiClient; | ||||
| using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models.PlaceOfWorkModel; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles; | ||||
|  | ||||
| public class RegisterApplicantRequestProfile : Profile | ||||
| { | ||||
|     public class RegisterApplicantRequestProfile : Profile | ||||
|     public RegisterApplicantRequestProfile() | ||||
|     { | ||||
|         public RegisterApplicantRequestProfile() | ||||
|         { | ||||
|             CreateMap<RegisterApplicantRequestModel, RegisterApplicantRequest>(MemberList.Destination); | ||||
|  | ||||
|             CreateMap<RegisterRequestModel, RegisterRequest>(MemberList.Destination); | ||||
|  | ||||
|             CreateMap<PlaceOfWorkModel, VisaApiClient.PlaceOfWorkModel>(MemberList.Destination); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,13 +2,12 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles; | ||||
|  | ||||
| public class VisaApplicationCreateRequestProfile : Profile | ||||
| { | ||||
|     public class VisaApplicationCreateRequestProfile : Profile | ||||
|     public VisaApplicationCreateRequestProfile() | ||||
|     { | ||||
|         public VisaApplicationCreateRequestProfile() | ||||
|         { | ||||
|             CreateMap<VisaApplicationCreateRequestModel, VisaApplicationCreateRequest>(MemberList.Destination); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,11 +1,11 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers; | ||||
|  | ||||
| public static class EnumExtensions | ||||
| { | ||||
|     public static class EnumExtensions | ||||
|     public static string GetDisplayName(this Enum value) | ||||
|     { | ||||
|         public static string GetDisplayName(this Enum value) | ||||
|         { | ||||
|             var enumMembers = value.GetType().GetMembers(); | ||||
|             var member = enumMembers.First(info => info.Name == value.ToString()); | ||||
|             var displayAttribute = (DisplayAttribute?)member | ||||
| @@ -14,5 +14,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
|             var displayName = displayAttribute?.Name ?? value.ToString(); | ||||
|             return displayName; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,15 +1,15 @@ | ||||
| using System.Text; | ||||
| using FluentValidation.Results; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| { | ||||
|     public static class ValidationResultExtensions | ||||
|     { | ||||
|         public static string ToErrorsString(this ValidationResult validationResult) | ||||
|             => ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage)); | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers; | ||||
|  | ||||
|         private static string ErrorsToString(IEnumerable<string> errors) | ||||
|         { | ||||
| public static class ValidationResultExtensions | ||||
| { | ||||
|     public static string ToErrorsString(this ValidationResult validationResult) | ||||
|         => ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage)); | ||||
|  | ||||
|     private static string ErrorsToString(IEnumerable<string> errors) | ||||
|     { | ||||
|             var stringBuilder = new StringBuilder(); | ||||
|             foreach (var error in errors) | ||||
|             { | ||||
| @@ -18,5 +18,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
|  | ||||
|             return stringBuilder.ToString(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,9 +1,8 @@ | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||
| { | ||||
|     public class DateTimeProvider : IDateTimeProvider | ||||
|     { | ||||
|         public DateTime Now() => DateTime.Now; | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
|  | ||||
|         public string FormattedNow() => Now().ToString("yyyy-MM-dd"); | ||||
|     } | ||||
| } | ||||
| public class DateTimeProvider : IDateTimeProvider | ||||
| { | ||||
|     public DateTime Now() => DateTime.Now; | ||||
|  | ||||
|     public string FormattedNow() => Now().ToString("yyyy-MM-dd"); | ||||
| } | ||||
| @@ -1,9 +1,8 @@ | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||
| { | ||||
|     public interface IDateTimeProvider | ||||
|     { | ||||
|         DateTime Now(); | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
|  | ||||
|         string FormattedNow(); | ||||
|     } | ||||
| } | ||||
| public interface IDateTimeProvider | ||||
| { | ||||
|     DateTime Now(); | ||||
|  | ||||
|     string FormattedNow(); | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Common.Exceptions; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions | ||||
| { | ||||
|     public class UnknownRoleException() : BlazorClientException("Unknown user role"); | ||||
| } | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions; | ||||
|  | ||||
| public class UnknownRoleException() : BlazorClientException("Unknown user role"); | ||||
| @@ -1,15 +1,14 @@ | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider; | ||||
|  | ||||
| public interface IUserDataProvider | ||||
| { | ||||
|     public interface IUserDataProvider | ||||
|     { | ||||
|         public string? CurrentRole { get; } | ||||
|     public string? CurrentRole { get; } | ||||
|  | ||||
|         public Action? OnRoleChanged { get; set; } | ||||
|     public Action? OnRoleChanged { get; set; } | ||||
|  | ||||
|         public Task<ApplicantModel> GetApplicant(); | ||||
|     public Task<ApplicantModel> GetApplicant(); | ||||
|  | ||||
|         public void UpdateCurrentRole(); | ||||
|     } | ||||
| } | ||||
|     public void UpdateCurrentRole(); | ||||
| } | ||||
| @@ -3,23 +3,23 @@ using System.Security.Claims; | ||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider; | ||||
|  | ||||
| public class UserDataProvider(Client client) : IUserDataProvider | ||||
| { | ||||
|     public class UserDataProvider(Client client) : IUserDataProvider | ||||
|     private readonly static JwtSecurityTokenHandler tokenHandler = new(); | ||||
|  | ||||
|     public string? CurrentRole { get; private set; } | ||||
|  | ||||
|     public Action? OnRoleChanged { get; set; } | ||||
|  | ||||
|     public async Task<ApplicantModel> GetApplicant() | ||||
|     { | ||||
|         private readonly static JwtSecurityTokenHandler tokenHandler = new(); | ||||
|  | ||||
|         public string? CurrentRole { get; private set; } | ||||
|  | ||||
|         public Action? OnRoleChanged { get; set; } | ||||
|  | ||||
|         public async Task<ApplicantModel> GetApplicant() | ||||
|         { | ||||
|             return await client.GetApplicantAsync(); | ||||
|         } | ||||
|  | ||||
|         public void UpdateCurrentRole() | ||||
|         { | ||||
|     public void UpdateCurrentRole() | ||||
|     { | ||||
|             var role = CurrentRole; | ||||
|  | ||||
|             if (client.AuthToken is null) | ||||
| @@ -49,5 +49,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide | ||||
|                 OnRoleChanged?.Invoke(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user