예제 #1
0
        public Job SeedJobs()
        {
            var lorem    = new Lorem(locale: "en");
            var testjobs = new Faker <Job>().CustomInstantiator(f => new Job())

                           .RuleFor(u => u.City, f => f.Address.City())
                           .RuleFor(u => u.MaxSalary, f => f.Random.Number(1000, 200000))
                           .RuleFor(u => u.MinSalary, f => f.Random.Number(1000, 80000))
                           .RuleFor(u => u.Opening, f => f.Random.Number(1, 15))
                           .RuleFor(u => u.Email, (f, u) => f.Internet.Email())
                           .RuleFor(u => u.PostedBy, f => f.PickRandom(JobPosterUserIds))
                           .RuleFor(u => u.Title, f => f.Name.JobTitle())
                           .RuleFor(u => u.PostedOn, (f, u) => f.Date.Past())
                           .RuleFor(u => u.Status, (f, u) => true)
                           .RuleFor(u => u.Tags, f => f.PickRandom(Tags))
                           .RuleFor(u => u.Requirement, f => lorem.Paragraphs(5))
                           .RuleFor(u => u.Responsibility, f => lorem.Paragraphs(5))
                           .RuleFor(u => u.Experience, f => f.Random.Number(1, 5))
                           .RuleFor(u => u.Category, f => f.PickRandom(JobCategories))
                           .RuleFor(u => u.Type, f => f.PickRandom(JobTypes))
                           .RuleFor(u => u.Location, f => f.PickRandom(JobLocations))
                           .RuleFor(u => u.Description, f => lorem.Paragraphs(5))
                           .RuleFor(u => u.Benefits, f => lorem.Paragraphs(5))
                           .RuleFor(u => u.Deadline, (f, u) => f.Date.Future());
            var data = testjobs.Generate();

            return(data);



            //Use a method outside scope.
        }
예제 #2
0
        public void Should_Generate_Multiple_Paragraphs([Range(3, 100)] int num)
        {
            IEnumerable <string> paragraphs = Lorem.Paragraphs(num);

            Assert.That(paragraphs.ToArray(), Is.Not.Null.And.Not.Empty.And.Length.EqualTo(num)
                        .And.All.Not.Empty);
        }
        public BlogTest(ITestOutputHelper outputHelper)
        {
            //for consistency:
            //gcloud beta emulators firestore start --host-port=localhost:8888 --
            Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8888");
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "/raid/repos/epsweb-firestore/EPSWeb.Common.Firestore/epsweb-217515-5631b4260996.json");
            //Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS","/your/credential/key.json");
            output = outputHelper;
            log    = output.BuildLoggerFor <BlogRepo>();

            blog = new BlogRepo(new FirestoreConfig
            {
                Root         = "blogtest",
                Emulator     = true,
                EmulatorUrl  = "http://localhost:8888",
                EmulatorPort = 8888,
                ProjectId    = "epsweb-217515"
            }, log);

            posts = new List <BlogPost>();

            for (int i = 0; i < 20; i++)
            {
                posts.Add(new BlogPost
                {
                    body     = Lorem.Paragraphs(500, 250, 3).ToCombinedString(),
                    overview = Lorem.Sentence(10),
                    tags     = Lorem.Words(5).Split(',').ToCombinedString(),
                    title    = $"blog post {i}",
                    slug     = $"blog-post-{i}"
                });
            }
        }
예제 #4
0
        public void ParagraphsTest()
        {
            int expected = 3;

            string[] actual;
            actual = Lorem.Paragraphs();
            Assert.AreEqual <int>(expected, actual.Length);
        }
예제 #5
0
파일: LoremTests.cs 프로젝트: RimuTec/Faker
        public void Paragraphs_HappyDays()
        {
            const int paragraphCount = 7;
            var       paragraphs     = Lorem.Paragraphs(paragraphCount);

            Assert.AreEqual(paragraphCount, paragraphs.Count());
            Assert.AreEqual(paragraphCount, paragraphs.Count(x => x.EndsWith(Lorem.PunctuationPeriod())));
            Assert.AreEqual(paragraphCount, paragraphs.Count(x => x.Contains(Lorem.PunctuationSpace())));
        }
예제 #6
0
        public void ParagraphsTest1()
        {
            int paragraphCount = 5;
            int expected       = 5;       // TODO: Initialize to an appropriate value

            string[] actual;
            actual = Lorem.Paragraphs(paragraphCount);
            Assert.AreEqual <int>(expected, actual.Length);
        }
예제 #7
0
        private ArticleModel CreateArticle()
        {
            var result = new ArticleModel();

            result.Body        = Lorem.Paragraph();
            result.Description = string.Join(" ", Lorem.Paragraphs(RandomNumber.Next(1, 3)));
            result.Info        = CreateInfo();
            result.IsHidden    = Convert.ToBoolean(RandomNumber.Next(0, 1));
            result.Title       = Faker.Lorem.Sentence();
            result.Comments    = CreateComments();

            return(result);
        }
예제 #8
0
        public void Lorem_Methods()
        {
            Func <object>[] actions = new[]
            {
                new Func <object>(() => Lorem.Character()),
                new Func <object>(() => Lorem.Characters()),
                new Func <object>(() => Lorem.Multibyte()),
                new Func <object>(() => Lorem.Paragraph()),
                new Func <object>(() => Lorem.ParagraphByChars()),
                new Func <object>(() => Lorem.Paragraphs()),
                new Func <object>(() => Lorem.Question()),
                new Func <object>(() => Lorem.Questions()),
                new Func <object>(() => Lorem.Sentence()),
                new Func <object>(() => Lorem.Sentences()),
                new Func <object>(() => Lorem.Word()),
                new Func <object>(() => Lorem.Words()),
            };

            bool success           = true;
            int  totalExecutions   = 0;
            int  successExecutions = 0;
            int  failedExecutions  = 0;

            foreach (Func <object> action in actions)
            {
                foreach (string loc in _localizations)
                {
                    ++totalExecutions;

                    if (!TryCatch(action, loc))
                    {
                        success = false;
                        ++failedExecutions;
                    }
                    else
                    {
                        ++successExecutions;
                    }
                }
            }

            Console.WriteLine($"{failedExecutions} of {totalExecutions} executions failed");

            Assert.IsTrue(success);
            Assert.AreEqual(totalExecutions, successExecutions);
        }
예제 #9
0
파일: LoremTests.cs 프로젝트: RimuTec/Faker
        public void Paragraphs_Without_Supplemental()
        {
            var paragraphs = Lorem.Paragraphs(supplemental: false);
            var checkCount = 0;

            foreach (var paragraph in paragraphs)
            {
                foreach (var word in paragraph.ToWordList())
                {
                    checkCount++;
                    if (!JointWords.Contains(word) &&
                        SupplementalWordList.Contains(word))
                    {
                        Assert.Fail("Paragraphs() shouldn't consider supplementary list.");
                    }
                }
            }
            Assert.Greater(checkCount, paragraphs.Count());
        }
예제 #10
0
        private static void SeedProductPhones(int seedNumber)
        {
            try
            {
                using (var timerLogger = new TimerLogger("Seeding db with phones"))
                    using (var bulkInsert = DocumentStoreHolder.Store.BulkInsert(options.Database))
                    {
                        Log.Information("Started building the faker database objects");

                        var platform = Builder <Platform> .CreateListOfSize(200).All()
                                       .With(p => p.Chipset = Builder <Chipset> .CreateNew().Build())
                                       .With(p => p.Cpu     = Builder <Cpu> .CreateNew().Build()).With(
                            p => p.Os = Builder <Os> .CreateNew()
                                        .With(o => o.NameList = new List <string>(Lorem.Words(5))).Build())
                                       .Random(100).Build();

                        var memory = Builder <Memory> .CreateListOfSize(30).All()
                                     .With(m => m.Internal = Builder <InternalMemory> .CreateNew().Build())
                                     .With(m => m.External = Builder <ExternalMemory> .CreateNew().Build()).Random(15).Build();

                        var frontCamera = Builder <Camera> .CreateListOfSize(45).All()
                                          .With(f => f.Specs    = new List <string>(Lorem.Paragraphs(3)))
                                          .With(f => f.Video    = new List <string>(Lorem.Words(2)))
                                          .With(f => f.Features = new List <string>(Lorem.Sentences(4))).Random(30).Build();

                        var backCamera = Builder <Camera> .CreateListOfSize(45).All()
                                         .With(f => f.Specs    = new List <string>(Lorem.Paragraphs(2)))
                                         .With(f => f.Video    = new List <string>(Lorem.Words(3)))
                                         .With(f => f.Features = new List <string>(Lorem.Sentences(6))).Random(25).Build();

                        var sound = Builder <Sound> .CreateListOfSize(10).All()
                                    .With(s => s.Feature = new List <string>(Lorem.Sentences(2))).Build();

                        var battery = Builder <Battery> .CreateListOfSize(25).All()
                                      .With(s => s.Feature = new List <string>(Lorem.Sentences(3))).Build();

                        var feature = Builder <Feature> .CreateListOfSize(30).All()
                                      .With(s => s.Sensors = new List <string>(Lorem.Words(5))).Random(30).Build();

                        var store = Builder <StoreProduct> .CreateListOfSize(50).All().Random(30).Build();

                        var mobilePhones = Builder <MobilePhone> .CreateListOfSize(seedNumber).All()
                                           .With(p => p.Platform    = Pick <Platform> .RandomItemFrom(platform))
                                           .With(p => p.Memory      = Pick <Memory> .RandomItemFrom(memory))
                                           .With(p => p.FrontCamera = Pick <Camera> .RandomItemFrom(frontCamera))
                                           .With(p => p.BackCamera  = Pick <Camera> .RandomItemFrom(backCamera))
                                           .With(p => p.Sound       = Pick <Sound> .RandomItemFrom(sound))
                                           .With(p => p.Battery     = Pick <Battery> .RandomItemFrom(battery))
                                           .With(p => p.Features    = Pick <Feature> .RandomItemFrom(feature))
                                           .With(p => p.Comms       = Builder <Comms> .CreateNew().Build())
                                           .With(p => p.Id          = Guid.NewGuid().ToString()).With(p => p.CategoryId = Guid.NewGuid().ToString())
                                           .With(
                            p => p.ProductName = new List <string>
                        {
                            $"Product-{Identification.UKNationalInsuranceNumber()}"
                        }).With(p => p.Store = Pick <StoreProduct> .RandomItemFrom(store))
                                           .Build();

                        timerLogger.OnTimedEventTemplate("Processing: {0} items so far...", seedCounter);
                        timerLogger.StartTimer();

                        Log.Information("Ready to start seeded database with {0:n0} phones", seedNumber);

                        foreach (var mobilePhone in mobilePhones)
                        {
                            bulkInsert.Store(mobilePhone);
                            timerLogger.UpdatePropertyValue(seedCounter++);
                        }
                    }
            }
            catch (Exception unknownException)
            {
                Log.Error(
                    unknownException,
                    "Failed while trying to seed the {Database} database with {SeedNumber} phones.",
                    options.Database,
                    seedNumber);
            }
            finally
            {
                Log.Information("Seeded database with {0:n0} phones", seedCounter);
                seedCounter = 0;
            }
        }
예제 #11
0
파일: LoremTests.cs 프로젝트: RimuTec/Faker
        public void Paragraphs_With_DefaultValues()
        {
            var paragraphs = Lorem.Paragraphs();

            Assert.AreEqual(3, paragraphs.Count());
        }
예제 #12
0
파일: LoremTests.cs 프로젝트: RimuTec/Faker
        public void Paragraphs_With_Invalid_ParagraphCount()
        {
            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => Lorem.Paragraphs(-1));

            Assert.AreEqual("Must be equal to or greater than zero. (Parameter 'paragraphCount')", ex.Message);
        }
예제 #13
0
        private async Task CreateBlogPagesAsync(IServiceProvider serviceProvider, SeederContext context, NodeId parentId)
        {
            // Create Blog overview
            var blogContent = EmbeddedContent.New(ContentTypeDefinition.Lookup <SimplePage>());

            this.AddContentValue(blogContent, nameof(ContentPage.NavigationTitle), "Blog", "Blog");

            context.BlogParentId = await this.CreatePageAsync(serviceProvider, context, parentId, blogContent, "Blog", "Blog", 4, "BlogOverview");

            var articleDate = DateTime.Today.AddDays(-_rnd.Next(0, 7));
            var imageFiles  = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), $"../seed-assets/blog".ToSafeFilePath()));
            var sortIndex   = 0;

            foreach (var imageFile in imageFiles)
            {
                var imageId = await CreateImageAsync(serviceProvider, context, imageFile, $"Blog Article Image {articleDate.ToShortDateString()}");

                var categories = Path.GetFileNameWithoutExtension(imageFile).Split('-').Skip(1);

                var content = EmbeddedContent.New(ContentTypeDefinition.Lookup <BlogArticle>());
                this.AddContentValue(content, nameof(BlogArticle.Image), NodeReference.New(imageId));
                this.AddContentValues(content, nameof(BlogArticle.Categories), categories);
                this.AddContentValue(content, nameof(BlogArticle.PublicationDate), articleDate);
                this.AddContentValue(content, nameof(BlogArticle.Author), Lorem.Words(2, 3));
                this.AddContentValue(content, nameof(BlogArticle.ListDescription), Lorem.Sentence(8, 14), Lorem.Sentence(8, 14));
                this.AddContentValue(content, nameof(BlogArticle.Body), "<p>" + string.Join("</p><p>", Lorem.Paragraphs(6, 16, 5, 10, 3)) + "</p>", "<p>" + string.Join("</p><p>", Lorem.Paragraphs(6, 16, 5, 10, 3)) + "</p>");

                await this.CreatePageAsync(serviceProvider, context, context.BlogParentId, content, Lorem.Words(4, 8), Lorem.Words(4, 8), sortIndex ++);

                articleDate = articleDate.AddDays(-_rnd.Next(0, 7));
            }
        }
예제 #14
0
파일: LoremTests.cs 프로젝트: RimuTec/Faker
        public void Paragraphs_With_Zero()
        {
            var paragraph = Lorem.Paragraphs(0);

            Assert.AreEqual(0, paragraph.Count());
        }
예제 #15
0
 public static string Paragraphs(int count, string separator) => Lorem.Paragraphs(count, separator);
예제 #16
0
 public void can_get_paragraphs()
 {
     lorem.Paragraphs()
     .Split("\n\n").Length.Should().Be(3);
 }
예제 #17
0
 private Exception ThrowException()
 {
     throw new Exception($"Some random error {lorem.Paragraphs(2)}");
 }
예제 #18
0
 public void Paragraphs1()
 {
     var result = Lorem.Paragraphs(2);
 }
예제 #19
0
 public void Should_Throw_ArgumentOutOfRangeException_If_Paragraphs_Count_Below_Zero()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Lorem.Paragraphs(-1));
 }
예제 #20
0
        private async Task CreateRoomPageAsync(IServiceProvider serviceProvider, SeederContext context, NodeId roomsPageId, string imageFolder, string englishName, string dutchName, int nightlyRate, int sortIndex)
        {
            var content = EmbeddedContent.New(ContentTypeDefinition.Lookup <RoomDetail>());
            var images  = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), $"../seed-assets/rooms/{imageFolder}".ToSafeFilePath()));

            var mainImageId = await CreateImageAsync(serviceProvider, context, images.First(), $"{englishName} Image 1");

            this.AddContentValue(content, nameof(RoomDetail.MainImage), NodeReference.New(mainImageId));

            for (var i = 1; i < images.Length; i++)
            {
                var additionalImageId = await CreateImageAsync(serviceProvider, context, images[i], $"{englishName} Image {i + 1}");

                this.AddContentValue(content, nameof(RoomDetail.AdditionalImages), NodeReference.New(additionalImageId));
            }

            this.AddContentValue(content, nameof(RoomDetail.NightlyRate), nightlyRate);
            this.AddContentValue(content, nameof(RoomDetail.DiscountedFrom), new Random().Next(nightlyRate, Convert.ToInt32(nightlyRate * 1.2)));
            this.AddContentValue(content, nameof(RoomDetail.ListDescription), Lorem.Sentence(8, 14), Lorem.Sentence(8, 14));
            this.AddContentValue(content, nameof(RoomDetail.LongDescription), "<p>" + string.Join("</p><p>", Lorem.Paragraphs(6, 16, 5, 10, 3)) + "</p>", "<p>" + string.Join("</p><p>", Lorem.Paragraphs(6, 16, 5, 10, 3)) + "</p>");

            var roomPage = await this.CreatePageAsync(serviceProvider, context, roomsPageId, content, englishName, dutchName, sortIndex);

            context.Rooms.Add(roomPage);
        }
예제 #21
0
        private void SeedCategoriesTicketsComments(TicketingSystemDbContext context)
        {
            if (context.Categories.Any())
            {
                return;
            }

            var users = context.Users.ToList();

            string[] urls = new string[]
            {
                "http://gcc-python-plugin.readthedocs.org/en/latest/_images/sample-html-error-report.png",
                "http://a3li.li/wp-content/uploads/2013/11/bugzie-prod-select-2.png",
                "https://hoopercharles.files.wordpress.com/2012/09/topicofprogramming2-12.jpg",
                "http://rules.ssw.com.au/Communication/RulesToBetterEmail/PublishingImages/emailbugreport_good.gif",
                "http://www.symantec.com/business/support/library/BUSINESS/ATLAS/images_v1/316952/mseo.jpg",
                "http://www.symantec.com/business/support/library/BUSINESS/ATLAS/images_v1/283798/inc_issue2.jpg"
            };

            for (int i = 0; i < 7; i++)
            {
                Category category = new Category
                {
                    Name = Lorem.Words(1).ToList()[0].ToUpper()
                };
                context.Categories.Add(category);
                context.SaveChanges();

                int ticketsCount = RandomGenerator.GetRandomNumber(5, 20);
                for (int j = 0; j < ticketsCount; j++)
                {
                    var    paragraphCount = RandomGenerator.GetRandomNumber(2, 3);
                    string description    = String.Empty;
                    for (int p = 0; p < paragraphCount; p++)
                    {
                        string paragraph = String.Join(" ", Lorem.Paragraphs(RandomGenerator.GetRandomNumber(2, 4)));
                        description += paragraph + Environment.NewLine;
                    }
                    description += String.Join(" ", Lorem.Paragraphs(RandomGenerator.GetRandomNumber(1, 3)));

                    string sentence = Lorem.Sentence();
                    if (sentence.Length > 50)
                    {
                        sentence = sentence.Substring(0, 50);
                    }

                    Ticket ticket = new Ticket
                    {
                        Title         = sentence,
                        CategoryId    = category.Id,
                        AuthorId      = users[RandomGenerator.GetRandomNumber(0, users.Count - 1)].Id,
                        ScreenshotUrl = urls[RandomGenerator.GetRandomNumber(0, urls.Length - 1)],
                        Description   = description,
                        Priority      = GetRandomPriority(RandomGenerator.GetRandomNumber())
                    };
                    context.Tickets.Add(ticket);
                    context.SaveChanges();

                    int commentsCount = RandomGenerator.GetRandomNumber(3, 15);
                    for (int k = 0; k < commentsCount; k++)
                    {
                        User author = users[RandomGenerator.GetRandomNumber(0, users.Count - 1)];

                        Comment comment = new Comment
                        {
                            Content  = Lorem.Paragraph(2),
                            AuthorId = author.Id,
                            TicketId = ticket.Id
                        };
                        author.Points++;
                        context.Comments.Add(comment);
                        context.SaveChanges();
                    }
                }
            }
            context.SaveChanges();
        }