diff --git a/NineteenSevenFour.Testing.Core.UnitTest/NineteenSevenFour.Testing.Core.UnitTest.csproj b/NineteenSevenFour.Testing.Core.UnitTest/NineteenSevenFour.Testing.Core.UnitTest.csproj
index 96acc87..34db5c1 100644
--- a/NineteenSevenFour.Testing.Core.UnitTest/NineteenSevenFour.Testing.Core.UnitTest.csproj
+++ b/NineteenSevenFour.Testing.Core.UnitTest/NineteenSevenFour.Testing.Core.UnitTest.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+ True
+ True
+ ..\nineteensevenfour-public.snk
..\NineteenFourSeven_logo.ico
diff --git a/NineteenSevenFour.Testing.Core/Extension/FluentExpression.cs b/NineteenSevenFour.Testing.Core/Extension/FluentExpression.cs
index 10f54e4..c616072 100644
--- a/NineteenSevenFour.Testing.Core/Extension/FluentExpression.cs
+++ b/NineteenSevenFour.Testing.Core/Extension/FluentExpression.cs
@@ -7,33 +7,71 @@ namespace NineteenSevenFour.Testing.Core.Extension;
[EditorBrowsable(EditorBrowsableState.Never)]
public static class FluentExpression
{
- #region Member NameFor<>
+ ///
+ /// Members the name for.
+ ///
+ ///
+ /// The type of the property.
+ /// The expression.
+ ///
public static string? MemberNameFor(Expression> expression)
{
Expression body = expression.Body;
return body.AsMemberExpression()?.Member.Name;
}
+ ///
+ /// Members the name for.
+ ///
+ ///
+ /// The expression.
+ ///
public static string? MemberNameFor(Expression> expression)
{
Expression body = expression.Body;
return body.AsMemberExpression()?.Member?.Name;
}
+ ///
+ /// Members the name for.
+ ///
+ /// The expression.
+ ///
public static string? MemberNameFor(Expression> expression)
{
Expression body = expression.Body;
return body.AsMemberExpression()?.Member?.Name;
}
- #endregion
- #region Memeber TypeFor<>
+ ///
+ /// Members the type for.
+ ///
+ ///
+ /// The type of the property.
+ /// The expression.
+ ///
public static Type? MemberTypeFor(Expression> expression) => expression.Body.MemberTypeFor();
+ ///
+ /// Members the type for.
+ ///
+ ///
+ /// The expression.
+ ///
public static Type? MemberTypeFor(Expression> expression) => expression.Body.MemberTypeFor();
+ ///
+ /// Members the type for.
+ ///
+ /// The expression.
+ ///
public static Type? MemberTypeFor(Expression> expression) => expression.Body.MemberTypeFor();
+ ///
+ /// Members the type for.
+ ///
+ /// The expression.
+ ///
private static Type? MemberTypeFor(this Expression expression)
{
var memberExp = expression?.AsMemberExpression();
@@ -41,8 +79,14 @@ public static class FluentExpression
? ((PropertyInfo)memberExp.Member).PropertyType.GetGenericArguments()[0]
: memberExp?.Type;
}
- #endregion
+ ///
+ /// Ensures the member exists.
+ ///
+ /// The type of the entity.
+ /// The property name or field.
+ /// The exception message.
+ ///
public static void EnsureMemberExists(string? propNameOrField, string? exceptionMessage = null)
where TEntity : class
{
@@ -59,6 +103,19 @@ public static void EnsureMemberExists(string? propNameOrField, string?
}
}
+ ///
+ /// Ases the member expression.
+ ///
+ /// The expression.
+ ///
+ ///
+ /// $"Your expression '{expressionString}' cant be used. Nested accessors like 'o => o.NestedObject.Foo' at " +
+ /// $"a parent level are not allowed. You should create a dedicated faker for " +
+ /// $"NestedObject like new Faker().RuleFor(o => o.Foo, ...) with its own rules " +
+ /// $"that define how 'Foo' is generated.
+ /// or
+ /// Expression was not of the form 'x => x.Property or x => x.Field'.
+ ///
public static MemberExpression? AsMemberExpression(this Expression expression)
{
var expressionString = expression.ToString();
@@ -91,6 +148,15 @@ public static void EnsureMemberExists(string? propNameOrField, string?
return memberExpression;
}
+ ///
+ /// Sets the field.
+ ///
+ /// The type of the dep.
+ /// The type of the key property.
+ /// The target.
+ /// The property expression.
+ /// The value.
+ ///
public static void SetField(TDep target, Expression> propExpression, TKeyProp value)
{
try
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/Faker/PersonFaker.cs b/NineteenSevenFour.Testing.Example.Domain/Faker/PersonFaker.cs
similarity index 86%
rename from NineteenSevenFour.Testing.FluentBogus.UnitTest/Faker/PersonFaker.cs
rename to NineteenSevenFour.Testing.Example.Domain/Faker/PersonFaker.cs
index 16b4cdd..39ed635 100644
--- a/NineteenSevenFour.Testing.FluentBogus.UnitTest/Faker/PersonFaker.cs
+++ b/NineteenSevenFour.Testing.Example.Domain/Faker/PersonFaker.cs
@@ -1,7 +1,12 @@
+using AutoBogus;
+
using NineteenSevenFour.Testing.Example.Domain.Model;
-namespace NineteenSevenFour.Testing.FluentBogus.UnitTest.Faker;
+using System.Diagnostics.CodeAnalysis;
+
+namespace NineteenSevenFour.Testing.Example.Domain.Faker;
+[ExcludeFromCodeCoverage]
public class PersonFaker : AutoFaker
{
public PersonFaker(int Id) : this()
diff --git a/NineteenSevenFour.Testing.Example.Domain/NineteenSevenFour.Testing.Example.Domain.csproj b/NineteenSevenFour.Testing.Example.Domain/NineteenSevenFour.Testing.Example.Domain.csproj
index 0361891..c4e9539 100644
--- a/NineteenSevenFour.Testing.Example.Domain/NineteenSevenFour.Testing.Example.Domain.csproj
+++ b/NineteenSevenFour.Testing.Example.Domain/NineteenSevenFour.Testing.Example.Domain.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+ True
+ True
+ ..\nineteensevenfour-public.snk
..\NineteenFourSeven_logo.ico
@@ -12,4 +15,8 @@
+
+
+
+
diff --git a/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest.csproj b/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest.csproj
index 2489e73..cefe1a9 100644
--- a/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest/NineteenSevenFour.Testing.FluentBogus.AutoMapper.UnitTest.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+ True
+ True
+ ..\nineteensevenfour-public.snk
..\NineteenFourSeven_logo.ico
diff --git a/NineteenSevenFour.Testing.FluentBogus.AutoMapper/NineteenSevenFour.Testing.FluentBogus.AutoMapper.csproj b/NineteenSevenFour.Testing.FluentBogus.AutoMapper/NineteenSevenFour.Testing.FluentBogus.AutoMapper.csproj
index 2df6797..68f995d 100644
--- a/NineteenSevenFour.Testing.FluentBogus.AutoMapper/NineteenSevenFour.Testing.FluentBogus.AutoMapper.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus.AutoMapper/NineteenSevenFour.Testing.FluentBogus.AutoMapper.csproj
@@ -50,4 +50,7 @@
+
+
+
diff --git a/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest.csproj b/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest.csproj
index ffe60ff..3da10fa 100644
--- a/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+ True
+ True
+ ..\nineteensevenfour-public.snk
..\NineteenFourSeven_logo.ico
diff --git a/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/Usings.cs b/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/Usings.cs
index cf05d78..6c83cb8 100644
--- a/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/Usings.cs
+++ b/NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/Usings.cs
@@ -1,2 +1 @@
global using AutoBogus;
-global using Xunit;
diff --git a/NineteenSevenFour.Testing.FluentBogus.Relation/NineteenSevenFour.Testing.FluentBogus.Relation.csproj b/NineteenSevenFour.Testing.FluentBogus.Relation/NineteenSevenFour.Testing.FluentBogus.Relation.csproj
index 720dad2..72cb748 100644
--- a/NineteenSevenFour.Testing.FluentBogus.Relation/NineteenSevenFour.Testing.FluentBogus.Relation.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus.Relation/NineteenSevenFour.Testing.FluentBogus.Relation.csproj
@@ -40,4 +40,7 @@
+
+
+
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Fake.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Fake.cs
new file mode 100644
index 0000000..3897395
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Fake.cs
@@ -0,0 +1,23 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_Fake
+{
+ [Fact]
+ public void Should_Return_ABuilder_WhenCalled()
+ {
+ // Arrange
+
+ // Act
+ var builder = FluentBogusBuilder.Fake();
+
+ // Assert
+ builder.Should()
+ .NotBeNull().And
+ .BeOfType>();
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Generate.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Generate.cs
new file mode 100644
index 0000000..e80588e
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Generate.cs
@@ -0,0 +1,114 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_Generate
+{
+ [Fact]
+ public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithoutSkipOrConfigOrSeed()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With ();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var person = builder.Generate();
+
+ // Assert
+ person.Should().NotBeNull();
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(0);
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+
+ [Fact]
+ public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithSkip()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var person = builder.Skip(p => p.Addresses).Generate();
+
+ // Assert
+ person.Should().NotBeNull();
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(1);
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+
+ [Fact]
+ public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithConfig()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var person = builder.UseConfig(b => b.WithTreeDepth(1)).Generate();
+
+ // Assert
+ person.Should().NotBeNull();
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(0);
+ typedBuilder.fakerConfigBuilder.Should().NotBeNull();
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+
+ [Fact]
+ public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithoutSkipOrConfigOrSeed()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var persons = builder.Generate(2);
+
+ // Assert
+ persons.Should().NotBeNullOrEmpty().And.HaveCount(2);
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(0);
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+
+ [Fact]
+ public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithSkip()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var persons = builder.Skip(p => p.Addresses).Generate(2);
+
+ // Assert
+ persons.Should().NotBeNullOrEmpty().And.HaveCount(2);
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(1);
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+
+ [Fact]
+ public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithConfig()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ var typedBuilder = builder as FluentBogusBuilder;
+
+ // Act
+ var persons = builder.UseConfig(b => b.WithTreeDepth(1)).Generate(2);
+
+ // Assert
+ persons.Should().NotBeNullOrEmpty().And.HaveCount(2);
+#pragma warning disable CS8602 // Dereference of a possibly null reference.
+ typedBuilder.skipProperties.Should().HaveCount(0);
+ typedBuilder.fakerConfigBuilder.Should().NotBeNull();
+#pragma warning restore CS8602 // Dereference of a possibly null reference.
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_RuleSetString.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_RuleSetString.cs
new file mode 100644
index 0000000..9991960
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_RuleSetString.cs
@@ -0,0 +1,43 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_RuleSetString
+{
+ [Fact]
+ public void Should_ReturnJoinedList_WhenCalled_WithRuleset()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseRuleSet("rule1", "rule2");
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.RuleSetString.Should()
+ .NotBeNullOrEmpty()
+ .And
+ .Be("rule1,rule2");
+ }
+
+ [Fact]
+ public void Should_ReturnEmptyString_WhenCalled_WithoutRuleset()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.RuleSetString.Should()
+ .BeNullOrEmpty();
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Skip.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Skip.cs
new file mode 100644
index 0000000..0e8a3f8
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Skip.cs
@@ -0,0 +1,114 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+using System.Linq.Expressions;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_Skip
+{
+ [Fact]
+ public void Should_AddPropertyToSkipList_WhenCalled_WithSinglePropertyLambdaExpression()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.Skip(e => e.Addresses);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.skipProperties.Should()
+ .NotBeNullOrEmpty()
+ .And
+ .HaveCount(1);
+ }
+
+ [Fact]
+ public void Should_ThrowInvalidOperationException__WhenCalled_WithDuplicateSinglePropertyLambdaExpression()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+ builder.Skip(e => e.Addresses);
+
+ // Act
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.Skip(e => e.Addresses);
+#pragma warning restore IDE0039 // Use local function
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should().NotBeNull();
+ exception.Message.Should().Be($"The property Addresses for type PersonModel is already set to be skipped.");
+ }
+
+ [Fact]
+ public void Should_AddPropertiesToSkipList_WhenCalled_WithMultiplePropertyLambdaExpression()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.Skip(e => e.Addresses, equals => equals.Relatives);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.skipProperties.Should()
+ .NotBeNullOrEmpty()
+ .And
+ .HaveCount(2);
+ }
+
+ [Fact]
+ public void Should_ThrowArgumentOutOfRangeException_WhenCalled_WithMultipleNullPropertyLambdaExpression()
+ {
+ // Arrange
+#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
+ Expression> property1 = null;
+ Expression> property2 = null;
+#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+#pragma warning disable CS8604 // Possible null reference argument.
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.Skip(property1, property2);
+#pragma warning restore IDE0039 // Use local function
+#pragma warning restore CS8604 // Possible null reference argument.
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should()
+ .NotBeNull();
+ exception.Message.Should()
+ .Be($"A List of properties must be provided. (Parameter 'properties')");
+ }
+
+ [Fact]
+ public void Should_ThrowArgumentOutOfRangeException_WhenCalled_WithEmptyArrayOfPropertyLambdaExpression()
+ {
+ // Arrange
+#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
+ Expression>[] properties = null;
+#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+#pragma warning disable CS8604 // Possible null reference argument.
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.Skip(properties);
+#pragma warning restore IDE0039 // Use local function
+#pragma warning restore CS8604 // Possible null reference argument.
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should().NotBeNull();
+ exception.Message.Should()
+ .Be($"A List of properties must be provided. (Parameter 'properties')");
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseArg.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseArg.cs
new file mode 100644
index 0000000..d14c1ce
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseArg.cs
@@ -0,0 +1,28 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_UseArg
+{
+ [Fact]
+ public void Should_StoreFakerArg_WhenCalled()
+ {
+ // Arrange
+ var args = new[] { "argOne", "argTwo" };
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseArgs(args);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.fakerArgs.Should()
+ .NotBeEmpty().And
+ .HaveCount(args.Length);
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseConfig.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseConfig.cs
new file mode 100644
index 0000000..4851881
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseConfig.cs
@@ -0,0 +1,28 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_UseConfig
+{
+ [Fact]
+ public void Should_StoreFakerconfig_WhenCalled()
+ {
+ // Arrange
+#pragma warning disable IDE0039 // Use local function
+ Action fakerConfig = (config) => config.WithTreeDepth(0);
+#pragma warning restore IDE0039 // Use local function
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseConfig(fakerConfig);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.fakerConfigBuilder.Should().NotBeNull().And.BeEquivalentTo(fakerConfig);
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseRule.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseRule.cs
new file mode 100644
index 0000000..3058c21
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseRule.cs
@@ -0,0 +1,131 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_UseRule
+{
+ [Fact]
+ public void Should_AddRulesetToList_WhenCalled_WithSingleRuleset()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseRuleSet("SomeRule");
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.ruleSets.Should()
+ .NotBeNullOrEmpty()
+ .And
+ .HaveCount(1);
+ }
+
+ [Fact]
+ public void Should_ThrowInvalidOperationException__WhenCalled_WithDuplicateSingleRuleset()
+ {
+ // Arrange
+ var ruleSet = "SomeRule";
+ var builder = FluentBogusBuilder.Fake().With();
+ builder.UseRuleSet(ruleSet);
+
+ // Act
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.UseRuleSet(ruleSet);
+#pragma warning restore IDE0039 // Use local function
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should().NotBeNull();
+ exception.Message.Should().Be($"The ruleset SomeRule is already set to be used.");
+ }
+
+ [Fact]
+ public void Should_ThrowArgumentOutOfRangeException__WhenCalled_WithEmptySingleRuleset()
+ {
+ // Arrange
+ var ruleSet = "";
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.UseRuleSet(ruleSet);
+#pragma warning restore IDE0039 // Use local function
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should().NotBeNull();
+ exception.Message.Should().Be($"A ruleset must be provided. (Parameter 'ruleset')");
+ }
+
+ [Fact]
+ public void Should_AddPropertiesToSkipList_WhenCalled_WithMultipleRuleset()
+ {
+ // Arrange
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseRuleSet("rule1", "rule2");
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.ruleSets.Should()
+ .NotBeNullOrEmpty()
+ .And
+ .HaveCount(2);
+ }
+
+ [Fact]
+ public void Should_ThrowArgumentOutOfRangeException_WhenCalled_WithMultipleNullRuleset()
+ {
+ // Arrange
+#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
+ string rule1 = null;
+ string rule2 = null;
+#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+#pragma warning disable CS8604 // Possible null reference argument.
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.UseRuleSet(rule1, rule2);
+#pragma warning restore IDE0039 // Use local function
+#pragma warning restore CS8604 // Possible null reference argument.
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should()
+ .NotBeNull();
+ exception.Message.Should()
+ .Be($"A List of ruleset must be provided. (Parameter 'rulesets')");
+ }
+
+ [Fact]
+ public void Should_ThrowArgumentOutOfRangeException_WhenCalled_WithEmptyArrayOfRuleset()
+ {
+ // Arrange
+#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
+ string[] rules = null;
+#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+#pragma warning disable CS8604 // Possible null reference argument.
+#pragma warning disable IDE0039 // Use local function
+ var result = () => builder.UseRuleSet(rules);
+#pragma warning restore IDE0039 // Use local function
+#pragma warning restore CS8604 // Possible null reference argument.
+
+ // Assert
+ var exception = Assert.Throws(result);
+ exception.Should().NotBeNull();
+ exception.Message.Should()
+ .Be($"A List of ruleset must be provided. (Parameter 'rulesets')");
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseSeed.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseSeed.cs
new file mode 100644
index 0000000..dbff595
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_UseSeed.cs
@@ -0,0 +1,27 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_UseSeed
+{
+ [Fact]
+ public void Should_StoreSeed_WhenCalled()
+ {
+ // Arrange
+ var seed = 456;
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Act
+ builder.UseSeed(seed);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.seed.Should()
+ .Be(seed);
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_With.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_With.cs
new file mode 100644
index 0000000..8158e51
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_With.cs
@@ -0,0 +1,41 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Faker;
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_With
+{
+ [Fact]
+ public void Should_Return_ABuilder_WithCustomFaker_WhenCalled_WithoutArguments()
+ {
+ // Arrange
+
+ // Act
+ var builder = FluentBogusBuilder.Fake().With();
+
+ // Assert
+ builder.Should()
+ .NotBeNull().And
+ .BeOfType>();
+ }
+
+ [Fact]
+ public void Should_StoreArguments_WhenCalled_WithArguments()
+ {
+ // Arrange
+ var args = new[] { "argOne", "argTwo" };
+
+ // Act
+ var builder = FluentBogusBuilder.Fake().With(args);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.fakerArgs.Should()
+ .NotBeEmpty().And
+ .HaveCount(args.Length);
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_WithDefault.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_WithDefault.cs
new file mode 100644
index 0000000..d20bdf8
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_WithDefault.cs
@@ -0,0 +1,40 @@
+using FluentAssertions;
+
+using NineteenSevenFour.Testing.Example.Domain.Model;
+using NineteenSevenFour.Testing.FluentBogus.Extension;
+
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusBuilder_WithDefault
+{
+ [Fact]
+ public void Should_Return_ABuilder_WithDefaultAutoFaker_WhenCalled_WithoutArguments()
+ {
+ // Arrange
+
+ // Act
+ var builder = FluentBogusBuilder.Fake().WithDefault();
+
+ // Assert
+ builder.Should()
+ .NotBeNull().And
+ .BeOfType, PersonModel>>();
+ }
+
+ [Fact]
+ public void Should_StoreArguments_WhenCalled_WithArguments()
+ {
+ // Arrange
+ var args = new[] { "argOne", "argTwo" };
+
+ // Act
+ var builder = FluentBogusBuilder.Fake().WithDefault(args);
+
+ // Assert
+ var typedBuilder = builder as FluentBogusBuilder, PersonModel>;
+ Assert.NotNull(typedBuilder);
+ typedBuilder.fakerArgs.Should()
+ .NotBeEmpty().And
+ .HaveCount(args.Length);
+ }
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusExample.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusExample.cs
new file mode 100644
index 0000000..e61b42a
--- /dev/null
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusExample.cs
@@ -0,0 +1,255 @@
+namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
+
+public class FluentBogusExample
+{
+ // TODO: Move to FluentBogus exemple project
+
+ //[Fact]
+ //public void Should_FakeOne_PersonModel_WithDefaultFaker()
+ //{
+ // // Arrange
+
+ // // Act
+ // var model = FluentBogusBuilder
+ // .Fake()
+ // .WithDefault()
+ // .Generate();
+
+ // // Assert
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().NotBeNullOrEmpty();
+ // model.Relatives.Should().NotBeNullOrEmpty();
+ //}
+
+ //[Fact]
+ //public void Should_FakeOne_PersonModel_WithCustomFaker()
+ //{
+ // // Arrange
+
+ // // Act
+ // var model = FluentBogusBuilder
+ // .Fake()
+ // .With()
+ // .Generate();
+
+ // // Assert
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeNullOrEmpty();
+ // model.Relatives.Should().BeNullOrEmpty();
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithDefaultFaker(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .WithDefault()
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().NotBeNullOrEmpty(); // Neither PersonModel nor Default Faker initialize the collection
+ // model.Relatives.Should().NotBeNullOrEmpty(); // Neither PersonModel nor Default Faker initialize the collection
+ // }
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithCustomFaker(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .With()
+ // .Skip(e => e.Addresses)
+ // .Skip(e => e.Relatives)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // }
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithDefaultFaker_And_SkipNavigationProperties(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .WithDefault()
+ // .Skip(e => e.Addresses)
+ // .Skip(e => e.Relatives)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
+ // model.Relatives.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
+ // }
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithDefaultFaker_And_SkipNavigationPropertiesByArrray(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .WithDefault()
+ // .Skip(
+ // e => e.Addresses,
+ // e => e.Relatives)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
+ // model.Relatives.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
+ // }
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithCustomFaker_And_SkipNavigationProperties(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .With()
+ // .Skip(e => e.Addresses)
+ // .Skip(e => e.Relatives)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // }
+ //}
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithCustomFaker_And_SkipNavigationPropertiesByArrray(int count)
+ //{
+ // // Arrange
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .With()
+ // .Skip(
+ // e => e.Addresses,
+ // e => e.Relatives)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // }
+ //}
+
+
+ //[Theory]
+ //[InlineData(0)]
+ //[InlineData(1)]
+ //[InlineData(3)]
+ //public void Should_FakeMany_PersonModel_WithCustomFaker_And_ArgumentsOnCreation(int count)
+ //{
+ // // Arrange
+ // var ruleSet = "default"; // use , as separator to use multiple ruleset.
+
+ // // Act
+ // var models = FluentBogusBuilder
+ // .Fake()
+ // .With()
+ // .UseSeed(count)
+ // .Skip(
+ // e => e.Addresses,
+ // e => e.Relatives)
+ // .UseRuleSet(ruleSet)
+ // .Generate(count);
+
+ // // Assert
+ // models.Should()
+ // .NotBeNull()
+ // .And
+ // .HaveCount(count);
+
+ // foreach (var model in models)
+ // {
+ // model.Should().NotBeNull();
+ // model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
+ // }
+ //}
+}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusTest.cs b/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusTest.cs
deleted file mode 100644
index 58c5be7..0000000
--- a/NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusTest.cs
+++ /dev/null
@@ -1,282 +0,0 @@
-using FluentAssertions;
-
-using NineteenSevenFour.Testing.Example.Domain.Model;
-using NineteenSevenFour.Testing.FluentBogus.Extension;
-using NineteenSevenFour.Testing.FluentBogus.UnitTest.Faker;
-
-namespace NineteenSevenFour.Testing.FluentBogus.UnitTest;
-
-public class FluentBogusTest
-{
- [Fact]
- public void Should_FakeOne_PersonModel_WithDefaultFaker()
- {
- // Arrange
-
- // Act
- var model = FluentBogusBuilder
- .Fake()
- .WithDefault()
- .Generate();
-
- // Assert
- model.Should().NotBeNull();
- model.Addresses.Should().NotBeNullOrEmpty();
- model.Relatives.Should().NotBeNullOrEmpty();
- }
-
- [Fact]
- public void Should_FakeOne_PersonModel_WithCustomFaker()
- {
- // Arrange
-
- // Act
- var model = FluentBogusBuilder
- .Fake()
- .With()
- .Generate();
-
- // Assert
- model.Should().NotBeNull();
- model.Addresses.Should().BeNullOrEmpty();
- model.Relatives.Should().BeNullOrEmpty();
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithDefaultFaker(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .WithDefault()
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().NotBeNullOrEmpty(); // Neither PersonModel nor Default Faker initialize the collection
- model.Relatives.Should().NotBeNullOrEmpty(); // Neither PersonModel nor Default Faker initialize the collection
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithCustomFaker(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .With()
- .Skip(e => e.Addresses)
- .Skip(e => e.Relatives)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithDefaultFaker_And_SkipNavigationProperties(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .WithDefault()
- .Skip(e => e.Addresses)
- .Skip(e => e.Relatives)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
- model.Relatives.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithDefaultFaker_And_SkipNavigationPropertiesByArrray(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .WithDefault()
- .Skip(
- e => e.Addresses,
- e => e.Relatives)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
- model.Relatives.Should().BeNull(); // Neither PersonModel nor Default Faker initialize the collection
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithCustomFaker_And_SkipNavigationProperties(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .With()
- .Skip(e => e.Addresses)
- .Skip(e => e.Relatives)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithCustomFaker_And_SkipNavigationPropertiesByArrray(int count)
- {
- // Arrange
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .With()
- .Skip(
- e => e.Addresses,
- e => e.Relatives)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- }
- }
-
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(3)]
- public void Should_FakeMany_PersonModel_WithCustomFaker_And_ArgumentsOnCreation(int count)
- {
- // Arrange
- var ruleSet = "default"; // use , as separator to use multiple ruleset.
-
- // Act
- var models = FluentBogusBuilder
- .Fake()
- .With()
- .UseSeed(count)
- .Skip(
- e => e.Addresses,
- e => e.Relatives)
- .UseRuleSet(ruleSet)
- .Generate(count);
-
- // Assert
- models.Should()
- .NotBeNull()
- .And
- .HaveCount(count);
-
- foreach (var model in models)
- {
- model.Should().NotBeNull();
- model.Addresses.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- model.Relatives.Should().BeEmpty(); // The PersonFaker have a rule to initialize the collection
- }
- }
-
- [Fact]
- public void Should_ThrowInvalidOperationException_OnDuplicateSkipCall()
- {
- // Arrange
-
- // Act
-#pragma warning disable IDE0039 // Use local function
- var result = () => FluentBogusBuilder
- .Fake()
- .With()
- .Skip(
- e => e.Addresses,
- e => e.Addresses,
- e => e.Relatives)
- .Generate();
-#pragma warning restore IDE0039 // Use local function
-
- // Assert
- var exception = Assert.Throws(result);
- exception.Should().NotBeNull();
- exception.Message.Should().Be($"The property Addresses for type PersonModel is already set to be skipped.");
- }
-}
diff --git a/NineteenSevenFour.Testing.FluentBogus.UnitTest/NineteenSevenFour.Testing.FluentBogus.UnitTest.csproj b/NineteenSevenFour.Testing.FluentBogus.UnitTest/NineteenSevenFour.Testing.FluentBogus.UnitTest.csproj
index 1abaea3..9871986 100644
--- a/NineteenSevenFour.Testing.FluentBogus.UnitTest/NineteenSevenFour.Testing.FluentBogus.UnitTest.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus.UnitTest/NineteenSevenFour.Testing.FluentBogus.UnitTest.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+ True
+ True
+ ..\nineteensevenfour-public.snk
..\NineteenFourSeven_logo.ico
diff --git a/NineteenSevenFour.Testing.FluentBogus/FluentBogusBuilder[TFaker].cs b/NineteenSevenFour.Testing.FluentBogus/FluentBogusBuilder[TFaker].cs
index 920166b..2c89c83 100644
--- a/NineteenSevenFour.Testing.FluentBogus/FluentBogusBuilder[TFaker].cs
+++ b/NineteenSevenFour.Testing.FluentBogus/FluentBogusBuilder[TFaker].cs
@@ -12,13 +12,13 @@ public class FluentBogusBuilder : FluentBogusBuilder,
where TFaker : AutoFaker, new()
where TEntity : class
{
- private Action? fakerConfigBuilder;
- private AutoFaker? faker;
- private object?[]? fakerArgs;
- private int seed;
- private readonly List skipProperties = new();
- private readonly List ruleSets = new();
- private string RuleSetString => string.Join(",", ruleSets);
+ internal Action? fakerConfigBuilder;
+ internal AutoFaker? faker;
+ internal object?[]? fakerArgs;
+ internal int seed;
+ internal readonly List skipProperties = new();
+ internal readonly List ruleSets = new();
+ internal string RuleSetString => string.Join(",", ruleSets);
internal void SkipInternal(Expression> expr)
{
@@ -94,7 +94,7 @@ internal void ConfigureFakerInternal(IAutoGenerateConfigBuilder builder)
}
}
- internal void EnsureFaker()
+ internal void EnsureFakerInternal()
{
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
faker = (AutoFaker)Activator.CreateInstance(typeof(TFaker), fakerArgs);
@@ -120,7 +120,7 @@ public FluentBogusBuilder(params object?[]? args)
/// >
public ICollection Generate(int count)
{
- EnsureFaker();
+ EnsureFakerInternal();
#pragma warning disable CS8602 // Dereference of a possibly null reference.
return faker
#pragma warning restore CS8602 // Dereference of a possibly null reference.
@@ -132,7 +132,7 @@ public ICollection Generate(int count)
/// >
public TEntity Generate()
{
- EnsureFaker();
+ EnsureFakerInternal();
#pragma warning disable CS8602 // Dereference of a possibly null reference.
return faker
#pragma warning restore CS8602 // Dereference of a possibly null reference.
@@ -160,10 +160,6 @@ public IFluentBogusBuilder Skip(params Expression>
public IFluentBogusBuilder Skip(Expression> property)
{
- if (property == null)
- {
- throw new ArgumentOutOfRangeException(nameof(property), $"A valid expression to a property must be provided.");
- }
SkipInternal(property);
return this;
}
@@ -183,10 +179,8 @@ public IFluentBogusBuilder UseRuleSet(params string[] rulesets)
throw new ArgumentOutOfRangeException(nameof(rulesets), $"A List of ruleset must be provided.");
}
- foreach (var rule in rulesets)
- {
- UseRuleSetInternal(rule);
- }
+ UseRuleSetInternal(rulesets);
+
return this;
}
diff --git a/NineteenSevenFour.Testing.FluentBogus/NineteenSevenFour.Testing.FluentBogus.csproj b/NineteenSevenFour.Testing.FluentBogus/NineteenSevenFour.Testing.FluentBogus.csproj
index cdb61e9..d73789d 100644
--- a/NineteenSevenFour.Testing.FluentBogus/NineteenSevenFour.Testing.FluentBogus.csproj
+++ b/NineteenSevenFour.Testing.FluentBogus/NineteenSevenFour.Testing.FluentBogus.csproj
@@ -30,7 +30,7 @@
-
+
@@ -53,4 +53,12 @@
+
+
+
+
+
+
+
+
diff --git a/NineteenSevenFour.Testing.FluentBogus/globals.cs b/NineteenSevenFour.Testing.FluentBogus/globals.cs
deleted file mode 100644
index 2490d82..0000000
--- a/NineteenSevenFour.Testing.FluentBogus/globals.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-
-using System.Runtime.CompilerServices;
-
-[assembly: InternalsVisibleTo("NineteenSevenFour.Testing.FluentMapper, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e114a017453ade67701d8efc0553940300ac3dd115f674722bd08adeb6931852e10d08d0c41176cd1f73ebe5b7558441efdc0e9e664d99dd3980c3305ed338072852ed74b8cbab3d53c54de5e8ba34b32e17cd2969f7393f161b3f98aeaeacef61c92465a3264118327ec551d6b6286192d111c550ee1f0275fdb3df15d109c0")]