Skip to content
Merged
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
29 changes: 21 additions & 8 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
NTestDataBuilder Breaking Changes
=================================
Breaking Changes
================

Version 2.0.0
-------------
Breaking change from NTestDataBuilder -> TestStack.Dossier 1.0
--------------------------------------------------------------

Namespace has changed from NTestDataBuilder to TestStack.Dossier.

### Reason

The project has been renamed.

### Fix

Do a global find and replace of `using NTestDataBuilder` with `using TestStack.Dossier`.

Breaking change from NTestDataBuilder -> TestStack.Dossier 1.0
--------------------------------------------------------------

When you don't `Set` a default value for a property that you later `Get` in your builder it will now generate an anonymous value for that property rather than throwing an exception.

Expand All @@ -16,8 +29,8 @@ The old behaviour of throwing an exception if a value hasn't been specified is n

If you want to fix a static value for a property then by all means you can still use `Set` calls in your builder constructor. If you aren't happy with the default anonymous value that is generated for a property you can use the `Any` property to generate a value from a different equivalence class in combination with a `Set` call in your builder constructor.

Version 2.0.0
-------------
Breaking change from NTestDataBuilder -> TestStack.Dossier 1.0
--------------------------------------------------------------

The way that lists are generated no longer uses NBuilder - the new syntax is backwards compatible with NBuilder except that the namespace you need to include is different. You can also refactor your list generation to be a lot more terse, but that is optional. Any `BuildList` extension methods you created will now need to be deleted since they are no longer needed. You also need to ensure that all of the methods you call are marked virtual so the list generation can proxy those method calls.

Expand Down Expand Up @@ -47,10 +60,10 @@ You also no longer need a custom extension method for the `BuildList` method so
Simply add the following to the files that generate lists of builders and change your builder modification methods to be virtual and the existing syntax should work:

```
using NTestDataBuilder.Lists;
using TestStack.Dossier.Lists;
```

Assuming you aren't using NBuilder for anything other than generating lists of entities with NTestDataBuilder 1.0 you should be abke to do a global find and replace against `using FizzWare.NBuilder;`.
Assuming you aren't using NBuilder for anything other than generating lists of entities with NTestDataBuilder 1.0 you should be able to do a global find and replace against `using FizzWare.NBuilder;`.

If you uninstall the NBuilder package then you will need to remove the using statements for that library too.

Expand Down
8 changes: 0 additions & 8 deletions NTestDataBuilder.Tests/packages.config

This file was deleted.

42 changes: 0 additions & 42 deletions NTestDataBuilder/NTestDataBuilder.nuspec

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,12 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using NTestDataBuilder.DataSources;
using NTestDataBuilder.DataSources.Geography;
using NTestDataBuilder.DataSources.Person;
using Shouldly;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Geography;
using TestStack.Dossier.DataSources.Person;
using Xunit;
using Xunit.Extensions;

namespace NTestDataBuilder.Tests.DataSources
namespace TestStack.Dossier.Tests.DataSources
{
public class DataSourceConventionTests
{
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
Loading