{"action":"created","issue":{"url":"https://api.github.com/repos/bchavez/Bogus/issues/42","repository_url":"https://api.github.com/repos/bchavez/Bogus","labels_url":"https://api.github.com/repos/bchavez/Bogus/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/bchavez/Bogus/issues/42/comments","events_url":"https://api.github.com/repos/bchavez/Bogus/issues/42/events","html_url":"https://github.com/bchavez/Bogus/issues/42","id":184536619,"number":42,"title":"Suggestion: allow faker rules to be overridden","user":{"login":"mattwcole","id":6730646,"avatar_url":"https://avatars.githubusercontent.com/u/6730646?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwcole","html_url":"https://github.com/mattwcole","followers_url":"https://api.github.com/users/mattwcole/followers","following_url":"https://api.github.com/users/mattwcole/following{/other_user}","gists_url":"https://api.github.com/users/mattwcole/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwcole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwcole/subscriptions","organizations_url":"https://api.github.com/users/mattwcole/orgs","repos_url":"https://api.github.com/users/mattwcole/repos","events_url":"https://api.github.com/users/mattwcole/events{/privacy}","received_events_url":"https://api.github.com/users/mattwcole/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-21T17:43:59Z","updated_at":"2016-10-21T19:32:32Z","closed_at":null,"body":"I think it would be useful to allow rules to be overridden on fakers. Currently there is an exception thrown when a rule has already been added for the property. If instead, the existing rule was replaced, you could very easily create test data builders like the following.\r\n\r\n```csharp\r\npublic class FakeCustomerBuilder\r\n{\r\n    private readonly Faker<Customer> _customerFaker;\r\n\r\n    public FakeCustomerBuilder()\r\n    {\r\n        _customerFaker = new Faker<Customer>()\r\n            .RuleFor(customer => customer.Forename, faker => faker.Name.FirstName())\r\n            .RuleFor(customer => customer.Surname, faker => faker.Name.LastName());\r\n    }\r\n\r\n    public CustomerBuilder WithSurname(string surname)\r\n    {\r\n        _customerFaker.RuleFor(c => c.Surname, faker => surname);\r\n        return this;\r\n    }\r\n\r\n    public Customer Build()\r\n    {\r\n        return _customerFaker.Generate();\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/bchavez/Bogus/issues/comments/255447280","html_url":"https://github.com/bchavez/Bogus/issues/42#issuecomment-255447280","issue_url":"https://api.github.com/repos/bchavez/Bogus/issues/42","id":255447280,"user":{"login":"mattwcole","id":6730646,"avatar_url":"https://avatars.githubusercontent.com/u/6730646?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwcole","html_url":"https://github.com/mattwcole","followers_url":"https://api.github.com/users/mattwcole/followers","following_url":"https://api.github.com/users/mattwcole/following{/other_user}","gists_url":"https://api.github.com/users/mattwcole/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwcole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwcole/subscriptions","organizations_url":"https://api.github.com/users/mattwcole/orgs","repos_url":"https://api.github.com/users/mattwcole/repos","events_url":"https://api.github.com/users/mattwcole/events{/privacy}","received_events_url":"https://api.github.com/users/mattwcole/received_events","type":"User","site_admin":false},"created_at":"2016-10-21T19:32:32Z","updated_at":"2016-10-21T19:32:32Z","body":"@bchavez you're right, I was just writing a follow up to this. There is also a problem if you want to create a reusable builder. The following will fail because of multiple calls to `FinishWith()`.\r\n\r\n```csharp\r\nvar builder = new FakeCustomerBuilder();\r\nvar mrFoo = builder.WithSurname(\"foo\").Build();\r\nvar mrBar = builder.WithSurname(\"bar\").Build();\r\n```\r\n\r\nRegardless of the builder pattern, I think in general it could be useful to be able to modify the rules on a `Faker` as needed. Creating a `Faker` with sensible defaults and modifying these later feels like it could be a common use case."}}
{"actor":{"display_login":"mattwcole"}}