-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
172 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" /> | ||
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.6" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" /> | ||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
namespace Api.Domain | ||
namespace Api.Domain; | ||
|
||
public class Company | ||
{ | ||
public class Company | ||
{ | ||
public string Name { get; set; } | ||
public string Name { get; set; } | ||
|
||
public string Address { get; set; } | ||
public string Address { get; set; } | ||
|
||
public string RegistrationNumber { get; set; } | ||
public string RegistrationNumber { get; set; } | ||
|
||
public CompanyStatus CompanyStatus { get; set; } | ||
} | ||
} | ||
public CompanyStatus CompanyStatus { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
using Api.Domain; | ||
|
||
namespace Api.Infrastructure | ||
namespace Api.Infrastructure; | ||
|
||
public class Proxy : IProxy | ||
{ | ||
public class Proxy : IProxy | ||
public Task<Company> GetCompanyAsync(string registrationNumber, CancellationToken cancellationToken = default) | ||
{ | ||
public Task<Company> GetCompanyAsync(string registrationNumber, CancellationToken cancellationToken = default) | ||
{ | ||
var nextValue = Randomize.Next(); | ||
var nextValue = Randomize.Next(); | ||
|
||
return nextValue switch | ||
return nextValue switch | ||
{ | ||
< 300 => Task.FromResult(new Company | ||
{ | ||
< 300 => Task.FromResult(new Company | ||
{ | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
Address = Randomize.RandomString(20), | ||
CompanyStatus = CompanyStatus.Active | ||
}), | ||
< 400 => Task.FromResult(new Company | ||
{ | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
Address = Randomize.RandomString(20), | ||
CompanyStatus = CompanyStatus.Delisted | ||
}), | ||
< 600 => Task.FromResult(new Company | ||
{ | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
CompanyStatus = CompanyStatus.Active | ||
}), | ||
< 700 => throw InfrastructureException.PartnerWebServiceIsDown(), | ||
< 800 => throw InfrastructureException.PartnerWebServiceIsTakingTooLongToRespond(), | ||
_ => throw InfrastructureException.PartnerWebServiceReceivingTooManyRequests() | ||
}; | ||
} | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
Address = Randomize.RandomString(20), | ||
CompanyStatus = CompanyStatus.Active | ||
}), | ||
< 400 => Task.FromResult(new Company | ||
{ | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
Address = Randomize.RandomString(20), | ||
CompanyStatus = CompanyStatus.Delisted | ||
}), | ||
< 600 => Task.FromResult(new Company | ||
{ | ||
Name = Randomize.RandomString(10), | ||
RegistrationNumber = registrationNumber, | ||
CompanyStatus = CompanyStatus.Active | ||
}), | ||
< 700 => throw InfrastructureException.PartnerWebServiceIsDown(), | ||
< 800 => throw InfrastructureException.PartnerWebServiceIsTakingTooLongToRespond(), | ||
_ => throw InfrastructureException.PartnerWebServiceReceivingTooManyRequests() | ||
}; | ||
} | ||
|
||
public class Randomize | ||
{ | ||
private static readonly Random Random = new(Guid.NewGuid().GetHashCode()); | ||
private sealed class Randomize | ||
{ | ||
private static readonly Random Random = new(Guid.NewGuid().GetHashCode()); | ||
|
||
public static int Next() => Random.Next(1, 1000); | ||
public static int Next() => Random.Next(1, 1000); | ||
|
||
public static string RandomString(int length) | ||
{ | ||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
return new string(Enumerable.Repeat(chars, length) | ||
.Select(s => s[Random.Next(s.Length)]).ToArray()); | ||
} | ||
public static string RandomString(int length) | ||
{ | ||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
return new string(Enumerable.Repeat(chars, length) | ||
.Select(s => s[Random.Next(s.Length)]).ToArray()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
using Api.Presentation.ViewModels; | ||
using FluentValidation; | ||
|
||
namespace Api.Presentation.Validators | ||
namespace Api.Presentation.Validators; | ||
|
||
public class CompanyRequestDtoValidator : AbstractValidator<CompanyRequestDto> | ||
{ | ||
public class CompanyRequestDtoValidator : AbstractValidator<CompanyRequestDto> | ||
public CompanyRequestDtoValidator() | ||
{ | ||
public CompanyRequestDtoValidator() | ||
{ | ||
RuleFor(x => x.RegistrationNumber) | ||
.NotEmpty() | ||
.MinimumLength(5) | ||
.MaximumLength(10); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
using Api.Domain; | ||
|
||
namespace Api.Presentation.ViewModels | ||
namespace Api.Presentation.ViewModels; | ||
|
||
public class CompanyResponseDto | ||
{ | ||
public class CompanyResponseDto | ||
{ | ||
public string Name { get; set; } | ||
public string Name { get; set; } | ||
|
||
public string Address { get; set; } | ||
public string Address { get; set; } | ||
|
||
public string RegistrationNumber { get; set; } | ||
public string RegistrationNumber { get; set; } | ||
|
||
public CompanyResponseDto(Company company) | ||
{ | ||
public CompanyResponseDto(Company company) | ||
{ | ||
Name = company.Name; | ||
Address = company.Address; | ||
RegistrationNumber = company.RegistrationNumber; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.