chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi, I was playing with IUnityContainer from http://www.codeplex.com/unity and found this bug.

   public interface IFailContainer //this one is IUnityContainer actully, but I removed all unused members
    {
        T Resolve<T>();
        
        object Resolve(Type t, string name); //delete this and all tests are green
    }

    public interface IWorkingContainer
    {
        T Resolve<T>();
    }

    public interface IChild
    {
        void DoSomething();
    }

  

    [TestFixture]
    public class TypeMockInterfaceBugVerify
    {
        [Test]
        public void MockMyTemplatedInterface()
        {

            var container = Isolate.Fake.Instance<IWorkingContainer>();
            Isolate.WhenCalled(
                () => container.Resolve<IChild>().DoSomething()
                ).IgnoreCall();
        }

        [Test]
        public void MockFailContainer_ManualRecurseFakeAsWorkaround()
        {
            var mockedUnityContainer = Isolate.Fake.Instance<IFailContainer>();

            Isolate.WhenCalled(() => mockedUnityContainer.
                    Resolve<IChild>()).ReturnRecursiveFake();
            Isolate.WhenCalled(
                () => mockedUnityContainer.
                    Resolve<IChild>().DoSomething()).
                IgnoreCall();
        }
        
        [Test]
        public void MockUnityContainer_Fails()
        {
            var mockedUnityContainer =
                Isolate.Fake.
                Instance<IFailContainer>();

            Isolate.WhenCalled(
                () => mockedUnityContainer.
                    Resolve<IChild>().DoSomething()).
                IgnoreCall();
        }

        [Test]
        public void MockUnityContainer_FailsAgain()
        {
            var mockedUnityContainer =
                Isolate.Fake.
                Instance<IFailContainer>(Members.ReturnRecursiveFakes);

            Isolate.WhenCalled(
                () => mockedUnityContainer.
                    Resolve<IChild>().DoSomething()).
                IgnoreCall();
        }

        [TearDown]
        public void TearDown()
        {
            Isolate.CleanUp();
        }
    }


Exception message for both failing tests:
System.NullReferenceException: Object reference not set to an instance of an object.
at ObjectTreeBrowserTests.ObjectTreeBrowser.TypeMockInterfaceBugVerify.<>c__DisplayClassb.<MockUnityContainer_FailsAgain>b__a() in TypeMockInterfaceBugVerify.cs: line 80
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at c9.e()
at c9.d()
at ObjectTreeBrowserTests.ObjectTreeBrowser.TypeMockInterfaceBugVerify.MockUnityContainer_FailsAgain() in TypeMockInterfaceBugVerify.cs: line 79
asked by Gmoorick (2.3k points)

1 Answer

0 votes
Hi

I checked it out and you right. We have a bug :twisted:
Thanks for reporting, we will update you as soon as we'll have a fix.
answered by ohad (35.5k points)
...