public void ExampleTest()
        {
            var factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseExtendedConventions();
                    c.UseDefaultConventions();
                });
                x.AddFromAssemblyContainingType <SampleData>();
            });

            var session = factory.CreateSession();

            var sampleData = session.Single <SampleData>().Get();

            sampleData.AddressLine1.Should().NotBeNullOrEmpty();
            sampleData.City.Should().NotBeNullOrEmpty();
            sampleData.StateProvidence.Should().NotBeNullOrEmpty();
            sampleData.PostalCode.Should().NotBeNullOrEmpty();
            sampleData.WebSite.Should().NotBeNullOrEmpty();
            sampleData.CompanyName.Should().NotBeNullOrEmpty();
            sampleData.EmailAddress.Should().NotBeNullOrEmpty();
            sampleData.BusinessPhone.Should().NotBeNullOrEmpty();
            sampleData.BusinessFax.Should().NotBeNullOrEmpty();
            sampleData.OtherPhone.Should().NotBeNullOrEmpty();

            sampleData.CreateDate.Should().NotBe(DateTime.MinValue);
            sampleData.UpdateDate.Should().NotBe(DateTime.MinValue);
        }
        public void Setup()
        {
            mSession = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseDefaultConventions();
                });

                x.Include <SimpleMethodClass>()
                .Invoke(c => c.SetSomething(
                            Use.Source <String, RandomStringSource>(5, 10),
                            Use.Source <String, LastNameSource>()))
                .Invoke(c => c.ReturnSomething());

                x.Include <SimpleUser>()
                .Setup(c => c.EmailAddress).Use <EmailAddressSource>()
                .Setup(c => c.FirstName).Use <FirstNameSource>()
                .Setup(c => c.LastName).Use <LastNameSource>();

                x.Include <SimpleUserRole>()
                .Setup(c => c.Name).Random(5, 10);

                x.Include <SimpleFieldClass>();
                x.Include <SimplePropertyClass>();
                x.Include <DefaultPropertyClass>();
                x.Include <DefaultFieldClass>();
            })
                       .CreateSession();
        }
示例#3
0
        public static List <Person> GetPeople100Collection()
        {
            // Perform factory set up (once for entire test run)
            var factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseDefaultConventions();
                });
                x.AddFromAssemblyContainingType <Person>();
                x.Include <Person>()
                .Setup(c => c.BornDate).Use <DateOfBirthSource>()
                .Setup(c => c.Register).Use <RegisterDateSource>(DateTime.Now)
                .Setup(c => c.Name).Use <FirstNameSource>()
                .Setup(c => c.FirstSurname).Use <LastNameSource>()
                .Setup(c => c.SecondSurname).Use <LastNameSource>()
                .Setup(c => c.Id).Use <IntegerIdSource>();
            });


            // Generate one of these per test (factory will be a static variable most likely)
            IGenerationSession session = factory.CreateSession();

            // Get a collection of persons
            List <Person> people = (List <Person>)session.List <Person>(100).Get();

            return(people);
        }
示例#4
0
        public ProblemControllerTest()
        {
            // Perform factory set up (once for entire test run)
            IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());
                x.AddFromAssemblyContainingType <Member>();

                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>();
            });

            // Generate one of these per test (factory will be a static variable most likely)
            _session = factory.CreateSession();
        }
示例#5
0
        static SampleData_Contact()
        {
            factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseDefaultConventions();
                });

                x.AddFromAssemblyContainingType <Contact>();

                x.Include <Contact>()
                .Setup(p => p.Name).Use <FirstNameSource>()
                .Setup(p => p.Mobile).Use <MobileDataSource>()
                .Setup(p => p.HomePhoneArea).Use <PhoneAreaDataSource>()
                .Setup(p => p.HomePhone).Use <PhoneDataSource>()
                .Setup(p => p.CompanyPhoneArea).Use <PhoneAreaDataSource>()
                .Setup(p => p.CompanyPhone).Use <PhoneDataSource>()
                .Setup(p => p.CompanyPhoneExt).Use <PhoneExtDataSource>()
                .Setup(p => p.Email).Use <EmailAddressSource>()
                .Setup(p => p.Msn).Use <MsnDataSource>()
                .Setup(p => p.Description).Use <DescriptionDataSource>()
                .Setup(p => p.Birthday).Use <BirthdaySource>(2005, 2010)
                .Setup(p => p.ImportantDay).Use <BirthdaySource>(2005, 2010)
                .Setup(p => p.Gender).Use <GenderSource>()
                ;
            });

            session = factory.CreateSession();

            randomNumberGenerator = new RandomNumberGenerator();
        }
示例#6
0
        public void Requesting_String_Uses_Default_Source()
        {
            var session = AutoPocoContainer.Configure(x => { }).CreateSession();
            var result  = session.Next <string>();

            Assert.NotNull(result);
        }
示例#7
0
        public void Requesting_Decimal_Uses_Default_Source()
        {
            var session = AutoPocoContainer.Configure(x => { }).CreateSession();
            var result  = session.Next <decimal>();

            Assert.AreEqual(0, result);
        }
示例#8
0
        public ActionResult Dutch()
        {
            // Create factory for poco's and setup datasources
            var pocoFactory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());
                x.AddFromAssemblyContainingType <DutchUser>();
                x.Include <DutchUser>()
                .Setup(c => c.Firstname).Use <FirstNameSource>()
                .Setup(c => c.Middlename).Use <DutchMiddlenameSource>()
                .Setup(c => c.Lastname).Use <LastNameSource>()
                .Setup(c => c.Email).Use <ExtendedEmailAddressSource>()
                .Setup(c => c.Telephone).Use <DutchTelephoneSource>()
                .Setup(c => c.Mobile).Use <DutchMobileSource>()
                .Setup(c => c.City).Use <DutchCitySource>()
                .Setup(c => c.Postal).Use <DutchPostalSource>();
            });

            // Get session from factory
            var pocoSession = pocoFactory.CreateSession();

            // Get ten dutch users
            var dutchUser = pocoSession.List <DutchUser>(10).Get();

            return(View(dutchUser));
        }
        public static IList <Contact> GetContacts()
        {
            // Perform factory set up (once for entire test run)
            var factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());
                x.AddFromAssemblyContainingType <Contact>();
                x.Include <Contact>()
                .Setup(c => c.FirstName).Use <FirstNameSource>()
                .Setup(c => c.LastName).Use <LastNameSource>()
                .Setup(c => c.DateOfBirth).Use <DateOfBirthSource>()
                .Setup(c => c.Email).Use <EmailAddressSource>()
                .Setup(c => c.Notes).Use <LoremIpsumSource>()
                .Setup(c => c.Appointments).Use <AppointmentDataSource>();
                x.Include <Address>()
                .Setup(m => m.AddressLine1).Use <AddressLine1Source>()
                .Setup(m => m.Country).Use <ValueSource <string> >("United States")
                .Setup(m => m.State).Use <UsStatesSource>()
                .Setup(m => m.Zip).Use <RandomStringSource>(10, 10)
                .Setup(m => m.Country);
                x.Include <Appointment>()
                .Setup(m => m.With).Use <LastNameSource>()
                .Setup(m => m.Date).Use <DateOfBirthSource>();
            });

            // Generate one of these per test (factory will be a static variable most likely)
            var session = factory.CreateSession();

            // Get a collection of users
            return(session.List <Contact>(10).Get());
        }
示例#10
0
        public ActionResult ValueTypes()
        {
            // Create factory for poco's and setup datasources
            var pocoFactory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());
                x.AddFromAssemblyContainingType <PocoLoco>();
                x.Include <PocoLoco>()
                .Setup(c => c.SomeInt).Use <IntegerSource>(100, 500)
                .Setup(c => c.SomeFloat).Use <FloatSource>(10, 50)
                .Setup(c => c.SomeDouble).Use <DoubleSource>(60, 5000)
                .Setup(c => c.SomeDecimal).Use <DecimalSource>(-50m, -30m)
                .Setup(c => c.SomeDateTime).Use <DateTimeSource>(DateTime.Now, DateTime.Now.AddYears(1))
                .Setup(c => c.SomeBool).Use <BooleanSource>()
                .Setup(c => c.SomeTimeSpan).Use <TimeSpanSource>(TimeSpan.Zero, TimeSpan.FromHours(10));
            });

            // Get session from factory
            var pocoSession = pocoFactory.CreateSession();

            // Get ten pocoloco's
            var pocoLoco = pocoSession.List <PocoLoco>(10).Get();

            return(View(pocoLoco));
        }
示例#11
0
        static SampleData_LogItem()
        {
            factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseDefaultConventions();
                });

                x.AddFromAssemblyContainingType <LogItem>();

                x.Include <LogItem>()
                .Setup(p => p.EntryAssembly).Use <SubjectDataSource>()
                .Setup(p => p.Class).Use <SubjectDataSource>()
                .Setup(p => p.Method).Use <SubjectDataSource>()
                .Setup(p => p.Message).Use <ContentDataSource>()
                .Setup(p => p.StackTrace).Use <ContentDataSource>()
                .Setup(p => p.CreatedTime).Use <DateTimeSource>(DateTime.UtcNow.AddYears(-10), DateTime.UtcNow.AddYears(10))
                .Setup(p => p.Host).Use <SubjectDataSource>()
                ;
            });

            session = factory.CreateSession();

            randomNumberGenerator = new RandomNumberGenerator();
        }
示例#12
0
        static SampleData_ApplicationUser()
        {
            factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.UseDefaultConventions();
                });

                x.AddFromAssemblyContainingType <ApplicationUser>();

                x.Include <ApplicationUser>()
                .Setup(p => p.Gender).Use <GenderSource>()
                .Setup(p => p.ContactPhone).Use <PhoneDataSource>()
                .Setup(p => p.ContactPhoneExt).Use <PhoneExtDataSource>()
                .Setup(p => p.ForeignSmsEnabled).Use <BooleanSource>()
                .Setup(p => p.Email).Use <EmailAddressSource>()
                .Setup(p => p.EmailConfirmed).Use <BooleanSource>()
                .Setup(p => p.PhoneNumber).Use <MobileDataSource>()
                .Setup(p => p.PhoneNumberConfirmed).Use <BooleanSource>()
                ;
            });

            session = factory.CreateSession();

            randomNumberGenerator = new RandomNumberGenerator();
        }
        public void NameAndTypeOverrideName()
        {
            var session = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c =>
                {
                    c.Register <DefaultTypeConvention>();
                    c.Register <SetFieldsOfStringCalledFirstTo3>();
                    c.Register <SetFieldsContainingFirstTo2>();
                    c.Register <SetFieldsOfStringTo1>();
                    c.Register <SetFieldsTo0>();
                });
                x.Include <TestMultipleFieldsConventionClass>();
            })
                          .CreateSession();

            TestMultipleFieldsConventionClass testObj
                = session.Single <TestMultipleFieldsConventionClass>().Get();

            Assert.True(
                testObj.FirstIntegerField == 2 &&
                testObj.FirstStringField == "3" &&
                testObj.SecondIntegerField == 0 &&
                testObj.SecondStringField == "1", "Conventions were not applied in expected order"
                );
        }
示例#14
0
        private void LoadGridData()
        {
            IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => { c.UseDefaultConventions(); });
                x.AddFromAssemblyContainingType <SimpleProduct>();

                x.Include <SimpleProduct>()
                .Setup(c => c.ProductName).Use <FirstNameSource>()
                .Setup(c => c.Id).Use <IntegerIdSource>()
                .Setup(c => c.ProductDescription).Use <RandomStringSource>(5, 20);
            });

            var session = factory.CreateSession();
            var r       = new Random(234234);
            var rn      = r.Next(5, 100);
            IList <SimpleProduct> products = session.List <SimpleProduct>(25)
                                             .Impose(x => x.Price, r.Next() * rn)
                                             .Get();
            var bl = new ProductList();

            foreach (var i in products)
            {
                bl.Add(i);
            }

            gv.DataSource = bl;
        }
示例#15
0
        public ActionResult Custom()
        {
            // Create factory for poco's and setup datasources
            var pocoFactory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());
                x.AddFromAssemblyContainingType <Company>();
                x.Include <Company>()
                .Setup(c => c.CompanyName).Use <CompanySource>()
                .Setup(c => c.CompanySize).Use <EnumSource <CompanySizeEnum> >()
                .Setup(c => c.Email).Use <ExtendedEmailAddressSource>()
                .Setup(c => c.Street).Use <StreetSource>()
                .Setup(c => c.Postal).Use <PostalSource>()
                .Setup(c => c.City).Use <CitySource>()
                .Setup(c => c.Url).Use <UrlSource>();
            });

            // Get session from factory
            var pocoSession = pocoFactory.CreateSession();

            // Get 10 companies
            var companies = pocoSession.List <Company>(10).Get();

            return(View(companies));
        }
        public void Next_Returns_Valid_Object()
        {
            var session = AutoPocoContainer.CreateDefaultSession();
            var user    = session.Next <SimpleUser>();

            Assert.NotNull(user, "User was not created");
            Assert.NotNull(user.FirstName, "User did not get first name");
        }
        public void Configure_ReturnsFactory()
        {
            IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
            {
            });

            Assert.NotNull(factory);
        }
 public void Setup()
 {
     mSession = AutoPocoContainer.Configure(x =>
     {
         x.Include <OpenGeneric <Object> >();
     })
                .CreateSession();
 }
        public void With_No_Config_Least_Greedy_Constructor_With_Default_Conventions_Is_Used_By_Default()
        {
            mSession = AutoPocoContainer.CreateDefaultSession();

            var result = mSession.Next <SimpleCtorClass>();

            Assert.NotNull(result.ReadOnlyProperty);
            Assert.Null(result.SecondaryProperty);
        }
 public void Setup()
 {
     mSession = AutoPocoContainer.Configure(x =>
     {
         x.Include <DefaultPropertyClass>();
         x.Include <DefaultFieldClass>();
     })
                .CreateSession();
 }
        public List <string> CreateAccounts([FromBody] int count)
        {
            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 N bank accounts

            ServiceEventSource.Current.Message("@AccountsController.Create - Instanciating and initializating '{0}' actors", count);
            // Console.WriteLine(": ");

            for (int j = 0; j < count; j++)
            {
                // generate random account number
                string accountNumber = r.Next(0, 50000000).ToString("00000000");

                // generate name of customer
                Person p            = session.Single <Person>().Get();
                string accountOwner = p.FirstName + " " + p.LastName;

                // generate starting balance for the account. Always multiple of 10 to make it easier to detect changes because of transfers
                int startingBalance = r.Next(0, 10000) * 10;

                // 'create' and initialize the actor
                ActorId      newActorId     = new ActorId(accountNumber);
                IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts");
                newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult();

                // debug
                BankAccountStateBase state = newBankAccount.GetAccountInfo().GetAwaiter().GetResult();
                ServiceEventSource.Current.Message("@AccountsController.Create - " + state.CustomerName + " has €" + state.Balance + " in account nb: " + state.AccountNumber);

                accounts.Add(accountNumber);
            }

            #endregion

            return(accounts);
        }
        public void With_Source_Source_Is_Used_To_Create_Object()
        {
            mSession = AutoPocoContainer.Configure(x => x.Include <SimpleCtorClass>()
                                                   .ConstructWith <TestFactory>()).CreateSession();

            var result = mSession.Next <SimpleCtorClass>();

            Assert.AreEqual("one", result.ReadOnlyProperty);
            Assert.AreEqual("two", result.SecondaryProperty);
        }
示例#23
0
 public void Setup()
 {
     mSession = AutoPocoContainer.Configure(x =>
     {
         x.Conventions(c => c.UseDefaultConventions());
         x.Include <SimpleNode>()
         .Setup(y => y.Children).Collection(0, 3);
     })
                .CreateSession();
 }
        public void Configure_RunsActions()
        {
            bool hasRun = false;

            AutoPocoContainer.Configure(x =>
            {
                hasRun = true;
            });
            Assert.IsTrue(hasRun);
        }
        public void Property_Is_Set_With_Parent_Value_If_Parent_Exists()
        {
            IGenerationSession session = AutoPocoContainer.Configure(
                x => x.Include <SimpleNode>()
                .Setup(y => y.Children).Collection(1, 1)
                .Setup(y => y.Parent).Use <ParentSource <SimpleNode> >()).CreateSession();

            var node = session.Next <SimpleNode>();

            Assert.AreEqual(node, node.Children.First().Parent);
        }
        private void create100button_Click(object sender, EventArgs e)
        {
            #region Random customer name generator
            // 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

            progressBar1.Value = 0;

            for (int j = 0; j < 20; j++)
            {
                // generate account number
                Random r             = new Random();
                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");
                System.Threading.Thread.Sleep(200);

                newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult();
                System.Threading.Thread.Sleep(200);

                //BankAccountStateBase state = newBankAccount.GetAccountInfo().GetAwaiter().GetResult();
                //textBox1.Text += state.CustomerName + " has £" + state.Balance + " in account " + state.AccountNumber + Environment.NewLine;
                //System.Threading.Thread.Sleep(200);

                _accounts.Add(accountNumber);

                progressBar1.PerformStep();
            }

            textBox1.Text += "100 Bank Account actors created" + Environment.NewLine;
        }
        public void Object_With_Collection_As_A_Property_Can_Be_Requested_From_Session()
        {
            var session = AutoPocoContainer.Configure(c =>
                                                      c.Include <TestObject>()
                                                      .Setup(x => x.Children).Collection(3, 3)).CreateSession();

            var result = session.Next <TestObject>();

            Assert.NotNull(result);
            Assert.AreEqual(3, result.Children.Count);
        }
        public void Next_WithNumber_Returns_Collection_Of_Valid_Objects()
        {
            var session = AutoPocoContainer.CreateDefaultSession();
            var users   = session.Collection <SimpleUser>(10).ToList();

            users.ForEach(x =>
            {
                Assert.NotNull(x, "User was not created");
                Assert.NotNull(x.FirstName, "User did not get first name");
            });
        }
        public void Property_Is_Set_With_Null_Value_If_No_Parent_Exists()
        {
            IGenerationSession session = AutoPocoContainer.Configure(
                x =>
            {
                x.Include <SimpleNode>().Setup(y => y.Children).Collection(1, 1);
            }).CreateSession();

            var node = session.Next <SimpleNode>();

            Assert.Null(node.Parent);
        }
 public void Setup()
 {
     mSession = AutoPocoContainer.Configure(x =>
     {
         x.Conventions(c =>
         {
             c.UseDefaultConventions();
         });
         x.Include <SimpleBaseClass>();
     })
                .CreateSession();
 }