Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soenneker committed Oct 17, 2024
1 parent 24f436c commit c96d5d3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/Soenneker.Utils.AutoBogus.Tests/AutoFakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,25 @@ public void TestClassWithPrivateProperty_should_be_null()
obj.GetValue().Should().BeNull();
}

[Fact]
public void TestClassWithTupleStringString_should_not_be_null()
{
var autoFaker = new AutoFaker();

var obj = autoFaker.Generate<TestClassWithTupleStringString>();
obj.Value.Item1.Should().NotBeNull();
obj.Value.Item2.Should().NotBeNull();
}

[Fact]
public void TestClassWithNullableInt_should_not_be_null()
{
var autoFaker = new AutoFaker();

var obj = autoFaker.Generate<TestClassWithNullableInt>();
obj.Value.Should().NotBeNull();
}

[Fact]
public void UseSeed_should_generate_same_value()
{
Expand Down
23 changes: 23 additions & 0 deletions test/Soenneker.Utils.AutoBogus.Tests/AutoFaker{T}Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,27 @@ public void TestClassWithFuncCtor_should_be_null()
TestClassWithFuncCtor<int> obj = autoFaker.Generate();
obj.Should().BeNull();
}

[Fact]
public void TestClass_with_rule_should_be_empty()
{
var autoFaker = new AutoFaker<TestClassWithListString>().RuleFor(c => c.Value, new List<string>());
var result = autoFaker.Generate();

result.Value.Should().BeEmpty();
}

[Fact]
public void TestClassWithCollectionBackedByReadOnlyCollection_with_rule_should_be_empty()
{
var config = new AutoFakerConfig
{
RecursiveDepth = 0
};

var autoFaker = new AutoFaker<TestClassWithCollectionBackedByReadOnlyCollection<string>>(config).RuleFor(c => c.PublicList, new List<string>());
var result = autoFaker.Generate();

result.PublicList.Should().BeEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

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

public class TestClassWithCollectionBackedByReadOnlyCollection<T>
{
public IReadOnlyCollection<T> PublicList { get; private set; }

protected ICollection<T> InternalList => (ICollection<T>)PublicList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

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

public class TestClassWithListString
{
public List<string> Value { get; set; } = default!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

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

public class TestClassWithNullableInt
{
public Nullable<int> Value { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Soenneker.Utils.AutoBogus.Tests.Dtos.Simple;

public class TestClassWithTupleStringString
{
public (string, string) Value { get; set; }
}

0 comments on commit c96d5d3

Please sign in to comment.