SanSYS

Untitled

Jun 14th, 2015
25,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5.  
  6. namespace TestDependencyInjection.Lib
  7. {
  8.     namespace Faker
  9.     {
  10.         public static class NumberFaker
  11.         {
  12.             private static Random _random = new Random();
  13.  
  14.             public static int Number()
  15.             {
  16.                 return _random.Next();
  17.             }
  18.  
  19.             public static int Number(int maxValue)
  20.             {
  21.                 return _random.Next(maxValue);
  22.             }
  23.  
  24.             public static int Number(int minValue, int maxValue)
  25.             {
  26.                 return _random.Next(minValue, maxValue);
  27.             }
  28.         }
  29.  
  30.         public static class ArrayFaker
  31.         {
  32.             public static T SelectFrom<T>(params T[] array)
  33.             {
  34.                 var index = NumberFaker.Number(0, array.Length);
  35.                 return (T)array.GetValue(index);
  36.             }
  37.  
  38.             public static T[] SelectFrom<T>(int numElements, params T[] array)
  39.             {
  40.                 var returned = new T[numElements];
  41.                 while (numElements > 0)
  42.                 {
  43.                     returned[numElements - 1] = SelectFrom(array);
  44.                     numElements--;
  45.                 }
  46.  
  47.                 return returned;
  48.             }
  49.         }
  50.  
  51.         public static class BooleanFaker
  52.         {
  53.             public static bool Boolean()
  54.             {
  55.                 return NumberFaker.Number(2) == 1;
  56.             }
  57.         }
  58.  
  59.         public static class NameFaker
  60.         {
  61.             public static string LastName()
  62.             {
  63.                 return ArrayFaker.SelectFrom(
  64.                     "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"
  65.                 );
  66.             }
  67.  
  68.             public static string FemaleFirstName()
  69.             {
  70.                 return ArrayFaker.SelectFrom(
  71.                     "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"
  72.                 );
  73.             }
  74.  
  75.             public static string MaleFirstName()
  76.             {
  77.                 return ArrayFaker.SelectFrom(
  78.                     "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"
  79.                 );
  80.             }
  81.  
  82.             public static string FirstName()
  83.             {
  84.                 return BooleanFaker.Boolean() ? FemaleFirstName() : MaleFirstName();
  85.             }
  86.  
  87.             public static string MaleName()
  88.             {
  89.                 return MaleFirstName() + " " + LastName();
  90.             }
  91.  
  92.             public static string FemaleName()
  93.             {
  94.                 return FemaleFirstName() + " " + LastName();
  95.             }
  96.  
  97.             public static string Name()
  98.             {
  99.                 return FirstName() + " " + LastName();
  100.             }
  101.         }
  102.  
  103.         public static class TextFaker
  104.         {
  105.             public static string Sentence()
  106.             {
  107.                 return Sentences(1);
  108.             }
  109.  
  110.             public static string Sentences(int numSentences)
  111.             {
  112.                 return String.Join(". ", ArrayFaker.SelectFrom(numSentences,
  113.                         "Lorem ipsum dolor sit amet  consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
  114.                         "Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat",
  115.                         "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur",
  116.                         "Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum"
  117.                     ));
  118.             }
  119.         }
  120.  
  121.         public static class DateTimeFaker
  122.         {
  123.             public static DateTime DateTime(DateTime from, DateTime to)
  124.             {
  125.                 var timeSpan = to - from;
  126.                 return from.AddDays((double)NumberFaker.Number(1, (int)timeSpan.TotalDays - 1)).AddSeconds(NumberFaker.Number(1, 86400));
  127.             }
  128.  
  129.             public static DateTime DateTime()
  130.             {
  131.                 return DateTimeBetweenDays(5);
  132.             }
  133.  
  134.             public static DateTime DateTimeBetweenDays(double fromDays, double toDays)
  135.             {
  136.                 return DateTime(System.DateTime.Now.AddDays(-1 * fromDays), System.DateTime.Now.AddDays(toDays));
  137.             }
  138.  
  139.             public static DateTime DateTimeBetweenDays(double days)
  140.             {
  141.                 return DateTime(System.DateTime.Now.AddDays(-1 * days), System.DateTime.Now.AddDays(days));
  142.             }
  143.  
  144.             public static DateTime DateTimeBetweenMonths(int fromMonths, int toMonths)
  145.             {
  146.                 return DateTime(System.DateTime.Now.AddMonths(-1 * fromMonths), System.DateTime.Now.AddMonths(toMonths));
  147.             }
  148.  
  149.             public static DateTime DateTimeBetweenMonths(int months)
  150.             {
  151.                 return DateTime(System.DateTime.Now.AddMonths(-1 * months), System.DateTime.Now.AddMonths(months));
  152.             }
  153.  
  154.             public static DateTime DateTimeBetweenYears(int fromYears, int toYears)
  155.             {
  156.                 return DateTime(System.DateTime.Now.AddYears(-1 * fromYears), System.DateTime.Now.AddYears(toYears));
  157.             }
  158.  
  159.             public static DateTime DateTimeBetweenYears(int years)
  160.             {
  161.                 return DateTime(System.DateTime.Now.AddYears(-1 * years), System.DateTime.Now.AddDays(years));
  162.             }
  163.  
  164.             public static DateTime BirthDay(int minAge, int maxAge)
  165.             {
  166.                 return DateTimeBetweenYears(maxAge, minAge);
  167.             }
  168.  
  169.             public static DateTime BirthDay(int minAge)
  170.             {
  171.                 return DateTimeBetweenYears(100, minAge);
  172.             }
  173.  
  174.             public static DateTime BirthDay()
  175.             {
  176.                 return BirthDay(18);
  177.             }
  178.         }
  179.     }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment