CreateAndFake 0.5.69-alpha

This is a prerelease version of CreateAndFake.
There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package CreateAndFake --version 0.5.69-alpha
NuGet\Install-Package CreateAndFake -Version 0.5.69-alpha
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="CreateAndFake" Version="0.5.69-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CreateAndFake --version 0.5.69-alpha
#r "nuget: CreateAndFake, 0.5.69-alpha"
#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 CreateAndFake as a Cake Addin
#addin nuget:?package=CreateAndFake&version=0.5.69-alpha&prerelease

// Install CreateAndFake as a Cake Tool
#tool nuget:?package=CreateAndFake&version=0.5.69-alpha&prerelease

Create & Fake

Appveyor Build status Travis Build Status Codacy Grade CodeCov Coverage

A C# class library in .NET Core designed to make testing a breeze and ultimately change the way developers think about testing. It handles the bulk of the work in creating data to test with, as well as providing mocking and stubbing behavior. Utilizing the tools provided will save a ton of time and make test code far cleaner as well as simpler.

Installation

The library is completely self-contained and requires no dependencies other than .NET Core 2.0. The recommended way to include the library is through a NuGet package reference inside your project under the name "CreateAndFake." Alternatively, binaries can be pulled from the build server linked above under artifacts or compiled manually.

Contributing

If you're looking to contribute, thanks for your interest. Feel free to submit reports for any issues you can find, or request potential features you'd like to see here. I am not looking for code contributions at this time however, so it's unlikely I'll accept any pull requests.

Functionality

The library provides a handful of tools that are both easy to use and customizable should the need arise:

  • Randomizer - Creates random instances of any type.
  • Randiffer - Creates random variants of objects.
  • Duplicator - Creates deep clones of objects.
  • Valuer - Compares objects by value.
  • Faker - Creates mocks and stubs.
  • Asserter - Handles common test scenarios.

One of the benefits of this library is that the tools are logically integrated with each other. For example, the randomizer will use stubs for interfaces that have no known implementations in the code. Or the mocks created by the faker utilize value equality in matching arguments.

Randomization and Equality Example

Imagine you have a class with a ton of data that you've marked with ISerializable. How do you verify that it, you know, actually serializes properly? You'd have to create an instance, populate it with data (which might be no small feat), then serialize it. But wait, are you sure the data actually serialized? You'll need to deserialize it, and probably create equality functions to handle figuring out if your data did in fact make it.

At the end of this you'll have a rather large test that you spent more time setting up than actually testing behavior, and then you have issues. The test has to change every time you change a property on the data class. What happens when a developer forgets to update the test when they added a new property? Potentially, your class now doesn't work correctly and your test is still green. At base, you only know your code works with that specific instance of canned data.

With those considerations in mind, I present to you the solution:

/// <summary>Verifies that class data can make a roundtrip.</summary>
[TestMethod]
public void DataHolder_BinarySerializes()
{
    DataHolder original = Tools.Randomizer.Create<DataHolder>();
    IFormatter formatter = new BinaryFormatter();
    
    using (Stream stream = new MemoryStream())
    {
        formatter.Serialize(stream, original);
        stream.Seek(0, SeekOrigin.Begin);
        
        Tools.Asserter.ValuesEqual(original, formatter.Deserialize(stream));
    }
}

Quick, easy, and most importantly functional. Visit the wiki for more information about these tools as well as others provided.

Mocking Example

The Faker tool provides mocks and stubs in a typical lambda based style with a very methodical structure:

/// <summary>Verifies setup functionality.</summary>
[TestMethod]
public void Setup_ObjectEquality()
{
    object data = new object();
    
    Fake<object> fake = Tools.Faker.Mock<object>();
    fake.Setup(
        d => d.Equals(Arg.Any<object>()),
        Behavior.Set((object o) => { return false; }));
    fake.Setup(
        d => d.Equals(data),
        Behavior.Returns(true, Times.Once));
        
    Tools.Asserter.Is(false, fake.Dummy.Equals(new object()));
    Tools.Asserter.Is(true, fake.Dummy.Equals(data));
    
    fake.Verify(2);
}

Please visit the wiki for more information.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.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.10.2 95 1/31/2024
1.10.1 79 1/31/2024
1.10.0 98 1/16/2024
1.9.14 654 8/26/2021
1.9.13 384 8/26/2021
1.9.12 318 8/6/2021
1.9.11 726 6/21/2021
1.9.10 403 5/2/2021
1.9.9 499 4/10/2021
1.9.8 396 3/13/2021
1.9.7 344 3/2/2021
1.9.6 320 3/1/2021
1.9.5 323 2/20/2021
1.9.4 348 2/19/2021
1.9.3 346 2/17/2021
1.9.2 328 2/13/2021
1.9.1 363 2/7/2021
1.9.0 337 2/4/2021
1.8.4 471 1/29/2021
1.8.3 363 1/27/2021
1.8.2 815 12/16/2019
1.8.1 511 12/9/2019
1.8.0 504 11/18/2019
1.7.6 494 10/23/2019
1.7.5 510 10/18/2019
1.7.4 543 10/15/2019
1.7.3 486 10/7/2019
1.7.2 510 10/1/2019
1.7.1 503 9/25/2019
1.7.0 517 9/20/2019
1.6.5 1,629 7/16/2018
1.6.4 1,098 7/9/2018
1.6.3 1,102 6/27/2018
1.6.2 1,122 6/25/2018
1.6.1 1,125 6/20/2018
1.6.0 1,099 6/7/2018
1.5.1 1,105 6/7/2018
1.5.0 1,077 6/4/2018
1.4.1 1,274 5/20/2018
1.4.0 1,310 5/15/2018