Skip to content

Commit 53946cf

Browse files
committed
Updated projects after migration
1 parent e20868e commit 53946cf

File tree

9 files changed

+116
-372
lines changed

9 files changed

+116
-372
lines changed

.github/workflows/continuous.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
- uses: actions/setup-dotnet@v4
3434
with:
3535
dotnet-version: |
36-
5.0.x
3736
6.0.x
3837
- name: Cache .nuke/temp, ~/.nuget/packages
3938
uses: actions/cache@v4

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
- uses: actions/setup-dotnet@v4
3333
with:
3434
dotnet-version: |
35-
5.0.x
3635
6.0.x
3736
- name: Cache .nuke/temp, ~/.nuget/packages
3837
uses: actions/cache@v4

AutoFixture.sln

Lines changed: 1 addition & 260 deletions
Large diffs are not rendered by default.

Common.Test.xUnit.props

Lines changed: 0 additions & 9 deletions
This file was deleted.

Common.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
<!-- NuGet options -->
2828
<Authors>AutoFixture Contributors</Authors>
29-
<PackageProjectUrl>https://github.com/AutoFixture/AutoFixture</PackageProjectUrl>
29+
<PackageProjectUrl>https://github.com/AutoFixture/AutoFixture.xUnit</PackageProjectUrl>
3030
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3131
<PackageLicenseExpression>MIT</PackageLicenseExpression>
3232
<PackageIconUrl>https://raw.githubusercontent.com/AutoFixture/AutoFixture/79c882c3f4af3cf52ad43e5c95851f25d217ac17/AutoFixtureLogo200x200.png</PackageIconUrl>
3333
<PackageIcon>icon.png</PackageIcon>
34+
<PackageReadmeFile>README.md</PackageReadmeFile>
3435
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
3536
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3637
</PropertyGroup>
@@ -40,6 +41,7 @@
4041
</ItemGroup>
4142

4243
<ItemGroup>
44+
<None Include="$(MSBuildThisFileDirectory)\README.md" Pack="true" PackagePath="\" />
4345
<None Include="$(MSBuildThisFileDirectory)\AutoFixtureLogo200x200.png" Pack="true" PackagePath="icon.png"/>
4446
</ItemGroup>
4547

README.md

Lines changed: 107 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,146 @@
1-
# AutoFixture
1+
# AutoFixture.xUnit
22

3-
[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/AutoFixture/AutoFixture/master/LICENCE.txt)
4-
[![release](https://github.com/AutoFixture/AutoFixture/actions/workflows/release.yml/badge.svg)](https://github.com/AutoFixture/AutoFixture/actions/workflows/release.yml)
5-
[![NuGet version](https://img.shields.io/nuget/v/AutoFixture?logo=nuget)](https://www.nuget.org/packages/AutoFixture)
6-
[![NuGet preview version](https://img.shields.io/nuget/vpre/AutoFixture?logo=nuget)](https://www.nuget.org/packages/AutoFixture)
7-
[![NuGet downloads](https://img.shields.io/nuget/dt/AutoFixture)](https://www.nuget.org/packages/AutoFixture)
8-
<a href="https://x.com/AutoFixture">
9-
<img src="https://img.shields.io/twitter/follow/AutoFixture?label=%40AutoFixture" alt="AutoFixture" align="right" />
10-
</a>
3+
[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/AutoFixture/AutoFixture.xUnit/master/LICENCE.txt)
4+
[![NuGet version](https://img.shields.io/nuget/v/AutoFixture.xUnit?logo=nuget)](https://www.nuget.org/packages/AutoFixture.xUnit)
5+
[![NuGet preview version](https://img.shields.io/nuget/vpre/AutoFixture.xUnit?logo=nuget)](https://www.nuget.org/packages/AutoFixture.xUnit)
6+
[![NuGet downloads](https://img.shields.io/nuget/dt/AutoFixture.xUnit)](https://www.nuget.org/packages/AutoFixture.xUnit)
117

12-
Write maintainable unit tests, faster.
8+
[AutoFixture.xUnit](https://github.com/AutoFixture/AutoFixture.xUnit) is a .NET library that integrates [AutoFixture](https://github.com/AutoFixture/AutoFixture) with xUnit 1.x, allowing you to effortlessly generate test data for your unit tests.
9+
By automatically populating your test parameters, it helps you write cleaner, more maintainable tests without having to manually construct test objects.
1310

14-
AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.
15-
16-
Check the [testimonials](https://github.com/AutoFixture/AutoFixture/wiki/Who-uses-AutoFixture) to see what other people have to say about AutoFixture.
11+
> [!WARNING]
12+
> While this package is still being developed, the xUnit 1 package is deprecated.<br/>
13+
> This package is intended only for legacy projects that are still using xUnit 1.x.<br/>
1714
1815
## Table of Contents
1916

20-
- [Overview](#overview)
21-
- [Downloads](#downloads)
22-
- [Documentation](#documentation)
23-
- [Feedback & Questions](#feedback--questions)
17+
- [Installation](#installation)
18+
- [Getting Started](#getting-started)
19+
- [Integrations](#integrations)
20+
- [Contributing](#contributing)
2421
- [License](#license)
2522

26-
## Overview
23+
## Installation
24+
25+
AutoFixture packages are distributed via NuGet.<br />
26+
To install the packages you can use the integrated package manager of your IDE, the .NET CLI, or reference the package directly in your project file.
27+
28+
```cmd
29+
dotnet add package AutoFixture.xUnit --version x.x.x
30+
```
31+
32+
```xml
33+
<PackageReference Include="AutoFixture.xUnit" Version="x.x.x" />
34+
```
2735

28-
(Jump straight to the [CheatSheet](https://github.com/AutoFixture/AutoFixture/wiki/Cheat-Sheet) if you just want to see some code samples right away.)
36+
## Getting Started
2937

30-
AutoFixture is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test's Fixture Setup phase. Among other features, it offers a generic implementation of the [Test Data Builder](http://www.natpryce.com/articles/000714.html) pattern.
38+
### Basic Usage
3139

32-
When writing unit tests, you typically need to create some objects that represent the initial state of the test. Often, an API will force you to specify much more data than you really care about, so you frequently end up creating objects that has no influence on the test, simply to make the code compile.
40+
`AutoFixture.xUnit` provides an `[AutoData]` attribute that automatically populates test method parameters with generated data.
3341

34-
AutoFixture can help by creating such [Anonymous Variables](https://docs.microsoft.com/en-us/archive/blogs/ploeh/anonymous-variables) for you. Here's a simple example:
42+
For example, imagine you have a simple calculator class:
3543

3644
```c#
37-
[Fact]
38-
public void IntroductoryTest()
45+
public class Calculator
3946
{
40-
// Arrange
41-
Fixture fixture = new Fixture();
42-
43-
int expectedNumber = fixture.Create<int>();
44-
MyClass sut = fixture.Create<MyClass>();
45-
// Act
46-
int result = sut.Echo(expectedNumber);
47-
// Assert
48-
Assert.Equal(expectedNumber, result);
47+
public int Add(int a, int b) => a + b;
4948
}
5049
```
5150

52-
This example illustrates the basic principle of AutoFixture: It can create values of virtually any type without the need for you to explicitly define which values should be used. The number *expectedNumber* is created by a call to `Create<T>` - this will create a 'nice', regular integer value, saving you the effort of explicitly coming up with one.
53-
54-
The example also illustrates how AutoFixture can be used as a [SUT Factory](http://blog.ploeh.dk/2009/02/13/SUTFactory.aspx) that creates the actual System Under Test (the MyClass instance).
55-
56-
Given the right combination of unit testing framework and extensions for AutoFixture, we can further reduce the above test to be even more declarative:
57-
58-
### [xUnit](http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx)
51+
You can write a test using AutoFixture to provide the input values:
5952

6053
```c#
61-
[Theory, AutoData]
62-
public void IntroductoryTest(int expectedNumber, MyClass sut)
54+
using Xunit;
55+
using AutoFixture.xUnit;
56+
57+
public class CalculatorTests
6358
{
64-
int result = sut.Echo(expectedNumber);
65-
Assert.Equal(expectedNumber, result);
59+
[Theory, AutoData]
60+
public void Add_SimpleValues_ReturnsCorrectResult(
61+
Calculator calculator, int a, int b)
62+
{
63+
// Act
64+
int result = calculator.Add(a, b);
65+
66+
// Assert
67+
Assert.AreEqual(a + b, result);
68+
}
6669
}
6770
```
6871

69-
### [NUnit](http://gertjvr.wordpress.com/2013/09/25/howto-autofixture-nunit2)
72+
### Inline Auto-Data
73+
74+
You can also combine auto-generated data with inline arguments using the `[InlineAutoData]` attribute.
75+
This allows you to specify some parameters while still letting AutoFixture generate the rest.
7076

7177
```c#
72-
[Test, AutoData]
73-
public void IntroductoryTest(int expectedNumber, MyClass sut)
78+
using Xunit;
79+
using AutoFixture.xUnit;
80+
using AutoFixture;
81+
82+
public class CalculatorTests
7483
{
75-
int result = sut.Echo(expectedNumber);
76-
Assert.Equal(expectedNumber, result);
84+
[Theory, InlineAutoData(5, 8)]
85+
public void Add_SpecificValues_ReturnsCorrectResult(
86+
int a, int b, Calculator calculator)
87+
{
88+
// Act
89+
int result = calculator.Add(a, b);
90+
91+
// Assert
92+
Assert.AreEqual(13, result);
93+
}
7794
}
7895
```
7996

80-
Notice how we can reduce unit tests to state only the relevant parts of the test. The rest (variables, Fixture object) is relegated to attributes and parameter values that are supplied automatically by AutoFixture. The test is now only two lines of code.
97+
### Freezing Dependencies
8198

82-
Using AutoFixture is as easy as referencing the library and creating a new instance of the Fixture class!
99+
AutoFixture's `[Frozen]` attribute can be used to ensure that the same instance of a dependency is injected into multiple parameters.
83100

84-
## Downloads
101+
For example, if you have a consumer class that depends on a shared dependency:
85102

86-
AutoFixture packages are distributed via NuGet.<br />
87-
To install the packages you can use the integrated package manager of your IDE, the .NET CLI, or reference the package directly in your project file.
103+
```c#
104+
public class Dependency { }
88105

89-
```cmd
90-
dotnet add package AutoFixture --version 4.18.0
106+
public class Consumer
107+
{
108+
public Dependency Dependency { get; }
109+
110+
public Consumer(Dependency dependency)
111+
{
112+
Dependency = dependency;
113+
}
114+
}
91115
```
92116

93-
```xml
94-
<PackageReference Include="AutoFixture" Version="4.18.0" />
117+
You can freeze the Dependency so that all requests for it within the test will return the same instance:
118+
119+
```c#
120+
using Xunit;
121+
using AutoFixture.xUnit;
122+
using AutoFixture;
123+
124+
public class ConsumerTests
125+
{
126+
[Theory, AutoData]
127+
public void Consumer_UsesSameDependency(
128+
[Frozen] Dependency dependency, Consumer consumer)
129+
{
130+
// Assert
131+
Assert.AreSame(dependency, consumer.Dependency);
132+
}
133+
}
95134
```
96135

136+
## Integrations
137+
97138
AutoFixture offers a variety of utility packages and integrations with most of the major mocking libraries and testing frameworks.
98139

140+
> [!NOTE]
141+
> Since AutoFixture tries maintain compatibility with a large number of package versions, the packages bundled with AutoFixture might not contain the latest features of your (e.g. mocking) library.<br />
142+
> Make sure to install the latest version of the integrated library package, alongside the AutoFixture packages.
143+
99144
### Core packages
100145

101146
The core packages offer the full set of AutoFixture's features without requring any testing framework or third party integration.
@@ -118,10 +163,6 @@ These integrations enable such features as configuring mocks, auto-injecting moc
118163
| FakeItEasy | [AutoFixture.AutoFakeItEasy](http://www.nuget.org/packages/AutoFixture.AutoFakeItEasy) | [![NuGet](https://img.shields.io/nuget/v/AutoFixture.AutoFakeItEasy)](https://www.nuget.org/packages/AutoFixture.AutoFakeItEasy) | [![NuGet](https://img.shields.io/nuget/vpre/AutoFixture.AutoFakeItEasy)](https://www.nuget.org/packages/AutoFixture.AutoFakeItEasy) | ![NuGet](https://img.shields.io/nuget/dt/autofixture.AutoFakeItEasy) |
119164
| Rhino Mocks | [AutoFixture.AutoRhinoMocks](http://www.nuget.org/packages/AutoFixture.AutoRhinoMocks) | [![NuGet](https://img.shields.io/nuget/v/AutoFixture.AutoRhinoMocks)](https://www.nuget.org/packages/AutoFixture.AutoRhinoMocks) | [![NuGet](https://img.shields.io/nuget/vpre/AutoFixture.AutoRhinoMocks)](https://www.nuget.org/packages/AutoFixture.AutoRhinoMocks) | ![NuGet](https://img.shields.io/nuget/dt/autofixture.AutoRhinoMocks) |
120165

121-
> **NOTE:**
122-
> Since AutoFixture tries maintain compatibility with a large number of package versions, the packages bundled with AutoFixture might not contain the latest features of your mocking library.<br />
123-
> Make sure to install the latest version of the mocking library package, alongside the AutoFixture package.
124-
125166
### Testing frameworks
126167

127168
AutoFixture offers integrations with most major .NET testing frameworks.<br />
@@ -139,41 +180,14 @@ These integrations enable auto-generation of test cases, combining auto-generate
139180

140181
You can check the compatibility with your target framework version on the [wiki](https://github.com/AutoFixture/AutoFixture/wiki#net-platforms-compatibility-table) or on the [NuGet](https://www.nuget.org/profiles/AutoFixture) website.
141182

142-
### vNext feed
143-
144-
The artifacts of the next major version are published to [nuget.org](https://www.nuget.org), and are marked with the `preview` suffix (e.g. `5.0.0-preview00007`).</br>
145-
You can use these packages to early access and test the next major version of the AutoFixture.</br>
146-
Make sure to enable the preview packages in your IDE in order to see the latest version.
147-
148-
> __NOTE:__ This preview versions exists for the _preview purpose_ only, so use them with caution:
149-
>
150-
>* New versions of packages might contain breaking changes and API could change drastically from package to package. By other words, we don't follow the SemVer policy for the packages in this feed;
151-
>* Preview packages might be unlisted over time, in order to not clutter the version suggestion dialog in IDEs, but will generally remain available
152-
153-
## Documentation
154-
155-
* [CheatSheet](https://github.com/AutoFixture/AutoFixture/wiki/Cheat-Sheet)
156-
* [FAQ](https://github.com/AutoFixture/AutoFixture/wiki/FAQ)
157-
158-
### Additional resources
159-
160-
* [Pluralsight course](https://www.pluralsight.com/courses/unit-testing-autofixture-dot-net)
161-
* [ploeh blog](http://blog.ploeh.dk/tags/#AutoFixture-ref)
162-
* [Nikos Baxevanis' blog](http://blog.nikosbaxevanis.com)
163-
* [Enrico Campidoglio's blog](http://megakemp.com/tag/autofixture)
164-
* [Gert Jansen van Rensburg's blog](http://gertjvr.wordpress.com/category/autofixture)
165-
* [Questions on Stack Overflow](http://stackoverflow.com/questions/tagged/autofixture)
166-
167-
## Feedback & Questions
168-
169-
If you have questions, feel free to ask. The best places to ask are:
183+
## Contributing
170184

171-
* [Stack Overflow - use the *autofixture* tag](http://stackoverflow.com/questions/tagged/autofixture)
172-
* [GitHub Q&A Discussions](https://github.com/AutoFixture/AutoFixture/discussions/categories/q-a)
185+
Contributions to `AutoFixture.xUnit` are welcome!
186+
If you would like to contribute, please review our [contributing guidelines](https://github.com/AutoFixture/AutoFixture.xUnit/blob/maste/CONTRIBUTING.md) and open an issue or pull request.
173187

174188
## License
175189

176-
AutoFixture is Open Source software and is released under the [MIT license](https://raw.githubusercontent.com/AutoFixture/AutoFixture/master/LICENCE.txt).<br />
190+
AutoFixture is Open Source software and is released under the [MIT license](https://raw.githubusercontent.com/AutoFixture/AutoFixture.xUnit/master/LICENCE.txt).<br />
177191
The licenses allows the use of AutoFixture libraries in free and commercial applications and libraries without restrictions.
178192

179193
### .NET Foundation

Src/AutoFixture.xUnit.UnitTest/AutoFixture.xUnit.UnitTest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
<Import Project="..\..\Common.Test.props" />
44

55
<PropertyGroup>
6-
<TargetFramework>net462</TargetFramework>
6+
<TargetFrameworks>net452;net462</TargetFrameworks>
77
<AssemblyTitle>AutoFixture.xUnit.net.UnitTest</AssemblyTitle>
88
<AssemblyName>AutoFixture.Xunit.UnitTest</AssemblyName>
99
<RootNamespace>AutoFixture.Xunit.UnitTest</RootNamespace>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="AutoFixture" Version="4.18.1" />
1314
<PackageReference Include="xunit" Version="1.9.2" />
1415
<PackageReference Include="xunit.extensions" Version="1.8.0.1549" />
1516
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
1617
</ItemGroup>
1718

1819
<ItemGroup>
19-
<ProjectReference Include="..\AutoFixture\AutoFixture.csproj" />
2020
<ProjectReference Include="..\AutoFixture.xUnit\AutoFixture.xUnit.csproj" />
2121
<ProjectReference Include="..\TestTypeFoundation\TestTypeFoundation.csproj" />
2222
</ItemGroup>

Src/AutoFixture.xUnit/AutoFixture.xUnit.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\Common.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net462</TargetFramework>
5+
<TargetFrameworks>net452;net462</TargetFrameworks>
66
<AssemblyTitle>AutoFixture.xUnit.net</AssemblyTitle>
77
<AssemblyName>AutoFixture.Xunit</AssemblyName>
88
<RootNamespace>AutoFixture.Xunit</RootNamespace>
@@ -14,13 +14,11 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17+
<PackageReference Include="AutoFixture" Version="4.18.1" />
1718
<PackageReference Include="xunit.extensions" Version="[1.8.0.1549,2.0.0)" />
1819
<!-- Isn't actually needed by this library, but is present as a NuGet guard to prevent installation of this package
1920
together with xUnit2 and higher. -->
2021
<PackageReference Include="xunit" Version="[1.8.0.1549,2.0.0)" />
2122
</ItemGroup>
2223

23-
<ItemGroup>
24-
<ProjectReference Include="..\AutoFixture\AutoFixture.csproj" />
25-
</ItemGroup>
2624
</Project>

Src/TestTypeFoundation/TestTypeFoundation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="..\..\Common.Test.props" />
44

55
<PropertyGroup>
6-
<TargetFrameworks>net462;netstandard2.0;net5.0;net6.0</TargetFrameworks>
6+
<TargetFrameworks>net452;net462;netstandard2.0</TargetFrameworks>
77
<AssemblyTitle>TestTypeFoundation</AssemblyTitle>
88
<AssemblyName>TestTypeFoundation</AssemblyName>
99
</PropertyGroup>

0 commit comments

Comments
 (0)