SFBLITesterTools 1.2.1
dotnet add package SFBLITesterTools --version 1.2.1
NuGet\Install-Package SFBLITesterTools -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SFBLITesterTools" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SFBLITesterTools" Version="1.2.1" />
<PackageReference Include="SFBLITesterTools" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SFBLITesterTools --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SFBLITesterTools, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SFBLITesterTools@1.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SFBLITesterTools&version=1.2.1
#tool nuget:?package=SFBLITesterTools&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SFBLITesterTools
A powerful .NET 8 library that simplifies unit testing by automatically creating test objects with realistic dummy data. Use reflection and fluent configuration to generate complex object graphs while maintaining full control over specific property values.
๐ Quick Start
using SFBLITesterTools.Tools;
// Create a test object with dummy data
var customer = TesterHelper.For<Customer>().Create();
// Create with specific property values
var customCustomer = TesterHelper.For<Customer>()
.With(c => c.Name, "John Doe")
.With(c => c.Email, "john@example.com")
.WithNull(c => c.Address) // Explicitly set to null
.Create();
โจ Key Features
- ๐ฏ Type-safe property configuration using lambda expressions
- ๐ง Automatic dummy data generation for all .NET primitive types
- ๐๏ธ Complex object graph creation with nested objects and collections
- ๐ Private constructor support - creates instances even with private/internal constructors
- ๐ Init-only property support - full C# 9+
init
property compatibility - ๐ Private property access via reflection and backing field manipulation
- โป๏ธ Circular reference protection with configurable depth limits
- ๐ Collection handling (Lists, Arrays, Dictionaries)
- ๐๏ธ Explicit null control to distinguish between "not set" and "explicitly null"
- โ Nullable reference type support with proper compiler satisfaction
๐ Usage Examples
Basic Object Creation
public class Product
{
public string Name { get; set; }
public decimal Price { get; set; }
public bool IsActive { get; set; }
public DateTime CreatedDate { get; set; }
}
// Simple creation with all dummy values
var product = TesterHelper.For<Product>().Create();
// Result: Name="DummyString", Price=42, IsActive=true, CreatedDate=2024-01-01
Property Customization
public class Order
{
public string OrderId { get; set; }
public DateTime OrderDate { get; set; }
public decimal Total { get; set; }
public Customer Customer { get; set; }
public List<OrderItem> Items { get; set; }
}
var customOrder = TesterHelper.For<Order>()
.With(o => o.OrderId, "ORD-12345")
.With(o => o.OrderDate, DateTime.Now)
.With(o => o.Total, 299.99m)
.Create();
// Customer and Items will be automatically populated with dummy data
Null Handling
public class User
{
public string Username { get; set; }
public string? Email { get; set; } // Nullable
public Profile? Profile { get; set; } // Nullable object
}
var userWithNulls = TesterHelper.For<User>()
.With(u => u.Username, "testuser")
.WithNull(u => u.Email) // Explicitly null
.WithNull(u => u.Profile) // Explicitly null
.Create();
Init-Only Properties (C# 9+)
public record PersonRecord
{
public string FirstName { get; init; } = string.Empty;
public string LastName { get; init; } = string.Empty;
public int Age { get; init; }
public DateTime BirthDate { get; init; }
}
var person = TesterHelper.For<PersonRecord>()
.With(p => p.FirstName, "Jane")
.With(p => p.Age, 25)
.Create();
// LastName and BirthDate get dummy values, init properties work perfectly
Private Constructor Support
public class Singleton
{
public string Name { get; set; }
public int Value { get; set; }
private Singleton() { } // Private constructor
public static Singleton Instance { get; } = new();
}
// Works automatically - finds and uses private constructor
var testSingleton = TesterHelper.For<Singleton>()
.With(s => s.Name, "Test Instance")
.Create();
Nested Objects and Collections
public class Company
{
public string Name { get; set; }
public Address HeadOffice { get; set; }
public List<Employee> Employees { get; set; }
public Dictionary<string, string> Metadata { get; set; }
}
public class Employee
{
public string Name { get; set; }
public string Department { get; set; }
public decimal Salary { get; set; }
}
var company = TesterHelper.For<Company>()
.With(c => c.Name, "Acme Corp")
.WithMaxDepth(3) // Control nesting depth
.Create();
// Result:
// - HeadOffice will be a populated Address object
// - Employees will contain Employee objects with dummy data
// - Metadata will contain at least one key-value pair
Depth Control
public class BlogPost
{
public string Title { get; set; }
public Author Author { get; set; }
public List<Comment> Comments { get; set; }
}
public class Comment
{
public string Text { get; set; }
public Author Author { get; set; } // Could cause deep nesting
}
var blogPost = TesterHelper.For<BlogPost>()
.WithMaxDepth(2) // Prevent excessive nesting
.Create();
๐ง Default Dummy Values
Type | Generated Value |
---|---|
string |
"DummyString" |
int |
42 |
decimal |
42.0m |
bool |
true |
DateTime |
January 1, 2024 |
Guid |
Random GUID |
Enum |
First defined value |
List<T> |
Single-item list |
Array |
Single-item array |
Dictionary<K,V> |
Single key-value pair |
๐ฏ API Reference
Core Methods
Method | Description |
---|---|
TesterHelper.For<T>() |
Start building an object of type T |
.With<TProp>(expr, value) |
Set a specific property value |
.WithNull<TProp>(expr) |
Explicitly set a nullable property to null |
.WithMaxDepth(int) |
Set maximum nesting depth (default: 3) |
.Create() |
Build and return the configured object |
Usage Patterns
// Minimal setup
var obj = TesterHelper.For<MyClass>().Create();
// Full configuration
var obj = TesterHelper.For<MyClass>()
.With(x => x.Property1, "custom value")
.With(x => x.Property2, 100)
.WithNull(x => x.NullableProperty)
.WithMaxDepth(2)
.Create();
๐ฆ Installation
NuGet Package
dotnet add package SFBLITesterTools
Package Manager Console
Install-Package SFBLITesterTools
Project Reference
<ItemGroup>
<ProjectReference Include="path\to\SFBLITesterTools.csproj" />
</ItemGroup>
๐งช Testing Scenarios
Unit Test Example
[Test]
public void CalculateOrderTotal_ShouldSumItemPrices()
{
// Arrange
var order = TesterHelper.For<Order>()
.With(o => o.Items, new List<OrderItem>
{
TesterHelper.For<OrderItem>().With(i => i.Price, 10.00m).Create(),
TesterHelper.For<OrderItem>().With(i => i.Price, 15.00m).Create()
})
.Create();
var calculator = new OrderCalculator();
// Act
var total = calculator.CalculateTotal(order);
// Assert
Assert.AreEqual(25.00m, total);
}
Testing Null Scenarios
[Test]
public void ProcessUser_WithNullEmail_ShouldHandleGracefully()
{
// Arrange
var user = TesterHelper.For<User>()
.With(u => u.Name, "Test User")
.WithNull(u => u.Email) // Explicitly null
.Create();
var processor = new UserProcessor();
// Act & Assert
Assert.DoesNotThrow(() => processor.Process(user));
}
โ ๏ธ Limitations
- Readonly fields cannot be modified after construction
- Static properties are not supported
- Abstract classes cannot be instantiated directly
- Complex generic constraints may require manual handling
- Performance overhead from reflection (test-only usage recommended)
๐ฏ Best Practices
- Use only in test projects - not intended for production code
- Set reasonable depth limits for complex object graphs
- Override critical properties explicitly rather than relying on defaults
- Use
WithNull()
explicitly when testing null-handling scenarios - Combine with test data builders for complex test scenarios
- Leverage init properties for immutable test objects
๐ Version History
- v1.2.1 - Fixed nullable reference type support in
WithNull()
method - v1.1.0 - Added init-only property support
- v1.0.0 - Initial release with core functionality
๐ License
MIT License - see LICENSE file for details
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add comprehensive tests
- Submit a pull request
Built for .NET 8 | Designed for Unit Testing | Powered by Reflection
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.2.1 | 11 | 8/11/2025 |