Skip to content

Commit

Permalink
Fixes issue with recursive constructor stack interfering with multi g…
Browse files Browse the repository at this point in the history
…eneration via AutoFaker<T>

#158
  • Loading branch information
soenneker committed May 12, 2024
1 parent bf9e1ff commit fdbb39f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/AutoFaker{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private void PrepareFinish(AutoFakerContext context)
}
}

context.RecursiveConstructorStack.Clear();
context.Binder.PopulateMembers(instance, context, cachedType, finalAutoMembers);

// Ensure the default finish with is invoke
Expand Down
3 changes: 1 addition & 2 deletions src/Generators/Types/BigIntegerGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Numerics;
using System.Numerics;
using Soenneker.Utils.AutoBogus.Context;
using Soenneker.Utils.AutoBogus.Generators.Abstract;

Expand Down
1 change: 0 additions & 1 deletion test/Soenneker.Utils.AutoBogus.Tests/AutoFakerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using FluentAssertions;
using Soenneker.Utils.AutoBogus.Config;
using Soenneker.Utils.AutoBogus.Config.Abstract;
using Soenneker.Utils.AutoBogus.Tests.Dtos;
using Soenneker.Utils.AutoBogus.Tests.Dtos.Complex;
using Soenneker.Utils.AutoBogus.Tests.Dtos.Simple;
using Soenneker.Utils.AutoBogus.Tests.Dtos.Simple.Abstract;
Expand Down
18 changes: 18 additions & 0 deletions test/Soenneker.Utils.AutoBogus.Tests/AutoFaker{T}Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,22 @@ public void Generate_with_set_RepeatCount_should_generate_correct_count()
CustomOrder order = autoFaker.Generate();
order.Items.Count().Should().Be(3);
}

[Fact]
public void Generate_budget_and_budget_entries_should_generate()
{
Budget? budget = new AutoFaker<Budget>()
.RuleFor(c => c.IsActive, true)
.Ignore(c => c.BudgetEntries)
.Generate();

budget.Should().NotBeNull();

List<BudgetEntry>? budgetEntries = new AutoFaker<BudgetEntry>()
.RuleFor(c => c.Budget, c => budget)
.Ignore(c => c.Currency)
.Generate(10);

budgetEntries.ForEach(c => c.Should().NotBeNull());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Soenneker.Utils.AutoBogus.Tests.Dtos.Complex.Abstract;

public interface ISoftDeleted
{
}
21 changes: 21 additions & 0 deletions test/Soenneker.Utils.AutoBogus.Tests/Dtos/Complex/Budget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using Soenneker.Utils.AutoBogus.Tests.Dtos.Complex.Abstract;

namespace Soenneker.Utils.AutoBogus.Tests.Dtos.Complex;

public partial class Budget : ISoftDeleted
{
public int Id { get; set; }

public string Name { get; set; }

public bool IsActive { get; set; }

public bool IsDeleted { get; set; }

public ICollection<BudgetEntry> BudgetEntries { get; set; }
public Budget()
{
BudgetEntries = new HashSet<BudgetEntry>();
}
}
21 changes: 21 additions & 0 deletions test/Soenneker.Utils.AutoBogus.Tests/Dtos/Complex/BudgetEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Bogus.DataSets;

namespace Soenneker.Utils.AutoBogus.Tests.Dtos.Complex;

public partial class BudgetEntry
{
public int Id { get; set; }

public int CurrencyId { get; set; }

public decimal Amount { get; set; }

public DateTime Date { get; set; }

public int BudgetId { get; set; }

public virtual Budget Budget { get; set; }

public virtual Currency Currency { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;
using Soenneker.Utils.AutoBogus.Tests.Enums;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.Immutable;

namespace Soenneker.Utils.AutoBogus.Tests.Dtos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Numerics;

namespace Soenneker.Utils.AutoBogus.Tests.TestData;

Expand Down

0 comments on commit fdbb39f

Please sign in to comment.