Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace TestDependencyInjection.Lib
- {
- namespace Faker
- {
- public static class NumberFaker
- {
- private static Random _random = new Random();
- public static int Number()
- {
- return _random.Next();
- }
- public static int Number(int maxValue)
- {
- return _random.Next(maxValue);
- }
- public static int Number(int minValue, int maxValue)
- {
- return _random.Next(minValue, maxValue);
- }
- }
- public static class ArrayFaker
- {
- public static T SelectFrom<T>(params T[] array)
- {
- var index = NumberFaker.Number(0, array.Length);
- return (T)array.GetValue(index);
- }
- public static T[] SelectFrom<T>(int numElements, params T[] array)
- {
- var returned = new T[numElements];
- while (numElements > 0)
- {
- returned[numElements - 1] = SelectFrom(array);
- numElements--;
- }
- return returned;
- }
- }
- public static class BooleanFaker
- {
- public static bool Boolean()
- {
- return NumberFaker.Number(2) == 1;
- }
- }
- public static class NameFaker
- {
- public static string LastName()
- {
- return ArrayFaker.SelectFrom(
- "Abel", "Anderson", "Andrews", "Anthony", "Baker", "Brown", "Burrows", "Clark", "Clarke", "Clarkson", "Davidson", "Davies", "Davis", "Dent", "Edwards", "Garcia", "Grant", "Hall", "Harris", "Harrison", "Jackson", "Jeffries", "Jefferson", "Johnson", "Jones", "Kirby", "Kirk", "Lake", "Lee", "Lewis", "Martin", "Martinez", "Major", "Miller", "Moore", "Oates", "Peters", "Peterson", "Robertson", "Robinson", "Rodriguez", "Smith", "Smythe", "Stevens", "Taylor", "Thatcher", "Thomas", "Thompson", "Walker", "Washington", "White", "Williams", "Wilson", "Yorke"
- );
- }
- public static string FemaleFirstName()
- {
- return ArrayFaker.SelectFrom(
- "Alison", "Ann", "Anna", "Anne", "Barbara", "Betty", "Beryl", "Carol", "Charlotte", "Cheryl", "Deborah", "Diana", "Donna", "Dorothy", "Elizabeth", "Eve", "Felicity", "Fiona", "Helen", "Helena", "Jennifer", "Jessica", "Judith", "Karen", "Kimberly", "Laura", "Linda", "Lisa", "Lucy", "Margaret", "Maria", "Mary", "Michelle", "Nancy", "Patricia", "Polly", "Robyn", "Ruth", "Sandra", "Sarah", "Sharon", "Susan", "Tabitha", "Ursula", "Victoria", "Wendy"
- );
- }
- public static string MaleFirstName()
- {
- return ArrayFaker.SelectFrom(
- "Adam", "Anthony", "Arthur", "Brian", "Charles", "Christopher", "Daniel", "David", "Donald", "Edgar", "Edward", "Edwin", "George", "Harold", "Herbert", "Hugh", "James", "Jason", "John", "Joseph", "Kenneth", "Kevin", "Marcus", "Mark", "Matthew", "Michael", "Paul", "Philip", "Richard", "Robert", "Roger", "Ronald", "Simon", "Steven", "Terry", "Thomas", "William"
- );
- }
- public static string FirstName()
- {
- return BooleanFaker.Boolean() ? FemaleFirstName() : MaleFirstName();
- }
- public static string MaleName()
- {
- return MaleFirstName() + " " + LastName();
- }
- public static string FemaleName()
- {
- return FemaleFirstName() + " " + LastName();
- }
- public static string Name()
- {
- return FirstName() + " " + LastName();
- }
- }
- public static class TextFaker
- {
- public static string Sentence()
- {
- return Sentences(1);
- }
- public static string Sentences(int numSentences)
- {
- return String.Join(". ", ArrayFaker.SelectFrom(numSentences,
- "Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
- "Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat",
- "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur",
- "Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum"
- ));
- }
- }
- public static class DateTimeFaker
- {
- public static DateTime DateTime(DateTime from, DateTime to)
- {
- var timeSpan = to - from;
- return from.AddDays((double)NumberFaker.Number(1, (int)timeSpan.TotalDays - 1)).AddSeconds(NumberFaker.Number(1, 86400));
- }
- public static DateTime DateTime()
- {
- return DateTimeBetweenDays(5);
- }
- public static DateTime DateTimeBetweenDays(double fromDays, double toDays)
- {
- return DateTime(System.DateTime.Now.AddDays(-1 * fromDays), System.DateTime.Now.AddDays(toDays));
- }
- public static DateTime DateTimeBetweenDays(double days)
- {
- return DateTime(System.DateTime.Now.AddDays(-1 * days), System.DateTime.Now.AddDays(days));
- }
- public static DateTime DateTimeBetweenMonths(int fromMonths, int toMonths)
- {
- return DateTime(System.DateTime.Now.AddMonths(-1 * fromMonths), System.DateTime.Now.AddMonths(toMonths));
- }
- public static DateTime DateTimeBetweenMonths(int months)
- {
- return DateTime(System.DateTime.Now.AddMonths(-1 * months), System.DateTime.Now.AddMonths(months));
- }
- public static DateTime DateTimeBetweenYears(int fromYears, int toYears)
- {
- return DateTime(System.DateTime.Now.AddYears(-1 * fromYears), System.DateTime.Now.AddYears(toYears));
- }
- public static DateTime DateTimeBetweenYears(int years)
- {
- return DateTime(System.DateTime.Now.AddYears(-1 * years), System.DateTime.Now.AddDays(years));
- }
- public static DateTime BirthDay(int minAge, int maxAge)
- {
- return DateTimeBetweenYears(maxAge, minAge);
- }
- public static DateTime BirthDay(int minAge)
- {
- return DateTimeBetweenYears(100, minAge);
- }
- public static DateTime BirthDay()
- {
- return BirthDay(18);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment