Bogus faker how to set a list of string array
Asked Answered
G

2

5

I would like to ask your help to use Bogus Faker.

I have this

private readonly Faker _faker;

_faker = new Faker("fr");

List<string> _randomString = (List<string>)_faker.Make(3, () => _faker.Random.Word()); // OK

List<string[]> _randomStrinArray = (List<string[]>)_faker.Make(3, () => _faker.Random.Word()); // KO
Georgiageorgian answered 30/8, 2019 at 11:33 Comment(0)
C
7

Looks like you found your solution. That's great by the way!

Here are some other alternatives if you're intrested:

var faker = new Faker();

List<string> randomStrings = Enumerable.Range(1,7)
                       .Select(_ => faker.Random.Word())
                       .ToList();
randomStrings.Dump();

output

List<string[]> randomStringArray = Enumerable.Range(1,7)
      .Select(_ => faker.Random.WordsArray(1,4))
      .ToList();

randomStringArray.Dump();

enter image description here

Cryptography answered 30/8, 2019 at 20:9 Comment(1)
Thanks Brian for the reply.Georgiageorgian
G
4

Hello I found the solution

List<string[]> _randomStrinArray = (List<string[]>) _faker.Make(3, () => _faker.Random.WordsArray(1,4));
Georgiageorgian answered 30/8, 2019 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.