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                
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="Franz.Common.Testing" Version="1.2.64" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Franz.Common.Testing --version 1.2.64                
#r "nuget: Franz.Common.Testing, 1.2.64"                
#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.
// 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.
  • 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.

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:

  1. Clone the repository. @ https://github.com/bestacio89/Franz.Common/
  2. Create a feature branch.
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.64 3 1/29/2025
1.2.63 55 1/27/2025
1.2.62 57 1/8/2025