public void Single_SimpleSeveralUsers_HaveUniqueEmailAddresses() { SimpleUser[] users = mSession.List <SimpleUser>(10).Get().ToArray(); Assert.True( users.Where(x => users.Count(y => y.EmailAddress == x.EmailAddress) > 1).Count() == 0); }
public void LoadProblemWithId() { var members = _session.List <Member>(3).Get(); _conn.Collection <Member>(CollectionNames.Member).InsertBatch(members); var responses = _session.List <Response>(5) .Random(3).Impose(x => x.UserId, members[0].Id) .Next(1).Impose(x => x.UserId, members[1].Id) .Next(1).Impose(x => x.UserId, members[2].Id) .All().Get(); var problem = _session.Single <Problem>() .Impose(x => x.Responses, responses) .Impose(x => x.UserId, members[0].Id) .Get(); _problemCollection.Save(problem); var fromDb = _problemRepository.Get(problem.Id.ToString()); Assert.That(fromDb, Is.Not.Null); Assert.That(new ObjectId(fromDb.Id), Is.EqualTo(problem.Id)); Assert.That(fromDb.Submitter.Id, Is.EqualTo(problem.UserId)); Assert.That(fromDb.Responses.Count, Is.EqualTo(responses.Count)); }
public static List <User> CreateUsers(int amount, UserRepository userRepository) { var users = new List <User>(); foreach (var pocoUser in Session.List <PocoUser>(100).Get()) { var user = new User(pocoUser.Email, pocoUser.DisplayName, new CultureInfo("nl-NL"), userRepository, new ApplicationSettings()); user.Roles.Add(Role.User); userRepository.Create(user, "secret"); users.Add(user); } return(users); }
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); }
private static void CreateAndSaveAgencies(IGenerationSession session, IRepository repository) { session.List <Agency>(10) .Impose(x => x.ClosingHour, DateTime.Now.Date.AddHours(19)) .Impose(x => x.OpeningHour, DateTime.Now.Date.AddHours(8)) .Get() .ForEach(x => repository.Save(x)); }
public static Page <T> PageOf <T>(this IGenerationSession generator, int pageNumber, int pageSize, int totalCount) { var items = generator.List <T>(pageSize).Get(); var page = new Page <T>(pageNumber, pageSize, totalCount); page.SetItems(items); return(page); }
public void IndexDisplayByDefaultTheFirstsProblems() { var problems = _session.List <Problem>(10).Get(); var problemRepository = A.Fake <IProblemRepository>(); var homeController = new HomeController(problemRepository); A.CallTo(() => problemRepository.All(0)).Returns(problems); A.CallTo(() => problemRepository.Count()).Returns(120); var result = homeController.Index() as ViewResult; var problemsResult = result.ViewData.Model as ProblemListModel; Assert.That(result, Is.Not.Null); Assert.That(problemsResult.NbProblemsTotal, Is.EqualTo(120)); Assert.That(problemsResult.Problems.Count(), Is.EqualTo(10)); A.CallTo(() => problemRepository.All(0)).MustHaveHappened(); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { // LogLevel var LogItems = session.List <LogItem>(randomNumberGenerator.Next(50, 200)) .Impose(p => p.UserName, user.UserName) .Impose(p => p.LogLevel, (LogLevel)randomNumberGenerator.Next(Enum.GetValues(typeof(LogLevel)).Length)) .Get(); context.LogItems.AddRange(LogItems); context.SaveChanges(); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { var TradeDetails = session.List <TradeDetail>(randomNumberGenerator.Next(50, 200)) .Impose(p => p.OwnerId, user.Id) .Impose(p => p.TargetId, user.Id) .Impose(p => p.TradeType, (TradeType)randomNumberGenerator.Next(Enum.GetValues(typeof(TradeType)).Length)) .Impose(x => x.Point, Convert.ToDecimal(randomNumberGenerator.Next(100))) .Get(); context.TradeDetails.AddRange(TradeDetails); context.SaveChanges(); }
private static void CreateCustomersWithAccounts(IGenerationSession session, IRepository repository, Role[] roles) { var customers = session. List <Customer>(CUSTOMERS_COUNT).Get(); for (int i = 0; i < customers.Count; i++) { customers[i].Identification = "00000000" + i; customers[i].PasswordSalt = GenerationUtils.RandomString(5); customers[i].Password = SHA256HashProvider.Instance.Hash("Test" + customers[i].PasswordSalt); repository.Save(customers[i]); AddAccountsAndOperations(customers[i], roles, repository, session); //create some bussiness partners for each customer session.List <BusinessPartner>(5) .Impose(x => x.Customer, customers[i]) .Get().ForEach(x => repository.Save(x)); } repository.Flush(); }
public void Setup() { mSession = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <SimpleUser>(); }) .CreateSession(); mResults = mSession.List <SimpleUser>(5) .Source(x => x.EmailAddress, new DummySource()) .Get(); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { // 已經有測試資料 if (context.Signatures.Any(x => x.CreatedUser.Id == user.Id)) { return; } var Signatures = session.List <Signature>(randomNumberGenerator.Next(50, 200)) .Impose(p => p.CreatedUser, user) .Get(); context.Signatures.AddRange(Signatures); context.SaveChanges(); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { // 已經有測試資料 if (context.Contacts.Any(x => x.CreatedUser.Id == user.Id)) { return; } var Contacts = session.List <Contact>(randomNumberGenerator.Next(50, 200)) .Impose(p => p.CreatedUser, user) .Impose(p => p.Groups, string.Empty) .Get(); context.Contacts.AddRange(Contacts); context.SaveChanges(); }
public void SimpleMethodClass_InvokeOnFirstCollection_CallsAction() { IList <SimpleMethodClass> items = mSession.List <SimpleMethodClass>(100) .First(50) .Invoke(x => x.SetSomething("Something")) .Next(50) .Invoke(x => x.SetSomething("SomethingElse")) .All() .Get(); Assert.True(items.Where(x => x.Value == "Something").Count() == 50 && items.Where(x => x.Value == "SomethingElse").Count() == 50); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { // 已經有測試資料 if (context.Blacklists.Any(x => x.CreatedUser.Id == user.Id)) { return; } var Blacklists = session.List <Blacklist>(randomNumberGenerator.Next(50, 200)) .Impose(p => p.CreatedUser, user) .Impose(p => p.UpdatedUserName, user.UserName) .Impose(p => p.UploadedFile, null) .Get(); context.Blacklists.AddRange(Blacklists); context.SaveChanges(); }
private static IEnumerable <Invoice> GenerateDemoInvoices(int customerId) { Random rnd = new Random(customerId); int amountOfInvoices = rnd.Next(0, 10); IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Invoice>(); x.Include <Invoice>() .Setup(c => c.Amount).Use <DecimalSource>(1m, 200m); }); IGenerationSession session = factory.CreateSession(); return(session.List <Invoice>(amountOfInvoices).Get()); }
private static IEnumerable <Customer> GenerateDemoCustomers() { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Customer>(); 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>(); }); IGenerationSession session = factory.CreateSession(); return(session.List <Customer>(1000).Get()); }
public static IList <Person> GeneratePeople(int numregisters) { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <Person>(); x.Include <Person>() .Setup(c => c.Id).Use <IntegerIdSource>() .Setup(c => c.FirstName).Use <FirstNameSource>() .Setup(c => c.DateEntityCreation).Use <DateOfBirthSource>() .Setup(c => c.DateEntityModification).Use <DateOfBirthSource>(); }); IGenerationSession session = factory.CreateSession(); IList <Person> students = session.List <Person>(numregisters).Get(); return(students); }
private static IList <Gutachter> GenerateDemoData() { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Gutachter>(); x.Include <Gutachter>() .Setup(c => c.Id).Use <IntegerIdSource>() .Setup(c => c.Vorname).Use <FirstNameSource>() .Setup(c => c.Nachname).Use <LastNameSource>() .Setup(c => c.EMail).Use <EmailAddressSource>(); }); IGenerationSession session = factory.CreateSession(); IList <Gutachter> gutachter = session.List <Gutachter>(1001).Get(); gutachter.RemoveAt(0); return(gutachter); }
private static IEnumerable <Customer> GenerateDemoCustomers() { IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => c.UseDefaultConventions()); x.AddFromAssemblyContainingType <Customer>(); 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>(); }); IGenerationSession session = factory.CreateSession(); return(session.List <Customer>(1000) .First(100) .Impose(x => x.LastName, "Ashton") .Next(100) .Impose(x => x.LastName, "Smith") .Next(100) .Impose(x => x.LastName, "Dexter") .Next(100) .Impose(x => x.LastName, "Grimes") .Next(100) .Impose(x => x.LastName, "Walsh") .Next(100) .Impose(x => x.LastName, "Rhee") .Next(100) .Impose(x => x.LastName, "Horvath") .Next(100) .Impose(x => x.LastName, "Dixon") .Next(100) .Impose(x => x.LastName, "Jones") .Next(100) .Impose(x => x.LastName, "Martinez") .All() .Get()); }
protected override void SeedEntity(ApplicationDbContext context, ApplicationUser user) { // 已經有測試資料 if (context.Groups.Any(x => x.CreatedUserId == user.Id)) { return; } var Groups = new List <Group>(); Groups.Add(new Group { CreatedUserId = user.Id, CreatedUser = user, Name = Group.CommonContactGroupName, Description = Group.CommonContactGroupName, Deletable = false, }); Groups.AddRange(session.List <Group>(randomNumberGenerator.Next(3, 20)) .Impose(p => p.CreatedUserId, user.Id) .Impose(p => p.CreatedUser, user) .Impose(p => p.Deletable, true) .Get()); Groups = Groups.Distinct(new ContactGroupCompare()).ToList(); Groups.ForEach((p) => { if (p.Name != Group.CommonContactGroupName) { p.Description = p.Name; } }); context.Groups.AddRange(Groups); context.SaveChanges(); }
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(); }
private static void AddAccountsAndOperations(Customer customer, Role[] roles, IRepository repository, IGenerationSession session) { //get the transaction data from csv file using (var reader = new StreamReader(@"Data\transactions.csv")) { _categorizedTransactions = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, _tagsBag); } Account account = session.Single <Account>().Get(); account.Name = "Savings account"; account.RelatedCustomers.Add(customer, roles[0]); account.Iban = GenerationUtils.GenerateIban(account.Number, "12345", "12345", "FR"); account.Currency = "EUR"; Account account2 = session.Single <Account>().Get(); account2.Name = "Checking account"; account2.RelatedCustomers.Add(customer, roles[1]); account2.Currency = "EUR"; customer.RelatedAccounts.Add(account, roles[0]); customer.RelatedAccounts.Add(account2, roles[1]); repository.Save(account); repository.Save(account2); repository.Save(customer); repository.Flush(); //Get random transactions from the list Random rnd = new Random(); var randomTransactions = _categorizedTransactions.Where(x => x.Tag.Name != "Not set").OrderBy(x => rnd.Next()); //add the first half to the first account SelectForAccount(repository, account, rnd, randomTransactions); SelectForAccount(repository, account2, rnd, randomTransactions); //IList<Operation> operations = session.List<Operation>(20) // .Impose(x => x.TransactionCode, Guid.NewGuid().ToString()) // .Impose(x => x.Currency, "EUR") // .Impose(x=>x.Tag,EmptyTag) // .First(10) // .Impose(x => x.Account, account) // .Next(10) // .Impose(x => x.Account, account2) // .All() // .Get(); //operations.ForEach(x => repository.Save(x)); repository.Flush(); var paymentEvents = session.List <PaymentEvent>(20) .First(10) .Impose(x => x.Account, account) .Impose(x => x.Customer, customer) .Next(10) .Impose(x => x.Account, account2) .Impose(x => x.Customer, customer) .All() .Get(); paymentEvents.ForEach(x => repository.Save(x)); repository.Flush(); }
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(); }
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(); }
private static void CreateCustomersWithAccounts(IGenerationSession session,IRepository repository, Role[] roles) { var customers = session. List<Customer>(CUSTOMERS_COUNT).Get(); for (int i = 0; i < customers.Count; i++) { customers[i].Identification = "00000000" + i; customers[i].PasswordSalt = GenerationUtils.RandomString(5); customers[i].Password = SHA256HashProvider.Instance.Hash("Test" + customers[i].PasswordSalt); repository.Save(customers[i]); AddAccountsAndOperations(customers[i], roles, repository, session); //create some bussiness partners for each customer session.List<BusinessPartner>(5) .Impose(x => x.Customer, customers[i]) .Get().ForEach(x => repository.Save(x)); } repository.Flush(); }
private static void CreateAndSaveAgencies(IGenerationSession session, IRepository repository) { session.List<Agency>(10) .Impose(x=>x.ClosingHour,DateTime.Now.Date.AddHours(19)) .Impose(x=>x.OpeningHour,DateTime.Now.Date.AddHours(8)) .Get() .ForEach(x => repository.Save(x)); }
private static void AddAccountsAndOperations(Customer customer, Role[] roles, IRepository repository, IGenerationSession session) { //get the transaction data from csv file using (var reader = new StreamReader(@"Data\transactions.csv")) { _categorizedTransactions = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, _tagsBag); } Account account = session.Single<Account>().Get(); account.Name = "Savings account"; account.RelatedCustomers.Add(customer, roles[0]); account.Iban = GenerationUtils.GenerateIban(account.Number, "12345", "12345", "FR"); account.Currency = "EUR"; Account account2 = session.Single<Account>().Get(); account2.Name = "Checking account"; account2.RelatedCustomers.Add(customer, roles[1]); account2.Currency = "EUR"; customer.RelatedAccounts.Add(account, roles[0]); customer.RelatedAccounts.Add(account2, roles[1]); repository.Save(account); repository.Save(account2); repository.Save(customer); repository.Flush(); //Get random transactions from the list Random rnd = new Random(); var randomTransactions = _categorizedTransactions.Where(x => x.Tag.Name != "Not set").OrderBy(x => rnd.Next()); //add the first half to the first account SelectForAccount(repository, account, rnd, randomTransactions); SelectForAccount(repository, account2, rnd, randomTransactions); //IList<Operation> operations = session.List<Operation>(20) // .Impose(x => x.TransactionCode, Guid.NewGuid().ToString()) // .Impose(x => x.Currency, "EUR") // .Impose(x=>x.Tag,EmptyTag) // .First(10) // .Impose(x => x.Account, account) // .Next(10) // .Impose(x => x.Account, account2) // .All() // .Get(); //operations.ForEach(x => repository.Save(x)); repository.Flush(); var paymentEvents = session.List<PaymentEvent>(20) .First(10) .Impose(x => x.Account, account) .Impose(x=>x.Customer,customer) .Next(10) .Impose(x => x.Account, account2) .Impose(x=>x.Customer, customer) .All() .Get(); paymentEvents.ForEach(x => repository.Save(x)); repository.Flush(); }