private static IEnumerable <Customer> GenerateDemoCustomers() { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Customer>(); Random rnd = new Random(); x.Include <Customer>() .Setup(c => c.FirstName).Use <FirstNameSource>() .Setup(c => c.LastName).Use <LastNameSource>() .Setup(c => c.Mail).Use <EmailAddressSource>() .Setup(c => c.DateOfBirth).Use <DateOfBirthSource>() .Setup(c => c.AmountOfOrders).Use <IntegerSource>(1, 100) .Setup(c => c.AmountOfInvoices).Use <SecondIntegerSource>(1, 100) ; }); IGenerationSession session = factory.CreateSession(); return(session.List <Customer>(100).Get()); }
static SampleData_Blacklist() { factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <Blacklist>(); x.Include <Blacklist>() .Setup(p => p.Name).Use <FirstNameSource>() .Setup(p => p.Mobile).Use <MobileDataSource>() .Setup(p => p.Enabled).Use <BooleanSource>() .Setup(p => p.Remark).Use <RemarkDataSource>() .Setup(p => p.UpdatedTime).Use <DateTimeSource>(DateTime.UtcNow.AddYears(-10), DateTime.UtcNow.AddYears(10)) ; }); session = factory.CreateSession(); randomNumberGenerator = new RandomNumberGenerator(); }
public void Setup() { // As default as it gets mSession = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <SimpleUser>(); }) .CreateSession(); SimpleUserRole roleOne = mSession.Single <SimpleUserRole>() .Impose(x => x.Name, "RoleOne").Get(); SimpleUserRole roleTwo = mSession.Single <SimpleUserRole>() .Impose(x => x.Name, "RoleTwo").Get(); SimpleUserRole roleThree = mSession.Single <SimpleUserRole>() .Impose(x => x.Name, "RoleThree").Get(); mUsers = mSession.List <SimpleUser>(100) .First(50) .Impose(x => x.FirstName, "Rob") .Impose(x => x.LastName, "Ashton") .Next(50) .Impose(x => x.FirstName, "Luke") .Impose(x => x.LastName, "Smith") .All() .Random(25) .Impose(x => x.Role, roleOne) .Next(25) .Impose(x => x.Role, roleTwo) .Next(50) .Impose(x => x.Role, roleThree) .All().Get(); }
public void TypeOverridesNone() { var session = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.Register <DefaultTypeConvention>(); c.Register <SetFieldsOfStringTo1>(); c.Register <SetFieldsTo0>(); }); x.Include <TestMultipleFieldsConventionClass>(); }) .CreateSession(); TestMultipleFieldsConventionClass testObj = session.Single <TestMultipleFieldsConventionClass>().Get(); Assert.True( testObj.FirstIntegerField == 0 && testObj.FirstStringField == "1" && testObj.SecondIntegerField == 0 && testObj.SecondStringField == "1", "Conventions were not applied in expected order" ); }
public HomeControllerTest() { // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Problem>(); x.Include <Member>() .Setup(m => m.Id).Use <ObjectIdDataSource>() .Setup(m => m.OpenId).Random(5, 10) .Setup(m => m.UserName).Random(5, 7); x.Include <Problem>() .Setup(p => p.Id).Use <ObjectIdDataSource>() .Setup(p => p.Text).Use <LoremIpsumSource>() .Setup(p => p.Title).Random(7, 12); x.Include <Response>() .Setup(r => r.Text).Use <LoremIpsumSource>(); }); _session = factory.CreateSession(); }
/// <summary> /// Configuration of generation session factory. Each property of each POCO object is configured. Several /// properties are configured to use Sources to generated meaningful values. /// Several properties have to be set to Value(null). If not then a empty POCO would be generated. This would cause problems /// later while saving to DB using NHibernate, while the generated POCO would not be persisted. /// </summary> /// <returns></returns> public static IGenerationSessionFactory ConfigureFactory() { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <UserIdentity>(); x.Include <UserIdentity>() .Setup(u => u.Email).Use <EmailAddressSource>() .Setup(u => u.ValidityEndDate).Use <ValidityEndDateSource>() .Setup(u => u.ValidityStartDate).Use <ValidityStartDateSource>(); x.AddFromAssemblyContainingType <Customer>(); x.Include <Customer>() .Setup(u => u.PhoneNumber).Use <PhoneNumberSource>() .Setup(c => c.FirstName).Use <FirstNameSource>() .Setup(c => c.LastName).Use <LastNameSource>() .Setup(c => c.Code).Use <IndividualCustomerCodeSource>() .Setup(c => c.BirthDate).Use <DateOfBirthSource>() .Setup(c => c.CustomerProfile).Value(null) .Setup(c => c.Situation).Use <RandomEnumerationDataSource <FamilySituation> >() .Setup(u => u.Advisor).Value(null); x.AddFromAssemblyContainingType <Account>(); x.Include <Account>() .Setup(a => a.Name).Use <AccountNameDataSource>() .Setup(a => a.Balance).Use <AccountBalanceDataSource>() .Setup(a => a.Iban).Use <IbanDataSource>() .Setup(a => a.Number).Use <AccountNumberSource>(); x.AddFromAssemblyContainingType <Operation>(); x.Include <Operation>() .Setup(o => o.Amount).Use <OperationAmountSource>() .Setup(o => o.Description).Use <DescriptionSource>() .Setup(o => o.Direction).Use <RandomEnumerationDataSource <Direction> >() .Setup(o => o.Tag).Value(null) .Setup(o => o.Date).Use <OperationDateSource>(); x.AddFromAssemblyContainingType <PaymentEvent>(); x.Include <PaymentEvent>() .Setup(o => o.Date).Use <OperationDateSource>() .Setup(o => o.Name).Use <MotifSource>() .Setup(o => o.Description).Use <MotifSource>() .Setup(o => o.Amount).Use <OperationAmountSource>() .Setup(o => o.Operation).Value(null) .Setup(o => o.Partner).Value(null); x.AddFromAssemblyContainingType <BusinessPartner>(); x.Include <BusinessPartner>() .Setup(b => b.Name).Use <CorporateNameDataSource>() //.Setup(b=>b.Description).Use<LoremIpsumSource>() .Setup(b => b.Iban).Use <IbanDataSource>(); x.AddFromAssemblyContainingType <CustomerProfile>(); x.Include <CustomerProfile>() .Setup(p => p.LowAge).Use <DecaDataSource>(0) .Setup(p => p.HighAge).Use <DecaDataSource>(10); double maxLng = 2.425575; double minLng = 2.276573; double minLat = 48.817264; double maxLat = 48.897678; x.AddFromAssemblyContainingType <Agency>(); x.Include <Agency>() .Setup(a => a.Lat).Use <DoubleFromRangeDataSource>(minLat, maxLat) .Setup(a => a.Lng).Use <DoubleFromRangeDataSource>(minLng, maxLng) .Setup(a => a.Address).Use <CorporateNameDataSource>(); }); return(factory); }
static void Main(string[] args) { // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); // allows for the scanning of an assembly x.AddFromAssemblyContainingType <User>(); // Optionally Setting up data sources for an object // AutoPoco provided built-in data sources: // https://autopoco.codeplex.com/wikipage?title=DataSourceList&referringTitle=Configuration x.Include <User>() .Setup(c => c.Id).Use <IntegerIdSource>() .Setup(c => c.EmailAddress).Use <EmailAddressSource>() .Setup(c => c.FirstName).Use <FirstNameSource>() .Setup(c => c.CreditCard).Use <CreditCardSource>() .Setup(c => c.DOB).Use <DateOfBirthSource>() .Setup(c => c.LastName).Use <LastNameSource>() .Setup(c => c.State).Use <UsStatesSource>(false) // true: abbreviated .Invoke(c => c.SetPassword(Use.Source <String, RandomStringSource>(8, 16))); // String min, max length }); // Generate one of these per test (factory will be a static variable most likely) IGenerationSession session = factory.CreateSession(); // Get a collection of users based on data sources ONLY //IList<User> users = session.List<User>(25).Get(); // Get a collection of users, with Customization IList <User> users = session.List <User>(100) .Impose(x => x.Role, "Admin") .Impose(x => x.Age, 21) .First(1) .Impose(x => x.FirstName, "Vincent") .Impose(x => x.LastName, "Leung") .Next(1) .Impose(x => x.FirstName, "Kayla") .Impose(x => x.LastName, "Leung") .All() .Random(25) .Impose(x => x.Role, "Admin") .Impose(x => x.Age, 35) .Next(25) .Impose(x => x.Role, "Guest") .Invoke(x => x.SetPassword("Password1")) .Next(50) .Impose(x => x.Role, "Operator") .All() .Get(); foreach (var u in users) { Console.WriteLine(u.Id + ", " + u.FirstName + ", " + u.LastName + ", " + u.Age + ", " + u.EmailAddress + ", " + u.DOB + ", " + u.CreditCard + ", " + u.Role + ", " + u.State + ", " + u.Password ); } // Get a single user User user = session.Single <User>().Get(); Console.ReadLine(); }
static void Main(string[] args) { List <string> _accounts = new List <string>(); Random r = new Random(); #region Random customer name generator with AutoPoco // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <Person>(); x.Include <Person>().Setup(p => p.FirstName).Use <FirstNameSource>() .Setup(p => p.LastName).Use <LastNameSource>(); }); // Generate one of these per test (factory will be a static variable most likely) IGenerationSession session = factory.CreateSession(); #endregion #region Create 100 bank accounts Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Instanciating and initializating 100 actors: "); Console.ForegroundColor = ConsoleColor.Gray; for (int j = 0; j < 100; j++) { // generate account number string accountNumber = r.Next(0, 50000000).ToString("00000000"); // generate name Person p = session.Single <Person>().Get(); string accountOwner = p.FirstName + " " + p.LastName; // generate starting balance int startingBalance = r.Next(0, 10000); // 'create' the actor ActorId newActorId = new ActorId(accountNumber); IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts"); newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult(); BankAccountStateBase state = newBankAccount.GetAccountInfo().GetAwaiter().GetResult(); Console.WriteLine(state.CustomerName + " has €" + state.Balance + " in account nb: " + state.AccountNumber); _accounts.Add(accountNumber); } #endregion #region Create 100 Standing Orders Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("100 Bank Account actors created. Press a key to create 100 standing orders."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadLine(); for (int j = 0; j < 100; j++) { int posSource = r.Next(0, _accounts.Count); int posTarget = r.Next(0, _accounts.Count); if (posSource == posTarget) { // one less transfer... continue; } ActorId sourceAccountId = new ActorId(_accounts[posSource]); IBankAccount sourceAccountProxy = ActorProxy.Create <IBankAccount>(sourceAccountId, "fabric:/SFActors.BankAccounts"); double howMuch = r.NextDouble() * 500; short onMinute = (short)r.Next(0, 60); sourceAccountProxy.AddStandingOrder(_accounts[posTarget], howMuch, onMinute); Console.WriteLine("SO payable to account {0} of €{1:f2} on minute {2}", _accounts[posTarget], howMuch, onMinute); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("100 Standing orders registered created"); Console.ForegroundColor = ConsoleColor.Gray; #endregion #region GO CRAZY with creating objects Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enter how many more actors you want to create (and SO's):"); string more = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; int howManyMore = int.Parse(more); for (int j = 0; j < howManyMore; j++) { // generate account number string accountNumber = r.Next(0, 50000000).ToString("00000000"); // generate name Person p = session.Single <Person>().Get(); string accountOwner = p.FirstName + " " + p.LastName; // generate starting balance int startingBalance = r.Next(0, 10000); // 'create' the actor ActorId newActorId = new ActorId(accountNumber); IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts"); newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult(); Console.Write("A"); _accounts.Add(accountNumber); } for (int j = 0; j < howManyMore; j++) { int posSource = r.Next(0, _accounts.Count); int posTarget = r.Next(0, _accounts.Count); if (posSource == posTarget) { // one less transfer... continue; } ActorId sourceAccountId = new ActorId(_accounts[posSource]); IBankAccount sourceAccountProxy = ActorProxy.Create <IBankAccount>(sourceAccountId, "fabric:/SFActors.BankAccounts"); double howMuch = r.NextDouble() * 500; short onMinute = (short)r.Next(0, 60); sourceAccountProxy.AddStandingOrder(_accounts[posTarget], howMuch, onMinute); Console.Write("S"); } #endregion Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Done! Press any key to exit this tool."); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; }