public void Lists_9() { BuilderSettings builderSettings = new BuilderSettings(); var products = new Builder(builderSettings).CreateListOfSize <Product>(5).Build(); Pick <Product> .UniqueRandomList(With.Between(5).And(10).Elements).From(products); }
public Task <List <CiCdBuildDto> > GetBuildsAsync(RepositoryDto repository, CiCdDto cicd) { var picker = new UniqueRandomPicker <string>(With.Between(1).And(FakeBuilds.Length).Elements, new UniqueRandomGenerator()); var items = picker.From(FakeBuilds); return(Task.FromResult(items.Select(x => new CiCdBuildDto { Name = x, WebUrl = $"http://ci.rbxd.ds:8090/path/to/build/{x}" }).ToList())); }
private async Task PopulateDependencyVersionVulnerabilities() { foreach (Dependency dependency in context.Dependencies) { UniqueRandomPicker <DependencyVersion> picker = Pick <DependencyVersion> .UniqueRandomList(With.Between(0).And(dependency.Versions.Count).Elements); foreach (DependencyVersion version in picker.From(dependency.Versions.ToList())) { context.Vulnerabilities.Add(new Vulnerability { DependencyVersion = version, DependencyVersionId = version.Id, Id = Guid.NewGuid(), CheckTime = DateTime.Now, Kind = ReporterKind.OSSIndex, ResponseData = FakeResponseData, Link = $"https://ossindex.sonatype.org/component/pkg:nuget/[email protected]" }); } } await context.SaveChangesAsync(); }
public void UsingTheWithBetween_And_SyntaxForGreaterReadability() { var builderSetup = new BuilderSettings(); var builder = new Builder(builderSetup); var categories = builder.CreateListOfSize <Category>(50).Build(); var products = builder .CreateListOfSize <Product>(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5).And(10).Elements).From(categories).ToList()) .Build(); foreach (var product in products) { Assert.That(product.Categories.Count, Is.AtLeast(5)); Assert.That(product.Categories.Count, Is.AtMost(10)); } }
public void CreatingAListOfProductsAndAddingThemToCategories() { var builderSetup = new BuilderSettings(); var builder = new Builder(builderSetup); var categories = builder.CreateListOfSize <Category>(50).Build(); var products = builder .CreateListOfSize <Product>(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5, 10).Elements).From(categories).ToList()) .Build(); foreach (var product in products) { Assert.That(product.Categories.Count, Is.AtLeast(5)); Assert.That(product.Categories.Count, Is.AtMost(10)); } }
public void ShouldBeAbleToUseWith_Between_LowerAndUpper() { var constraint = With.Between(1, 5); constraint.ShouldBeOfType <BetweenConstraint>(); }
public void ShouldBeAbleToUseWith_Between_LowerOnly() { var constraint = With.Between(1); constraint.ShouldBeOfType <BetweenConstraint>(); }
public void UsingTheWithBetween_And_SyntaxForGreaterReadability() { var builderSetup = new BuilderSettings(); var builder = new Builder(builderSetup); var categories = builder.CreateListOfSize <Category>(50).Build(); var products = builder .CreateListOfSize <Product>(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5).And(10).Elements).From(categories).ToList()) .Build(); foreach (var product in products) { product.Categories.Count.ShouldBeGreaterThanOrEqualTo(5);; product.Categories.Count.ShouldBeLessThanOrEqualTo(10); } }
public void CreatingAListOfProductsAndAddingThemToCategories() { var builderSetup = new BuilderSettings(); var builder = new Builder(builderSetup); var categories = builder.CreateListOfSize <Category>(50).Build(); var products = builder .CreateListOfSize <Product>(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5, 10).Elements).From(categories).ToList()) .Build(); foreach (var product in products) { product.Categories.Count.ShouldBeGreaterThanOrEqualTo(5); product.Categories.Count.ShouldBeLessThanOrEqualTo(10); } }
public void Lists_9() { var products = Builder <Product> .CreateListOfSize(5).Build(); Pick <Product> .UniqueRandomList(With.Between(5).And(10).Elements).From(products); }
protected override void Seed(ApplicationDbContext context) { try { if (!context.Roles.Any(r => r.Name == "Manager")) { var store = new RoleStore <IdentityRole>(context); var manager = new RoleManager <IdentityRole>(store); var mgr = new IdentityRole { Name = "Manager" }; manager.Create(mgr); var assistant = new IdentityRole { Name = "Assistant" }; manager.Create(assistant); } if (!context.Users.Any(u => u.UserName == "*****@*****.**")) { var store = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(store); var manager = new ApplicationUser { FullName = "Manager", UserName = "******", Email = "*****@*****.**" }; userManager.Create(manager, "Password@123"); userManager.AddToRole(manager.Id, "Manager"); var assistant = new ApplicationUser { FullName = "Assistant", UserName = "******", Email = "*****@*****.**" }; userManager.Create(assistant, "Password@123"); userManager.AddToRole(assistant.Id, "Assistant"); } context.SaveChanges(); var randomNumber = new RandomGenerator(); var publishers = Builder <Publisher> .CreateListOfSize(10) .All() .With(p => p.Name = Faker.Company.Name()) .Build(); context.Publishers.AddOrUpdate(publishers.ToArray()); context.SaveChanges(); var authors = Builder <Author> .CreateListOfSize(20) .All() .With(a => a.FirstName = Faker.Name.First()) .With(a => a.MiddleName = "") .With(a => a.LastName = Faker.Name.Last()) .Build(); context.Authors.AddOrUpdate(authors.ToArray()); context.SaveChanges(); var categories = new Category[] { new Category { Name = "Adventure", AgeRestricted = false }, new Category { Name = "Animals", AgeRestricted = false }, new Category { Name = "Art and Music", AgeRestricted = false }, new Category { Name = "Biographies", AgeRestricted = false }, new Category { Name = "Character", AgeRestricted = false }, new Category { Name = "Classics", AgeRestricted = false }, new Category { Name = "Folklore, Fairytales and Mythology", AgeRestricted = false }, new Category { Name = "General Fiction", AgeRestricted = false }, new Category { Name = "Graphic Novels", AgeRestricted = false }, new Category { Name = "Health and Human Body", AgeRestricted = false }, new Category { Name = "History", AgeRestricted = false }, new Category { Name = "Language Arts", AgeRestricted = false }, new Category { Name = "Math", AgeRestricted = false }, new Category { Name = "Other", AgeRestricted = false }, new Category { Name = "Reference", AgeRestricted = false }, new Category { Name = "Romance", AgeRestricted = true }, new Category { Name = "Sci-Fi and Fantasy", AgeRestricted = false }, new Category { Name = "Science", AgeRestricted = false }, new Category { Name = "Social Studies", AgeRestricted = false }, new Category { Name = "Sports and Recreation", AgeRestricted = false }, new Category { Name = "Supernatural", AgeRestricted = true }, new Category { Name = "Technology and Transportation", AgeRestricted = false } }; context.Categories.AddOrUpdate(categories); context.SaveChanges(); var books = Builder <Book> .CreateListOfSize(25) .All() .With(b => b.ISBN = Faker.RandomNumber.Next().ToString()) .With(b => b.Name = string.Join(" ", Faker.Lorem.Words(5))) .With(b => b.Publisher = Pick <Publisher> .RandomItemFrom(publishers)) .With(b => b.PublishedDate = DateTime.Now.AddYears(-randomNumber.Next(1, 10))) .With(b => b.Charge = randomNumber.Next(1, 10)) .With(b => b.PenaltyCharge = randomNumber.Next(2, 20)) .With(b => b.Authors = Pick <Author> .UniqueRandomList(With.Between(1).And(5).Elements).From(authors)) .With(b => b.Categories = Pick <Category> .UniqueRandomList(With.Between(1).And(3).Elements).From(categories)) .Build(); context.Books.AddOrUpdate(books.ToArray()); context.SaveChanges(); foreach (var book in books.ToList()) { var bookCopies = Builder <BookCopy> .CreateListOfSize(randomNumber.Next(3, 10)) .All() .With(b => b.Book = book) .With(b => b.AddedOn = DateTime.Now.AddMonths(-randomNumber.Next(1, 90))) .Build(); context.BookCopies.AddOrUpdate(bookCopies.ToArray()); } context.SaveChanges(); /*var memberships = new Membership[] { * new Membership { Name = "Normal", MaxLoans = 5 }, * new Membership { Name = "Premium", MaxLoans = 10 } * }; * * context.Memberships.AddOrUpdate(memberships); * * context.SaveChanges(); */ /* * var members = Builder<Member>.CreateListOfSize(100) * .All() * .With(a => a.FirstName = Faker.Name.First()) * .With(a => a.MiddleName = "") * .With(a => a.LastName = Faker.Name.Last()) * .With(a => a.DateOfBirth = DateTime.Now.AddYears(-randomNumber.Next(15, 40))) * .With(a => a.Membership = Pick<Membership>.RandomItemFrom(memberships)) * .With(a => a.Address = Faker.Address.StreetAddress()) * .With(a => a.PhoneNumber = Faker.Phone.Number()) * .Build(); * * context.Members.AddOrUpdate(members.ToArray()); * context.SaveChanges(); * * var loanTypes = new LoanType[] { * new LoanType { Name="Weekly", Duration=7 }, * new LoanType { Name="Fortnightly", Duration=15 }, * new LoanType { Name="Monthly", Duration=30 } * * }; * * context.LoanTypes.AddOrUpdate(loanTypes); * context.SaveChanges(); * * List<Loan> loans = new List<Loan>(); * * for(int i = 1; i <= 200; i++) * { * var book = Pick<Book>.RandomItemFrom(books); * var bookCopy = Pick<BookCopy>.RandomItemFrom(book.Copies.ToList()); * if (bookCopy.Available) * { * var loanType = Pick<LoanType>.RandomItemFrom(loanTypes); * var dateIssued = DateTime.Now.AddDays(-randomNumber.Next(1, 90)); * var dueDate = dateIssued.AddDays(loanType.Duration); * var dateReturned = randomNumber.Next(1, 100) > 50 ? dateIssued.AddDays(loanType.Duration + randomNumber.Next(-5, 10)) : DateTime.MinValue; * var penalty = dateReturned.Equals(DateTime.MinValue) ? 0 : (dateReturned < dueDate ? 0 : (dateReturned - dueDate).TotalDays * book.PenaltyCharge); * * var validMember = false; * var member = Pick<Member>.RandomItemFrom(members); * * do * { * if (DateTime.Now.AddYears(-18).CompareTo(member.DateOfBirth) == -1 && bookCopy.Book.Categories.Any(c => c.AgeRestricted == true)) * { * member = Pick<Member>.RandomItemFrom(members); * continue; * } * * validMember = true; * } while (!validMember); * * var loan = new Loan * { * BookCopy = bookCopy, * Member = member, * IssuedOn = dateIssued, * DueDate = dueDate, * LoanCharge = loanType.Duration * book.Charge, * PenaltyCharge = penalty, * LoanType = loanType, * LoanedBy = context.Users.First() * }; * * if (!dateReturned.Equals(DateTime.MinValue)) * { * loan.ReturnedOn = dateReturned; * } * * bookCopy.Available = dateReturned != DateTime.MinValue; * loans.Add(loan); * } * } * * context.Loans.AddOrUpdate(loans.ToArray()); * context.SaveChanges(); */ } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), ex ); } }
static void SeedData() { using (var db = new DataContext()) { IList <Category> categories = null; IList <Person> people = null; if (db.Categories.Any() == false) { categories = Builder <Category> .CreateListOfSize(5).Build(); db.Categories.AddRange(categories); } if (db.People.Any() == false) { people = Builder <Person> .CreateListOfSize(5).Build(); db.People.AddRange(people); } if (db.Books.Any() == false) { if (categories == null) { categories = db.Categories.ToList(); } if (people == null) { people = db.People.ToList(); } var books = Builder <Book> .CreateListOfSize(10) .All() .With(b => b.Category = Pick <Category> .RandomItemFrom(categories)) .With(b => b.Authors = Pick <Person> .UniqueRandomList(With.Between(1).And(3).Elements).From(people)) .Build(); db.Books.AddRange(books); } db.SaveChanges(); } }
public void ShouldBeAbleToUseWith_Between_LowerAndUpper() { var constraint = With.Between(1, 5); Assert.That(constraint, Is.TypeOf(typeof(BetweenConstraint))); }
public void ShouldBeAbleToPickUsingBetweenPickerConstraint() { var simpleClasses = Builder <SimpleClass> .CreateListOfSize(10).Build(); var products = Builder <MyClass> .CreateListOfSize(10) .All() .With(x => x.SimpleClasses = Pick <SimpleClass> .UniqueRandomList(With.Between(1, 5).Elements).From(simpleClasses)).Build(); for (int i = 0; i < products.Count; i++) { Assert.That(products[i].SimpleClasses.Count, Is.AtLeast(1)); Assert.That(products[i].SimpleClasses.Count, Is.AtMost(5)); } }
public void ShouldBeAbleToPickUsingBetweenPickerConstraint() { var builderSetup = new BuilderSettings(); var simpleClasses = Builder <SimpleClass> .CreateListOfSize(10).Build(); var products = Builder <MyClass> .CreateListOfSize(10) .All() .With(x => x.SimpleClasses = Pick <SimpleClass> .UniqueRandomList(With.Between(1, 5).Elements).From(simpleClasses)).Build(); for (int i = 0; i < products.Count; i++) { products[i].SimpleClasses.Count.ShouldBeGreaterThanOrEqualTo(1); products[i].SimpleClasses.Count.ShouldBeLessThanOrEqualTo(5); } }