Published 18th of September, 2011, by Nikos Baxevanis. Tagged as autofixture.

StringLengthAttribute support in AutoFixture

Continuing the support of DataAnnotations as described here, there is now added support for the StringLengthAttribute class. Starting with version 2.4.0, when this attribute is applied on a data field it can specify the maximum length of characters that are allowed.

Let's take as an example the following type:

public class StringLengthValidatedType
{
    [StringLength(3)]
    public string Property { get; set; }
}

Prior to version 2.4.0 if we request an anonymous instance from AutoFixture, by default we would get back an instance of the above type with it's Property containing a value similar to the one below.

Prior verion 2.4.0

However, after version 2.4.0 AutoFixture can handle requests with string length constraints through the StringLengthAttribute class by issuing a new request for a constrained string.

After verion 2.4.0

An automatically published release created from the latest successful build can be downloaded from here. The latest version is also live on NuGet.



Wish to comment?

You can comment on this post on GitHub. Alternatively, you can discuss this post on Twitter or elsewhere with a permalink. Ping me with the link, and I may respond.