Franz.Common.Testing
1.2.64
dotnet add package Franz.Common.Testing --version 1.2.64
NuGet\Install-Package Franz.Common.Testing -Version 1.2.64
<PackageReference Include="Franz.Common.Testing" Version="1.2.64" />
paket add Franz.Common.Testing --version 1.2.64
#r "nuget: Franz.Common.Testing, 1.2.64"
// Install Franz.Common.Testing as a Cake Addin #addin nuget:?package=Franz.Common.Testing&version=1.2.64 // Install Franz.Common.Testing as a Cake Tool #tool nuget:?package=Franz.Common.Testing&version=1.2.64
Franz.Common.Testing
A library within the Franz Framework designed to enhance unit testing in .NET applications. This package simplifies test development by integrating with popular testing frameworks and providing utilities for mock setups and fluent assertions.
Features
- Unit Testing Simplification:
- Includes
UnitTest
base class to standardize test setup and execution.
- Includes
- Fluent Assertions:
- Integrates FluentAssertions for writing readable and expressive assertions.
- Mocking Support:
- Utilizes Moq and MockQueryable.Moq for creating and managing mock objects.
- Includes Moq.AutoMock for automatic mock generation.
- Resource Management:
- Provides
Resources.resx
for managing test-specific resources.
- Provides
Version Information
- Current Version: 1.2.64
- Part of the private Franz Framework ecosystem.
Dependencies
This package leverages the following dependencies:
- FluentAssertions (6.12.0): For fluent and expressive test assertions.
- MockQueryable.Moq (7.0.0): Simplifies mocking IQueryable and LINQ queries.
- Moq.AutoMock (3.5.0): Automates the creation of mocks for dependency injection scenarios.
Installation
From Private Azure Feed
Since this package is hosted privately, configure your NuGet client:
dotnet nuget add source "https://your-private-feed-url" \
--name "AzurePrivateFeed" \
--username "YourAzureUsername" \
--password "YourAzurePassword" \
--store-password-in-clear-text
Install the package:
dotnet add package Franz.Common.Testing --Version 1.2.64
Usage
1. Create Unit Tests Using the Base Class
Leverage the UnitTest
base class for consistent test initialization:
using Franz.Common.Testing;
public class MyUnitTest : UnitTest
{
[Fact]
public void TestExample()
{
// Arrange
var value = 1;
// Act
value++;
// Assert
value.Should().Be(2);
}
}
2. Use Fluent Assertions
Write expressive and readable assertions with FluentAssertions:
[Fact]
public void String_ShouldContainExpectedValue()
{
// Arrange
var result = "Hello, Franz Framework!";
// Assert
result.Should().Contain("Franz");
}
3. Mock LINQ Queries
Use MockQueryable.Moq to mock IQueryable data sources:
using MockQueryable.Moq;
using Moq;
[Fact]
public void ShouldReturnFilteredData()
{
// Arrange
var mockData = new List<string> { "Alice", "Bob", "Charlie" }.AsQueryable().BuildMock();
var repository = new Mock<IRepository>();
repository.Setup(r => r.GetData()).Returns(mockData.Object);
// Act
var result = repository.Object.GetData().Where(x => x.Contains("a"));
// Assert
result.Should().Contain("Charlie").And.NotContain("Bob");
}
4. Automate Mock Creation
Simplify mock setups with Moq.AutoMock:
using Moq.AutoMock;
[Fact]
public void ShouldInjectDependenciesAutomatically()
{
// Arrange
var mocker = new AutoMocker();
var service = mocker.CreateInstance<MyService>();
// Act
service.DoSomething();
// Assert
mocker.GetMock<IDependency>().Verify(d => d.PerformAction(), Times.Once);
}
Integration with Franz Framework
The Franz.Common.Testing package integrates seamlessly with other Franz Framework packages, providing consistent and efficient testing utilities for the ecosystem.
Contributing
This package is part of a private framework. Contributions are limited to the internal development team. If you have access, follow these steps:
- Clone the repository. @ https://github.com/bestacio89/Franz.Common/
- Create a feature branch.
- Submit a pull request for review.
License
This library is licensed under the MIT License. See the LICENSE
file for more details.
Changelog
Version 1.2.64
- Added
UnitTest
base class for standardized test setup. - Integrated FluentAssertions for fluent and expressive assertions.
- Added support for MockQueryable.Moq and Moq.AutoMock for efficient mocking.
- Provided
Resources.resx
for managing test-specific resources.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- FluentAssertions (>= 8.0.1)
- MockQueryable.Moq (>= 7.0.3)
- Moq.AutoMock (>= 3.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.