diff --git a/Source/Bogus.Tests/Bogus.Tests.csproj b/Source/Bogus.Tests/Bogus.Tests.csproj index c4a233ab..4dcfddb7 100644 --- a/Source/Bogus.Tests/Bogus.Tests.csproj +++ b/Source/Bogus.Tests/Bogus.Tests.csproj @@ -17,6 +17,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Source/Bogus.Tests/RecordTest.cs b/Source/Bogus.Tests/RecordTest.cs new file mode 100644 index 00000000..6579119d --- /dev/null +++ b/Source/Bogus.Tests/RecordTest.cs @@ -0,0 +1,22 @@ +using FluentAssertions; +using Xunit; + +namespace Bogus.Tests; + +public class RecordTest +{ + private record User(string FirstName, string Email, string LastName); + + [Fact] + public void Can_generate_a_record() + { + var faker = new Faker() + .RuleFor(d => d.FirstName, f => f.Person.FirstName) + .RuleFor(d => d.LastName, _ => "x"); + + var user = faker.Generate(); + user.FirstName.Should().NotBeNull(); + user.LastName.Should().Be("x"); + user.Email.Should().BeNull(); + } +} \ No newline at end of file diff --git a/Source/Bogus/Faker[T].cs b/Source/Bogus/Faker[T].cs index c58f84bf..f8b9e834 100644 --- a/Source/Bogus/Faker[T].cs +++ b/Source/Bogus/Faker[T].cs @@ -149,7 +149,11 @@ public Faker(string locale = "en", IBinder binder = null) this.Locale = locale; FakerHub = new Faker(locale); TypeProperties = this.binder.GetMembers(typeof(T)); - this.CreateActions[Default] = faker => Activator.CreateInstance(); + this.CreateActions[Default] = faker => + { + var constructor = typeof(T).GetConstructors().First(); + return (T)constructor.Invoke(new object[constructor.GetParameters().Length]); + }; } /// diff --git a/Source/Bogus/Properties/AssemblyInfo.cs b/Source/Bogus/Properties/AssemblyInfo.cs index a3d358e3..49bf02b6 100644 --- a/Source/Bogus/Properties/AssemblyInfo.cs +++ b/Source/Bogus/Properties/AssemblyInfo.cs @@ -6,10 +6,10 @@ [assembly: AssemblyProduct("Bogus")] [assembly: AssemblyTitle("Bogus Fake Data Generator for .NET")] [assembly: AssemblyCompany("Brian Chavez")] -[assembly: AssemblyCopyright("Brian Chavez © 2015")] +[assembly: AssemblyCopyright("Brian Chavez © 2025")] [assembly: AssemblyVersion("0.0.0")] [assembly: AssemblyFileVersion("0.0.0")] -[assembly: AssemblyInformationalVersion("0.0.0-localbuild built on 2015-01-01 00:00:00Z")] +[assembly: AssemblyInformationalVersion("0.0.0-localbuild built on 2025-06-24 13:41:48Z")] [assembly: AssemblyTrademark("MIT License")] [assembly: AssemblyDescription("https://github.com/bchavez/Bogus")] [assembly: InternalsVisibleTo("Bogus.Tests")] @@ -18,10 +18,10 @@ internal static class AssemblyVersionInformation { internal const System.String AssemblyProduct = "Bogus"; internal const System.String AssemblyTitle = "Bogus Fake Data Generator for .NET"; internal const System.String AssemblyCompany = "Brian Chavez"; - internal const System.String AssemblyCopyright = "Brian Chavez © 2015"; + internal const System.String AssemblyCopyright = "Brian Chavez © 2025"; internal const System.String AssemblyVersion = "0.0.0"; internal const System.String AssemblyFileVersion = "0.0.0"; - internal const System.String AssemblyInformationalVersion = "0.0.0-localbuild built on 2015-01-01 00:00:00Z"; + internal const System.String AssemblyInformationalVersion = "0.0.0-localbuild built on 2025-06-24 13:41:48Z"; internal const System.String AssemblyTrademark = "MIT License"; internal const System.String AssemblyDescription = "https://github.com/bchavez/Bogus"; internal const System.String InternalsVisibleTo = "Bogus.Tests";