Repository tests
This commit is contained in:
		| @@ -0,0 +1,29 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Bogus; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Generates past visas | ||||
|     /// </summary> | ||||
|     public sealed class PastVisaFaker : Faker<PastVisa> | ||||
|     { | ||||
|         private IDateTimeProvider dateTimeProvider; | ||||
|  | ||||
|         public PastVisaFaker(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             this.dateTimeProvider = dateTimeProvider; | ||||
|  | ||||
|             RuleFor(pv => pv.Name, f => f.Random.Words()); | ||||
|         } | ||||
|  | ||||
|         public PastVisa GenerateValid() | ||||
|         { | ||||
|             var result = Generate(); | ||||
|             result.IssueDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900)); | ||||
|             result.ExpirationDate = result.IssueDate.AddDays(Random.Shared.Next(1, 11)); | ||||
|             return result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,29 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Bogus; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Generates past visas | ||||
|     /// </summary> | ||||
|     public sealed class PastVisitFaker : Faker<PastVisit> | ||||
|     { | ||||
|         private IDateTimeProvider dateTimeProvider; | ||||
|  | ||||
|         public PastVisitFaker(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             this.dateTimeProvider = dateTimeProvider; | ||||
|  | ||||
|             RuleFor(pv => pv.DestinationCountry, f => f.Address.Country()); | ||||
|         } | ||||
|  | ||||
|         public PastVisit GenerateValid() | ||||
|         { | ||||
|             var result = Generate(); | ||||
|             result.StartDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900)); | ||||
|             result.EndDate = result.StartDate.AddDays(Random.Shared.Next(1, 11)); | ||||
|             return result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Bogus; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Generates permissions to destination Country | ||||
|     /// </summary> | ||||
|     public sealed class PermissionToDestCountryFaker : Faker<PermissionToDestCountry> | ||||
|     { | ||||
|         public PermissionToDestCountryFaker(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             RuleFor(p => p.Issuer, f => f.Company.CompanyName()); | ||||
|  | ||||
|             RuleFor(p => p.ExpirationDate, | ||||
|                 f => f.Date.Future(4, dateTimeProvider.Now())); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Bogus; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Generates re-entry permissions | ||||
|     /// </summary> | ||||
|     public sealed class ReentryPermitFaker : Faker<ReentryPermit> | ||||
|     { | ||||
|         public ReentryPermitFaker(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             RuleFor(p => p.Number, | ||||
|                 f => f.Random.String(ConfigurationConstraints.ReentryPermitNumberLength)); | ||||
|  | ||||
|             RuleFor(p => p.ExpirationDate, | ||||
|                 f => f.Date.Future(4, dateTimeProvider.Now())); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,10 +1,65 @@ | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Bogus; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace VisaApi.Fakers.VisaApplications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Generates visa applications | ||||
|     /// </summary> | ||||
|     public class VisaApplicationFaker | ||||
|     public sealed class VisaApplicationFaker : Faker<VisaApplication> | ||||
|     { | ||||
|         private static ReentryPermitFaker reentryPermitFaker = null!; | ||||
|         private static PermissionToDestCountryFaker permissionToDestCountryFaker = null!; | ||||
|  | ||||
|         public VisaApplicationFaker(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             reentryPermitFaker = new(dateTimeProvider); | ||||
|             permissionToDestCountryFaker = new(dateTimeProvider); | ||||
|             var pastVisaFaker = new PastVisaFaker(dateTimeProvider); | ||||
|             var pastVisitFaker = new PastVisitFaker(dateTimeProvider); | ||||
|  | ||||
|             RuleFor(va => va.Status, f => f.Random.Enum<ApplicationStatus>()); | ||||
|  | ||||
|             RuleFor(va => va.DestinationCountry, f => f.Address.Country()); | ||||
|  | ||||
|             RuleFor(va => va.PastVisas, | ||||
|                 f => f.PickRandom(pastVisaFaker.Generate(3), f.Random.Int(0, 3)).ToList()); | ||||
|  | ||||
|             RuleFor(va => va.PastVisits, | ||||
|                 f => f.PickRandom(pastVisitFaker.Generate(3), f.Random.Int(0, 3)).ToList()); | ||||
|  | ||||
|             RuleFor(va => va.VisaCategory, f => f.Random.Enum<VisaCategory>()); | ||||
|  | ||||
|             RuleFor(va => va.ForGroup, f => f.Random.Bool()); | ||||
|  | ||||
|             RuleFor(va => va.RequestedNumberOfEntries, | ||||
|                 f => f.Random.Enum<RequestedNumberOfEntries>()); | ||||
|  | ||||
|             RuleFor(va => va.RequestDate, dateTimeProvider.Now); | ||||
|  | ||||
|             RuleFor(va => va.ValidDaysRequested, | ||||
|                 f => f.Random.Int(1, ConfigurationConstraints.MaxValidDays)); | ||||
|         } | ||||
|  | ||||
|         public VisaApplication GenerateValid(Applicant applicant) | ||||
|         { | ||||
|             var result = Generate(); | ||||
|  | ||||
|             result.ApplicantId = applicant.Id; | ||||
|             if (applicant.IsNonResident) | ||||
|             { | ||||
|                 result.ReentryPermit = reentryPermitFaker.Generate(); | ||||
|             } | ||||
|  | ||||
|             if (result.VisaCategory is VisaCategory.Transit) | ||||
|             { | ||||
|                 result.PermissionToDestCountry = permissionToDestCountryFaker.Generate(); | ||||
|             } | ||||
|  | ||||
|             return result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user