Skip to content

Commit

Permalink
Added showcase unit test for [Any] Attribute
Browse files Browse the repository at this point in the history
This attribute, just like [Random] is not supported yet by VS Test
Runner, but Mighty Moose and NUnit GUI Runner handle it just fine.
  • Loading branch information
grzesiek-galezowski committed Oct 20, 2013
1 parent 1315ef6 commit c0d3580
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public object GetReturnTypeFor(IInvocation invocation)
if (!_cache.AlreadyContainsValueFor(cacheKey))
{
var returnType = invocation.Method.ReturnType;
var returnValue = AnyReturnValue.Of(returnType).Generate();
var returnValue = Any.Instance(returnType);
_cache.Add(cacheKey, returnValue);
}

Expand Down
43 changes: 43 additions & 0 deletions TddToolkitSpecification/AnyAttributeSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TddEbook.TddToolkit;
using TddEbook.TddToolkit.NUnitExtensions;

namespace TddToolkitSpecification
{
public class AnyAttributeSpecification
{
[Test]
public void ShouldAllowPassingDifferentObjectsAndPrimitivesThroughParameters
(
[Any] int anInt,
[Any] int anInt2,
[Any] string aString,
[Any] AnySpecification.ISimple interfaceImplementation,
[Any] IEnumerable<int> anEnumerable,
[Any] List<string> concreteList,
[Any] IEnumerable<AnySpecification.ISimple> interfaceImplementationList,
[Any] ProperValueType value
)
{
XAssert.NotEqual(default(int), anInt);
XAssert.NotEqual(anInt2, anInt);
Assert.False(string.IsNullOrEmpty(aString));
Assert.NotNull(interfaceImplementation);
Assert.Greater(anEnumerable.Count(), 0);
Assert.Greater(concreteList.Count(), 0);
Assert.Greater(concreteList.Count(), 0);

Assert.Greater(interfaceImplementationList.Count(), 0);
Assert.NotNull(interfaceImplementationList.ToArray()[0]);
Assert.NotNull(interfaceImplementationList.ToArray()[1]);
Assert.NotNull(interfaceImplementationList.ToArray()[2]);

Assert.NotNull(value);
}

}
}
1 change: 1 addition & 0 deletions TddToolkitSpecification/TddToolkitSpecification.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="AnyAttributeSpecification.cs" />
<Compile Include="CircularListSpecification.cs" />
<Compile Include="ConstraintsViolationsSpecification.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit c0d3580

Please sign in to comment.