https://github.com/stone-payments/strangerdata
:alien: A .NET database populator for testing purposes
https://github.com/stone-payments/strangerdata
net-database-populator sec-squad-payments-finance sec-tribo-finance test-driven-development testing-tools
Last synced: 9 months ago
JSON representation
:alien: A .NET database populator for testing purposes
- Host: GitHub
- URL: https://github.com/stone-payments/strangerdata
- Owner: stone-payments
- License: mit
- Created: 2016-07-25T18:32:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-18T14:44:32.000Z (over 1 year ago)
- Last Synced: 2024-11-11T20:13:26.462Z (about 1 year ago)
- Topics: net-database-populator, sec-squad-payments-finance, sec-tribo-finance, test-driven-development, testing-tools
- Language: C#
- Homepage:
- Size: 121 KB
- Stars: 26
- Watchers: 36
- Forks: 9
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: Contributing.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# StrangerData - A .NET database populator for testing purposes
## Project Description ##
StrangerData is a tool designed to automatically fills your database with random data to make your unit/integration tests faster.
The generator will auto maps all foreign keys and generates records to related tables.
## Getting Started ##
1. Install StrangerData with NuGet Package Manager:
> Install-Package StrangerData
2. Install your database dialect, example:
> Install-Package StrangerData.SqlServer
3. Configure the required connection strings.
To start generating your test data, create a new DataFactory object:
```csharp
using StrangerData;
using StrangerData.SqlServer;
...
var dataFactory = new DataFactory("MyConnectionString");
```
## Usage ##
Consider the example schema:
#### Person Table
| Column | Data Type | PK | FK |
| --- | --- | --- | --- |
| Id | INT | True | False |
| Name | VARCHAR(20) | False | False |
| Email | VARCHAR(50) | False | False |
| Age | INT | False | False |
| TeamId | INT | False | Team(Id) |
#### Team Table
| Column | Data Type | PK | FK |
| --- | --- | --- | --- |
| Id | INT | True | False |
| Name | VARCHAR(20) | False | False |
### 1. Creates a single record:
```csharp
...
IDicionary record = dataFactory.CreateOne("dbo.Person");
```
The method will creates an record in the group table, and associates it to the created user. The dictionary will contains:
```json
{
"Id": "Generated User's Id",
"Name": "Random string",
"Email": "Random string",
"Age": "Random integer number",
"TeamId": "Id from generated group record"
}
```
So you can specify your custom values. Do following:
```csharp
User user = dataFactory.CreateOne("dbo.Person", t => {
t.WithValue("Name", "Will Byers");
});
```
The dictionary will contains:
```json
{
"Id": "Generated User's Id",
"Name": "Will Byers",
"Email": "Random string",
"Age": "Random integer number",
"TeamId": "Id from generated group record"
}
```
### 2. Delete generated records:
To delete all generated records, just run:
```csharp
...
dataFactory.TearDown();
...
```
We suggest to use the TearDown() method inside yor Finally scope. This way it will run even if you code crashes on running, avoiding to have dirty data on your database.