-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed regression from #170 which threw an exception when CreateSetter…
… couldn't find a public setter. This change allows setting of non-public members. Reverts back to previous Bogus behavior which originally allowed setting of non-public members. Related #179.
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
|
||
namespace Bogus.Tests.GitHubIssues | ||
{ | ||
public class Issue179 : SeededTest | ||
{ | ||
private readonly ITestOutputHelper console; | ||
|
||
public Issue179(ITestOutputHelper console) | ||
{ | ||
this.console = console; | ||
} | ||
|
||
[Fact] | ||
public void should_be_able_to_set_non_public_members_of_T() | ||
{ | ||
var fooFaker = new Faker<Buz>() | ||
.RuleFor(x => x.Baz, f => f.Random.String2(10)) | ||
.RuleFor(x => x.Bar, f => f.Random.String2(10)) | ||
.RuleFor( x => x.Normal, f => f.Random.String2(10)) | ||
; | ||
|
||
var foos = fooFaker.Generate(10); | ||
|
||
foreach (var foo in foos) | ||
{ | ||
console.WriteLine($"{foo.Baz} / {foo.Bar} / {foo.Normal}"); | ||
foo.Baz.Should().NotBeNullOrWhiteSpace(); | ||
foo.Bar.Should().NotBeNullOrWhiteSpace(); | ||
foo.Normal.Should().NotBeNullOrWhiteSpace(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void can_set_members_on_internal_class() | ||
{ | ||
var boxFaker = new Faker<Box>() | ||
.RuleFor(x => x.Bub, f => f.Random.String2(10)) | ||
.RuleFor(x => x.Normal, f => f.Random.String2(10)) | ||
; | ||
|
||
var boxes = boxFaker.Generate(10); | ||
|
||
foreach( var box in boxes ) | ||
{ | ||
console.WriteLine($"{box.Bub} / {box.Normal}"); | ||
box.Bub.Should().NotBeNullOrWhiteSpace(); | ||
box.Normal.Should().NotBeNullOrWhiteSpace(); | ||
} | ||
} | ||
} | ||
|
||
|
||
public class Buz | ||
{ | ||
public string Baz { get; internal set; } | ||
|
||
internal string Bar { get; set; } | ||
|
||
public string Normal { get; set; } | ||
} | ||
|
||
internal class Box | ||
{ | ||
internal string Bub { get; private set; } | ||
public string Normal { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters