Giter VIP home page Giter VIP logo

tdd-toolkit's Introduction

Build status NuGet version License

Tdd Toolkit

Tdd Toolkit now has a successor called "Any", based on .NET Standard 2.0: https://github.com/grzesiek-galezowski/any

Toolkit used in Test-Driven Development ebook tutorial: github.com/grzesiek-galezowski/tdd-ebook.

The idea of "Any" class is taken from guys at www.sustainabletdd.com

Note: this project does not aim to implement a general-purpose tool with extensibility points, rather, it's an example to start working from when creating your own customized wrapper. If you need hardcore extensibility, go straight to https://github.com/AutoFixture and grab the general purpose tool that has possibilities far beyond generating anonymous data.

Implemented generation methods:

Numbers

A distinct integer value:

Any.Integer()

A distinct double value:

Any.Double()

A distinct long integer value:

Any.LongInteger()

A distinct short integer value:

Any.ShortInteger()

A distinct integer value different than any of the passed values:

Any.IntegerOtherThan(params int[] excluded)

A distinct byte value:

Any.Byte()

A distinct byte value different than any of the passed values:

Any.ByteOtherThan(params byte[] others)

Strings & chars

A distinct string:

Any.String()

A string matching a regex (only a small subset of features is supported - you'll have ti try and see if it fits you)

Any.StringMatching(string pattern)

A distinct string of a given length:

Any.StringOfLength(int charactersCount)

A distinct string other that all passed strings (may be a subset or superset though):

Any.StringOtherThan(params string[] alreadyUsedStrings)

A distinct string that does not contain any of given strings:

Any.StringNotContaining(params string[] excludedSubstrings)

A distinct string that contains a given string:

Any.StringContaining(string str)

A distinct alpha-numeric string:

Any.AlphaString()

A distinct alpha-string (latin characters only, no regional characters):

Any.AlphaString(int maxLength)

A distinct string matching Identifier requirements (first character is letter, the rest is alphanumeric):

Any.Identifier()

A single distinct letter character:

Any.AlphaChar()

A single distinct digit character:

Any.DigitChar()

Enums

A distinct value from all in an enum (of course, for single-value enums will always return the same value :-)):

Any.Of<T>() where T : struct, IConvertible

A distinct value from all in enum besides the passed one (if all-but-one values are specified, always returns the same value. If all values are specified, throws exception):

Any.Besides<T>(params T[] excludedValues) where T : struct, IConvertible

Collections

Sorted Set:

Any.SortedSet<T>()

Enumerable of objects of type T:

Any.Enumerable<T>()

Enumerable of objects of type T different than passed excluded ones:

Any.EnumerableWithout<T>(params T[] excluded)

Array of objects of type T:

Any.Array<T>()

Array of objects of type T different than passed excluded ones:

Any.ArrayWithout<T>(params T[] excluded)

List of objects of type T:

Any.List<T> List<T>()

Set of objects of type T:

Any.Set<T>()

Set of objects of type TKey, TValue:

Any.Dictionary<TKey, TValue>()

Enumerable of objects of type T sorted descending:

Any.EnumerableSortedDescending<T>()

Others

A main generic generation method, capable of generating both primitive and reference types:

Any.Instance<T>()

Picks any element from collection:

Any.From<T>(params T[] possibleValues)

DateTime:

Any.DateTime()

TimeSpan:

Any.TimeSpan()

Generic generation method for values only (subset of Any.Instance()):

Any.ValueOf<T>()
Any.Value<T>()

Like above, but makes sure none of the passed values will not get returned:

Any.ValueOtherThan<T>(params T[] omittedValues)

For booleans:

Any.Boolean()

For objects (useful e.g. for synchronization roots):

Any.Object()

For exceptions:

Any.Exception()

For Type and MethodInfo:

Any.Method()
Any.Type()

Legal XML tag name:

Any.LegalXmlTagName()

Exploding type (any overridable method called on created instance throws an exception) - useful for specifying null objects:

Any.Exploding<T>() where T : class

Generic generation method for objects only (subset of Any.Instance()):

Any.InstanceOf<T>()
Any.Instance<T>()

URI object:

Any.Uri()

URL string:

Any.UrlString()

Port number:

Any.Port()

string containing IP address:

Any.Ip()

Get more details at codescene.io.

tdd-toolkit's People

Contributors

grzesiek-galezowski avatar vanklompf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tdd-toolkit's Issues

Exception when formatting string

This fails:

    [Test]
    public void ShouldFail()
    {
      // GIVEN
      var x1 = new List<string> { "aaa" };
      var x2 = new List<string> { "aaa" };

      XAssert.All(recorder => recorder.Equal(x1, x2));
    }

With this exception:

System.FormatException : Input string was not in a correct format.
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(String format, Object[] args)
   at FluentAssertions.Execution.AssertionScope.BecauseOf(String because, Object[] reasonArgs)
   at FluentAssertions.Primitives.ObjectAssertions.Be(Object expected, String because, Object[] reasonArgs)
   at BladTdd.Class1.ShouldFail() in Class1.cs: line 20

Add Times helper

public static class SpecExtensions
{
public static void Times(this int times, Action action)
{
for (int i = 0; i < times; ++i)
{
action.Invoke();
}
}
}

This does not pass

[Test]
public void ShouldHaveXMessageAsY()
{
XAssert.Equal("Session ID cannot be null.", SubscriptionValidationRules.SessionIdCannotBeNullMessage);

 var data = Any.Instance<SubscriptionRequestData>();

  var prevData = Clone.Of(data);

  Do(data);

  XAssert.Alike(prevData, data);
}

private void Do(SubscriptionRequestData data)
{
data.Duration = TimeSpan.FromDays(12334);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.