DavidSSL (5) [Avatar] Offline
#1
Hi,

I've got the latest source code from the Manning site (last updated 2011.04.11 while finalizing the manuscript) and while I'm running the unit tests, I get the following issues

[Fact]
public void AboutWillReturnInstance()
{
// Fixture setup
var fixture = new Fixture().Customize(new CommerceWebCustomization());
var sut = fixture.CreateAnonymous<HomeController>();

The failure happens on the last line and the exception is:

System.Reflection.TargetInvocationException was unhandled by user code
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Ploeh.AutoFixture.Kernel.AutoPropertiesCommand`1.Execute(T specimen, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
at Ploeh.AutoFixture.Kernel.SeedIgnoringRelay.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
at Ploeh.AutoFixture.Kernel.PropertyRequestRelay.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
at Ploeh.AutoFixture.Kernel.AutoPropertiesCommand`1.Execute(T specimen, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
at Ploeh.AutoFixture.Kernel.SeedIgnoringRelay.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.<>c__DisplayClass6.<Create>b__1(ISpecimenBuilder b)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__a5`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
at Ploeh.AutoFixture.SpecimenFactory.CreateAnonymous[T](ISpecimenContext context, T seed)
at Ploeh.AutoFixture.SpecimenFactory.CreateAnonymous[T](ISpecimenContext context)
at Ploeh.AutoFixture.SpecimenFactory.CreateAnonymous[T](ISpecimenBuilderComposer composer)
at Ploeh.Samples.Commerce.WebUnitTest.HomeControllerTest.AboutWillReturnInstance() in SimpleCommerceCommerceWebUnitTestHomeControllerTest.cs:line 39
InnerException: System.NotImplementedException
HResult=-2147467263
Message=The method or operation is not implemented.
Source=System.Web
StackTrace:
at System.Web.HttpContextBase.get_Items()
at System.Web.WebPages.DisplayModeProvider.SetDisplayMode(HttpContextBase context, IDisplayMode displayMode)
at System.Web.Mvc.ControllerContext.set_DisplayMode(IDisplayMode value)
InnerException:

-----------------------

Can you please advise?
mark.seemann (383) [Avatar] Offline
#2
Re: Simple commerce unit tests failing
Please make sure that you have the correct version of ASP.NET MVC installed.

These threads may be of help:

http://www.manning-sandbox.com/thread.jspa?messageID=121946
http://www.manning-sandbox.com/thread.jspa?messageID=131457

HTH
DavidSSL (5) [Avatar] Offline
#3
Re: Simple commerce unit tests failing
Hi,

I've looked at both these threads and the links in them as well. I've ensured that the MVC dll being referenced is version 3. FYI, I'm using .NET 4.0 with Visual Studio 2012.

I still get the same exception. It's related to AutoFixture I believe but I don't know it well enough to move forward.

David
mark.seemann (383) [Avatar] Offline
#4
Re: Simple commerce unit tests failing
How did you manage to get the code opened in VS 2012?

Perhaps you can help out over on this thread http://www.manning-sandbox.com/thread.jspa?threadID=56452

Which version of AutoFixture are you using?
DavidSSL (5) [Avatar] Offline
#5
Re: Simple commerce unit tests failing
Hi Mark,

I've answered how I got the solutions to work in VS 2012 in the other thread and didn't want to crosspost. Anyway, the version of AutoFixture I'm using is the one that came with the package which was 2.0.0.2.

David
DavidSSL (5) [Avatar] Offline
#6
Re: Simple commerce unit tests failing
There is an inner exception "{"The method or operation is not implemented."}"

and the stack trace is:

at System.Web.HttpContextBase.get_Items()
at System.Web.WebPages.DisplayModeProvider.SetDisplayMode(HttpContextBase context, IDisplayMode displayMode)
at System.Web.Mvc.ControllerContext.set_DisplayMode(IDisplayMode value)
mark.seemann (383) [Avatar] Offline
#7
Re: Simple commerce unit tests failing
FWIW, I just tried to open the project in VS2012 and run all the tests. With AutoFixture 2.0, all my tests are passing.

The exception you are seeing comes from MVC, and IIRC there has been some (breaking) changes between the various versions of MVC related to Controllers, so I'm wondering if it isn't, after all, a versioning issue.

When I look at the test project in question on my machine (where it works), the System.Web.Mvc reference points to Csmilierogram Files (x86)Microsoft ASP.NETASP.NET MVC 3AssembliesSystem.Web.Mvc.dll

I'm wondering whether that's also the case on your system?
DavidS (15) [Avatar] Offline
#8
Re: Simple commerce unit tests failing
My sincere apologies Mark. You were indeed spot on with your solution first time around. I believe I had indeed updated the reference to MVC3 in the production code but not in the Test code (or vice versa). Now that I've done it the tests pass. Thanks very much!