https://github.com/cbinet/fixtures
Creates complete fixtures for your C# unit tests projects.
https://github.com/cbinet/fixtures
autofixture csharp fixture mstest netcore tests
Last synced: over 1 year ago
JSON representation
Creates complete fixtures for your C# unit tests projects.
- Host: GitHub
- URL: https://github.com/cbinet/fixtures
- Owner: CBinet
- Created: 2017-09-04T03:56:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-12T02:12:48.000Z (almost 9 years ago)
- Last Synced: 2024-04-27T05:20:56.586Z (about 2 years ago)
- Topics: autofixture, csharp, fixture, mstest, netcore, tests
- Homepage: https://www.nuget.org/packages/BetaSoftwares.Fixture/
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BetaSoftwares.Fixture
## **Installation**
To install **BetaSoftwares.Fixture**, you can either browse the Package Manager or run the following command in the Package Manager Console :
```
PM> Install-Package BetaSoftwares.Fixture
```
## **Usage**
To start using **BetaSoftwares.Fixture**, you will first need to create an instance of the Fixture class :
```cs
using BetaSoftwares.Fixtures;
Fixture fixture = new Fixture();
```
### **Create**
To generate a new fixture of any type, use the **Fixture.Create** method :
```cs
string random = fixture.Create();
// or..
string random = fixture.Create(typeof(string));
```
### **CreateMany**
To generate many fixtures at the same time, you can use the **Fixture.CreateMany** method :
```cs
ICollection random = fixture.CreateMany();
// or..
ICollection random = fixture.CreateMany(typeof(string));
```
### **AddManyTo**
To add many fixtures an already existing list, you can use the **Fixture.AddManyTo** method :
```cs
List list = new List();
// Add 5 fixture to the list
fixture.AddManyTo(list, 5);
int count = list.Count; // count = 5
```
### **Build**, **With**, **Without** and **Do**
You can also customize a fixture on creation using the **Fixture.Build** with the **FixtureDefinition.With**, **FixtureDefinition.Without** and **FixtureDefinition.Do** methods :
```cs
// With
ICollection random = fixture.Build().With(c => c.MyString, "Hello world").Create();
// Without
ICollection random = fixture.Build().Without(c => c.MyString).Create();
// Do
ICollection random = fixture.Build().Do(c => c.MyList.Clear()).Create();
// You can mix .With, .Without and .Do
ICollection random = fixture.Build().With(c => c.MyString, "Hello world").Do(c => c.MyList.Clear()).Create();
```
### **Register**
To register a type default value, you can use the **Fixture.Register** method :
```cs
// Registers a new default value
fixture.Register(() => new MyClass());
// The instance will be of the registered type
MyClass myClass = fixture.Create();
```
### **Customize**
To customize a complex type default properties, you can use the **Fixture.Customize** method :
```cs
// Customize the class default properties
_fixture.Customize(c => c.With(c => c.MyInteger, 42));
// The instance will have the custom properties
ComplexType myClass = fixture.Create();
int value = myClass.MyInteger; // value = 42
```
## Supported types
Here is the index of currently supported types. If the type is not supported, the property will be set to the default value of the type.
### Basic types :
- [string](https://msdn.microsoft.com/en-us/library/system.string)
- [bool](https://msdn.microsoft.com/en-us/library/system.boolean)
- [object](https://msdn.microsoft.com/en-us/library/system.object)
- [char](https://msdn.microsoft.com/en-us/library/system.char)
- [short](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/short)
- [ushort](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ushort)
- [int](https://msdn.microsoft.com/fr-fr/library/system.int32(v=vs.110).aspx)
- [uint](https://msdn.microsoft.com/en-us/library/system.uint32(v=vs.110).aspx)
- [float](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/float)
- [double](https://msdn.microsoft.com/en-us/library/system.double(v=vs.110).aspx)
- [decimal](https://msdn.microsoft.com/en-us/library/system.decimal(v=vs.110).aspx)
- [long](https://msdn.microsoft.com/en-us/library/system.int64(v=vs.110).aspx)
- [ulong](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ulong)
- [byte](https://msdn.microsoft.com/fr-fr/library/system.byte(v=vs.110).aspx)
- [sbyte](https://msdn.microsoft.com/en-us/library/system.sbyte(v=vs.110).aspx)
### Data structures :
- [ICollection](https://msdn.microsoft.com/en-us/library/92t2ye13(v=vs.110).aspx)
- [IDictionary](https://msdn.microsoft.com/fr-fr/library/s4ys34ea(v=vs.110).aspx)
- [Tuple](https://msdn.microsoft.com/fr-fr/library/system.tuple(v=vs.110).aspx)