Exemplo n.º 1
0
        public List <Partenza> GeneraListaPartenze(string CodiceSede, string codMezzo)
        {
            Bogus.Faker faker = new Bogus.Faker();

            int numeroFaker = faker.Random.Number(0, 100);

            Sede distaccamento = new Sede("1", "Tuscolano I", "Via Tuscolana 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma");

            List <Componente> ListaComponentiSquadra = new List <Componente>()
            {
                new Componente("CS", "Riccardo Trionfera", "RT", true, false, false),
                new Componente("CS", "Davide Cappa", "DC", false, true, false),
                new Componente("CS", "Michele Dragonetti", "MD", false, false, false),
                new Componente("CS", "Davide Durante", "MD", false, false, false),
            };

            List <Squadra> ListaSquadre = new List <Squadra>()
            {
                new Squadra("SO115", Squadra.StatoSquadra.InViaggio, ListaComponentiSquadra, distaccamento)
            };

            Mezzo mezzo = new Mezzo(codMezzo, "APS", "Auto pompa serbatoio", "In sede", "CMOB", distaccamento, coordinate: null);

            Partenza partenza = new Partenza();

            partenza.Mezzo   = mezzo;
            partenza.Squadre = ListaSquadre;

            List <Partenza> NewPartenza = new List <Partenza>()
            {
                partenza
            };

            return(NewPartenza);
        }
Exemplo n.º 2
0
        private void buttonFillRandom_Click(object sender, EventArgs e)
        {
            Faker faker = new Bogus.Faker();

            tbBody.Text    = faker.Lorem.Sentences(new Random().Next(10, 50));
            tbSubject.Text = faker.Lorem.Sentence();
        }
Exemplo n.º 3
0
        public static Assignment GenerateGrade(this Assignment a)
        {
            var faker = new Bogus.Faker();

            a.Grade = faker.Random.Int(0, a.PointsPossible);
            return(a);
        }
Exemplo n.º 4
0
        public static Utente GeneraOperatore()
        {
            Bogus.Faker faker = new Bogus.Faker("it");

            string Nome    = faker.Name.FirstName();
            string Cognome = faker.Name.LastName();

            return(new Utente(Nome + Cognome + faker.Random.Number(0, 99).ToString(), Nome, Cognome, faker.Random.AlphaNumeric(16)));
        }
Exemplo n.º 5
0
 private static async Task BulkUpload(Container container)
 {
     List <Food> foods = new Bogus.Faker <Food>()
                         .RuleFor(p => p.Id, f => (-1 - f.IndexGlobal).ToString())
                         .RuleFor(p => p.Description, f => f.Commerce.ProductName())
                         .RuleFor(p => p.ManufacturerName, f => f.Company.CompanyName())
                         .RuleFor(p => p.FoodGroup, f => "Energy Bars")
                         .Generate(10000);
 }
        static void Main(string[] args)
        {
            var faker  = new Bogus.Faker();
            var ticket = new Ticket
            {
                TicketId   = faker.UniqueIndex,
                BasePrice  = 200.0m,
                PremiumFee = 25.0m,
                IsPremium  = true
            };

            Console.WriteLine(ticket);
        }
Exemplo n.º 7
0
    public static async Task Main(string[] args)
    {
        using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey))
        {
            await client.OpenAsync();

            Uri         collectionSelfLink = UriFactory.CreateDocumentCollectionUri("FinancialDatabase", "TransactionCollection");
            Stopwatch   timer   = new Stopwatch();
            FeedOptions options = new FeedOptions
            {
                EnableCrossPartitionQuery = true,
                MaxItemCount           = 1000,
                MaxDegreeOfParallelism = -1,
                MaxBufferedItemCount   = 50000
            };
            await Console.Out.WriteLineAsync($"MaxItemCount:\t{options.MaxItemCount}");

            await Console.Out.WriteLineAsync($"MaxDegreeOfParallelism:\t{options.MaxDegreeOfParallelism}");

            await Console.Out.WriteLineAsync($"MaxBufferedItemCount:\t{options.MaxBufferedItemCount}");

            string sql = "SELECT * FROM c WHERE c.processed = true ORDER BY c.amount DESC";
            timer.Start();
            IDocumentQuery <Document> query = client.CreateDocumentQuery <Document>(collectionSelfLink, sql, options).AsDocumentQuery();
            while (query.HasMoreResults)
            {
                var result = await query.ExecuteNextAsync <Document>();
            }
            timer.Stop();
            await Console.Out.WriteLineAsync($"Elapsed Time:\t{timer.Elapsed.TotalSeconds}");

            Uri collectionSelfLink = UriFactory.CreateDocumentCollectionUri("FinancialDatabase", "TransactionCollection");
            var transactions       = new Bogus.Faker <Transaction>()
                                     .RuleFor(t => t.amount, (fake) => Math.Round(fake.Random.Double(5, 500), 2))
                                     .RuleFor(t => t.processed, (fake) => fake.Random.Bool(0.6f))
                                     .RuleFor(t => t.paidBy, (fake) => $"{fake.Name.FirstName().ToLower()}.{fake.Name.LastName().ToLower()}")
                                     .RuleFor(t => t.costCenter, (fake) => fake.Commerce.Department(1).ToLower())
                                     .GenerateLazy(500);
            List <Task <ResourceResponse <Document> > > tasks = new List <Task <ResourceResponse <Document> > >();
            foreach (var transaction in transactions)
            {
                Task <ResourceResponse <Document> > resultTask = client.CreateDocumentAsync(collectionSelfLink, transaction);
                tasks.Add(resultTask);
            }
            Task.WaitAll(tasks.ToArray());
            foreach (var task in tasks)
            {
                await Console.Out.WriteLineAsync($"Document Created\t{task.Result.Resource.Id}");
            }
        }
    }
Exemplo n.º 8
0
    private static async Task LoadMapViews(Container container)
    {
        var mapInteractions = new Bogus.Faker <ViewMap>()
                              .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                              .RuleFor(i => i.type, (fake) => nameof(ViewMap))
                              .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                              .GenerateLazy(500);

        foreach (var interaction in mapInteractions)
        {
            ItemResponse <ViewMap> result = await container.CreateItemAsync(interaction);

            await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
        }
    }
Exemplo n.º 9
0
    public static async Task Main(string[] args)
    {
        using (CosmosClient client = new CosmosClient(_endpointUri, _primaryKey))
        {
            Database  database  = client.GetDatabase(_databaseId);
            Container container = database.GetContainer(_containerId);

            List <Food> foods = new Bogus.Faker <Food>()
                                .RuleFor(p => p.Id, f => (-1 - f.IndexGlobal).ToString())
                                .RuleFor(p => p.Description, f => f.Commerce.ProductName())
                                .RuleFor(p => p.ManufacturerName, f => f.Company.CompanyName())
                                .RuleFor(p => p.FoodGroup, f => "Energy Bars")
                                .Generate(10000);
        }
    }
Exemplo n.º 10
0
            public void HaveMultipleContacts(int numberOfContactInfo)
            {
                var faker = new Bogus.Faker();

                for (int i = 0; i < numberOfContactInfo; i++)
                {
                    var contactInfo = new ContactInfo();
                    contactInfo.Type  = faker.Random.AlphaNumeric(10);
                    contactInfo.Value = faker.Random.AlphaNumeric(10);

                    _customer.AddContact(contactInfo);
                }

                Assert.Equal(numberOfContactInfo, _customer.Contacts.Count());
            }
Exemplo n.º 11
0
        public void Validate_GamePlayList_ReturnsTrue()
        {
            var fakePerson = new Bogus.Person()
            {
                Random = new Randomizer(1080)
            };

            var randomPhrase = new Bogus.DataSets.Hacker()
            {
                Random = new Randomizer(1080)
            };

            var randomFluent = new Bogus.Faker()
            {
                Random = new Randomizer(1080)
            };


            GameTrackPlaylist gameTrackPlaylist = new GameTrackPlaylist();

            for (int count = 0; count < 10; count++)
            {
                Song fakeSong = new Song()
                {
                    Title    = randomPhrase.Phrase(),
                    Album    = randomPhrase.Phrase(),
                    Composer = fakePerson.FullName
                };

                Game fakeGame = new Game()
                {
                    Title = randomPhrase.Phrase()
                };

                DifficultyMode fakeMode = new DifficultyMode();

                gameTrackPlaylist.Add(new Ez2OnGameTrack(fakeSong, fakeGame, fakeMode));
            }

            gameTrackPlaylist.Name             = randomPhrase.Phrase();
            gameTrackPlaylist.DateTimeCreated  = randomFluent.Date.Past(10, DateTime.Now);
            gameTrackPlaylist.DateTimeModified = randomFluent.Date.Future(10, DateTime.Now);

            GamePlayListValidator validator = new GamePlayListValidator();
            ValidationResult      results   = validator.Validate(gameTrackPlaylist);

            Assert.True(results.IsValid);
        }
        public void TestMethod1()
        {
            Bogus.Faker gerador   = new Bogus.Faker("pt_BR");
            string      nome      = gerador.Name.FirstName();
            string      sobrenome = gerador.Name.LastName();

            Console.WriteLine(nome + " " + sobrenome);

            Console.WriteLine(nome);

            string email = gerador.Internet.Email();

            Console.WriteLine(email);

            string emailCustomizado = gerador.Internet.Email(nome, sobrenome);

            Console.WriteLine(emailCustomizado);

            DateTime dataNascimento = gerador.Date.Past();

            Console.WriteLine(dataNascimento);

            //Simular que a data de aniversário seja de alguém entre 18 e 70 anos(agora também formatando a data):

            string birthDate = gerador.Date.Past(70, DateTime.Now.AddYears(-18)).ToString("dd/MM/yyyy");

            Console.WriteLine(birthDate);

            string telefone = gerador.Phone.PhoneNumber().ToString();

            Console.WriteLine(telefone);

            string celular = gerador.Phone.PhoneNumber("(##)9########").ToString();

            Console.WriteLine(celular);

            string lorem = gerador.Lorem.Paragraph(5);

            Console.WriteLine(lorem);

            string cpf = gerador.Person.Cpf();

            Console.WriteLine(cpf);
            string cnpj = gerador.Company.Cnpj();

            Console.WriteLine(cnpj);
        }
Exemplo n.º 13
0
    private static async Task LoadFoodAndBeverage(Container container)
    {
        var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>()
                               .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                               .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage))
                               .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2))
                               .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5))
                               .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2))
                               .GenerateLazy(500);

        foreach (var interaction in foodInteractions)
        {
            ItemResponse <PurchaseFoodOrBeverage> result = await container.CreateItemAsync(interaction, new PartitionKey(interaction.type));

            await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
        }
    }
Exemplo n.º 14
0
        public void Assign_DefaultDateTimeModified_To_GamePlayList_ReturnsFalse()
        {
            var fakePerson = new Bogus.Person()
            {
                Random = new Randomizer(1080)
            };

            var randomPhrase = new Bogus.DataSets.Hacker()
            {
                Random = new Randomizer(1080)
            };

            var randomFluent = new Bogus.Faker()
            {
                Random = new Randomizer(1080)
            };


            GameTrackPlaylist gameTrackPlaylist = new GameTrackPlaylist();

            for (int count = 0; count < 10; count++)
            {
                Song fakeSong = new Song()
                {
                    Title    = randomPhrase.Phrase(),
                    Album    = randomPhrase.Phrase(),
                    Composer = fakePerson.FullName
                };

                Game fakeGame = new Game()
                {
                    Title = randomPhrase.Phrase()
                };

                DifficultyMode fakeMode = new DifficultyMode();

                gameTrackPlaylist.Add(new Ez2OnGameTrack(fakeSong, fakeGame, fakeMode));
            }

            gameTrackPlaylist.Name            = randomPhrase.Phrase();
            gameTrackPlaylist.DateTimeCreated = DateTime.Now;
            GamePlayListValidator validator = new GamePlayListValidator();
            ValidationResult      results   = validator.Validate(gameTrackPlaylist);

            Assert.Contains(results.Errors, x => x.ErrorMessage == GamePlayListValidator.DateTimeModifiedErrorMessage);
        }
Exemplo n.º 15
0
        public virtual async Task FindEntriesWithNe()
        {
            var provider = CreateProvider();

            var faker   = new Bogus.Faker();
            var model   = Generator.Generate();
            var member  = faker.Random.ArrayElement(Members);
            var created = await provider.CreateAsync(model, cancellationToken);

            var filter = Filter.Ne(member.Name, member.Get(model));

            var result = await provider.FindAsync(filter, cancellationToken : cancellationToken);

            Assert.All(result, (u) =>
            {
                Assert.NotEqual(member.Get(model), member.Get(u));
            });
        }
Exemplo n.º 16
0
    private static async Task LoadTelevision(Container container)
    {
        var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>()
                             .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                             .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel))
                             .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                             .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> {
            "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8"
        }))
                             .GenerateLazy(500);

        foreach (var interaction in tvInteractions)
        {
            ItemResponse <WatchLiveTelevisionChannel> result = await container.CreateItemAsync(interaction, new PartitionKey(interaction.type));

            await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
        }
    }
Exemplo n.º 17
0
    private static async Task BulkUpload(Container container)
    {
        List <Food> foods = new Bogus.Faker <Food>()
                            .RuleFor(p => p.Id, f => (-1 - f.IndexGlobal).ToString())
                            .RuleFor(p => p.Description, f => f.Commerce.ProductName())
                            .RuleFor(p => p.ManufacturerName, f => f.Company.CompanyName())
                            .RuleFor(p => p.FoodGroup, f => "Energy Bars")
                            .Generate(1000);

        int pointer = 0;

        while (pointer < foods.Count)
        {
            StoredProcedureExecuteResponse <int> result = await container.Scripts.ExecuteStoredProcedureAsync <int>("bulkUpload", new PartitionKey("Energy Bars"), new dynamic[] { foods.Skip(pointer) });

            pointer += result.Resource;
            await Console.Out.WriteLineAsync($"{pointer} Total Items\t{result.Resource} Items Uploaded in this Iteration");
        }
    }
Exemplo n.º 18
0
        private List <Sede> GeneraCompetenze()
        {
            Bogus.Faker faker = new Bogus.Faker();

            int numeroFaker = faker.Random.Number(0, 100);

            List <Sede> sede = new List <Sede>()
            {
                new Sede("1", "Tuscolano I", "Via Tuscolana 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("2", "Tuscolano II", "Via Tuscolana 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("3", "Ostiense", "Via Ostiense 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma")
            };

            List <Sede> sede2 = new List <Sede>()
            {
                new Sede("1", "Eur", "Viale delle tre fontane 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("2", "Torrino", "Via della grande muraglia 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("3", "Colombo", "via Leonori 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma")
            };

            List <Sede> sede3 = new List <Sede>()
            {
                new Sede("1", "Pisana", "Via della Pisana 2", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("2", "Aurelia", "Via Aurelia 44", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma"),
                new Sede("3", "Bufalotta", "Via della Bufalotta 54", new Coordinate(faker.Random.Double() + 41.895, faker.Random.Double() + 12.495), "Distaccamento", null, null, "Lazio", "Roma")
            };

            switch (numeroFaker)
            {
            case int n when(n <= 30):
                return(sede);

            case int n when(n > 30) && (n <= 60):
                return(sede2);

            case int n when(n >= 61):
                return(sede3);

            default:
                return(sede);
            }
        }
Exemplo n.º 19
0
        private Board()
        {
            var faker = new Bogus.Faker();

            var baseTaskBogus = new Faker <TaskCore.Task>()
                                .RuleFor(r => r.Discription, f => f.Lorem.Paragraph())
                                .RuleFor(r => r.Estimation, f => f.Random.Double(0, 7))
                                .RuleFor(r => r.Id, f => Guid.NewGuid().ToString())
                                .RuleFor(r => r.TaskOwner, f => new User(f.Person.FirstName, f.Person.LastName, f.Person.Avatar))
                                .RuleFor(r => r.taskCreator, f => new User(f.Person.FirstName, f.Person.LastName, f.Person.Avatar))
                                .RuleFor(r => r.Title, f => f.Lorem.Word())
                                .RuleFor(r => r.Status, f => (Statuses)f.Random.Int(1, 6))
                                .RuleFor(r => r.Type, f => (TaskEnums)f.Random.Int(1, 4))
                                .RuleFor(r => r.UpdatedDate, f => f.Date.Past(8));


            var tasks = baseTaskBogus.Generate(faker.Random.Number(50, 100));

            _tasks = tasks;
        }
Exemplo n.º 20
0
    public static async Task Main(string[] args)
    {
        Database  database  = _client.GetDatabase(_databaseId);
        Container container = database.GetContainer(_containerId);

        List <Food> foods = new Bogus.Faker <Food>()
                            .RuleFor(p => p.Id, f => (-1 - f.IndexGlobal).ToString())
                            .RuleFor(p => p.Description, f => f.Commerce.ProductName())
                            .RuleFor(p => p.ManufacturerName, f => f.Company.CompanyName())
                            .RuleFor(p => p.FoodGroup, f => "Energy Bars")
                            .Generate(10000);

        int pointer = 0;

        while (pointer < foods.Count)
        {
            var parameters = new dynamic[] { foods.Skip(pointer) };
            StoredProcedureExecuteResponse <int> result = await container.Scripts.ExecuteStoredProcedureAsync <int>("bulkUpload", new PartitionKey("Energy Bars"), parameters);

            pointer += result.Resource;
            await Console.Out.WriteLineAsync($"{pointer} Total Items\t{result.Resource} Items Uploaded in this Iteration");
        }

        Console.WriteLine("Execution paused for verification. Press any key to continue to delete.");
        Console.ReadKey();

        bool resume;

        do
        {
            string query      = "SELECT * FROM foods f WHERE f.foodGroup = 'Energy Bars'";
            var    parameters = new dynamic[] { query };
            StoredProcedureExecuteResponse <DeleteStatus> result = await container.Scripts.ExecuteStoredProcedureAsync <DeleteStatus>("bulkDelete", new PartitionKey("Energy Bars"), parameters);

            await Console.Out.WriteLineAsync($"Batch Delete Completed.\tDeleted: {result.Resource.Deleted}\tContinue: {result.Resource.Continuation}");

            resume = result.Resource.Continuation;
        }while (resume);
    }
Exemplo n.º 21
0
        public void GameSong_MustBeAssociatedWith_EitherGameOrDlc(string locale)
        {
            var lorem = new Bogus.DataSets.Lorem(locale)
            {
                Random = new Randomizer(1080)
            };

            Game fakeGame = new Game()
            {
                Title = lorem.Letter(1)
            };

            Song fakeSong = new Song()
            {
                Title    = lorem.Letter(1),
                Composer = lorem.Letter((1)),
                Album    = lorem.Letter(1)
            };
            var randomFluent = new Bogus.Faker()
            {
                Random = new Randomizer(1080)
            };
            DifficultyMode fakeMode = new DifficultyMode();

            fakeMode.Level    = randomFluent.Random.Int(1, 20);
            fakeMode.Category = DifficultyCategory.Easy;

            Ez2OnGameTrack fakeGameTrack = new Ez2OnGameTrack(fakeSong, fakeGame, fakeMode);

            SongValidator fakeSongValidator = new SongValidator();
            GameValidator fakeGameValidator = new GameValidator();

            GameTrackValidator mockValidator = new GameTrackValidator(fakeSongValidator, fakeGameValidator);

            var gameMusicResults = mockValidator.Validate(fakeGameTrack);

            Assert.True(gameMusicResults.IsValid);
        }
Exemplo n.º 22
0
    private static async Task CreateTransactions(Container transactionContainer)
    {
        var transactions = new Bogus.Faker <Transaction>()
                           .RuleFor(t => t.id, (fake) => Guid.NewGuid().ToString())
                           .RuleFor(t => t.amount, (fake) => Math.Round(fake.Random.Double(5, 500), 2))
                           .RuleFor(t => t.processed, (fake) => fake.Random.Bool(0.6f))
                           .RuleFor(t => t.paidBy, (fake) => $"{fake.Name.FirstName().ToLower()}.{fake.Name.LastName().ToLower()}")
                           .RuleFor(t => t.costCenter, (fake) => fake.Commerce.Department(1).ToLower())
                           .GenerateLazy(10000);

        List <Task <ItemResponse <Transaction> > > tasks = new List <Task <ItemResponse <Transaction> > >();

        foreach (var transaction in transactions)
        {
            Task <ItemResponse <Transaction> > resultTask = transactionContainer.CreateItemAsync(transaction);
            tasks.Add(resultTask);
        }
        Task.WaitAll(tasks.ToArray());
        foreach (var task in tasks)
        {
            await Console.Out.WriteLineAsync($"Item Created\t{task.Result.Resource.id}");
        }
    }
 public static Naughty Naughty(this Faker faker)
 {
     Guard.AgainstNull(faker, nameof(faker));
     return(ContextHelper.GetOrSet(faker, () => new Naughty()));
 }
Exemplo n.º 24
0
    public static async Task Main(string[] args)
    {
        using (CosmosClient client = new CosmosClient(_endpointUri, _primaryKey))
        {
            DatabaseResponse databaseResponse = await client.CreateDatabaseIfNotExistsAsync("EntertainmentDatabase");

            Database targetDatabase = databaseResponse.Database;
            await Console.Out.WriteLineAsync($"Database Id:\t{targetDatabase.Id}");

            ContainerResponse response = await targetDatabase.CreateContainerIfNotExistsAsync("DefaultCollection", "/id");

            Container defaultContainer = response.Container;
            await Console.Out.WriteLineAsync($"Default Container Id:\t{defaultContainer.Id}");

            IndexingPolicy indexingPolicy = new IndexingPolicy
            {
                IndexingMode  = IndexingMode.Consistent,
                Automatic     = true,
                IncludedPaths =
                {
                    new IncludedPath
                    {
                        Path = "/*"
                    }
                }
            };

            ContainerProperties containerProperties = new ContainerProperties("CustomCollection", $"/{nameof(IInteraction.type)}")
            {
                IndexingPolicy = indexingPolicy,
            };
            var containerResponse = await targetDatabase.CreateContainerIfNotExistsAsync(containerProperties, 10000);

            var customContainer = containerResponse.Container;
            //var customContainer = targetDatabase.GetContainer("CustomCollection");
            await Console.Out.WriteLineAsync($"Custom Container Id:\t{customContainer.Id}");

            var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>()
                                   .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                                   .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage))
                                   .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2))
                                   .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5))
                                   .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2))
                                   .GenerateLazy(500);

            foreach (var interaction in foodInteractions)
            {
                ItemResponse <PurchaseFoodOrBeverage> result = await customContainer.CreateItemAsync(interaction);

                await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
            }

            var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>()
                                 .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                                 .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel))
                                 .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                                 .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> {
                "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8"
            }))
                                 .GenerateLazy(500);

            foreach (var interaction in tvInteractions)
            {
                ItemResponse <WatchLiveTelevisionChannel> result = await customContainer.CreateItemAsync(interaction);

                await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
            }

            var mapInteractions = new Bogus.Faker <ViewMap>()
                                  .RuleFor(i => i.id, (fake) => Guid.NewGuid().ToString())
                                  .RuleFor(i => i.type, (fake) => nameof(ViewMap))
                                  .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                                  .GenerateLazy(500);

            foreach (var interaction in mapInteractions)
            {
                ItemResponse <ViewMap> result = await customContainer.CreateItemAsync(interaction);

                await Console.Out.WriteLineAsync($"Item Created\t{result.Resource.id}");
            }

            FeedIterator <GeneralInteraction> query = customContainer.GetItemQueryIterator <GeneralInteraction>("SELECT * FROM c");
            while (query.HasMoreResults)
            {
                foreach (GeneralInteraction interaction in await query.ReadNextAsync())
                {
                    Console.Out.WriteLine($"[{interaction.type}]\t{interaction.id}");
                }
            }
        }
    }
Exemplo n.º 25
0
    public static async Task Main(string[] args)
    {
        using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey))
        {
            await client.OpenAsync();

            Database targetDatabase = new Database {
                Id = "EntertainmentDatabase"
            };
            targetDatabase = await client.CreateDatabaseIfNotExistsAsync(targetDatabase);

            await Console.Out.WriteLineAsync($"Database Self-Link:\t{targetDatabase.SelfLink}");

            DocumentCollection defaultCollection = new DocumentCollection
            {
                Id = "DefaultCollection"
            };
            defaultCollection = await client.CreateDocumentCollectionIfNotExistsAsync(targetDatabase.SelfLink, defaultCollection);

            await Console.Out.WriteLineAsync($"Default Collection Self-Link:\t{defaultCollection.SelfLink}");

            IndexingPolicy indexingPolicy = new IndexingPolicy
            {
                IndexingMode  = IndexingMode.Consistent,
                Automatic     = true,
                IncludedPaths = new Collection <IncludedPath>
                {
                    new IncludedPath
                    {
                        Path    = "/*",
                        Indexes = new Collection <Index>
                        {
                            new RangeIndex(DataType.Number, -1),
                            new RangeIndex(DataType.String, -1)
                        }
                    }
                }
            };
            PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition
            {
                Paths = new Collection <string> {
                    $"/{nameof(IInteraction.type)}"
                }
            };
            DocumentCollection customCollection = new DocumentCollection
            {
                Id             = "CustomCollection",
                PartitionKey   = partitionKeyDefinition,
                IndexingPolicy = indexingPolicy
            };
            RequestOptions requestOptions = new RequestOptions
            {
                OfferThroughput = 10000
            };
            customCollection = await client.CreateDocumentCollectionIfNotExistsAsync(targetDatabase.SelfLink, customCollection, requestOptions);

            await Console.Out.WriteLineAsync($"Custom Collection Self-Link:\t{customCollection.SelfLink}");

            var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>()
                                   .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage))
                                   .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2))
                                   .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5))
                                   .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2))
                                   .GenerateLazy(500);

            foreach (var interaction in foodInteractions)
            {
                ResourceResponse <Document> result = await client.CreateDocumentAsync(customCollection.SelfLink, interaction);

                await Console.Out.WriteLineAsync($"Document Created\t{result.Resource.Id}");
            }

            var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>()
                                 .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel))
                                 .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                                 .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> {
                "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8"
            }))
                                 .GenerateLazy(500);

            foreach (var interaction in tvInteractions)
            {
                ResourceResponse <Document> result = await client.CreateDocumentAsync(customCollection.SelfLink, interaction);

                await Console.Out.WriteLineAsync($"Document Created\t{result.Resource.Id}");
            }

            var mapInteractions = new Bogus.Faker <ViewMap>()
                                  .RuleFor(i => i.type, (fake) => nameof(ViewMap))
                                  .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45))
                                  .GenerateLazy(500);

            foreach (var interaction in mapInteractions)
            {
                ResourceResponse <Document> result = await client.CreateDocumentAsync(customCollection.SelfLink, interaction);

                await Console.Out.WriteLineAsync($"Document Created\t{result.Resource.Id}");
            }

            Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection");
            IQueryable <GeneralInteraction> query = client.CreateDocumentQuery <GeneralInteraction>(collectionLink, new FeedOptions {
                EnableCrossPartitionQuery = true
            });
            foreach (GeneralInteraction interaction in query)
            {
                Console.Out.WriteLine($"[{interaction.type}]\t{interaction.id}");
            }
        }
    }
Exemplo n.º 26
0
 public static NodaTimeDataSet Noda(this Faker faker)
 {
     return(Noda(faker, () => DateTimeZone.Utc));
 }