Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions NTestDataBuilder.Tests/packages.config

This file was deleted.

148 changes: 74 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
NTestDataBuilder
================
# Dossier

NTestDataBuilder provides you with the code infrastructure to easily and quickly generate test fixture data for your automated tests in a terse, readable and maintainable way using the Test Data Builder pattern.
Dossier provides you with the code infrastructure to easily and quickly generate test fixture data for your automated tests in a terse, readable and maintainable way using the Test Data Builder pattern.

For more information please see the [blog post](http://robdmoore.id.au/blog/2013/05/26/test-data-generation-the-right-way-object-mother-test-data-builders-nsubstitute-nbuilder/) that gives the theory behind the approach this library was intended for and the [presentation and example code](https://github.com/robdmoore/TestFixtureDataGenerationPresentation) that gives a concrete example of the usage of the library (and the theory behind it).

NTestDataBuilder is integrated with NSubstitute for proxy/mock/substitute object generation and AutoFixture for anonymous value generation. Version 1 was integrated with NBuilder for list generation, but that is now replaced with internal code that uses Castle Dynamic Proxy (il-merged into the dll) for an even terser syntax.
Dossier is integrated with NSubstitute for proxy/mock/substitute object generation and AutoFixture for anonymous value generation. Version 1 was integrated with NBuilder for list generation, but that is now replaced with internal code that uses Castle Dynamic Proxy (il-merged into the dll) for an even terser syntax.

How do I get started?
---------------------
## How do I get started?

1. `Install-Package NTestDataBuilder`
2. Create a builder class for one of your objects, e.g. if you have a customer:
```c#
// Customer.cs

public class Customer
{
protected Customer() {}
1. `Install-Package TestStack.Dossier`

public Customer(string firstName, string lastName, int yearJoined)
{
if (string.IsNullOrEmpty(firstName))
throw new ArgumentNullException("firstName");
if (string.IsNullOrEmpty(lastName))
throw new ArgumentNullException("lastName");

FirstName = firstName;
LastName = lastName;
YearJoined = yearJoined;
}

public virtual int CustomerForHowManyYears(DateTime since)
{
if (since.Year < YearJoined)
throw new ArgumentException("Date must be on year or after year that customer joined.", "since");
return since.Year - YearJoined;
}
2. Create a builder class for one of your objects, e.g. if you have a customer:

public virtual string FirstName { get; private set; }
public virtual string LastName { get; private set; }
public virtual int YearJoined { get; private set; }
}

// CustomerBuilder.cs

public class CustomerBuilder : TestDataBuilder<Customer, CustomerBuilder>
{
public CustomerBuilder()
{
// Can set up defaults here - any that you don't set will have an anonymous value generated by default.
WhoJoinedIn(2013);
}
// Customer.cs

public class Customer
{
protected Customer() {}

public Customer(string firstName, string lastName, int yearJoined)
{
if (string.IsNullOrEmpty(firstName))
throw new ArgumentNullException("firstName");
if (string.IsNullOrEmpty(lastName))
throw new ArgumentNullException("lastName");

FirstName = firstName;
LastName = lastName;
YearJoined = yearJoined;
}

public virtual int CustomerForHowManyYears(DateTime since)
{
if (since.Year < YearJoined)
throw new ArgumentException("Date must be on year or after year that customer joined.", "since");
return since.Year - YearJoined;
}

public virtual string FirstName { get; private set; }
public virtual string LastName { get; private set; }
public virtual int YearJoined { get; private set; }
}

// CustomerBuilder.cs

public class CustomerBuilder : TestDataBuilder<Customer, CustomerBuilder>
{
public CustomerBuilder()
{
// Can set up defaults here - any that you don't set will have an anonymous value generated by default.
WhoJoinedIn(2013);
}

public CustomerBuilder WithFirstName(string firstName)
{
return Set(x => x.FirstName, firstName);
}

public CustomerBuilder WithLastName(string lastName)
{
return Set(x => x.LastName, lastName);
}

public CustomerBuilder WhoJoinedIn(int yearJoined)
{
return Set(x => x.YearJoined, yearJoined);
}

protected override Customer BuildObject()
{
return new Customer(
Get(x => x.FirstName),
Get(x => x.LastName),
Get(x => x.YearJoined)
);
}
}

public CustomerBuilder WithFirstName(string firstName)
{
return Set(x => x.FirstName, firstName);
}

public CustomerBuilder WithLastName(string lastName)
{
return Set(x => x.LastName, lastName);
}
3. Use the builder in a test, e.g.

public CustomerBuilder WhoJoinedIn(int yearJoined)
{
return Set(x => x.YearJoined, yearJoined);
}
var customer = new CustomerBuilder().WithFirstName("Robert").Build();

protected override Customer BuildObject()
{
return new Customer(
Get(x => x.FirstName),
Get(x => x.LastName),
Get(x => x.YearJoined)
);
}
}
```
3. Use the builder in a test, e.g.
```c#
var customer = new CustomerBuilder().WithFirstName("Robert").Build();
```
4. Consider using the Object Mother pattern in combination with the builders, see [my blog post](http://robdmoore.id.au/blog/2013/05/26/test-data-generation-the-right-way-object-mother-test-data-builders-nsubstitute-nbuilder/) for a description of how I use this library.

How can I create a list of entities using my builders?
Expand Down Expand Up @@ -187,10 +187,10 @@ If you need to alter the proxy before calling `Build` to add complex behaviours

*Remember that when using proxy objects of real classes that you need to mark properties and methods as virtual and have a protected empty constructor.*

Why does NTestDataBuilder have NSubstitute and AutoFixture as dependencies?
Why does Dossier have NSubstitute and AutoFixture as dependencies?
------------------------------------------------------------------------

NTestDataBuilder is an opinionated framework and as such prescribes how to build your fixture data, including how to build lists, anonymous data and mock objects. Because of this we have decided to bundle it with the best of breed libraries for this purpose: AutoFixture and NSubstitute.
Dossier is an opinionated framework and as such prescribes how to build your fixture data, including how to build lists, anonymous data and mock objects. Because of this we have decided to bundle it with the best of breed libraries for this purpose: AutoFixture and NSubstitute.

This allows for this library to provide a rich value-add on top of the basics of tracking properties in a dictionary in the `TestDataBuilder` base class. If you want to use different libraries or want a cut down version that doesn't come with NSubstitute or AutoFixture and the extra functionality they bring then take the `TestDataBuilder.cs` file and cut out the bits you don't want - open source ftw :).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using NSubstitute;
using NTestDataBuilder.Tests.Builders;
using Shouldly;
using TestStack.Dossier.Tests.Builders;
using Xunit;

namespace NTestDataBuilder.Tests
namespace TestStack.Dossier.Tests
{
public class AsProxyTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using NTestDataBuilder.DataSources.Generators;
using NTestDataBuilder.Lists;
using NTestDataBuilder.Tests.Builders;
using NTestDataBuilder.Tests.Entities;
using Shouldly;
using TestStack.Dossier.DataSources.Generators;
using TestStack.Dossier.Lists;
using TestStack.Dossier.Tests.Builders;
using TestStack.Dossier.Tests.Entities;
using Xunit;

namespace NTestDataBuilder.Tests
namespace TestStack.Dossier.Tests
{
public class BuildListTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using NTestDataBuilder.Tests.Builders;
using NTestDataBuilder.Tests.Entities;
using Shouldly;
using Shouldly;
using TestStack.Dossier.Tests.Builders;
using TestStack.Dossier.Tests.Entities;
using Xunit;

namespace NTestDataBuilder.Tests
namespace TestStack.Dossier.Tests
{
public class BuildTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Linq.Expressions;
using NTestDataBuilder.Tests.Entities;
using TestStack.Dossier.Tests.Entities;

namespace NTestDataBuilder.Tests.Builders
namespace TestStack.Dossier.Tests.Builders
{
public class BasicCustomerBuilder : TestDataBuilder<Customer, BasicCustomerBuilder>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NTestDataBuilder.Tests.Entities;
using TestStack.Dossier.Tests.Entities;

namespace NTestDataBuilder.Tests.Builders
namespace TestStack.Dossier.Tests.Builders
{
public class CustomerBuilder : TestDataBuilder<Customer, CustomerBuilder>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using NSubstitute;
using NTestDataBuilder.Tests.Entities;
using TestStack.Dossier.Tests.Entities;

namespace NTestDataBuilder.Tests.Builders
namespace TestStack.Dossier.Tests.Builders
{
class ProxyAlteringCustomerBuilder : TestDataBuilder<Customer, ProxyAlteringCustomerBuilder>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Shouldly;
using Xunit;

namespace NTestDataBuilder.Tests
namespace TestStack.Dossier.Tests
{
public class ChildBuilderTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Linq;
using NTestDataBuilder.DataSources;
using NTestDataBuilder.DataSources.Geography;
using NTestDataBuilder.DataSources.Person;
using Shouldly;
using Xunit.Extensions;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Geography;
using TestStack.Dossier.DataSources.Person;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources
namespace TestStack.Dossier.Tests.DataSources
{
public class DataSourceConventionTests
{
[Theory]
[PropertyData("TestCases")]
[MemberData("TestCases")]
public void DataSourceConventions(DataSource<string> sut, int expectedCount)
{
var collection = sut.Data.ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using NTestDataBuilder.DataSources;
using NTestDataBuilder.DataSources.Generators;
using Shouldly;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Generators;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources
namespace TestStack.Dossier.Tests.DataSources
{
public class DataSourceTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using NTestDataBuilder.DataSources.Dictionaries;
using Shouldly;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources.Dictionaries
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class CacheTests : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.IO;
using NTestDataBuilder.DataSources.Dictionaries;
using Shouldly;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources.Dictionaries
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class FileDictionaryRepositoryIntegrationTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using NSubstitute;
using NTestDataBuilder.DataSources.Dictionaries;
using NTestDataBuilder.DataSources.Generators;
using TestStack.Dossier.DataSources.Dictionaries;
using TestStack.Dossier.DataSources.Generators;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources.Dictionaries
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class FileDictionarySourceTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using Xunit;

namespace NTestDataBuilder.Tests.DataSources.Dictionaries.Resources
namespace TestStack.Dossier.Tests.DataSources.Dictionaries.Resources
{
public class FileDataConventions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using NTestDataBuilder.DataSources.Generators;
using Shouldly;
using TestStack.Dossier.DataSources.Generators;
using Xunit;
using Xunit.Extensions;

namespace NTestDataBuilder.Tests.DataSources.Generators
namespace TestStack.Dossier.Tests.DataSources.Generators
{
public class RandomGeneratorTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using NTestDataBuilder.DataSources.Generators;
using Shouldly;
using TestStack.Dossier.DataSources.Generators;
using Xunit;
using Xunit.Extensions;

namespace NTestDataBuilder.Tests.DataSources.Generators
namespace TestStack.Dossier.Tests.DataSources.Generators
{
public class SequentiaGeneratorTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NTestDataBuilder.Tests.Entities
namespace TestStack.Dossier.Tests.Entities
{
public class Company
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace NTestDataBuilder.Tests.Entities
namespace TestStack.Dossier.Tests.Entities
{
public class Customer
{
Expand Down
Loading