From 679f9aa5f2498e6e2bb361faadbfbe3ca3e6e6fc Mon Sep 17 00:00:00 2001 From: Boyan MIlenkov Date: Mon, 27 Mar 2023 12:23:56 +0300 Subject: [PATCH] MockData in progress --- DevDatesAPI.sln | 8 +++++++- MockData/DataGenerator.cs | 37 +++++++++++++++++++++++++++++++++++++ MockData/MockData.csproj | 14 ++++++++++++++ MockData/Person.cs | 28 ++++++++++++++++++++++++++++ MockData/Program.cs | 17 +++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 MockData/DataGenerator.cs create mode 100644 MockData/MockData.csproj create mode 100644 MockData/Person.cs create mode 100644 MockData/Program.cs diff --git a/DevDatesAPI.sln b/DevDatesAPI.sln index b87de89..db0df34 100644 --- a/DevDatesAPI.sln +++ b/DevDatesAPI.sln @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevDatesAPI", "DevDatesAPI\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevDates.Model", "DevDates.Model\DevDates.Model.csproj", "{2FD5579F-464F-432B-B0DD-510B636CC921}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevDates.DBModel", "DevDates.DBModel\DevDates.DBModel.csproj", "{59BD3631-3C1A-4487-9CE6-36B8E1CC36FC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevDates.DBModel", "DevDates.DBModel\DevDates.DBModel.csproj", "{59BD3631-3C1A-4487-9CE6-36B8E1CC36FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockData", "MockData\MockData.csproj", "{D3911377-5509-42F8-88BE-4616F8124F23}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +29,10 @@ Global {59BD3631-3C1A-4487-9CE6-36B8E1CC36FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {59BD3631-3C1A-4487-9CE6-36B8E1CC36FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {59BD3631-3C1A-4487-9CE6-36B8E1CC36FC}.Release|Any CPU.Build.0 = Release|Any CPU + {D3911377-5509-42F8-88BE-4616F8124F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3911377-5509-42F8-88BE-4616F8124F23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3911377-5509-42F8-88BE-4616F8124F23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3911377-5509-42F8-88BE-4616F8124F23}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MockData/DataGenerator.cs b/MockData/DataGenerator.cs new file mode 100644 index 0000000..0176387 --- /dev/null +++ b/MockData/DataGenerator.cs @@ -0,0 +1,37 @@ +using Bogus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MockData.Person; + +namespace MockData +{ + public class DataGenerator + { + + public static Faker GetPersonGenerator() + { + return new Faker() + .RuleFor(e => e.FirstName, f => f.Name.FirstName()) + .RuleFor(e => e.LastName, f => f.Name.LastName()) + .RuleFor(e => e.DateFBirth, f => f.Person.DateOfBirth) + .RuleFor(e => e.GenderSelection, f => f.Person.Gender.ToString()) + .RuleFor(e => e.Bio, f => f.Lorem.Paragraph(1)) + .RuleFor(e => e.Email, (f, e) => f.Internet.Email(e.FirstName, e.LastName)) + /*.RuleFor(e => e.Created, f => f.PickRandom)*/ + .RuleFor(e => e.Modified, f => f.Date.Recent()) + .RuleFor(e => e.ModifiedBy, (f, e) => f.Name.FirstName()); + + } + public static readonly List Persons = new List(); + public const int NumOfPeople = 7; + public static void ResultData() + { + var generated = GetPersonGenerator(); + var generatedU = generated.Generate(NumOfPeople); + Persons.AddRange(generatedU); + } + } +} diff --git a/MockData/MockData.csproj b/MockData/MockData.csproj new file mode 100644 index 0000000..6314e31 --- /dev/null +++ b/MockData/MockData.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/MockData/Person.cs b/MockData/Person.cs new file mode 100644 index 0000000..b6ff0e2 --- /dev/null +++ b/MockData/Person.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace MockData +{ + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + public DateTime DateFBirth { get; set; } + public string GenderSelection { get; set; } + public string Bio { get; set; } + public string Email { get; set; } + public DateTime Created { get; set; } + public DateTime Modified { get; set; } + public string ModifiedBy { get; set; } + + + public override string ToString() + { + return System.Text.Json.JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); + } + } +} diff --git a/MockData/Program.cs b/MockData/Program.cs new file mode 100644 index 0000000..aaa7d6b --- /dev/null +++ b/MockData/Program.cs @@ -0,0 +1,17 @@ +using Bogus; +using System; + +namespace MockData // Note: actual namespace depends on the project name. +{ + public class Program + { + static void Main(string[] args) + { + + Console.WriteLine("Initializing data with Bogus..."); + DataGenerator.ResultData(); + Console.WriteLine("Several Users: "); + DataGenerator.Persons.ForEach(Console.WriteLine); + } + } +} \ No newline at end of file