generated from Kentico/repo-template
-
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.
feat(Generator): project to generate test csv files
- Loading branch information
1 parent
5520d90
commit 02fcf60
Showing
5 changed files
with
746 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
test/Kentico.Xperience.Contacts.Importer.Generator/ContactsGenerator.cs
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using CMS.ContactManagement; | ||
|
||
namespace Kentico.Xperience.Contacts.Importer.Generator; | ||
|
||
public static class ContactsGenerator | ||
{ | ||
public static IEnumerable<ContactInfo> Generate(int count) | ||
{ | ||
var faker = new Bogus.Faker<ContactInfo>(); | ||
|
||
faker.RuleFor(c => c.ContactGUID, f => f.Random.Guid()) | ||
.RuleFor(c => c.ContactCreated, f => f.Date.Between(new DateTime(), new DateTime())) | ||
.RuleFor(c => c.ContactFirstName, f => f.Person.FirstName) | ||
.RuleFor(c => c.ContactEmail, f => f.Internet.Email()) | ||
.RuleFor(c => c.ContactLastName, f => f.Person.LastName) | ||
.RuleFor(c => c.ContactMiddleName, f => f.Person.FirstName) | ||
.RuleFor(c => c.ContactAge, f => f.Random.Number(18, 64)) | ||
.RuleFor(c => c.ContactAddress1, f => f.Address.StreetAddress()); | ||
|
||
foreach (int _ in Enumerable.Range(0, count)) | ||
{ | ||
yield return faker.Generate(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...perience.Contacts.Importer.Generator/Kentico.Xperience.Contacts.Importer.Generator.csproj
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="34.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Kentico.Xperience.Contacts.Importer\Kentico.Xperience.Contacts.Importer.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
48 changes: 48 additions & 0 deletions
48
test/Kentico.Xperience.Contacts.Importer.Generator/Program.cs
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Globalization; | ||
using CMS.ContactManagement; | ||
using CsvHelper; | ||
using Kentico.Xperience.Contacts.Importer.Generator; | ||
using static Kentico.Xperience.Contacts.Importer.Services.ImportService; | ||
|
||
string? solutionFolder = FindSolutionFolder(); | ||
|
||
ArgumentNullException.ThrowIfNull(solutionFolder); | ||
|
||
using var writer = new StreamWriter(Path.Combine(solutionFolder, "data\\contact_sample.csv")); | ||
using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture); | ||
csv.Context.RegisterClassMap<ContactInfoMap>(); | ||
|
||
csv.WriteHeader<ContactInfo>(); | ||
csv.NextRecord(); | ||
|
||
foreach (var contact in ContactsGenerator.Generate(200000)) | ||
{ | ||
csv.WriteRecord(contact); | ||
csv.NextRecord(); | ||
} | ||
|
||
csv.Flush(); | ||
|
||
|
||
static string? FindSolutionFolder() | ||
{ | ||
// Get the current directory where the application is running | ||
string? currentDirectory = Directory.GetCurrentDirectory(); | ||
|
||
// Navigate up the directory tree until the solution file is found | ||
while (currentDirectory != null) | ||
{ | ||
// Check if the current directory contains a .sln file | ||
string[] solutionFiles = Directory.GetFiles(currentDirectory, "*.sln"); | ||
if (solutionFiles.Length > 0) | ||
{ | ||
return currentDirectory; | ||
} | ||
|
||
// Move up to the parent directory | ||
currentDirectory = Directory.GetParent(currentDirectory)?.FullName; | ||
} | ||
|
||
// If no solution file is found, return null or an empty string | ||
return null; | ||
} |
Oops, something went wrong.